diff --git a/composer.json b/composer.json index 932edad2b3c..4819fff17ab 100644 --- a/composer.json +++ b/composer.json @@ -28,12 +28,13 @@ "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^7.0", "pestphp/pest": "^2.6", - "pestphp/pest-plugin-laravel": "^2.0", + "pestphp/pest-plugin-laravel": "^2.2", "phpunit/phpunit": "^10.2", "ramsey/conventional-commits": "^1.5", "spatie/laravel-ignition": "^2.0", "webgriffe/captainhook": "^2.1", - "worksome/coding-style": "^2.5" + "worksome/coding-style": "^2.5", + "worksome/request-factories": "^3.2" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index eeb7cc941c8..25c07003f44 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "44f11c8f581a998d8425ccad1f2f8c89", + "content-hash": "0a06d61d405a90aac2e31f17f55170c4", "packages": [ { "name": "brick/math", @@ -12924,6 +12924,79 @@ "source": "https://github.com/worksome/coding-style/tree/v2.6.1" }, "time": "2023-10-10T08:46:36+00:00" + }, + { + "name": "worksome/request-factories", + "version": "v3.2.0", + "source": { + "type": "git", + "url": "https://github.com/worksome/request-factories.git", + "reference": "ab609788dbc66cbfdf334fe1bbbb72ac849599c2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/worksome/request-factories/zipball/ab609788dbc66cbfdf334fe1bbbb72ac849599c2", + "reference": "ab609788dbc66cbfdf334fe1bbbb72ac849599c2", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^10.0", + "php": "^8.2" + }, + "require-dev": { + "nunomaduro/collision": "^7.0", + "nunomaduro/larastan": "^2.0", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.0", + "pestphp/pest-plugin-laravel": "^2.0", + "worksome/coding-style": "^2.0.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Worksome\\RequestFactories\\RequestFactoriesServiceProvider" + ] + } + }, + "autoload": { + "files": [ + "src/PestAutoload.php" + ], + "psr-4": { + "Worksome\\RequestFactories\\": "src", + "Worksome\\RequestFactories\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "luke", + "email": "lukeraymonddowning@gmail.com", + "role": "Developer" + } + ], + "description": "Test Form Requests in Laravel without all of the boilerplate.", + "homepage": "https://github.com/worksome/request-factories", + "keywords": [ + "laravel", + "request-factories", + "worksome" + ], + "support": { + "issues": "https://github.com/worksome/request-factories/issues", + "source": "https://github.com/worksome/request-factories/tree/v3.2.0" + }, + "funding": [ + { + "url": "https://github.com/worksome", + "type": "github" + } + ], + "time": "2023-03-22T14:31:02+00:00" } ], "aliases": [], diff --git a/cspell.json b/cspell.json index f318ad86ea6..25a8c716674 100644 --- a/cspell.json +++ b/cspell.json @@ -50,6 +50,7 @@ "Nuno", "PAPERTRAIL", "Parens", + "passw", "phpredis", "Phpstan", "phpstorm", diff --git a/phpunit.xml b/phpunit.xml index f3f188335eb..8a821db8a6a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,30 +1,27 @@ - - - - tests/Unit - - - tests/Feature - - - - - ./src - - - - - - - - - - - - + + + + tests/Unit + + + tests/Feature + + + + + + + + + + + + + + + + ./src + + diff --git a/src/App/Users/Controllers/StoreUserController.php b/src/App/Users/Controllers/StoreUserController.php index 357b229b6c1..5ebe3c08c5c 100644 --- a/src/App/Users/Controllers/StoreUserController.php +++ b/src/App/Users/Controllers/StoreUserController.php @@ -17,6 +17,6 @@ public function __invoke(StoreUserRequest $request, StoreUserAction $storeUserAc return responder() ->success($user, UserTransformer::class) - ->respond(); + ->respond(JsonResponse::HTTP_CREATED); } } diff --git a/tests/Feature/Users/ListUserTest.php b/tests/Feature/Users/ListUserTest.php new file mode 100644 index 00000000000..6376aa848eb --- /dev/null +++ b/tests/Feature/Users/ListUserTest.php @@ -0,0 +1,32 @@ + $users */ + $users = UserFactory::new() + ->count(5) + ->create(); + + $transformer = new UserTransformer(); + + getJson(url('/api/users')) + ->assertSuccessful() + ->assertExactJson([ + 'status' => 200, + 'success' => true, + 'data' => $users->map(fn(User $user) => $transformer->transform($user))->toArray(), + ]); + }); +}); diff --git a/tests/Feature/Users/StoreUserTest.php b/tests/Feature/Users/StoreUserTest.php new file mode 100644 index 00000000000..ccabca69cc9 --- /dev/null +++ b/tests/Feature/Users/StoreUserTest.php @@ -0,0 +1,25 @@ +create(); + + postJson(url('/api/users'), $data) + ->assertCreated(); + + assertDatabaseHas('users', [ + 'name' => $data['name'], + 'email' => $data['email'] + ]); + }); +}); diff --git a/tests/Pest.php b/tests/Pest.php index 171aba04f0d..2448ecd6bbf 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -15,7 +15,7 @@ uses( Tests\TestCase::class, - // Illuminate\Foundation\Testing\RefreshDatabase::class, + Illuminate\Foundation\Testing\RefreshDatabase::class, )->in('Feature'); /* diff --git a/tests/RequestFactories/StoreUserRequestFactory.php b/tests/RequestFactories/StoreUserRequestFactory.php new file mode 100644 index 00000000000..8249b7ffb47 --- /dev/null +++ b/tests/RequestFactories/StoreUserRequestFactory.php @@ -0,0 +1,20 @@ + $this->faker->name, + 'email' => $this->faker->email, + 'password' => 'passw0rd', + 'password_confirmation' => 'passw0rd' + ]; + } +}