Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fr3on committed Apr 2, 2023
1 parent 5ea0a73 commit 63b8d33
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 88 deletions.
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Sleuren\\Tests\\TestCommandTest::it_detects_if_the_project_key_is_set":7,"Sleuren\\Tests\\TestCommandTest::it_detects_that_its_running_in_the_correct_environment":7,"Sleuren\\Tests\\TestCommandTest::it_detects_that_it_fails_to_send_to_sleuren":7},"times":{"Sleuren\\Tests\\Fakes\\SleurenFakeTest::it_will_sent_exception_to_sleuren_if_exception_is_thrown":0.022,"Sleuren\\Tests\\Fakes\\SleurenFakeTest::it_will_sent_nothing_to_sleuren_if_no_exceptions_thrown":0,"Sleuren\\Tests\\LoggingTest::it_will_not_send_log_information_to_sleuren":0.002,"Sleuren\\Tests\\LoggingTest::it_will_only_send_throwables_to_sleuren":0.001,"Sleuren\\Tests\\SleurenTest::is_will_not_crash_if_sleuren_returns_error_bad_response_exception":0.028,"Sleuren\\Tests\\SleurenTest::is_will_not_crash_if_sleuren_returns_normal_exception":0.019,"Sleuren\\Tests\\SleurenTest::it_can_skip_exceptions_based_on_class":0,"Sleuren\\Tests\\SleurenTest::it_can_skip_exceptions_based_on_environment":0,"Sleuren\\Tests\\SleurenTest::it_will_return_false_for_sleeping_cache_exception_if_disabled":0,"Sleuren\\Tests\\SleurenTest::it_can_check_if_is_a_sleeping_cache_exception":0,"Sleuren\\Tests\\SleurenTest::it_can_get_formatted_exception_data":0.018,"Sleuren\\Tests\\SleurenTest::it_filters_the_data_based_on_the_configuration":0,"Sleuren\\Tests\\SleurenTest::it_can_report_an_exception_to_sleuren":0.021,"Sleuren\\Tests\\TestCommandTest::it_detects_if_the_project_key_is_set":0.024,"Sleuren\\Tests\\TestCommandTest::it_detects_that_its_running_in_the_correct_environment":0.001,"Sleuren\\Tests\\TestCommandTest::it_detects_that_it_fails_to_send_to_sleuren":0.004,"Sleuren\\Tests\\UserTest::it_return_custom_user":0.001,"Sleuren\\Tests\\UserTest::it_return_custom_user_with_to_sleuren":0,"Sleuren\\Tests\\UserTest::it_returns_nothing_for_ghost":0}}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "sleuren/laravel",
"type": "library",
"description": "Laravel 5.x/6.x/7.x/8.x/9.x bug tracker.",
"homepage": "http://sleuren.com",
"description": "Official Sleuren SDK for Laravel",
"homepage": "https://sleuren.com",
"keywords": [
"laravel",
"log",
Expand All @@ -18,7 +18,7 @@
"require": {
"php": "^7.4 || ^8.0",
"guzzlehttp/guzzle": "^6.0.2 || ^7.0",
"illuminate/support": "^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"nesbot/carbon": "^2.62.1",
"jean85/pretty-package-versions": "^1.5|^2.0.4"
},
Expand Down
2 changes: 1 addition & 1 deletion config/sleuren.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/

'except' => [
'Symfony\Component\HttpKernel\Exception\NotFoundHttpException',

],

/*
Expand Down
66 changes: 16 additions & 50 deletions src/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sleuren\Commands;

use Exception;
use Sleuren\Sleuren;
use Illuminate\Console\Command;

class TestCommand extends Command
Expand All @@ -14,19 +15,23 @@ class TestCommand extends Command
public function handle()
{
try {
// Test proc_open function availability
try {
proc_open("", [], $pipes);
} catch (\Throwable $exception) {
$this->warn("❌ proc_open function disabled.");
return;
/** @var Sleuren $sleuren */
$sleuren = app('sleuren');

if (config('sleuren.project_key')) {
$this->info('✅ [sleuren] Found project key');
} else {
$this->error('❌ [sleuren] Could not find your project key, set this in your .env');
$this->info('More information on setting your project key: https://www.sleuren.com/docs/how-to-use/installation');
}

$this->checkKey();
$this->checkLogger();
if (in_array(config('app.env'), config('sleuren.environments'))) {
$this->info('✅ [sleuren] Correct environment found (' . config('app.env') . ')');
} else {
$this->error('❌ [sleuren] Environment (' . config('app.env') . ') not allowed to send errors to sleuren, set this in your config');
$this->info('More information about environment configuration: https://www.sleuren.com/docs/how-to-use/installation');
}

/** @var Sleuren $sleuren */
$sleuren = app('sleuren');
$response = $sleuren->handle(
$this->generateException()
);
Expand All @@ -42,51 +47,12 @@ public function handle()
$this->error("❌ [Sleuren] {$ex->getMessage()}");
}
}

