-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавлены тесты получения списка пользователей, создания и изменения
- Loading branch information
Showing
8 changed files
with
139 additions
and
68 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
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,27 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache"> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="Feature"> | ||
<directory suffix="Test.php">./tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<!-- <env name="DB_CONNECTION" value="sqlite"/> --> | ||
<!-- <env name="DB_DATABASE" value=":memory:"/> --> | ||
<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">./app</directory> | ||
</include> | ||
</source> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="Feature"> | ||
<directory suffix="Test.php">./tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="DB_CONNECTION" value="sqlite"/> | ||
<env name="DB_DATABASE" value=":memory:"/> | ||
<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">./app</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 was deleted.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Users; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Modules\Users\Models\User; | ||
use Tests\TestCase; | ||
|
||
class AdminUsersTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testAccessToPages(): void | ||
{ | ||
$response = $this->get(route('admin.users.index')); | ||
$response->assertRedirect('/'); | ||
} | ||
|
||
public function testIndexPage(): void | ||
{ | ||
$user = User::query()->find(1); | ||
$this->actingAs($user, 'web'); | ||
$response = $this->get(route('admin.users.index')); | ||
|
||
$response->assertStatus(200) | ||
->assertJsonStructure( | ||
[ | ||
'data' => [ | ||
'*' => [ | ||
'id', | ||
'name', | ||
'active', | ||
'email', | ||
'role', | ||
'createdAt', | ||
'updatedAt', | ||
'createdBy', | ||
'updatedBy', | ||
], | ||
], | ||
'current_page', | ||
'last_page', | ||
'total', | ||
'per_page', | ||
] | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,4 +9,6 @@ | |
abstract class TestCase extends BaseTestCase | ||
{ | ||
use CreatesApplication; | ||
|
||
protected bool $seed = true; | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit\Users\Services; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Hash; | ||
use Modules\Users\DTO\Request\AdminCreateUserRequestDTO; | ||
use Modules\Users\DTO\Request\AdminUpdateUserRequestDTO; | ||
use Modules\Users\Services\UsersService; | ||
use Tests\TestCase; | ||
|
||
class UsersServiceTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testCreateAndUpdateUser(): void | ||
{ | ||
$userService = new UsersService(); | ||
$userDTO = new AdminCreateUserRequestDTO( | ||
true, | ||
'UserName', | ||
'user-email@example.com', | ||
'admin', | ||
'password' | ||
); | ||
$createdUser = $userService->create($userDTO); | ||
|
||
$this->assertTrue($createdUser->active); | ||
$this->assertEquals('UserName', $createdUser->name); | ||
$this->assertEquals('user-email@example.com', $createdUser->email); | ||
$this->assertEquals('admin', $createdUser->role); | ||
$this->assertNotEmpty($createdUser->password); | ||
|
||
|
||
$updateRequest = new AdminUpdateUserRequestDTO( | ||
$createdUser->id, | ||
false, | ||
'UpdateUserName', | ||
'updated-user-email@example.com', | ||
'user', | ||
Hash::make('password2') | ||
); | ||
|
||
$updatedUser = $userService->update($updateRequest); | ||
|
||
$this->assertFalse($updatedUser->active); | ||
$this->assertEquals('UpdateUserName', $updatedUser->name); | ||
$this->assertEquals('updated-user-email@example.com', $updatedUser->email); | ||
$this->assertEquals('user', $updatedUser->role); | ||
$this->assertNotEmpty($updatedUser->password); | ||
} | ||
} |