changed some PHPUnit assertions to more specific ones

This commit is contained in:
Fabien Potencier 2014-03-01 18:20:14 +01:00
parent a4f0f0cc98
commit 4927d0c8a3
19 changed files with 55 additions and 55 deletions

View File

@ -35,7 +35,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
$result = $this->transformer->transform(new PropelObjectCollection());
$this->assertTrue(is_array($result));
$this->assertEquals(0, count($result));
$this->assertCount(0, $result);
}
public function testTransformWithNull()
@ -43,7 +43,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
$result = $this->transformer->transform(null);
$this->assertTrue(is_array($result));
$this->assertEquals(0, count($result));
$this->assertCount(0, $result);
}
/**
@ -62,7 +62,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
$result = $this->transformer->transform($coll);
$this->assertTrue(is_array($result));
$this->assertEquals(2, count($result));
$this->assertCount(2, $result);
$this->assertEquals('foo', $result[0]);
$this->assertEquals('bar', $result[1]);
}
@ -72,7 +72,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
$result = $this->transformer->reverseTransform(null);
$this->assertInstanceOf('\PropelObjectCollection', $result);
$this->assertEquals(0, count($result->getData()));
$this->assertCount(0, $result->getData());
}
public function testReverseTransformWithEmptyString()
@ -80,7 +80,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
$result = $this->transformer->reverseTransform('');
$this->assertInstanceOf('\PropelObjectCollection', $result);
$this->assertEquals(0, count($result->getData()));
$this->assertCount(0, $result->getData());
}
/**
@ -101,7 +101,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
$this->assertInstanceOf('\PropelObjectCollection', $result);
$this->assertTrue(is_array($data));
$this->assertEquals(2, count($data));
$this->assertCount(2, $data);
$this->assertEquals('foo', $data[0]);
$this->assertEquals('bar', $data[1]);
$this->assertsame($inputData, $data);

View File

@ -46,7 +46,7 @@ class TemplateFinderTest extends TestCase
$finder->findAllTemplates()
);
$this->assertEquals(6, count($templates), '->findAllTemplates() find all templates in the bundles and global folders');
$this->assertCount(6, $templates, '->findAllTemplates() find all templates in the bundles and global folders');
$this->assertContains('BaseBundle::base.format.engine', $templates);
$this->assertContains('BaseBundle::this.is.a.template.format.engine', $templates);
$this->assertContains('BaseBundle:controller:base.format.engine', $templates);

View File

@ -73,7 +73,7 @@ class TwigLoaderPassTest extends \PHPUnit_Framework_TestCase
$this->pass->process($this->builder);
$calls = $this->chainLoader->getMethodCalls();
$this->assertEquals(2, count($calls));
$this->assertCount(2, $calls);
$this->assertEquals('addLoader', $calls[0][0]);
}

View File

@ -45,7 +45,7 @@ class NodeBuilderTest extends \PHPUnit_Framework_TestCase
->setNodeClass('newtype', $class)
->node('', 'newtype');
$this->assertEquals(get_class($node), $class);
$this->assertInstanceOf($class, $node);
}
public function testOverridingAnExistingNodeType()
@ -57,7 +57,7 @@ class NodeBuilderTest extends \PHPUnit_Framework_TestCase
->setNodeClass('variable', $class)
->node('', 'variable');
$this->assertEquals(get_class($node), $class);
$this->assertInstanceOf($class, $node);
}
public function testNodeTypesAreNotCaseSensitive()
@ -67,14 +67,14 @@ class NodeBuilderTest extends \PHPUnit_Framework_TestCase
$node1 = $builder->node('', 'VaRiAbLe');
$node2 = $builder->node('', 'variable');
$this->assertEquals(get_class($node1), get_class($node2));
$this->assertInstanceOf(get_class($node1), $node2);
$builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition');
$node1 = $builder->node('', 'CUSTOM');
$node2 = $builder->node('', 'custom');
$this->assertEquals(get_class($node1), get_class($node2));
$this->assertInstanceOf(get_class($node1), $node2);
}
public function testNumericNodeCreation()
@ -82,10 +82,10 @@ class NodeBuilderTest extends \PHPUnit_Framework_TestCase
$builder = new NodeBuilder();
$node = $builder->integerNode('foo')->min(3)->max(5);
$this->assertEquals('Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition', get_class($node));
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition', $node);
$node = $builder->floatNode('bar')->min(3.0)->max(5.0);
$this->assertEquals('Symfony\Component\Config\Definition\Builder\FloatNodeDefinition', get_class($node));
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\FloatNodeDefinition', $node);
}
}

View File

@ -28,11 +28,11 @@ class TreeBuilderTest extends \PHPUnit_Framework_TestCase
$nodeBuilder = $root->children();
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder');
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder', $nodeBuilder);
$nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder');
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder', $nodeBuilder);
}
public function testOverrideABuiltInNodeType()
@ -42,7 +42,7 @@ class TreeBuilderTest extends \PHPUnit_Framework_TestCase
$definition = $root->children()->variableNode('variable');
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition');
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition', $definition);
}
public function testAddANodeType()
@ -52,7 +52,7 @@ class TreeBuilderTest extends \PHPUnit_Framework_TestCase
$definition = $root->children()->barNode('variable');
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Tests\Definition\Builder\BarNodeDefinition');
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\BarNodeDefinition', $definition);
}
public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
@ -62,7 +62,7 @@ class TreeBuilderTest extends \PHPUnit_Framework_TestCase
$definition = $root->children()->booleanNode('boolean');
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition');
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition', $definition);
}
public function testPrototypedArrayNodeUseTheCustomNodeBuilder()

View File

@ -97,11 +97,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
{
$application = new Application();
$commands = $application->all();
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($commands['help']), '->all() returns the registered commands');
$this->assertInstanceOf('Symfony\\Component\\Console\\Command\\HelpCommand', $commands['help'], '->all() returns the registered commands');
$application->add(new \FooCommand());
$commands = $application->all('foo');
$this->assertEquals(1, count($commands), '->all() takes a namespace as its first argument');
$this->assertCount(1, $commands, '->all() takes a namespace as its first argument');
}
public function testRegister()
@ -481,8 +481,8 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->run();
ob_end_clean();
$this->assertSame('Symfony\Component\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
$this->assertSame('Symfony\Component\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given');
$this->assertInstanceOf('Symfony\Component\Console\Input\ArgvInput', $command->input, '->run() creates an ArgvInput by default if none is given');
$this->assertInstanceOf('Symfony\Component\Console\Output\ConsoleOutput', $command->output, '->run() creates a ConsoleOutput by default if none is given');
$application = new Application();
$application->setAutoExit(false);

View File

@ -47,7 +47,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new Parser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var SelectorNode $selector */
$selector = $selectors[0];
@ -60,7 +60,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new Parser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var SelectorNode $selector */
$selector = $selectors[0];
@ -72,7 +72,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new Parser();
$selectors = $parser->parse(sprintf(':nth-child(%s)', $series));
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var FunctionNode $function */
$function = $selectors[0]->getTree();
@ -84,7 +84,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new Parser();
$selectors = $parser->parse(sprintf(':nth-child(%s)', $series));
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var FunctionNode $function */
$function = $selectors[0]->getTree();

