forked from laravel/laravel
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new package worksome/request-factories and some test to exa…
…mple
- Loading branch information
Showing
9 changed files
with
182 additions
and
33 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
"Nuno", | ||
"PAPERTRAIL", | ||
"Parens", | ||
"passw", | ||
"phpredis", | ||
"Phpstan", | ||
"phpstorm", | ||
|
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 |
---|---|---|
@@ -1,30 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="Feature"> | ||
<directory>tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="DB_DATABASE" value="testing"/> | ||
<env name="MAIL_MAILER" value="array"/> | ||
<env name="QUEUE_CONNECTION" value="sync"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="TELESCOPE_ENABLED" value="false"/> | ||
</php> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache"> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="Feature"> | ||
<directory>tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage/> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="DB_DATABASE" value="testing"/> | ||
<env name="MAIL_MAILER" value="array"/> | ||
<env name="QUEUE_CONNECTION" value="sync"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="TELESCOPE_ENABLED" value="false"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Users; | ||
|
||
use App\Users\Controllers\StoreUserController; | ||
use App\Users\Transformers\UserTransformer; | ||
use Database\Factories\UserFactory; | ||
use Domain\Users\Models\User; | ||
use Illuminate\Support\Collection; | ||
use function Pest\Laravel\getJson; | ||
|
||
describe('users', function () { | ||
/** @see StoreUserController */ | ||
it('can list users successfully', function () { | ||
/** @var Collection<int, User> $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(), | ||
]); | ||
}); | ||
}); |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Users; | ||
|
||
use App\Users\Controllers\StoreUserController; | ||
use Tests\RequestFactories\StoreUserRequestFactory; | ||
use function Pest\Laravel\assertDatabaseHas; | ||
use function Pest\Laravel\postJson; | ||
|
||
describe('users', function () { | ||
/** @see StoreUserController */ | ||
it('can create a user successfully', function () { | ||
$data = StoreUserRequestFactory::new()->create(); | ||
|
||
postJson(url('/api/users'), $data) | ||
->assertCreated(); | ||
|
||
assertDatabaseHas('users', [ | ||
'name' => $data['name'], | ||
'email' => $data['email'] | ||
]); | ||
}); | ||
}); |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\RequestFactories; | ||
|
||
use Worksome\RequestFactories\RequestFactory; | ||
|
||
class StoreUserRequestFactory extends RequestFactory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'name' => $this->faker->name, | ||
'email' => $this->faker->email, | ||
'password' => 'passw0rd', | ||
'password_confirmation' => 'passw0rd' | ||
]; | ||
} | ||
} |