Skip to content

Commit 224f347

Browse files
authored
Normalize tests to use dedicated PHPUnit assertions
1 parent 7e4e56c commit 224f347

31 files changed

+98
-83
lines changed

system/Test/TestResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function getRedirectUrl(): ?string
268268
*/
269269
public function assertSessionHas(string $key, $value = null)
270270
{
271-
$this->assertTrue(array_key_exists($key, $_SESSION), "'{$key}' is not in the current \$_SESSION");
271+
$this->assertArrayHasKey($key, $_SESSION, "'{$key}' is not in the current \$_SESSION");
272272

273273
if (is_null($value)) {
274274
return;
@@ -290,7 +290,7 @@ public function assertSessionHas(string $key, $value = null)
290290
*/
291291
public function assertSessionMissing(string $key)
292292
{
293-
$this->assertFalse(array_key_exists($key, $_SESSION), "'{$key}' should not be present in \$_SESSION.");
293+
$this->assertArrayNotHasKey($key, $_SESSION, "'{$key}' should not be present in \$_SESSION.");
294294
}
295295

296296
//--------------------------------------------------------------------

tests/system/CLI/CLITest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function testParseCommand()
276276
];
277277
$_SERVER['argc'] = 3;
278278
CLI::init();
279-
$this->assertEquals(null, CLI::getSegment(3));
279+
$this->assertNull(CLI::getSegment(3));
280280
$this->assertEquals('b', CLI::getSegment(1));
281281
$this->assertEquals('c', CLI::getSegment(2));
282282
$this->assertEquals('b/c', CLI::getURI());
@@ -301,7 +301,7 @@ public function testParseCommandMixed()
301301
'sure',
302302
];
303303
CLI::init();
304-
$this->assertEquals(null, CLI::getSegment(7));
304+
$this->assertNull(CLI::getSegment(7));
305305
$this->assertEquals('b', CLI::getSegment(1));
306306
$this->assertEquals('c', CLI::getSegment(2));
307307
$this->assertEquals('d', CLI::getSegment(3));
@@ -362,12 +362,12 @@ public function testWindow()
362362
$height = new ReflectionProperty(CLI::class, 'height');
363363
$height->setAccessible(true);
364364
$height->setValue(null);
365-
$this->assertTrue(is_int(CLI::getHeight()));
365+
$this->assertIsInt(CLI::getHeight());
366366

367367
$width = new ReflectionProperty(CLI::class, 'width');
368368
$width->setAccessible(true);
369369
$width->setValue(null);
370-
$this->assertTrue(is_int(CLI::getWidth()));
370+
$this->assertIsInt(CLI::getWidth());
371371
}
372372

