From 029ab4f9c1cbfa1af80c7d464b78d9b399111cdf Mon Sep 17 00:00:00 2001 From: yaozm Date: Wed, 8 May 2024 12:09:15 +0800 Subject: [PATCH] test(Commands): update TestCommandTest.php and PipeTest.php - Updated TestCommandTest.php to use assertSuccessful instead of assertExitCode - Updated PipeTest.php to reformat code for better readability --- tests/Commands/TestCommandTest.php | 3 +-- tests/Datasets/InvalidJsons.php | 2 +- tests/Pipes/PipeTest.php | 5 +++-- tests/Support/HeplersTest.php | 23 +++++++++++++++++++++++ tests/Support/JsonFixerTest.php | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/tests/Commands/TestCommandTest.php b/tests/Commands/TestCommandTest.php index 0327231..6f1f339 100644 --- a/tests/Commands/TestCommandTest.php +++ b/tests/Commands/TestCommandTest.php @@ -15,12 +15,11 @@ */ use Guanguans\LaravelExceptionNotify\Commands\TestCommand; -use Symfony\Component\Console\Command\Command; use function Pest\Laravel\artisan; it('can test for exception-notify', function (): void { config()->set('exception-notify.enabled', false); - artisan(TestCommand::class)->assertExitCode(Command::SUCCESS); + artisan(TestCommand::class)->assertSuccessful(); })->group(__DIR__, __FILE__); it('will throws RuntimeException', function (): void { diff --git a/tests/Datasets/InvalidJsons.php b/tests/Datasets/InvalidJsons.php index 38f056b..4a42075 100644 --- a/tests/Datasets/InvalidJsons.php +++ b/tests/Datasets/InvalidJsons.php @@ -11,7 +11,7 @@ * @see https://github.com/guanguans/laravel-exception-notify */ -dataset('InvalidJsons', [ +dataset('invalid jsons', [ [ 'json' => '', 'expect' => '', diff --git a/tests/Pipes/PipeTest.php b/tests/Pipes/PipeTest.php index 6b2120b..382436b 100644 --- a/tests/Pipes/PipeTest.php +++ b/tests/Pipes/PipeTest.php @@ -42,8 +42,9 @@ /** * @throws JsonException */ - static fn (Collection $collectors): Stringable => str(json_pretty_encode($collectors->jsonSerialize())) - ->substr(-256) + static fn ( + Collection $collectors + ): Stringable => str(json_pretty_encode($collectors->jsonSerialize()))->substr(-256) ); expect($report)->toBeInstanceOf(Stringable::class); diff --git a/tests/Support/HeplersTest.php b/tests/Support/HeplersTest.php index 83e12a4..1919d07 100644 --- a/tests/Support/HeplersTest.php +++ b/tests/Support/HeplersTest.php @@ -1,5 +1,6 @@ toBeInstanceOf(ReportUsingCreator::class); +})->group(__DIR__, __FILE__); + it('can explode env', function (): void { expect(env_explode('ENV_EXPLODE_STRING'))->toBeArray()->toBeTruthy() ->and(env_explode('ENV_EXPLODE_EMPTY'))->toBe(['']) @@ -24,12 +31,28 @@ // ->and(env_explode('ENV_EXPLODE_NULL'))->toBeNull() })->group(__DIR__, __FILE__); +it('can human bytes', function (): void { + expect([ + human_bytes(0), + human_bytes(10), + human_bytes(10000), + human_bytes(10000000), + ])->sequence( + static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('0B'), + static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('10B'), + static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('9.77kB'), + static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('9.54MB') + ); +})->group(__DIR__, __FILE__); + it('can human milliseconds', function (): void { expect([ + human_milliseconds(0), human_milliseconds(0.5), human_milliseconds(500), human_milliseconds(500000), ])->sequence( + static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('0μs'), static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('500μs'), static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('500ms'), static fn (Pest\Expectation $expectation): Pest\Expectation => $expectation->toBe('500s') diff --git a/tests/Support/JsonFixerTest.php b/tests/Support/JsonFixerTest.php index bfe2f34..20d3d00 100644 --- a/tests/Support/JsonFixerTest.php +++ b/tests/Support/JsonFixerTest.php @@ -19,7 +19,7 @@ it('can fix invalid json', function (string $json, string $expect): void { expect(new JsonFixer)->fix($json)->toBe($expect); -})->group(__DIR__, __FILE__)->with('InvalidJsons'); +})->group(__DIR__, __FILE__)->with('invalid jsons'); it('can fix invalid json with missing value', function (): void { expect(new JsonFixer)->missingValue('')