-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from iamgergo/master
- Loading branch information
Showing
6 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="Feature"> | ||
<directory suffix="Test.php">./tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<server name="APP_KEY" value="base64:ybq4vTLI2AtF1xqSRZ8A52CtU9dUXu1yAcClXsNKGq4="/> | ||
<server name="APP_ENV" value="testing"/> | ||
<server name="BCRYPT_ROUNDS" value="4"/> | ||
<server name="CACHE_DRIVER" value="array"/> | ||
<server name="DB_CONNECTION" value="sqlite"/> | ||
<server name="DB_DATABASE" value=":memory:"/> | ||
<server name="MAIL_DRIVER" value="array"/> | ||
<server name="QUEUE_CONNECTION" value="sync"/> | ||
<server name="SESSION_DRIVER" value="array"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Larawelders\QueueEventLogger; | ||
|
||
use Illuminate\Queue\Events\JobExceptionOccurred; | ||
use Illuminate\Queue\Events\JobFailed; | ||
use Illuminate\Queue\Events\JobProcessed; | ||
use Illuminate\Queue\Events\JobProcessing; | ||
use Illuminate\Queue\Events\Looping; | ||
use Illuminate\Queue\Events\WorkerStopping; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class QueueEventLoggerServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Boot any application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot(): void | ||
{ | ||
Event::listen(JobExceptionOccurred::class, static function (JobExceptionOccurred $event): void { | ||
Log::channel('queue')->error( | ||
sprintf( | ||
'[%s] Uncaught exception %s in job %s: %s%s', | ||
$event->job->getJobId(), | ||
get_class($event->exception), | ||
$event->job->resolveName(), | ||
$event->exception->getMessage(), | ||
property_exists($event->job, 'contextString') ? ', '.$event->job->contextString : '' | ||
) | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Larawelders\QueueEventLogger\Tests; | ||
|
||
use Illuminate\Contracts\Console\Kernel; | ||
use Illuminate\Foundation\Application; | ||
use Larawelders\QueueEventLogger\QueueEventLoggerServiceProvider; | ||
|
||
trait CreatesApplication | ||
{ | ||
/** | ||
* Creates the application. | ||
* | ||
* @return \Illuminate\Foundation\Application | ||
*/ | ||
public function createApplication(): Application | ||
{ | ||
$app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php'; | ||
|
||
$app->booting(static function () use ($app): void { | ||
$app->register(QueueEventLoggerServiceProvider::class); | ||
}); | ||
|
||
$app->make(Kernel::class)->bootstrap(); | ||
|
||
return $app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Larawelders\QueueEventLogger\Tests\Feature; | ||
|
||
use Exception; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Queue\Events\JobExceptionOccurred; | ||
use Illuminate\Support\Facades\Log; | ||
use Larawelders\QueueEventLogger\Tests\TestCase; | ||
|
||
class QueueEventLoggerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_logs_job_exception_occurred_event() | ||
{ | ||
$job = new TestJob; | ||
$exception = new Exception('TestJob failed'); | ||
|
||
$this->app['events']->dispatch( | ||
new JobExceptionOccurred('default', $job, $exception) | ||
); | ||
|
||
Log::shouldReceive('queue')->with( | ||
'[test-job] Uncaught exception Exception in job Larawelders\\QueueEventLogger\\Tests\\Feature\\TestJob: TestJob failed', | ||
); | ||
} | ||
} | ||
|
||
class TestJob implements ShouldQueue | ||
{ | ||
public function resolveName() | ||
{ | ||
return static::class; | ||
} | ||
|
||
public function getJobId() | ||
{ | ||
return 'test-job'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Larawelders\QueueEventLogger\Tests; | ||
|
||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
use CreatesApplication; | ||
} |