-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Update tests and refactor code
- Removed unnecessary code related to GuzzleHttp in NotifyChannelTest.php - Added a new test file DefaultNotifyClientExtenderTest.php - Refactored ExceptionNotifyManagerTest.php - Removed ExceptionNotify usage in FeatureTest.php - Updated configuration settings in TestCase.php
- Loading branch information
Showing
8 changed files
with
83 additions
and
26 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
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,24 @@ | ||
<?php | ||
|
||
/** @noinspection AnonymousFunctionStaticInspection */ | ||
/** @noinspection StaticClosureCanBeUsedInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2024 guanguans<[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/guanguans/laravel-exception-notify | ||
*/ | ||
|
||
namespace Guanguans\LaravelExceptionNotify\Tests; | ||
|
||
use Guanguans\LaravelExceptionNotify\DefaultNotifyClientExtender; | ||
use Guanguans\Notify\Foundation\Client; | ||
|
||
it('can extend notify client', function (): void { | ||
expect(app(DefaultNotifyClientExtender::class)(new Client))->toBeInstanceOf(Client::class); | ||
})->group(__DIR__, __FILE__); |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2024 guanguans<[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/guanguans/laravel-exception-notify | ||
*/ | ||
|
||
namespace Guanguans\LaravelExceptionNotify\Tests; | ||
|
||
use Faker\Factory; | ||
use Faker\Generator; | ||
|
||
trait Faker | ||
{ | ||
final protected function faker(string $locale = 'en_US'): Generator | ||
{ | ||
/** | ||
* @var array<string, Generator> $fakers | ||
*/ | ||
static $fakers = []; | ||
|
||
if (!\array_key_exists($locale, $fakers)) { | ||
$faker = Factory::create($locale); | ||
|
||
$faker->seed(9001); | ||
|
||
$fakers[$locale] = $faker; | ||
} | ||
|
||
return $fakers[$locale]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -38,13 +38,16 @@ | |
use Guanguans\LaravelExceptionNotify\Pipes\ReplaceStrPipe; | ||
use Guanguans\LaravelExceptionNotify\Pipes\SprintfHtmlPipe; | ||
use Guanguans\LaravelExceptionNotify\Pipes\SprintfMarkdownPipe; | ||
use Guanguans\Notify\Foundation\Client; | ||
use GuzzleHttp\Psr7\HttpFactory; | ||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait; | ||
|
||
class TestCase extends \Orchestra\Testbench\TestCase | ||
{ | ||
use MockeryPHPUnitIntegration; | ||
use VarDumperTestTrait; | ||
use Faker; | ||
|
||
protected function setUp(): void | ||
{ | ||
|
@@ -68,9 +71,10 @@ protected function getPackageProviders($app): array | |
protected function defineEnvironment($app): void | ||
{ | ||
config()->set('exception-notify.job.queue', 'exception-notify'); | ||
// config()->set('exception-notify.channels.mail.dsn', 'smtp://[email protected]:[email protected]:465?verify_peer=0'); | ||
// config()->set('exception-notify.channels.mail.from', '[email protected]'); | ||
// config()->set('exception-notify.channels.mail.to', '[email protected]'); | ||
config()->set('exception-notify.channels.bark.authenticator.token', $this->faker()->uuid()); | ||
config()->set('exception-notify.channels.bark.client.extender', static fn (Client $client): Client => $client->mock([ | ||
(new HttpFactory)->createResponse(200, '{"code":200,"message":"success","timestamp":1708331409}'), | ||
])); | ||
config()->set('exception-notify.collectors', [ | ||
ApplicationCollector::class, | ||
ChoreCollector::class, | ||
|
@@ -80,12 +84,12 @@ protected function defineEnvironment($app): void | |
PhpInfoCollector::class, | ||
RequestBasicCollector::class, | ||
RequestCookieCollector::class, | ||
RequestRawFileCollector::class, | ||
RequestFileCollector::class, | ||
RequestHeaderCollector::class, | ||
RequestMiddlewareCollector::class, | ||
RequestPostCollector::class, | ||
RequestQueryCollector::class, | ||
RequestRawFileCollector::class, | ||
RequestServerCollector::class, | ||
RequestSessionCollector::class, | ||
]); | ||
|
@@ -102,7 +106,7 @@ protected function defineEnvironment($app): void | |
protected function defineRoutes($router): void | ||
{ | ||
$router->any('report-exception', static fn () => tap(response('report-exception'), static function (): void { | ||
ExceptionNotify::report(new RuntimeException('What happened?'), ['lark', 'dump']); | ||
ExceptionNotify::report(new RuntimeException('What happened?'), ['dump', 'log', 'bark', 'lark']); | ||
})); | ||
|
||
$router->any('exception', static fn () => tap(response('exception'), static function (): void { | ||
|