View File

@ -24,7 +24,7 @@ class ClassParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new ClassParser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var SelectorNode $selector */
$selector = $selectors[0];

View File

@ -24,7 +24,7 @@ class ElementParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new ElementParser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var SelectorNode $selector */
$selector = $selectors[0];

View File

@ -23,13 +23,13 @@ class EmptyStringParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new EmptyStringParser();
$selectors = $parser->parse('');
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var SelectorNode $selector */
$selector = $selectors[0];
$this->assertEquals('Element[*]', (string) $selector->getTree());
$selectors = $parser->parse('this will produce an empty array');
$this->assertEquals(0, count($selectors));
$this->assertCount(0, $selectors);
}
}

View File

@ -24,7 +24,7 @@ class HashParserTest extends \PHPUnit_Framework_TestCase
{
$parser = new HashParser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);
/** @var SelectorNode $selector */
$selector = $selectors[0];

View File

@ -113,7 +113,7 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
$this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
$this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception');
$this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
}

View File

@ -89,7 +89,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
}
$xml = $m->invoke($loader, self::$fixturesPath.'/xml/services1.xml');
$this->assertEquals('Symfony\\Component\\DependencyInjection\\SimpleXMLElement', get_class($xml), '->parseFile() returns an SimpleXMLElement object');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\SimpleXMLElement', $xml, '->parseFile() returns an SimpleXMLElement object');
}
public function testLoadParameters()
@ -134,20 +134,20 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services5.xml');
$services = $container->getDefinitions();
$this->assertEquals(4, count($services), '->load() attributes unique ids to anonymous services');
$this->assertCount(4, $services, '->load() attributes unique ids to anonymous services');
// anonymous service as an argument
$args = $services['foo']->getArguments();
$this->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($args[0]), '->load() converts anonymous services to references to "normal" services');
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
$inner = $services[(string) $args[0]];
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
// inner anonymous services
$args = $inner->getArguments();
$this->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($args[0]), '->load() converts anonymous services to references to "normal" services');
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
$inner = $services[(string) $args[0]];
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
@ -155,7 +155,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
// anonymous service as a property
$properties = $services['foo']->getProperties();
$property = $properties['p'];
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($property), '->load() converts anonymous services to references to "normal" services');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
$this->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
$inner = $services[(string) $property];
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
@ -168,7 +168,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->load('services6.xml');
$services = $container->getDefinitions();
$this->assertTrue(isset($services['foo']), '->load() parses <service> elements');
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Definition', get_class($services['foo']), '->load() converts <service> element to Definition instances');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts <service> element to Definition instances');
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
$this->assertEquals('container', $services['scope.container']->getScope());
$this->assertEquals('custom', $services['scope.custom']->getScope());
@ -361,11 +361,11 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader1 = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml/extension1'));
$loader1->load('services.xml');
$services = $container->getDefinitions();
$this->assertEquals(2, count($services), '->load() attributes unique ids to anonymous services');
$this->assertCount(2, $services, '->load() attributes unique ids to anonymous services');
$loader2 = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml/extension2'));
$loader2->load('services.xml');
$services = $container->getDefinitions();
$this->assertEquals(4, count($services), '->load() attributes unique ids to anonymous services');
$this->assertCount(4, $services, '->load() attributes unique ids to anonymous services');
$services = $container->getDefinitions();
$args1 = $services['extension1.foo']->getArguments();