373373
/**

tests/system/Cache/Handlers/FileHandlerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ public function testDeleteMatchingPrefix()
163163
}
164164

165165
// check that there are 101 items is cache store
166-
$this->assertSame(101, count($this->fileHandler->getCacheInfo()));
166+
$this->assertCount(101, $this->fileHandler->getCacheInfo());
167167

168168
// Checking that given the prefix "key_1", deleteMatching deletes 13 keys:
169169
// (key_1, key_10, key_11, key_12, key_13, key_14, key_15, key_16, key_17, key_18, key_19, key_100, key_101)
170170
$this->assertSame(13, $this->fileHandler->deleteMatching('key_1*'));
171171

172172
// check that there remains (101 - 13) = 88 items is cache store
173-
$this->assertSame(88, count($this->fileHandler->getCacheInfo()));
173+
$this->assertCount(88, $this->fileHandler->getCacheInfo());
174174

175175
// Clear all files
176176
$this->fileHandler->clean();
@@ -184,14 +184,14 @@ public function testDeleteMatchingSuffix()
184184
}
185185

186186
// check that there are 101 items is cache store
187-
$this->assertSame(101, count($this->fileHandler->getCacheInfo()));
187+
$this->assertCount(101, $this->fileHandler->getCacheInfo());
188188

189189
// Checking that given the suffix "1", deleteMatching deletes 11 keys:
190190
// (key_1, key_11, key_21, key_31, key_41, key_51, key_61, key_71, key_81, key_91, key_101)
191191
$this->assertSame(11, $this->fileHandler->deleteMatching('*1'));
192192

193193
// check that there remains (101 - 13) = 88 items is cache store
194-
$this->assertSame(90, count($this->fileHandler->getCacheInfo()));
194+
$this->assertCount(90, $this->fileHandler->getCacheInfo());
195195

196196
// Clear all files
197197
$this->fileHandler->clean();

tests/system/CommonFunctionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function testSessionVariableNotThere()
194194
$this->injectSessionMock();
195195

196196
$_SESSION['bogus'] = 'Hi there';
197-
$this->assertEquals(null, session('notbogus'));
197+
$this->assertNull(session('notbogus'));
198198
}
199199

200200
public function testRouteTo()

tests/system/Config/BaseConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,6 @@ public function testDidDiscovery()
257257
$method = $this->getPrivateMethodInvoker($config, 'registerProperties');
258258
$method();
259259

260-
$this->assertSame(true, $this->getPrivateProperty($config, 'didDiscovery'));
260+
$this->assertTrue($this->getPrivateProperty($config, 'didDiscovery'));
261261
}
262262
}

tests/system/Config/FactoriesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testSetsOptions()
6262
$result = Factories::getOptions('widgets');
6363

6464
$this->assertEquals('bar', $result['foo']);
65-
$this->assertEquals(true, $result['preferApp']);
65+
$this->assertTrue($result['preferApp']);
6666
}
6767

6868
public function testUsesConfigOptions()

tests/system/Database/ConfigTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public function testConnectionGroupWithDSN()
130130
$this->assertEquals('3306', $this->getPrivateProperty($conn, 'port'));
131131
$this->assertEquals('MySQLi', $this->getPrivateProperty($conn, 'DBDriver'));
132132
$this->assertEquals('test_', $this->getPrivateProperty($conn, 'DBPrefix'));
133-
$this->assertEquals(true, $this->getPrivateProperty($conn, 'pConnect'));
133+
$this->assertTrue($this->getPrivateProperty($conn, 'pConnect'));
134134
$this->assertEquals('latin1', $this->getPrivateProperty($conn, 'charset'));
135135
$this->assertEquals('latin1_swedish_ci', $this->getPrivateProperty($conn, 'DBCollat'));
136-
$this->assertEquals(true, $this->getPrivateProperty($conn, 'strictOn'));
136+
$this->assertTrue($this->getPrivateProperty($conn, 'strictOn'));
137137
$this->assertEquals([], $this->getPrivateProperty($conn, 'failover'));
138138
}
139139

@@ -150,10 +150,10 @@ public function testConnectionGroupWithDSNPostgre()
150150
$this->assertEquals('5432', $this->getPrivateProperty($conn, 'port'));
151151
$this->assertEquals('Postgre', $this->getPrivateProperty($conn, 'DBDriver'));
152152
$this->assertEquals('test_', $this->getPrivateProperty($conn, 'DBPrefix'));
153-
$this->assertEquals(false, $this->getPrivateProperty($conn, 'pConnect'));
153+
$this->assertFalse($this->getPrivateProperty($conn, 'pConnect'));
154154
$this->assertEquals('utf8', $this->getPrivateProperty($conn, 'charset'));
155155
$this->assertEquals('utf8_general_ci', $this->getPrivateProperty($conn, 'DBCollat'));
156-
$this->assertEquals(true, $this->getPrivateProperty($conn, 'strictOn'));
156+
$this->assertTrue($this->getPrivateProperty($conn, 'strictOn'));
157157
$this->assertEquals([], $this->getPrivateProperty($conn, 'failover'));
158158
$this->assertEquals('5', $this->getPrivateProperty($conn, 'connect_timeout'));
159159
$this->assertEquals('1', $this->getPrivateProperty($conn, 'sslmode'));
@@ -178,10 +178,10 @@ public function testConnectionGroupWithDSNPostgreNative()
178178
$this->assertEquals('5432', $this->getPrivateProperty($conn, 'port'));
179179
$this->assertEquals('Postgre', $this->getPrivateProperty($conn, 'DBDriver'));
180180
$this->assertEquals('t_', $this->getPrivateProperty($conn, 'DBPrefix'));
181-
$this->assertEquals(false, $this->getPrivateProperty($conn, 'pConnect'));
181+
$this->assertFalse($this->getPrivateProperty($conn, 'pConnect'));
182182
$this->assertEquals('utf8', $this->getPrivateProperty($conn, 'charset'));
183183
$this->assertEquals('utf8_general_ci', $this->getPrivateProperty($conn, 'DBCollat'));
184-
$this->assertEquals(true, $this->getPrivateProperty($conn, 'strictOn'));
184+
$this->assertTrue($this->getPrivateProperty($conn, 'strictOn'));
185185
$this->assertEquals([], $this->getPrivateProperty($conn, 'failover'));
186186
}
187187
}

tests/system/Database/Live/AliasTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testAlias()
2626
->where('j.name', 'Developer')
2727
->get();
2828

29-
$this->assertEquals(1, count($jobs->getResult()));
29+
$this->assertCount(1, $jobs->getResult());
3030
}
3131

3232
//--------------------------------------------------------------------

tests/system/Database/Live/BadQueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testBadQueryDebugFalse()
4949
$this->setPrivateProperty($this->db, 'DBDebug', false);
5050
// this throws an exception when DBDebug is true, but it'll return FALSE when DBDebug is false
5151
$query = $this->db->query('SELECT * FROM table_does_not_exist');
52-
$this->assertEquals(false, $query);
52+
$this->assertFalse($query);
5353

5454
// restore the DBDebug value in effect when this unit test began
5555
$this->setPrivateProperty($this->db, 'DBDebug', self::$origDebug);

tests/system/Database/Live/ConnectTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public function testConnectWithMultipleCustomGroups()
4141
{
4242
// We should have our test database connection already.
4343
$instances = $this->getPrivateProperty(Database::class, 'instances');
44-
$this->assertEquals(1, count($instances));
44+
$this->assertCount(1, $instances);
4545

4646
$db1 = Database::connect($this->group1);
4747
$db2 = Database::connect($this->group2);
4848

4949
$this->assertNotSame($db1, $db2);
5050

5151
$instances = $this->getPrivateProperty(Database::class, 'instances');
52-
$this->assertEquals(3, count($instances));
52+
$this->assertCount(3, $instances);
5353
}
5454

5555
public function testConnectReturnsProvidedConnection()

tests/system/Database/Live/DEBugTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testDBDebugFalse()
2727
{
2828
$this->setPrivateProperty($this->db, 'DBDebug', false);
2929
$result = $this->db->simpleQuery('SELECT * FROM db_error');
30-
$this->assertEquals(false, $result);
30+
$this->assertFalse($result);
3131
}
3232

3333
public function tearDown(): void

tests/system/Database/Live/GetTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ public function testGetFieldData()
163163
$this->assertEquals('int', $typeTest[5]->type_name); //INTEGER
164164
$this->assertEquals('float', $typeTest[6]->type_name); //FLOAT
165165
$this->assertEquals('numeric', $typeTest[7]->type_name); //NUMERIC
166-
$this->assertEquals(null, $typeTest[8]->type_name); //DATE
167-
$this->assertEquals(null, $typeTest[9]->type_name); //TIME
168-
$this->assertEquals(null, $typeTest[10]->type_name); //DATETIME
166+
$this->assertNull($typeTest[8]->type_name); //DATE
167+
$this->assertNull($typeTest[9]->type_name); //TIME
168+
$this->assertNull($typeTest[10]->type_name); //DATETIME
169169
$this->assertEquals('bigint', $typeTest[11]->type_name); //BIGINT
170170
$this->assertEquals('real', $typeTest[12]->type_name); //REAL
171171
$this->assertEquals('decimal', $typeTest[13]->type_name); //DECIMAL

tests/system/Database/Live/SQLite/AlterTableTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,29 @@ public function testFromTableFillsDetails()
8585
$fields = $this->getPrivateProperty($this->table, 'fields');
8686

8787
$this->assertCount(4, $fields);
88-
$this->assertTrue(array_key_exists('id', $fields));
88+
$this->assertArrayHasKey('id', $fields);
8989
$this->assertNull($fields['id']['default']);
9090
$this->assertTrue($fields['id']['null']);
9191
$this->assertEquals('integer', strtolower($fields['id']['type']));
9292

93-
$this->assertTrue(array_key_exists('name', $fields));
93+
$this->assertArrayHasKey('name', $fields);
9494
$this->assertNull($fields['name']['default']);
9595
$this->assertFalse($fields['name']['null']);
9696
$this->assertEquals('varchar', strtolower($fields['name']['type']));
9797

98-
$this->assertTrue(array_key_exists('email', $fields));
98+
$this->assertArrayHasKey('email', $fields);
9999
$this->assertNull($fields['email']['default']);
100100
$this->assertTrue($fields['email']['null']);
101101
$this->assertEquals('varchar', strtolower($fields['email']['type']));
102102

103103
$keys = $this->getPrivateProperty($this->table, 'keys');
104104

105105
$this->assertCount(3, $keys);
106-
$this->assertTrue(array_key_exists('foo_name', $keys));
106+
$this->assertArrayHasKey('foo_name', $keys);
107107
$this->assertEquals(['fields' => ['name'], 'type' => 'index'], $keys['foo_name']);
108-
$this->assertTrue(array_key_exists('id', $keys));
108+
$this->assertArrayHasKey('id', $keys);
109109
$this->assertEquals(['fields' => ['id'], 'type' => 'primary'], $keys['id']);
110-
$this->assertTrue(array_key_exists('id', $keys));
110+
$this->assertArrayHasKey('id', $keys);
111111
$this->assertEquals(['fields' => ['id'], 'type' => 'primary'], $keys['id']);
112112
}
113113

@@ -135,8 +135,8 @@ public function testDropColumnMaintainsKeys()
135135

136136
$oldKeys = $this->db->getIndexData('foo');
137137

138-
$this->assertTrue(array_key_exists('foo_name', $oldKeys));
139-
$this->assertTrue(array_key_exists('foo_email', $oldKeys));
138+
$this->assertArrayHasKey('foo_name', $oldKeys);
139+
$this->assertArrayHasKey('foo_email', $oldKeys);
140140

141141
$result = $this->table
142142
->fromTable('foo')
@@ -145,8 +145,8 @@ public function testDropColumnMaintainsKeys()
145145

146146
$newKeys = $this->db->getIndexData('foo');
147147

148-
$this->assertFalse(array_key_exists('foo_name', $newKeys));
149-
$this->assertTrue(array_key_exists('foo_email', $newKeys));
148+
$this->assertArrayNotHasKey('foo_name', $newKeys);
149+
$this->assertArrayHasKey('foo_email', $newKeys);
150150

151151
$this->assertTrue($result);
152152
}
@@ -189,7 +189,7 @@ public function testDropForeignKeySuccess()
189189
$this->assertTrue($result);
190190

191191
$keys = $this->db->getForeignKeyData('aliens');
192-
$this->assertTrue(empty($keys));
192+
$this->assertEmpty($keys);
193193
}
194194

195195
public function testProcessCopiesOldData()

tests/system/EntityTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ public function testIssetWorksWithMapping()
144144

145145
$attributes = $this->getPrivateProperty($entity, 'attributes');
146146

147-
$this->assertTrue(array_key_exists('foo', $attributes));
148-
$this->assertFalse(array_key_exists('bar', $attributes));
147+
$this->assertArrayHasKey('foo', $attributes);
148+
$this->assertArrayNotHasKey('bar', $attributes);
149149
}
150150

151151
public function testUnsetWorksWithMapping()
@@ -492,9 +492,9 @@ public function testCastNullable()
492492
{
493493
$entity = $this->getCastNullableEntity();
494494

495-
$this->assertSame(null, $entity->string_null);
495+
$this->assertNull($entity->string_null);
496496
$this->assertSame('', $entity->string_empty);
497-
$this->assertSame(null, $entity->integer_null);
497+
$this->assertNull($entity->integer_null);
498498
$this->assertSame(0, $entity->integer_0);
499499
$this->assertSame('value', $entity->string_value_not_null);
500500
}

tests/system/HTTP/CLIRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public function testFetchGlobalWithArrayChildElement()
423423
$this->request->setGlobal('post', $post);
424424

425425
$this->assertEquals(['zipcode' => 90210], $this->request->fetchGlobal('post', 'clients[address]'));
426-
$this->assertEquals(null, $this->request->fetchGlobal('post', 'clients[zipcode]'));
426+
$this->assertNull($this->request->fetchGlobal('post', 'clients[zipcode]'));
427427
}
428428

429429
public function testFetchGlobalWithKeylessArrayChildElement()

tests/system/HTTP/CURLRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public function testDebugOptionTrue()
575575
$this->assertEquals(1, $options[CURLOPT_VERBOSE]);
576576

577577
$this->assertArrayHasKey(CURLOPT_STDERR, $options);
578-
$this->assertTrue(is_resource($options[CURLOPT_STDERR]));
578+
$this->assertIsResource($options[CURLOPT_STDERR]);
579579
}
580580

581581
public function testDebugOptionFalse()
@@ -604,7 +604,7 @@ public function testDebugOptionFile()
604604
$this->assertEquals(1, $options[CURLOPT_VERBOSE]);
605605

606606
$this->assertArrayHasKey(CURLOPT_STDERR, $options);
607-
$this->assertTrue(is_resource($options[CURLOPT_STDERR]));
607+
$this->assertIsResource($options[CURLOPT_STDERR]);
608608
}
609609

610610
//--------------------------------------------------------------------

tests/system/HTTP/Files/FileCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function testExtensionGuessing()
195195
$this->assertInstanceOf(UploadedFile::class, $file);
196196
$this->assertEquals('txt', $file->getExtension());
197197
// but not client mime type
198-
$this->assertEquals(null, Mimes::guessExtensionFromType($file->getClientMimeType(), $file->getClientExtension()));
198+
$this->assertNull(Mimes::guessExtensionFromType($file->getClientMimeType(), $file->getClientExtension()));
199199

200200
// proposed extension does not match finfo_open mime type (text/plain)
201201
// but can be resolved by reverse searching

tests/system/HTTP/HeaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testHeaderSetters()
6060

6161
$header = new Header($name);
6262
$this->assertEquals($name, $header->getName());
63-
$this->assertEquals(null, $header->getValue());
63+
$this->assertEmpty($header->getValue());
6464
$this->assertEquals($name . ': ', (string) $header);
6565

6666
$name = 'foo2';

tests/system/HTTP/RequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function testFetchGlobalWithArrayChildElement()
238238
$this->request->setGlobal('post', $post);
239239

240240
$this->assertEquals(['zipcode' => 90210], $this->request->fetchGlobal('post', 'clients[address]'));
241-
$this->assertEquals(null, $this->request->fetchGlobal('post', 'clients[zipcode]'));
241+
$this->assertNull($this->request->fetchGlobal('post', 'clients[zipcode]'));
242242
}
243243

244244
public function testFetchGlobalWithKeylessArrayChildElement()

tests/system/HTTP/URITest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public function testSetPortInvalidValuesSilent()
298298

299299
$uri->setSilent()->setPort(70000);
300300

301-
$this->assertEquals(null, $uri->getPort());
301+
$this->assertNull($uri->getPort());
302302
}
303303

304304
//--------------------------------------------------------------------

tests/system/Helpers/HTMLHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function testDocTypeDefault()
295295
public function testDocTypeInvalid()
296296
{
297297
$target = 'good-guess';
298-
$this->assertEquals(false, doctype($target));
298+
$this->assertEmpty(doctype($target));
299299
}
300300

301301
// ------------------------------------------------------------------------

tests/system/Helpers/NumberHelperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function testRomanNumber()
2727

2828
public function testRomanNumberRange()
2929
{
30-
$this->assertEquals(null, number_to_roman(-1));
31-
$this->assertEquals(null, number_to_roman(0));
32-
$this->assertEquals(null, number_to_roman(4000));
30+
$this->assertNull(number_to_roman(-1));
31+
$this->assertNull(number_to_roman(0));
32+
$this->assertNull(number_to_roman(4000));
3333
}
3434

3535
public function testFormatNumber()

tests/system/Honeypot/HoneypotTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public function testHasntContent()
7070
unset($_POST[$this->config->name]);
7171
$this->request = Services::request();
7272

73-
$this->assertEquals(false, $this->honeypot->hasContent($this->request));
73+
$this->assertFalse($this->honeypot->hasContent($this->request));
7474
}
7575

7676
public function testHasContent()
7777
{
78-
$this->assertEquals(true, $this->honeypot->hasContent($this->request));
78+
$this->assertTrue($this->honeypot->hasContent($this->request));
7979
}
8080

8181
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)