protected function checkKey(): self
{
$message = empty($this->config->get('sleuren.project_key'))
? '❌ Sleuren key not specified. Make sure you specify a value in the `key` key of the `sleuren` config file.'
: '✅ Sleuren key specified';

$this->info($message);

return $this;
}

public function checkLogger(): self
{
$defaultLogChannel = $this->config->get('logging.default');

$activeStack = $this->config->get("logging.channels.{$defaultLogChannel}");

if (is_null($activeStack)) {
$this->info("❌ The default logging channel `{$defaultLogChannel}` is not configured in the `logging` config file");
}

if (! isset($activeStack['channels']) || ! in_array('sleuren', $activeStack['channels'])) {
$this->info("❌ The logging channel `{$defaultLogChannel}` does not contain the 'sleuren' channel");
}

if (is_null($this->config->get('logging.channels.sleuren'))) {
$this->info('❌ There is no logging channel named `sleuren` in the `logging` config file');
}

if ($this->config->get('logging.channels.sleuren.driver') !== 'sleuren') {
$this->info('❌ The `sleuren` logging channel defined in the `logging` config file is not set to `sleuren`.');
}

$this->info('✅ The Sleuren logging driver was configured correctly.');

return $this;
}

public function generateException(): ?Exception
{
try {
throw new Exception($this->argument('exception') ?? 'This is an exception to test if the integration with Sleuren works.');
} catch (Exception $ex) {
return $ex->getMessage();
return $ex;
}
}
}
19 changes: 10 additions & 9 deletions src/Sleuren.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Sleuren;

use Composer\InstalledVersions;
use Jean85\PrettyVersions;
use Symfony\Component\Process\Process;
use Throwable;
use Sleuren\Http\Client;
use Jean85\PrettyVersions;
use Illuminate\Support\Str;
use Composer\InstalledVersions;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\Process\Process;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Session;

Expand Down Expand Up @@ -368,16 +368,17 @@ public function addExceptionToSleep(array $data)
return Cache::put($exceptionString, $exceptionString, config('sleuren.sleep'));
}

private function getGitInfo(){
try{
private function getGitInfo()
{
try {
$git = [
'hash' => $this->hash(),
'message' => $this->message(),
'tag' => $this->tag(),
'remote' => $this->remote(),
];
return $git;
}catch (\Exception $e){
} catch (\Exception $e) {
return 'unknown';
}
}
Expand Down Expand Up @@ -410,7 +411,7 @@ private function command($command)
return trim($process->getOutput());
}

private function getComposerPackages(): array
private function getComposerPackages(): array
{
if (empty($this->packages)) {
foreach ($this->getInstalledPackages() as $package) {
Expand All @@ -428,7 +429,7 @@ private function getComposerPackages(): array
/**
* @return string[]
*/
private function getInstalledPackages(): array
private function getInstalledPackages(): array
{
if (class_exists(InstalledVersions::class)) {
return InstalledVersions::getInstalledPackages();
Expand All @@ -443,7 +444,7 @@ private function getInstalledPackages(): array
return [];
}

private function getNpmPackages(): array
private function getNpmPackages(): array
{
$npmPackages = [];
if (file_exists(base_path('package.json'))) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fakes/SleurenFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Sleuren\Tests\TestCase;
use Sleuren\Facade as SleurenFacade;

class SleurenTest extends TestCase
class SleurenFakeTest extends TestCase
{
public function setUp(): void
{
Expand Down
24 changes: 0 additions & 24 deletions tests/TestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Sleuren\Tests;

use Sleuren\Sleuren;
use Sleuren\Tests\Mocks\SleurenClient;

class TestCommandTest extends TestCase
{
/** @test */
Expand Down Expand Up @@ -39,25 +36,4 @@ public function it_detects_that_its_running_in_the_correct_environment()
->expectsOutput('✅ [sleuren] Correct environment found (' . config('app.env') . ')')
->assertExitCode(0);
}

/** @test */
public function it_detects_that_it_fails_to_send_to_sleuren()
{
$this->artisan('sleuren:test')
->expectsOutput('❌ [sleuren] Failed to send exception to sleuren')
->assertExitCode(0);

$this->app['config']['sleuren.environments'] = [
'testing',
];
$this->app['sleuren'] = new Sleuren($this->client = new SleurenClient(
'project_key'
));

$this->artisan('sleuren:test')
->expectsOutput('✅ [sleuren] Sent exception to sleuren with ID: '.SleurenClient::RESPONSE_ID)
->assertExitCode(0);

$this->assertEquals(SleurenClient::RESPONSE_ID, $this->app['sleuren']->getLastExceptionId());
}
}

0 comments on commit 63b8d33

Please sign in to comment.