View File

@ -113,7 +113,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->load('services6.yml');
$services = $container->getDefinitions();
$this->assertTrue(isset($services['foo']), '->load() parses service elements');
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Definition', get_class($services['foo']), '->load() converts service element to Definition instances');
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts service element to Definition instances');
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
$this->assertEquals('container', $services['scope.container']->getScope());
$this->assertEquals('custom', $services['scope.custom']->getScope());

View File

@ -584,7 +584,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
{
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($form->get('bar')), '->get() returns the field object associated with the given name');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Field\\InputFormField', $form->get('bar'), '->get() returns the field object associated with the given name');
try {
$form->get('foo');
@ -599,8 +599,8 @@ class FormTest extends \PHPUnit_Framework_TestCase
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
$fields = $form->all();
$this->assertEquals(1, count($fields), '->all() return an array of form field objects');
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($fields['bar']), '->all() return an array of form field objects');
$this->assertCount(1, $fields, '->all() return an array of form field objects');
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Field\\InputFormField', $fields['bar'], '->all() return an array of form field objects');
}
public function testSubmitWithoutAFormButton()

View File

@ -554,7 +554,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
$finder = $this->buildFinder($adapter);
$finder->in($locations)->depth('< 1')->name('test.php');
$this->assertEquals(1, count($finder));
$this->assertCount(1, $finder);
}
/**
@ -735,7 +735,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
$this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator());
$this->fail('Finder should throw an exception when opening a non-readable directory.');
} catch (\Exception $e) {
$this->assertEquals('Symfony\\Component\\Finder\\Exception\\AccessDeniedException', get_class($e));
$this->assertInstanceOf('Symfony\\Component\\Finder\\Exception\\AccessDeniedException', $e);
}
// restore original permissions

View File

@ -150,6 +150,6 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase
}
$this->assertEquals(count($flashes), $i);
$this->assertEquals(0, count($this->bag->all()));
$this->assertCount(0, $this->bag->all());
}
}

View File

@ -217,7 +217,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
$this->session->set('hello', 'world');
$this->session->set('symfony2', 'rocks');
$this->assertEquals(2, count($this->session));
$this->assertCount(2, $this->session);
}
public function testGetMeta()

View File

@ -79,11 +79,11 @@ class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
{
$storage = new PdoSessionHandler($this->pdo, array('db_table' => 'sessions'), array());
$storage->write('foo', 'bar');
$this->assertEquals(1, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
$this->assertCount(1, $this->pdo->query('SELECT * FROM sessions')->fetchAll());
$storage->destroy('foo');
$this->assertEquals(0, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
$this->assertCount(0, $this->pdo->query('SELECT * FROM sessions')->fetchAll());
}
public function testSessionGC()
@ -93,9 +93,9 @@ class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
$storage->write('foo', 'bar');
$storage->write('baz', 'bar');
$this->assertEquals(2, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
$this->assertCount(2, $this->pdo->query('SELECT * FROM sessions')->fetchAll());
$storage->gc(-1);
$this->assertEquals(0, count($this->pdo->query('SELECT * FROM sessions')->fetchAll()));
$this->assertCount(0, $this->pdo->query('SELECT * FROM sessions')->fetchAll());
}
}