8000 minor #26002 Improve assertions (carusogabriel) · symfony/symfony@9a3aa07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a3aa07

Browse files
minor #26002 Improve assertions (carusogabriel)
This PR was merged into the 3.4 branch. Discussion ---------- Improve assertions | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Following #25420 in `3.4` branch. Commits ------- 829f59d Improve assertions
2 parents 1d5c229 + 829f59d commit 9a3aa07

File tree

12 files changed

+20
-20
lines changed

12 files changed

+20
-20
lines changed

src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testResetService()
4040
$registry->resetManager();
4141

4242
$this->assertSame($foo, $container->get('foo'));
43-
$this->assertFalse(isset($foo->bar));
43+
$this->assertObjectNotHasAttribute('bar', $foo);
4444
}
4545
}
4646

src/Symfony/Bridge/Monolog/Tests/LoggerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testGetLogsWithDebugHandler()
2828
$logger = new Logger(__METHOD__, array($handler));
2929

3030
$this->assertTrue($logger->error('error message'));
31-
$this->assertSame(1, count($logger->getLogs()));
31+
$this->assertCount(1, $logger->getLogs());
3232
}
3333

3434
public function testGetLogsWithoutDebugProcessor()
@@ -93,7 +93,7 @@ public function testGetLogsWithDebugProcessor()
9393
$logger = new Logger(__METHOD__, array($handler), array($processor));
9494

9595
$this->assertTrue($logger->error('error message'));
96-
$this->assertSame(1, count($logger->getLogs()));
96+
$this->assertCount(1, $logger->getLogs());
9797
}
9898

9999
public function testCountErrorsWithDebugProcessor()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
11231123
$this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id));
11241124

