From 4009a436b5f54950fe834e1348168216c7bf4da2 Mon Sep 17 00:00:00 2001 From: eparusov Date: Thu, 19 Dec 2024 17:21:09 +0300 Subject: [PATCH] #166: Automatically add .json extension --- tests/AuthTest.php | 18 +++++++-------- tests/RoleTest.php | 8 +++---- tests/SettingTest.php | 32 +++++++++++++------------- tests/UserTest.php | 52 +++++++++++++++++++++---------------------- 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/tests/AuthTest.php b/tests/AuthTest.php index f39f6cf..806584e 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -22,7 +22,7 @@ public function setUp(): void { parent::setUp(); - self::$users ??= $this->getJsonFixture('users.json'); + self::$users ??= $this->getJsonFixture('users'); self::$admin ??= User::find(1); self::$userState ??= new ModelTestState(User::class); @@ -104,20 +104,20 @@ public function testRegisterAuthorizedUser() { $this->mockBcryptHasher(); - $data = $this->getJsonFixture('new_user.json'); + $data = $this->getJsonFixture('new_user'); $response = $this->actingAs(self::$admin)->json('post', '/register', $data); $response->assertOk(); - self::$userState->assertChangesEqualsFixture('register_authorized_user_users_state.json'); + self::$userState->assertChangesEqualsFixture('register_authorized_user_users_state'); } public function testRegisterFromGuestUser() { $this->mockBcryptHasher(); - $data = $this->getJsonFixture('new_user.json'); + $data = $this->getJsonFixture('new_user'); $response = $this->json('post', '/register', $data); @@ -127,12 +127,12 @@ public function testRegisterFromGuestUser() $response->assertCookie('token'); $this->assertEquals(0, $response->getCookie('token', false)->getExpiresTime()); - self::$userState->assertChangesEqualsFixture('register_from_guest_user_users_state.json'); + self::$userState->assertChangesEqualsFixture('register_from_guest_user_users_state'); } public function testRegisterFromGuestUserWithRemember() { - $data = $this->getJsonFixture('new_user.json'); + $data = $this->getJsonFixture('new_user'); $response = $this->json('post', '/register', [ ...$data, @@ -292,13 +292,13 @@ public function testRestorePassword() { $this->mockBcryptHasher(); - $data = $this->getJsonFixture('restore_password.json'); + $data = $this->getJsonFixture('restore_password'); $response = $this->json('post', '/auth/restore-password', $data); $response->assertNoContent(); - self::$userState->assertChangesEqualsFixture('restore_password_users_state.json'); + self::$userState->assertChangesEqualsFixture('restore_password_users_state'); $this->assertDatabaseMissing('password_reset_tokens', [ 'email' => 'fidel.kutch@example.com', @@ -307,7 +307,7 @@ public function testRestorePassword() public function testRestorePasswordWrongToken() { - $data = $this->getJsonFixture('restore_password_wrong_token.json'); + $data = $this->getJsonFixture('restore_password_wrong_token'); $response = $this->json('post', '/auth/restore-password', $data); diff --git a/tests/RoleTest.php b/tests/RoleTest.php index eba8a8f..a491322 100644 --- a/tests/RoleTest.php +++ b/tests/RoleTest.php @@ -12,25 +12,25 @@ public static function getSearchFilters(): array return [ [ 'filter' => ['all' => 1], - 'fixture' => 'search_by_all.json', + 'fixture' => 'search_by_all', ], [ 'filter' => [ 'page' => 2, 'per_page' => 1, ], - 'fixture' => 'search_by_page_per.json', + 'fixture' => 'search_by_page_per', ], [ 'filter' => ['query' => 'us'], - 'fixture' => 'get_roles_by_name.json', + 'fixture' => 'get_roles_by_name', ], [ 'filter' => [ 'desc' => true, 'order_by' => 'name', ], - 'fixture' => 'get_roles_check_order.json', + 'fixture' => 'get_roles_check_order', ], ]; } diff --git a/tests/SettingTest.php b/tests/SettingTest.php index 0bbfb8f..ac7d1d5 100644 --- a/tests/SettingTest.php +++ b/tests/SettingTest.php @@ -21,7 +21,7 @@ public function setUp(): void public function testUpdate() { - $setting = $this->getJsonFixture('update_setting.json'); + $setting = $this->getJsonFixture('update_setting'); $response = $this->actingAs(self::$admin)->json('put', "/settings/{$setting['name']}", $setting['value']); @@ -35,7 +35,7 @@ public function testUpdate() public function testUpdateNotExists() { - $setting = $this->getJsonFixture('update_setting.json'); + $setting = $this->getJsonFixture('update_setting'); $response = $this->actingAs(self::$admin)->json('put', '/settings/not-exists', $setting['value']); @@ -44,7 +44,7 @@ public function testUpdateNotExists() public function testUpdateNoAuth() { - $setting = $this->getJsonFixture('update_setting.json'); + $setting = $this->getJsonFixture('update_setting'); $response = $this->json('put', "/settings/{$setting['name']}", $setting['value']); @@ -58,7 +58,7 @@ public function testUpdateNoAuth() public function testUpdateNoPermission() { - $setting = $this->getJsonFixture('update_setting.json'); + $setting = $this->getJsonFixture('update_setting'); $response = $this->actingAs(self::$user)->json('put', "/settings/{$setting['name']}", $setting['value']); @@ -95,7 +95,7 @@ public function testGetCheckResponse() { $response = $this->actingAs(self::$admin)->json('get', '/settings/states'); - $this->assertEqualsFixture('get_setting.json', $response->json()); + $this->assertEqualsFixture('get_setting', $response->json()); } public function testGetNotExists() @@ -110,33 +110,33 @@ public static function getSearchFilters(): array return [ [ 'filter' => ['query' => 'states'], - 'fixture' => 'get_setting_by_key.json', + 'fixture' => 'get_setting_by_key', ], [ 'filter' => [ 'order_by' => 'name', 'desc' => false, ], - 'fixture' => 'get_settings_check_order.json', + 'fixture' => 'get_settings_check_order', ], [ 'filter' => [ 'per_page' => 2, ], - 'fixture' => 'search_per_page.json', + 'fixture' => 'search_per_page', ], [ 'filter' => [ 'all' => 1, ], - 'fixture' => 'search_all.json', + 'fixture' => 'search_all', ], [ 'filter' => [ 'per_page' => 1, 'query' => 'states', ], - 'fixture' => 'search_complex.json', + 'fixture' => 'search_complex', ], ]; } @@ -156,7 +156,7 @@ public static function getUserSearchFilters(): array return [ [ 'filter' => [], - 'fixture' => 'get_public_settings.json', + 'fixture' => 'get_public_settings', ], ]; } @@ -180,7 +180,7 @@ public function testSetNotExistsSetting() $result = app(SettingService::class)->set($setting['name'], $setting['value']); - $this->assertEqualsFixture('setting_set_not_exists.json', $result->jsonSerialize()); + $this->assertEqualsFixture('setting_set_not_exists', $result->jsonSerialize()); $this->assertDatabaseHas('settings', [ 'name' => $setting['name'], @@ -197,7 +197,7 @@ public function testSetExistsSetting() $result = app(SettingService::class)->set($setting['name'], $setting['value']); - $this->assertEqualsFixture('setting_set_exists.json', $result->jsonSerialize()); + $this->assertEqualsFixture('setting_set_exists', $result->jsonSerialize()); $this->assertDatabaseHas('settings', [ 'name' => $setting['name'], @@ -209,20 +209,20 @@ public function testGetExistsSetting() { $result = app(SettingService::class)->get('attribute'); - $this->assertEqualsFixture('setting_get_exists.json', $result); + $this->assertEqualsFixture('setting_get_exists', $result); } public function testGetExistsJsonSetting() { $result = app(SettingService::class)->get('settings.timezone'); - $this->assertEqualsFixture('setting_get_exists_json.json', $result); + $this->assertEqualsFixture('setting_get_exists_json', $result); } public function testGetNotExistsSetting() { $result = app(SettingService::class)->get('not_exists_attribute'); - $this->assertEqualsFixture('setting_get_not_exists.json', $result); + $this->assertEqualsFixture('setting_get_not_exists', $result); } } diff --git a/tests/UserTest.php b/tests/UserTest.php index 36fc4de..8beb1ac 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -30,20 +30,20 @@ public function testCreate() { $this->mockBcryptHasher(); - $data = $this->getJsonFixture('create_user.json'); + $data = $this->getJsonFixture('create_user'); $response = $this->actingAs(self::$admin)->json('post', '/users', $data); $response->assertCreated(); - $this->assertEqualsFixture('user_created.json', $response->json()); + $this->assertEqualsFixture('user_created', $response->json()); - self::$userState->assertChangesEqualsFixture('user_created_users_state.json'); + self::$userState->assertChangesEqualsFixture('user_created_users_state'); } public function testCreateNoAuth() { - $data = $this->getJsonFixture('create_user.json'); + $data = $this->getJsonFixture('create_user'); $response = $this->json('post', '/users', $data); @@ -54,7 +54,7 @@ public function testCreateNoAuth() public function testCreateNoPermission() { - $data = $this->getJsonFixture('create_user.json'); + $data = $this->getJsonFixture('create_user'); $response = $this->actingAs(self::$user)->json('post', '/users', $data); @@ -72,18 +72,18 @@ public function testCreateUserExists() public function testUpdate() { - $data = $this->getJsonFixture('update_user.json'); + $data = $this->getJsonFixture('update_user'); $response = $this->actingAs(self::$admin)->json('put', '/users/2', $data); $response->assertNoContent(); - self::$userState->assertChangesEqualsFixture('user_updated_users_state.json'); + self::$userState->assertChangesEqualsFixture('user_updated_users_state'); } public function testUpdateByUser() { - $data = $this->getJsonFixture('update_user.json'); + $data = $this->getJsonFixture('update_user'); $response = $this->actingAs(self::$user)->json('put', '/users/2', $data); @@ -103,7 +103,7 @@ public function testUpdateWithEmailOfAnotherUser() public function testUpdateNotExists() { - $data = $this->getJsonFixture('update_user.json'); + $data = $this->getJsonFixture('update_user'); $response = $this->actingAs(self::$admin)->json('put', '/users/0', $data); @@ -112,7 +112,7 @@ public function testUpdateNotExists() public function testUpdateNoAuth() { - $data = $this->getJsonFixture('update_user.json'); + $data = $this->getJsonFixture('update_user'); $response = $this->json('put', '/users/1', $data); @@ -123,18 +123,18 @@ public function testUpdateNoAuth() public function testUpdateProfile() { - $data = $this->getJsonFixture('update_user.json'); + $data = $this->getJsonFixture('update_user'); $response = $this->actingAs(self::$admin)->json('put', '/profile', $data); $response->assertNoContent(); - self::$userState->assertChangesEqualsFixture('profile_updated_users_state.json'); + self::$userState->assertChangesEqualsFixture('profile_updated_users_state'); } public function testUpdateProfileWithPassword() { - $data = $this->getJsonFixture('update_profile_with_password.json'); + $data = $this->getJsonFixture('update_profile_with_password'); $response = $this->actingAs(self::$user)->json('put', '/profile', $data); @@ -143,7 +143,7 @@ public function testUpdateProfileWithPassword() public function testUpdateProfileWithPasswordEmptyOldPassword() { - $data = $this->getJsonFixture('update_profile_with_password_without_old.json'); + $data = $this->getJsonFixture('update_profile_with_password_without_old'); $response = $this->actingAs(self::$user)->json('put', '/profile', $data); @@ -152,7 +152,7 @@ public function testUpdateProfileWithPasswordEmptyOldPassword() public function testUpdateProfileWithPasswordWrongOldPassword() { - $data = $this->getJsonFixture('update_profile_with_password_with_wrong_old.json'); + $data = $this->getJsonFixture('update_profile_with_password_with_wrong_old'); $response = $this->actingAs(self::$user)->json('put', '/profile', $data); @@ -161,7 +161,7 @@ public function testUpdateProfileWithPasswordWrongOldPassword() public function testUpdateProfileNoAuth() { - $data = $this->getJsonFixture('update_user.json'); + $data = $this->getJsonFixture('update_user'); $response = $this->json('put', '/profile', $data); @@ -212,7 +212,7 @@ public function testDelete() $response->assertNoContent(); - self::$userState->assertChangesEqualsFixture('user_deleted_users_state.json'); + self::$userState->assertChangesEqualsFixture('user_deleted_users_state'); } public function testDeleteOwnUser() @@ -246,7 +246,7 @@ public function testGetProfile() $response->assertOk(); - $this->assertEqualsFixture('get_user.json', $response->json()); + $this->assertEqualsFixture('get_user', $response->json()); } public function testGet() @@ -257,7 +257,7 @@ public function testGet() $response->assertOk(); - $this->assertEqualsFixture('get_user.json', $response->json()); + $this->assertEqualsFixture('get_user', $response->json()); } public function testGetNotExists() @@ -272,26 +272,26 @@ public static function getSearchFilters(): array return [ [ 'filter' => ['all' => 1], - 'fixture' => 'search_by_all_user.json', + 'fixture' => 'search_by_all_user', ], [ 'filter' => [ 'page' => 1, 'per_page' => 2, ], - 'fixture' => 'search_by_page_per_page_user.json', + 'fixture' => 'search_by_page_per_page_user', ], [ 'filter' => ['query' => 'Another User'], - 'fixture' => 'get_users_by_name.json', + 'fixture' => 'get_users_by_name', ], [ 'filter' => ['query' => 'admin@example.com'], - 'fixture' => 'get_users_by_email.json', + 'fixture' => 'get_users_by_email', ], [ 'filter' => ['query' => 'Admin'], - 'fixture' => 'get_users_by_query.json', + 'fixture' => 'get_users_by_query', ], [ 'filter' => [ @@ -300,14 +300,14 @@ public static function getSearchFilters(): array 'order_by' => 'created_at', 'desc' => false, ], - 'fixture' => 'get_users_complex.json', + 'fixture' => 'get_users_complex', ], [ 'filter' => [ 'desc' => false, 'order_by' => 'name', ], - 'fixture' => 'get_users_check_order.json', + 'fixture' => 'get_users_check_order', ], ]; }