Skip to content

Commit

Permalink
changed some PHPUnit assertions to more specific ones
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 1, 2014
1 parent a4f0f0c commit 4927d0c
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 55 deletions.
Expand Up @@ -35,15 +35,15 @@ public function testTransform()
$result = $this->transformer->transform(new PropelObjectCollection());

$this->assertTrue(is_array($result));
$this->assertEquals(0, count($result));
$this->assertCount(0, $result);
}

public function testTransformWithNull()
{
$result = $this->transformer->transform(null);

$this->assertTrue(is_array($result));
$this->assertEquals(0, count($result));
$this->assertCount(0, $result);
}

/**
Expand All @@ -62,7 +62,7 @@ public function testTransformWithData()
$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]);
}
Expand All @@ -72,15 +72,15 @@ public function testReverseTransformWithNull()
$result = $this->transformer->reverseTransform(null);

$this->assertInstanceOf('\PropelObjectCollection', $result);
$this->assertEquals(0, count($result->getData()));
$this->assertCount(0, $result->getData());
}

public function testReverseTransformWithEmptyString()
{
$result = $this->transformer->reverseTransform('');

$this->assertInstanceOf('\PropelObjectCollection', $result);
$this->assertEquals(0, count($result->getData()));
$this->assertCount(0, $result->getData());
}

/**
Expand All @@ -101,7 +101,7 @@ public function testReverseTransformWithData()
$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);
Expand Down
Expand Up @@ -46,7 +46,7 @@ function ($template) { return $template->getLogicalName(); },
$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);
Expand Down
Expand Up @@ -73,7 +73,7 @@ public function testMapperPassWithTwoTaggedLoaders()

$this->pass->process($this->builder);
$calls = $this->chainLoader->getMethodCalls();
$this->assertEquals(2, count($calls));
$this->assertCount(2, $calls);
$this->assertEquals('addLoader', $calls[0][0]);
}

Expand Down
Expand Up @@ -45,7 +45,7 @@ public function testAddingANewNodeType()
->setNodeClass('newtype', $class)
->node('', 'newtype');

$this->assertEquals(get_class($node), $class);
$this->assertInstanceOf($class, $node);
}

public function testOverridingAnExistingNodeType()
Expand All @@ -57,7 +57,7 @@ public function testOverridingAnExistingNodeType()
->setNodeClass('variable', $class)
->node('', 'variable');

$this->assertEquals(get_class($node), $class);
$this->assertInstanceOf($class, $node);
}

public function testNodeTypesAreNotCaseSensitive()
Expand All @@ -67,25 +67,25 @@ public function testNodeTypesAreNotCaseSensitive()
$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()
{
$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);
}
}

Expand Down
Expand Up @@ -28,11 +28,11 @@ public function testUsingACustomNodeBuilder()

$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()
Expand All @@ -42,7 +42,7 @@ public function testOverrideABuiltInNodeType()

$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()
Expand All @@ -52,7 +52,7 @@ public function testAddANodeType()

$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()
Expand All @@ -62,7 +62,7 @@ public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()

$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()
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -97,11 +97,11 @@ public function testAll()
{
$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()
Expand Down Expand Up @@ -481,8 +481,8 @@ public function testRun()
$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);
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php
Expand Up @@ -47,7 +47,7 @@ public function testPseudoElements($source, $element, $pseudo)
{
$parser = new Parser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);

/** @var SelectorNode $selector */
$selector = $selectors[0];
Expand All @@ -60,7 +60,7 @@ public function testSpecificity($source, $value)
{
$parser = new Parser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);

/** @var SelectorNode $selector */
$selector = $selectors[0];
Expand All @@ -72,7 +72,7 @@ public function testParseSeries($series, $a, $b)
{
$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();
Expand All @@ -84,7 +84,7 @@ public function testParseSeriesException($series)
{
$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();
Expand Down
Expand Up @@ -24,7 +24,7 @@ public function testParse($source, $representation)
{
$parser = new ClassParser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);

/** @var SelectorNode $selector */
$selector = $selectors[0];
Expand Down
Expand Up @@ -24,7 +24,7 @@ public function testParse($source, $representation)
{
$parser = new ElementParser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);

/** @var SelectorNode $selector */
$selector = $selectors[0];
Expand Down
Expand Up @@ -23,13 +23,13 @@ public function testParse()
{
$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);
}
}
Expand Up @@ -24,7 +24,7 @@ public function testParse($source, $representation)
{
$parser = new HashParser();
$selectors = $parser->parse($source);
$this->assertEquals(1, count($selectors));
$this->assertCount(1, $selectors);

/** @var SelectorNode $selector */
$selector = $selectors[0];
Expand Down
Expand Up @@ -113,7 +113,7 @@ public function testFlattenHttpException(\Exception $exception, $statusCode)

$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');

}

Expand Down
Expand Up @@ -89,7 +89,7 @@ public function testParseFile()
}

$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()
Expand Down Expand Up @@ -134,28 +134,28 @@ public function testLoadAnonymousServices()
$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');

// 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');
Expand All @@ -168,7 +168,7 @@ public function testLoadServices()
$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());
Expand Down Expand Up @@ -361,11 +361,11 @@ public function testNoNamingConflictsForAnonymousServices()
$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();
Expand Down
Expand Up @@ -113,7 +113,7 @@ public function testLoadServices()
$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());
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Expand Up @@ -584,7 +584,7 @@ public function testGet()
{
$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');
Expand All @@ -599,8 +599,8 @@ public function testAll()
$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()
Expand Down

0 comments on commit 4927d0c

Please sign in to comment.