11251125
$tag = $poolDefinition->getTag('cache.pool');
1126-
$this->assertTrue(isset($tag[0]['default_lifetime']), 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
1126+
$this->assertArrayHasKey('default_lifetime', $tag[0], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
11271127
$this->assertSame($defaultLifetime, $tag[0]['default_lifetime'], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
11281128

11291129
$parentDefinition = $poolDefinition;

src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testGetItems()
5353
$itemKey = $item->getKey();
5454

5555
$this->assertEquals($itemKey, $key, 'Keys must be preserved when fetching multiple items');
56-
$this->assertTrue(in_array($key, $keys), 'Cache key can not change.');
56+
$this->assertContains($key, $keys, 'Cache key can not change.');
5757
$this->assertFalse($item->isHit());
5858

5959
// Remove $key for $keys

src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testProxyfiedItem()
4343

4444
$proxyItem = $pool->getItem('foo');
4545

46-
$this->assertFalse($proxyItem === $item);
46+
$this->assertNotSame($item, $proxyItem);
4747
$pool->save($proxyItem->set('bar'));
4848
}
4949
}

src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testGetMultiple()
4747
$count = 0;
4848

4949
foreach ($items as $key => $item) {
50-
$this->assertTrue(in_array($key, $keys), 'Cache key can not change.');
50+
$this->assertContains($key, $keys, 'Cache key can not change.');
5151
$this->assertSame($default, $item);
5252

5353
// Remove $key for $keys

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function testHashedSignature($changeExpected, $changedLine, $changedCode)
100100
$signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
101101

102102
if ($changeExpected) {
103-
$this->assertTrue($expectedSignature !== $signature);
103+
$this->assertNotSame($expectedSignature, $signature);
104104
} else {
105105
$this->assertSame($expectedSignature, $signature);
106106
}

src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,9 @@ public function testCollectSubmittedDataExpandedFormsErrors()
690690

691691
$this->assertTrue($formData['has_children_error']);
692692
$this->assertTrue($child1Data['has_children_error']);
693-
$this->assertFalse(isset($child11Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
693+
$this->assertArrayNotHasKey('has_children_error', $child11Data, 'The leaf data does not contains "has_children_error" property.');
694694
$this->assertFalse($child2Data['has_children_error']);
695-
$this->assertFalse(isset($child21Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
695+
$this->assertArrayNotHasKey('has_children_error', $child21Data, 'The leaf data does not contains "has_children_error" property.');
696696
}
697697

698698
public function testReset()

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testConstruct()
3232
{
3333
$handler = new NativeSessionHandler();
3434

35-
$this->assertTrue($handler instanceof \SessionHandler);
35+
$this->assertInstanceOf('SessionHandler', $handler);
3636
$this->assertTrue($handler instanceof NativeSessionHandler);
3737
}
3838
}

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,14 +849,14 @@ public function testKernelReset()
849849
$kernel = new CustomProjectDirKernel();
850850
$kernel->boot();
851851

852-
$this->assertSame($containerClass, get_class($kernel->getContainer()));
852+
$this->assertInstanceOf($containerClass, $kernel->getContainer());
853853
$this->assertFileExists($containerFile);
854854
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
855855

856856
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
857857
$kernel->boot();
858858

859-
$this->assertTrue(get_class($kernel->getContainer()) !== $containerClass);
859+
$this->assertNotInstanceOf($containerClass, $kernel->getContainer());
860860
$this->assertFileExists($containerFile);
861861
$this->assertFileExists(dirname($containerFile).'.legacy');
862862
}

src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,22 @@ public function testStoreSpecialCharsInUrl()
8383
$profile = new Profile('simple_quote');
8484
$profile->setUrl('http://foo.bar/\'');
8585
$this->storage->write($profile);
86-
$this->assertTrue(false !== $this->storage->read('simple_quote'), '->write() accepts single quotes in URL');
86+
$this->assertNotFalse($this->storage->read('simple_quote'), '->write() accepts single quotes in URL');
8787

8888
$profile = new Profile('double_quote');
8989
$profile->setUrl('http://foo.bar/"');
9090
$this->storage->write($profile);
91-
$this->assertTrue(false !== $this->storage->read('double_quote'), '->write() accepts double quotes in URL');
91+
$this->assertNotFalse($this->storage->read('double_quote'), '->write() accepts double quotes in URL');
9292

9393
$profile = new Profile('backslash');
9494
$profile->setUrl('http://foo.bar/\\');
9595
$this->storage->write($profile);
96-
$this->assertTrue(false !== $this->storage->read('backslash'), '->write() accepts backslash in URL');
96+
$this->assertNotFalse($this->storage->read('backslash'), '->write() accepts backslash in URL');
9797

9898
$profile = new Profile('comma');
9999
$profile->setUrl('http://foo.bar/,');
100100
$this->storage->write($profile);
101-
$this->assertTrue(false !== $this->storage->read('comma'), '->write() accepts comma in URL');
101+
$this->assertNotFalse($this->storage->read('comma'), '->write() accepts comma in URL');
102102
}
103103

104104
public function testStoreDuplicateToken()
@@ -247,7 +247,7 @@ public function testPurge()
247247
$profile->setMethod('GET');
248248
$this->storage->write($profile);
249249

250-
$this->assertTrue(false !== $this->storage->read('token1'));
250+
$this->assertNotFalse($this->storage->read('token1'));
251251
$this->assertCount(1, $this->storage->find('127.0.0.1', '', 10, 'GET'));
252252

253253
$profile = new Profile('token2');
@@ -256,7 +256,7 @@ public function testPurge()
256256
$profile->setMethod('GET');
257257
$this->storage->write($profile);
258258

259-
$this->assertTrue(false !== $this->storage->read('token2'));
259+
$this->assertNotFalse($this->storage->read('token2'));
260260
$this->assertCount(2, $this->storage->find('127.0.0.1', '', 10, 'GET'));
261261

262262
$this->storage->purge();

src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public function testAddsThePrefixOnlyOnceWhenLoadingMultipleCollections()
357357
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
358358
$routes = $routeCollectionBuilder->build()->all();
359359

360-
$this->assertEquals(2, count($routes));
360+
$this->assertCount(2, $routes);
361361
$this->assertEquals('/other/a', $routes['a']->getPath());
362362
$this->assertEquals('/other/b', $routes['b']->getPath());
363363
}

0 commit comments

Comments
 (0)
0