From 17d5669f4563b2acc0fbd8a64995c132c4b8899e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 8 Nov 2024 07:37:49 +0700 Subject: [PATCH] refactor: flip assert and actuals value on tests --- tests/system/Database/Live/ForgeTest.php | 70 +++++++++---------- .../Live/OCI8/CallStoredProcedureTest.php | 4 +- .../Database/Live/OCI8/LastInsertIDTest.php | 8 +-- tests/system/Files/FileCollectionTest.php | 2 +- tests/system/HTTP/ResponseCookieTest.php | 6 +- tests/system/Helpers/DateHelperTest.php | 2 +- tests/system/Helpers/TextHelperTest.php | 10 +-- tests/system/Models/EventsModelTest.php | 2 +- .../Models/ValidationModelRuleGroupTest.php | 12 ++-- tests/system/Models/ValidationModelTest.php | 12 ++-- tests/system/Pager/PagerTest.php | 12 ++-- tests/system/Router/RouteCollectionTest.php | 4 +- tests/system/Router/RouterTest.php | 8 +-- 13 files changed, 76 insertions(+), 76 deletions(-) diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 64d8dbd7e576..9aecdd969c78 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -278,15 +278,15 @@ public function testCreateTableApplyBigInt(): void $fieldsData = $this->db->getFieldData('forge_test_table'); if ($this->db->DBDriver === 'MySQLi') { - $this->assertSame(strtolower($fieldsData[0]->type), 'bigint'); + $this->assertSame('bigint', strtolower($fieldsData[0]->type)); } elseif ($this->db->DBDriver === 'Postgre') { - $this->assertSame(strtolower($fieldsData[0]->type), 'bigint'); + $this->assertSame('bigint', strtolower($fieldsData[0]->type)); } elseif ($this->db->DBDriver === 'SQLite3') { - $this->assertSame(strtolower($fieldsData[0]->type), 'integer'); + $this->assertSame('integer', strtolower($fieldsData[0]->type)); } elseif ($this->db->DBDriver === 'OCI8') { - $this->assertSame(strtolower($fieldsData[0]->type), 'number'); + $this->assertSame('number', strtolower($fieldsData[0]->type)); } elseif ($this->db->DBDriver === 'SQLSRV') { - $this->assertSame(strtolower($fieldsData[0]->type), 'bigint'); + $this->assertSame('bigint', strtolower($fieldsData[0]->type)); } $this->forge->dropTable('forge_test_table', true); @@ -1166,65 +1166,65 @@ public function testCompositeKey(): void $keys = $this->db->getIndexData('forge_test_1'); if ($this->db->DBDriver === 'MySQLi') { - $this->assertSame($keys['PRIMARY']->name, 'PRIMARY'); + $this->assertSame('PRIMARY', $keys['PRIMARY']->name); $this->assertSame($keys['PRIMARY']->fields, ['id']); - $this->assertSame($keys['PRIMARY']->type, 'PRIMARY'); + $this->assertSame('PRIMARY', $keys['PRIMARY']->type); - $this->assertSame($keys['code_company']->name, 'code_company'); + $this->assertSame('code_company', $keys['code_company']->name); $this->assertSame($keys['code_company']->fields, ['code', 'company']); - $this->assertSame($keys['code_company']->type, 'INDEX'); + $this->assertSame('INDEX', $keys['code_company']->type); - $this->assertSame($keys['code_active']->name, 'code_active'); + $this->assertSame('code_active', $keys['code_active']->name); $this->assertSame($keys['code_active']->fields, ['code', 'active']); - $this->assertSame($keys['code_active']->type, 'UNIQUE'); + $this->assertSame('UNIQUE', $keys['code_active']->type); } elseif ($this->db->DBDriver === 'Postgre') { - $this->assertSame($keys['pk_db_forge_test_1']->name, 'pk_db_forge_test_1'); + $this->assertSame('pk_db_forge_test_1', $keys['pk_db_forge_test_1']->name); $this->assertSame($keys['pk_db_forge_test_1']->fields, ['id']); - $this->assertSame($keys['pk_db_forge_test_1']->type, 'PRIMARY'); + $this->assertSame('PRIMARY', $keys['pk_db_forge_test_1']->type); - $this->assertSame($keys['db_forge_test_1_code_company']->name, 'db_forge_test_1_code_company'); + $this->assertSame('db_forge_test_1_code_company', $keys['db_forge_test_1_code_company']->name); $this->assertSame($keys['db_forge_test_1_code_company']->fields, ['code', 'company']); - $this->assertSame($keys['db_forge_test_1_code_company']->type, 'INDEX'); + $this->assertSame('INDEX', $keys['db_forge_test_1_code_company']->type); - $this->assertSame($keys['db_forge_test_1_code_active']->name, 'db_forge_test_1_code_active'); + $this->assertSame('db_forge_test_1_code_active', $keys['db_forge_test_1_code_active']->name); $this->assertSame($keys['db_forge_test_1_code_active']->fields, ['code', 'active']); - $this->assertSame($keys['db_forge_test_1_code_active']->type, 'UNIQUE'); + $this->assertSame('UNIQUE', $keys['db_forge_test_1_code_active']->type); } elseif ($this->db->DBDriver === 'SQLite3') { - $this->assertSame($keys['PRIMARY']->name, 'PRIMARY'); + $this->assertSame('PRIMARY', $keys['PRIMARY']->name); $this->assertSame($keys['PRIMARY']->fields, ['id']); - $this->assertSame($keys['PRIMARY']->type, 'PRIMARY'); + $this->assertSame('PRIMARY', $keys['PRIMARY']->type); - $this->assertSame($keys['db_forge_test_1_code_company']->name, 'db_forge_test_1_code_company'); + $this->assertSame('db_forge_test_1_code_company', $keys['db_forge_test_1_code_company']->name); $this->assertSame($keys['db_forge_test_1_code_company']->fields, ['code', 'company']); - $this->assertSame($keys['db_forge_test_1_code_company']->type, 'INDEX'); + $this->assertSame('INDEX', $keys['db_forge_test_1_code_company']->type); - $this->assertSame($keys['db_forge_test_1_code_active']->name, 'db_forge_test_1_code_active'); + $this->assertSame('db_forge_test_1_code_active', $keys['db_forge_test_1_code_active']->name); $this->assertSame($keys['db_forge_test_1_code_active']->fields, ['code', 'active']); - $this->assertSame($keys['db_forge_test_1_code_active']->type, 'UNIQUE'); + $this->assertSame('UNIQUE', $keys['db_forge_test_1_code_active']->type); } elseif ($this->db->DBDriver === 'SQLSRV') { - $this->assertSame($keys['pk_db_forge_test_1']->name, 'pk_db_forge_test_1'); + $this->assertSame('pk_db_forge_test_1', $keys['pk_db_forge_test_1']->name); $this->assertSame($keys['pk_db_forge_test_1']->fields, ['id']); - $this->assertSame($keys['pk_db_forge_test_1']->type, 'PRIMARY'); + $this->assertSame('PRIMARY', $keys['pk_db_forge_test_1']->type); - $this->assertSame($keys['db_forge_test_1_code_company']->name, 'db_forge_test_1_code_company'); + $this->assertSame('db_forge_test_1_code_company', $keys['db_forge_test_1_code_company']->name); $this->assertSame($keys['db_forge_test_1_code_company']->fields, ['code', 'company']); - $this->assertSame($keys['db_forge_test_1_code_company']->type, 'INDEX'); + $this->assertSame('INDEX', $keys['db_forge_test_1_code_company']->type); - $this->assertSame($keys['db_forge_test_1_code_active']->name, 'db_forge_test_1_code_active'); + $this->assertSame('db_forge_test_1_code_active', $keys['db_forge_test_1_code_active']->name); $this->assertSame($keys['db_forge_test_1_code_active']->fields, ['code', 'active']); - $this->assertSame($keys['db_forge_test_1_code_active']->type, 'UNIQUE'); + $this->assertSame('UNIQUE', $keys['db_forge_test_1_code_active']->type); } elseif ($this->db->DBDriver === 'OCI8') { - $this->assertSame($keys['pk_db_forge_test_1']->name, 'pk_db_forge_test_1'); + $this->assertSame('pk_db_forge_test_1', $keys['pk_db_forge_test_1']->name); $this->assertSame($keys['pk_db_forge_test_1']->fields, ['id']); - $this->assertSame($keys['pk_db_forge_test_1']->type, 'PRIMARY'); + $this->assertSame('PRIMARY', $keys['pk_db_forge_test_1']->type); - $this->assertSame($keys['db_forge_test_1_code_company']->name, 'db_forge_test_1_code_company'); + $this->assertSame('db_forge_test_1_code_company', $keys['db_forge_test_1_code_company']->name); $this->assertSame($keys['db_forge_test_1_code_company']->fields, ['code', 'company']); - $this->assertSame($keys['db_forge_test_1_code_company']->type, 'INDEX'); + $this->assertSame('INDEX', $keys['db_forge_test_1_code_company']->type); - $this->assertSame($keys['db_forge_test_1_code_active']->name, 'db_forge_test_1_code_active'); + $this->assertSame('db_forge_test_1_code_active', $keys['db_forge_test_1_code_active']->name); $this->assertSame($keys['db_forge_test_1_code_active']->fields, ['code', 'active']); - $this->assertSame($keys['db_forge_test_1_code_active']->type, 'UNIQUE'); + $this->assertSame('UNIQUE', $keys['db_forge_test_1_code_active']->type); } $this->forge->dropTable('forge_test_1', true); diff --git a/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php b/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php index 2baffb669957..43816b7301b3 100644 --- a/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php +++ b/tests/system/Database/Live/OCI8/CallStoredProcedureTest.php @@ -55,7 +55,7 @@ public function testCallPackageProcedure(): void ], ]); - $this->assertSame($result, '7'); + $this->assertSame('7', $result); } public function testCallStoredProcedure(): void @@ -77,7 +77,7 @@ public function testCallStoredProcedure(): void ], ]); - $this->assertSame($result, '7'); + $this->assertSame('7', $result); } public function testCallStoredProcedureForCursor(): void diff --git a/tests/system/Database/Live/OCI8/LastInsertIDTest.php b/tests/system/Database/Live/OCI8/LastInsertIDTest.php index 5cc88e39510b..33945cf7d276 100644 --- a/tests/system/Database/Live/OCI8/LastInsertIDTest.php +++ b/tests/system/Database/Live/OCI8/LastInsertIDTest.php @@ -49,7 +49,7 @@ public function testGetInsertIDWithInsert(): void $this->db->table('job')->insert($jobData); $actual = $this->db->insertID(); - $this->assertSame($actual, 5); + $this->assertSame(5, $actual); } public function testGetInsertIDWithQuery(): void @@ -57,7 +57,7 @@ public function testGetInsertIDWithQuery(): void $this->db->query('INSERT INTO "db_job" ("name", "description") VALUES (?, ?)', ['Grocery Sales', 'Discount!']); $actual = $this->db->insertID(); - $this->assertSame($actual, 5); + $this->assertSame(5, $actual); } public function testGetInsertIDWithHasCommentQuery(): void @@ -73,7 +73,7 @@ public function testGetInsertIDWithHasCommentQuery(): void $this->db->query($sql, ['Discount!']); $actual = $this->db->insertID(); - $this->assertSame($actual, 5); + $this->assertSame(5, $actual); } public function testGetInsertIDWithPreparedQuery(): void @@ -87,6 +87,6 @@ public function testGetInsertIDWithPreparedQuery(): void $query->execute('foo', 'bar'); $actual = $this->db->insertID(); - $this->assertSame($actual, 5); + $this->assertSame(5, $actual); } } diff --git a/tests/system/Files/FileCollectionTest.php b/tests/system/Files/FileCollectionTest.php index 81005356fee3..f1431b36de8c 100644 --- a/tests/system/Files/FileCollectionTest.php +++ b/tests/system/Files/FileCollectionTest.php @@ -577,6 +577,6 @@ public function testIterable(): void $count++; } - $this->assertSame($count, 5); + $this->assertSame(5, $count); } } diff --git a/tests/system/HTTP/ResponseCookieTest.php b/tests/system/HTTP/ResponseCookieTest.php index 9782287fd70a..6fb03d516a9f 100644 --- a/tests/system/HTTP/ResponseCookieTest.php +++ b/tests/system/HTTP/ResponseCookieTest.php @@ -203,7 +203,7 @@ public function testCookieDelete(): void $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => 1000]); $response->deleteCookie('bee'); $cookie = $response->getCookie('bee'); - $this->assertSame($cookie->getExpiresTimestamp(), 0); + $this->assertSame(0, $cookie->getExpiresTimestamp()); // delete cookie with wrong prefix? $config->prefix = 'mine'; @@ -214,7 +214,7 @@ public function testCookieDelete(): void $this->assertFalse($cookie->isExpired(), $cookie->getExpiresTimestamp() . ' should be less than ' . time()); $response->deleteCookie('bee', '', '', 'mine'); $cookie = $response->getCookie('bee'); - $this->assertSame($cookie->getExpiresTimestamp(), 0); + $this->assertSame(0, $cookie->getExpiresTimestamp()); // delete cookie with wrong domain? $config->domain = '.mine.com'; @@ -225,7 +225,7 @@ public function testCookieDelete(): void $this->assertFalse($cookie->isExpired(), $cookie->getExpiresTimestamp() . ' should be less than ' . time()); $response->deleteCookie('bees', '.mine.com', '', ''); $cookie = $response->getCookie('bees'); - $this->assertSame($cookie->getExpiresTimestamp(), 0); + $this->assertSame(0, $cookie->getExpiresTimestamp()); } public function testCookieDefaultSetSameSite(): void diff --git a/tests/system/Helpers/DateHelperTest.php b/tests/system/Helpers/DateHelperTest.php index 173a979e29e3..4e7acf649ae7 100644 --- a/tests/system/Helpers/DateHelperTest.php +++ b/tests/system/Helpers/DateHelperTest.php @@ -34,7 +34,7 @@ public function testNowDefault(): void { Time::setTestNow('June 20, 2022', 'America/Chicago'); - $this->assertSame(now(), 1_655_701_200); + $this->assertSame(1_655_701_200, now()); Time::setTestNow(); } diff --git a/tests/system/Helpers/TextHelperTest.php b/tests/system/Helpers/TextHelperTest.php index 3ba265f3a1b5..dc5072a59217 100644 --- a/tests/system/Helpers/TextHelperTest.php +++ b/tests/system/Helpers/TextHelperTest.php @@ -345,17 +345,17 @@ public function testWordWrap(): void { $string = 'Here is a simple string of text that will help us demonstrate this function.'; $expected = "Here is a simple string\nof text that will help us\ndemonstrate this\nfunction."; - $this->assertSame(substr_count(word_wrap($string, 25), "\n"), 3); + $this->assertSame(3, substr_count(word_wrap($string, 25), "\n")); $this->assertSame($expected, word_wrap($string, 25)); $string2 = "Here is a\nbroken up sentence\rspanning lines\r\nwoohoo!"; $expected2 = "Here is a\nbroken up sentence\nspanning lines\nwoohoo!"; - $this->assertSame(substr_count(word_wrap($string2, 25), "\n"), 3); + $this->assertSame(3, substr_count(word_wrap($string2, 25), "\n")); $this->assertSame($expected2, word_wrap($string2, 25)); $string3 = "Here is another slightly longer\nbroken up sentence\rspanning lines\r\nwoohoo!"; $expected3 = "Here is another slightly\nlonger\nbroken up sentence\nspanning lines\nwoohoo!"; - $this->assertSame(substr_count(word_wrap($string3, 25), "\n"), 4); + $this->assertSame(4, substr_count(word_wrap($string3, 25), "\n")); $this->assertSame($expected3, word_wrap($string3, 25)); } @@ -363,7 +363,7 @@ public function testWordWrapUnwrap(): void { $string = 'Here is a {unwrap}simple string of text{/unwrap} that will help us demonstrate this function.'; $expected = "Here is a simple string of text\nthat will help us\ndemonstrate this\nfunction."; - $this->assertSame(substr_count(word_wrap($string, 25), "\n"), 3); + $this->assertSame(3, substr_count(word_wrap($string, 25), "\n")); $this->assertSame($expected, word_wrap($string, 25)); } @@ -386,7 +386,7 @@ public function testWordWrapURL(): void public function testDefaultWordWrapCharlim(): void { $string = 'Here is a longer string of text that will help us demonstrate the default charlim of this function.'; - $this->assertSame(strpos(word_wrap($string), "\n"), 73); + $this->assertSame(73, strpos(word_wrap($string), "\n")); } public function testExcerpt(): void diff --git a/tests/system/Models/EventsModelTest.php b/tests/system/Models/EventsModelTest.php index d697437d3534..4c6b2640723a 100644 --- a/tests/system/Models/EventsModelTest.php +++ b/tests/system/Models/EventsModelTest.php @@ -84,7 +84,7 @@ public function testBeforeFindReturnsData(): void $result = $this->model->find(1); $this->assertTrue($this->model->hasToken('beforeFind')); - $this->assertSame($result, 'foobar'); + $this->assertSame('foobar', $result); } public function testBeforeFindReturnDataPreventsAfterFind(): void diff --git a/tests/system/Models/ValidationModelRuleGroupTest.php b/tests/system/Models/ValidationModelRuleGroupTest.php index 4274d5d1578f..b08f73c9a04e 100644 --- a/tests/system/Models/ValidationModelRuleGroupTest.php +++ b/tests/system/Models/ValidationModelRuleGroupTest.php @@ -398,8 +398,8 @@ public function testUpdateEntityWithPropertyCleanValidationRulesTrueAndCallingCl $errors = $model->errors(); $this->assertCount(1, $errors); $this->assertSame( - $errors['field1'], - 'The field1 field is required when field2,field3,field4 is present.' + 'The field1 field is required when field2,field3,field4 is present.', + $errors['field1'] ); } @@ -438,8 +438,8 @@ public function testUpdateEntityWithPropertyCleanValidationRulesFalse(): void $errors = $model->errors(); $this->assertCount(1, $errors); $this->assertSame( - $errors['field1'], - 'The field1 field is required when field2,field3,field4 is present.' + 'The field1 field is required when field2,field3,field4 is present.', + $errors['field1'] ); } @@ -471,8 +471,8 @@ public function testInsertEntityValidateEntireRules(): void $errors = $model->errors(); $this->assertCount(1, $errors); $this->assertSame( - $errors['field2'], - 'The field2 field is required.' + 'The field2 field is required.', + $errors['field2'] ); } } diff --git a/tests/system/Models/ValidationModelTest.php b/tests/system/Models/ValidationModelTest.php index d2c9c7d0dab8..ca41e29e78ad 100644 --- a/tests/system/Models/ValidationModelTest.php +++ b/tests/system/Models/ValidationModelTest.php @@ -410,8 +410,8 @@ public function testUpdateEntityWithPropertyCleanValidationRulesTrueAndCallingCl $errors = $model->errors(); $this->assertCount(1, $errors); $this->assertSame( - $errors['field1'], - 'The field1 field is required when field2,field3,field4 is present.' + 'The field1 field is required when field2,field3,field4 is present.', + $errors['field1'] ); } @@ -450,8 +450,8 @@ public function testUpdateEntityWithPropertyCleanValidationRulesFalse(): void $errors = $model->errors(); $this->assertCount(1, $errors); $this->assertSame( - $errors['field1'], - 'The field1 field is required when field2,field3,field4 is present.' + 'The field1 field is required when field2,field3,field4 is present.', + $errors['field1'] ); } @@ -483,8 +483,8 @@ public function testInsertEntityValidateEntireRules(): void $errors = $model->errors(); $this->assertCount(1, $errors); $this->assertSame( - $errors['field2'], - 'The field2 field is required.' + 'The field2 field is required.', + $errors['field2'] ); } } diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index 047637a2025f..c652a3793738 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -123,9 +123,9 @@ public function testStoreDoesBasicCalcs(): void $details = $this->pager->getDetails('foo'); - $this->assertSame($details['total'], 100); - $this->assertSame($details['perPage'], 25); - $this->assertSame($details['currentPage'], 3); + $this->assertSame(100, $details['total']); + $this->assertSame(25, $details['perPage']); + $this->assertSame(3, $details['currentPage']); } public function testStoreDoesBasicCalcsOnPerPageReadFromPagerConfig(): void @@ -134,9 +134,9 @@ public function testStoreDoesBasicCalcsOnPerPageReadFromPagerConfig(): void $details = $this->pager->getDetails('foo'); - $this->assertSame($details['total'], 100); - $this->assertSame($details['perPage'], 20); - $this->assertSame($details['currentPage'], 3); + $this->assertSame(100, $details['total']); + $this->assertSame(20, $details['perPage']); + $this->assertSame(3, $details['currentPage']); } public function testStoreAndHasMore(): void diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 5c06154a5d31..bfd53a3ebf7c 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -1296,7 +1296,7 @@ public function testWillDiscoverLocal(): void $match = $routes->getRoutes(); $this->assertArrayHasKey('testing', $match); - $this->assertSame($match['testing'], '\TestController::index'); + $this->assertSame('\TestController::index', $match['testing']); } public function testDiscoverLocalAllowsConfigToOverridePackages(): void @@ -1315,7 +1315,7 @@ public function testDiscoverLocalAllowsConfigToOverridePackages(): void $match = $routes->getRoutes(); $this->assertArrayHasKey('testing', $match); - $this->assertSame($match['testing'], '\MainRoutes::index'); + $this->assertSame('\MainRoutes::index', $match['testing']); } public function testRoutesOptions(): void diff --git a/tests/system/Router/RouterTest.php b/tests/system/Router/RouterTest.php index 5d51bf2fd38c..04e3d191bbf6 100644 --- a/tests/system/Router/RouterTest.php +++ b/tests/system/Router/RouterTest.php @@ -212,10 +212,10 @@ public function testClosures(): void $closure = $router->controllerName(); - $expects = $closure(...$router->params()); + $actual = $closure(...$router->params()); $this->assertIsCallable($router->controllerName()); - $this->assertSame($expects, '123-alpha'); + $this->assertSame('123-alpha', $actual); } public function testClosuresWithTranslateURIDashes(): void @@ -228,10 +228,10 @@ public function testClosuresWithTranslateURIDashes(): void $this->assertInstanceOf(Closure::class, $closure); - $expects = $closure(...$router->params()); + $actual = $closure(...$router->params()); $this->assertIsCallable($router->controllerName()); - $this->assertSame($expects, '123-alpha'); + $this->assertSame('123-alpha', $actual); } public function testAutoRouteFindsDefaultControllerAndMethod(): void