Skip to content

Commit

Permalink
test(Commands): update TestCommandTest.php and PipeTest.php
Browse files Browse the repository at this point in the history
- Updated TestCommandTest.php to use assertSuccessful instead of assertExitCode
- Updated PipeTest.php to reformat code for better readability
  • Loading branch information
guanguans committed May 8, 2024
1 parent 0546979 commit 029ab4f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
3 changes: 1 addition & 2 deletions tests/Commands/TestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/Datasets/InvalidJsons.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/guanguans/laravel-exception-notify
*/

dataset('InvalidJsons', [
dataset('invalid jsons', [
[
'json' => '',
'expect' => '',
Expand Down
5 changes: 3 additions & 2 deletions tests/Pipes/PipeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions tests/Support/HeplersTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

/** @noinspection PhpInternalEntityUsedInspection */
/** @noinspection AnonymousFunctionStaticInspection */
/** @noinspection StaticClosureCanBeUsedInspection */
/** @noinspection NullPointerExceptionInspection */
Expand All @@ -15,6 +16,12 @@
* @see https://github.com/guanguans/laravel-exception-notify
*/

use Guanguans\LaravelExceptionNotify\ReportUsingCreator;

it('can make object', function (): void {
expect(make(ReportUsingCreator::class))->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([''])
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/JsonFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down

0 comments on commit 029ab4f

Please sign in to comment.