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
This commit is contained in:
Nicolas Grekas 2018-02-04 11:29:43 +01:00
commit 9a3aa07d35
12 changed files with 20 additions and 20 deletions

View File

@ -40,7 +40,7 @@ class ManagerRegistryTest extends TestCase
$registry->resetManager();
$this->assertSame($foo, $container->get('foo'));
$this->assertFalse(isset($foo->bar));
$this->assertObjectNotHasAttribute('bar', $foo);
}
}

View File

@ -28,7 +28,7 @@ class LoggerTest extends TestCase
$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()
@ -93,7 +93,7 @@ class LoggerTest extends TestCase
$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()

View File

@ -1123,7 +1123,7 @@ abstract class FrameworkExtensionTest extends TestCase
$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;

View File

@ -53,7 +53,7 @@ class NullAdapterTest extends TestCase
$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

View File

@ -43,7 +43,7 @@ class ProxyAdapterTest extends AdapterTestCase
$proxyItem = $pool->getItem('foo');
$this->assertFalse($proxyItem === $item);
$this->assertNotSame($item, $proxyItem);
$pool->save($proxyItem->set('bar'));
}
}

View File

@ -47,7 +47,7 @@ class NullCacheTest extends TestCase
$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

View File

@ -100,7 +100,7 @@ EOPHP;
$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);
}

View File

@ -690,9 +690,9 @@ class FormDataCollectorTest extends TestCase
$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()

View File

@ -32,7 +32,7 @@ class NativeSessionHandlerTest extends TestCase
{
$handler = new NativeSessionHandler();
$this->assertTrue($handler instanceof \SessionHandler);
$this->assertInstanceOf('SessionHandler', $handler);
$this->assertTrue($handler instanceof NativeSessionHandler);
}
}

View File

@ -849,14 +849,14 @@ EOF;
$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');
}

View File

@ -83,22 +83,22 @@ class FileProfilerStorageTest extends TestCase
$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()
@ -247,7 +247,7 @@ class FileProfilerStorageTest extends TestCase
$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');
@ -256,7 +256,7 @@ class FileProfilerStorageTest extends TestCase
$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();

View File

@ -357,7 +357,7 @@ class RouteCollectionBuilderTest extends TestCase
$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());
}