From a2a5c14c143a8d88c323aae6e5de2c0708acac8a Mon Sep 17 00:00:00 2001 From: Maurizio Date: Mon, 11 Apr 2022 09:15:14 +0200 Subject: [PATCH] chore: update dependencies (#2) * chore: update deps * chore: improve Pest configuration * chore: edit CHANGELOG.md --- CHANGELOG.md | 8 +++++- composer.json | 11 ++++++-- src/Commands/stubs/phpunit.xml.stub | 15 ++++++----- src/Commands/stubs/tests/Helpers.php.stub | 33 +++++++++++++++++++++++ src/Commands/stubs/tests/Pest.php.stub | 6 +++++ 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e69155..4d3a754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,13 @@ All notable changes to `toolbox` will be documented in this file. -## 3.0.0 - 2023-02-03 +## 3.1.0 - 2022-04-11 + +- use `infection/infection` -> `dev-master` branch +- add `support` and `suggest` sections to composer.json +- improve `Pest` configuration + +## 3.0.0 - 2022-02-03 - added laravel 9 support - added new packages: diff --git a/composer.json b/composer.json index 6f9af06..c0aba14 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "friendsofphp/php-cs-fixer": "^v3.0", "graham-campbell/analyzer": "^3.0", "illuminate/contracts": "^8.0|^9.0", - "infection/infection": "^0.26.4", + "infection/infection": "dev-master", "johnkary/phpunit-speedtrap": "^v4.0", "laravel/dusk": "^6.0", "nunomaduro/larastan": "^1.0|^2.0", @@ -74,5 +74,12 @@ } }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "support": { + "issues": "https://github.com/leMaur/toolbox/issues" + }, + "suggest": { + "thecodingmachine/safe": "A set of core PHP functions rewritten to throw exceptions instead of returning false when an error is encountered.", + "thecodingmachine/phpstan-safe-rule": "PHPStan rule to help you detect unsafe function call and will propose you to use the thecodingmachine/safe variant instead." + } } diff --git a/src/Commands/stubs/phpunit.xml.stub b/src/Commands/stubs/phpunit.xml.stub index 6f0af98..c417763 100644 --- a/src/Commands/stubs/phpunit.xml.stub +++ b/src/Commands/stubs/phpunit.xml.stub @@ -12,9 +12,6 @@ ./tests/Feature - - ./tests/Browser - @@ -23,10 +20,14 @@ - - - - + + + + + + + + diff --git a/src/Commands/stubs/tests/Helpers.php.stub b/src/Commands/stubs/tests/Helpers.php.stub index e91f4bc..b97b1b5 100644 --- a/src/Commands/stubs/tests/Helpers.php.stub +++ b/src/Commands/stubs/tests/Helpers.php.stub @@ -2,6 +2,7 @@ declare(strict_types=1); +use App\Models\User; use Illuminate\Contracts\Auth\Authenticatable; use Tests\TestCase; @@ -16,6 +17,15 @@ use Tests\TestCase; | */ +function actingAs(?Authenticatable $user = null): TestCase +{ + if ($user === null) { + $user = User::factory()->withUuid()->create(); + } + + return test()->actingAs($user); +} + function actingAs(Authenticatable $user): TestCase { return test()->actingAs($user); @@ -25,3 +35,26 @@ function logout(): void { auth()->logout(); } + +/** + * @throws JsonException + * @throws InvalidArgumentException + */ +function fixture(string $name): array +{ + $file = file_get_contents( + filename: base_path("tests/Fixtures/$name.json"), + ); + + if (! $file) { + throw new InvalidArgumentException( + message: "Cannot find fixture: [$name] at tests/Fixtures/$name.json", + ); + } + + return json_decode( + json: $file, + associative: true, + flags: JSON_THROW_ON_ERROR + ); +} diff --git a/src/Commands/stubs/tests/Pest.php.stub b/src/Commands/stubs/tests/Pest.php.stub index b158869..c8dbdfa 100644 --- a/src/Commands/stubs/tests/Pest.php.stub +++ b/src/Commands/stubs/tests/Pest.php.stub @@ -14,6 +14,7 @@ declare(strict_types=1); */ use Illuminate\Foundation\Testing\RefreshDatabase; +use Ramsey\Uuid\Uuid; use Tests\DuskTestCase; use Tests\TestCase; @@ -35,3 +36,8 @@ uses(DuskTestCase::class, RefreshDatabase::class)->group('e2e')->in('Browser'); expect()->extend('toBeOne', function () { return $this->toBe(1); }); + +expect()->extend('toBeUuid4', function () { + expect($this->value)->toMatch('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'); + expect(Uuid::isValid($this->value))->toBeTrue(); +});