Skip to content

Commit

Permalink
Merge pull request #9260 from samsonasik/refactor-flip-assert-actual
Browse files Browse the repository at this point in the history
refactor: flip assert and actual value position on tests
  • Loading branch information
samsonasik authored Nov 8, 2024
2 parents c7d012d + 17d5669 commit 91275ed
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 76 deletions.
70 changes: 35 additions & 35 deletions tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Database/Live/OCI8/CallStoredProcedureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testCallPackageProcedure(): void
],
]);

$this->assertSame($result, '7');
$this->assertSame('7', $result);
}

public function testCallStoredProcedure(): void
Expand All @@ -77,7 +77,7 @@ public function testCallStoredProcedure(): void
],
]);

$this->assertSame($result, '7');
$this->assertSame('7', $result);
}

public function testCallStoredProcedureForCursor(): void
Expand Down
8 changes: 4 additions & 4 deletions tests/system/Database/Live/OCI8/LastInsertIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ 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
{
$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
Expand All @@ -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
Expand All @@ -87,6 +87,6 @@ public function testGetInsertIDWithPreparedQuery(): void
$query->execute('foo', 'bar');
$actual = $this->db->insertID();

$this->assertSame($actual, 5);
$this->assertSame(5, $actual);
}
}
2 changes: 1 addition & 1 deletion tests/system/Files/FileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,6 @@ public function testIterable(): void
$count++;
}

$this->assertSame($count, 5);
$this->assertSame(5, $count);
}
}
6 changes: 3 additions & 3 deletions tests/system/HTTP/ResponseCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Helpers/DateHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions tests/system/Helpers/TextHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,25 +345,25 @@ 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));
}

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));
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Models/EventsModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/system/Models/ValidationModelRuleGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}

Expand Down Expand Up @@ -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']
);
}

Expand Down Expand Up @@ -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']
);
}
}
12 changes: 6 additions & 6 deletions tests/system/Models/ValidationModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}

Expand Down Expand Up @@ -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']
);
}

Expand Down Expand Up @@ -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']
);
}
}
12 changes: 6 additions & 6 deletions tests/system/Pager/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/system/Router/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 91275ed

Please sign in to comment.