mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #9260 from samsonasik/refactor-flip-assert-actual
refactor: flip assert and actual value position on tests
This commit is contained in:
commit
91275ed668
@ -278,15 +278,15 @@ final class ForgeTest extends CIUnitTestCase
|
||||
|
||||
$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 @@ final class ForgeTest extends CIUnitTestCase
|
||||
$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);
|
||||
|
@ -55,7 +55,7 @@ final class CallStoredProcedureTest extends CIUnitTestCase
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame($result, '7');
|
||||
$this->assertSame('7', $result);
|
||||
}
|
||||
|
||||
public function testCallStoredProcedure(): void
|
||||
@ -77,7 +77,7 @@ final class CallStoredProcedureTest extends CIUnitTestCase
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame($result, '7');
|
||||
$this->assertSame('7', $result);
|
||||
}
|
||||
|
||||
public function testCallStoredProcedureForCursor(): void
|
||||
|
@ -49,7 +49,7 @@ final class LastInsertIDTest extends CIUnitTestCase
|
||||
$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 @@ final class LastInsertIDTest extends CIUnitTestCase
|
||||
$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 @@ final class LastInsertIDTest extends CIUnitTestCase
|
||||
$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 @@ final class LastInsertIDTest extends CIUnitTestCase
|
||||
$query->execute('foo', 'bar');
|
||||
$actual = $this->db->insertID();
|
||||
|
||||
$this->assertSame($actual, 5);
|
||||
$this->assertSame(5, $actual);
|
||||
}
|
||||
}
|
||||
|
@ -577,6 +577,6 @@ final class FileCollectionTest extends CIUnitTestCase
|
||||
$count++;
|
||||
}
|
||||
|
||||
$this->assertSame($count, 5);
|
||||
$this->assertSame(5, $count);
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ final class ResponseCookieTest extends CIUnitTestCase
|
||||
$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 @@ final class ResponseCookieTest extends CIUnitTestCase
|
||||
$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 @@ final class ResponseCookieTest extends CIUnitTestCase
|
||||
$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
|
||||
|
@ -34,7 +34,7 @@ final class DateHelperTest extends CIUnitTestCase
|
||||
{
|
||||
Time::setTestNow('June 20, 2022', 'America/Chicago');
|
||||
|
||||
$this->assertSame(now(), 1_655_701_200);
|
||||
$this->assertSame(1_655_701_200, now());
|
||||
|
||||
Time::setTestNow();
|
||||
}
|
||||
|
@ -345,17 +345,17 @@ final class TextHelperTest extends CIUnitTestCase
|
||||
{
|
||||
$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 @@ final class TextHelperTest extends CIUnitTestCase
|
||||
{
|
||||
$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 @@ final class TextHelperTest extends CIUnitTestCase
|
||||
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
|
||||
|
@ -84,7 +84,7 @@ final class EventsModelTest extends LiveModelTestCase
|
||||
|
||||
$result = $this->model->find(1);
|
||||
$this->assertTrue($this->model->hasToken('beforeFind'));
|
||||
$this->assertSame($result, 'foobar');
|
||||
$this->assertSame('foobar', $result);
|
||||
}
|
||||
|
||||
public function testBeforeFindReturnDataPreventsAfterFind(): void
|
||||
|
@ -398,8 +398,8 @@ final class ValidationModelRuleGroupTest extends LiveModelTestCase
|
||||
$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 @@ final class ValidationModelRuleGroupTest extends LiveModelTestCase
|
||||
$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 @@ final class ValidationModelRuleGroupTest extends LiveModelTestCase
|
||||
$errors = $model->errors();
|
||||
$this->assertCount(1, $errors);
|
||||
$this->assertSame(
|
||||
$errors['field2'],
|
||||
'The field2 field is required.'
|
||||
'The field2 field is required.',
|
||||
$errors['field2']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -410,8 +410,8 @@ final class ValidationModelTest extends LiveModelTestCase
|
||||
$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 @@ final class ValidationModelTest extends LiveModelTestCase
|
||||
$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 @@ final class ValidationModelTest extends LiveModelTestCase
|
||||
$errors = $model->errors();
|
||||
$this->assertCount(1, $errors);
|
||||
$this->assertSame(
|
||||
$errors['field2'],
|
||||
'The field2 field is required.'
|
||||
'The field2 field is required.',
|
||||
$errors['field2']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -123,9 +123,9 @@ final class PagerTest extends CIUnitTestCase
|
||||
|
||||
$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 @@ final class PagerTest extends CIUnitTestCase
|
||||
|
||||
$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
|
||||
|
@ -1296,7 +1296,7 @@ final class RouteCollectionTest extends CIUnitTestCase
|
||||
$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 @@ final class RouteCollectionTest extends CIUnitTestCase
|
||||
$match = $routes->getRoutes();
|
||||
|
||||
$this->assertArrayHasKey('testing', $match);
|
||||
$this->assertSame($match['testing'], '\MainRoutes::index');
|
||||
$this->assertSame('\MainRoutes::index', $match['testing']);
|
||||
}
|
||||
|
||||
public function testRoutesOptions(): void
|
||||
|
@ -212,10 +212,10 @@ final class RouterTest extends CIUnitTestCase
|
||||
|
||||
$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 @@ final class RouterTest extends CIUnitTestCase
|
||||
|
||||
$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
|
||||
|
Loading…
x
Reference in New Issue
Block a user