8000 Improve assertions by carusogabriel · Pull Request #26002 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Improve assertions #26002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testResetService()
$registry->resetManager();

$this->assertSame($foo, $container->get('foo'));
$this->assertFalse(isset($foo->bar));
$this->assertObjectNotHasAttribute('bar', $foo);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Monolog/Tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testGetLogsWithDebugHandler()
$logger = new Logger(__METHOD__, array($handler));

$this->assertTrue($logger->error('error message'));
$this->assertSame(1, count($logger->getLogs()));
$this->assertCount(1, $logger->getLogs());
}

public function testGetLogsWithoutDebugProcessor()
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testGetLogsWithDebugProcessor()
$logger = new Logger(__METHOD__, array($handler), array($processor));

$this->assertTrue($logger->error('error message'));
$this->assertSame(1, count($logger->getLogs()));
$this->assertCount(1, $logger->getLogs());
}

public function testCountErrorsWithDebugProcessor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
$this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id));

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

$parentDefinition = $poolDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testGetItems()
$itemKey = $item->getKey();

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

// Remove $key for $keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testProxyfiedItem()

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

$this->assertFalse($proxyItem === $item);
$this->assertNotSame($item, $proxyItem);
$pool->save($proxyItem->set('bar'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testGetMultiple()
$count = 0;

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

// Remove $key for $keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testHashedSignature($changeExpected, $changedLine, $changedCode)
$signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));

if ($changeExpected) {
$this->assertTrue($expectedSignature !== $signature);
$this->assertNotSame($expectedSignature, $signature);
} else {
$this->assertSame($expectedSignature, $signature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,9 @@ public function testCollectSubmittedDataExpandedFormsErrors()

$this->assertTrue($formData['has_children_error']);
$this->assertTrue($child1Data['has_children_error']);
$this->assertFalse(isset($child11Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
$this->assertArrayNotHasKey('has_children_error', $child11Data, 'The leaf data does not contains "has_children_error" property.');
$this->assertFalse($child2Data['has_children_error']);
$this->assertFalse(isset($child21Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
$this->assertArrayNotHasKey('has_children_error', $child21Data, 'The leaf data does not contains "has_children_error" property.');
}

public function testReset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testConstruct()
{
$handler = new NativeSessionHandler();

$this->assertTrue($handler instanceof \SessionHandler);
$this->assertInstanceOf('SessionHandler', $handler);
$this->assertTrue($handler instanceof NativeSessionHandler);
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,14 +849,14 @@ public function testKernelReset()
$kernel = new CustomProjectDirKernel();
$kernel->boot();

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

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

$this->assertTrue(get_class($kernel->getContainer()) !== $containerClass);
$this->assertNotInstanceOf($containerClass, $kernel->getContainer());
$this->assertFileExists($containerFile);
$this->assertFileExists(dirname($containerFile).'.legacy');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ public function testStoreSpecialCharsInUrl()
$profile = new Profile('simple_quote');
$profile->setUrl('http://foo.bar/\'');
$this->storage->write($profile);
$this->assertTrue(false !== $this->storage->read('simple_quote'), '->write() accepts single quotes in URL');
$this->assertNotFalse($this->storage->read('simple_quote'), '->write() accepts single quotes in URL');

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

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

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

public function testStoreDuplicateToken()
Expand Down Expand Up @@ -247,7 +247,7 @@ public function testPurge()
$profile->setMethod('GET');
$this->storage->write($profile);

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

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

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

$this->storage->purge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function testAddsThePrefixOnlyOnceWhenLoadingMultipleCollections()
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
$routes = $routeCollectionBuilder->build()->all();

$this->assertEquals(2, count($routes));
$this->assertCount(2, $routes);
$this->assertEquals('/other/a', $routes['a']->getPath());
$this->assertEquals('/other/b', $routes['b']->getPath());
}
Expand Down
0