Skip to content

Commit 4927d0c

Browse files
committed
changed some PHPUnit assertions to more specific ones
1 parent a4f0f0c commit 4927d0c

File tree

19 files changed

+55
-55
lines changed

19 files changed

+55
-55
lines changed

src/Symfony/Bridge/Propel1/Tests/Form/DataTransformer/CollectionToArrayTransformerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function testTransform()
3535
$result = $this->transformer->transform(new PropelObjectCollection());
3636

3737
$this->assertTrue(is_array($result));
38-
$this->assertEquals(0, count($result));
38+
$this->assertCount(0, $result);
3939
}
4040

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

4545
$this->assertTrue(is_array($result));
46-
$this->assertEquals(0, count($result));
46+
$this->assertCount(0, $result);
4747
}
4848

4949
/**
@@ -62,7 +62,7 @@ public function testTransformWithData()
6262
$result = $this->transformer->transform($coll);
6363

6464
$this->assertTrue(is_array($result));
65-
$this->assertEquals(2, count($result));
65+
$this->assertCount(2, $result);
6666
$this->assertEquals('foo', $result[0]);
6767
$this->assertEquals('bar', $result[1]);
6868
}
@@ -72,15 +72,15 @@ public function testReverseTransformWithNull()
7272
$result = $this->transformer->reverseTransform(null);
7373

7474
$this->assertInstanceOf('\PropelObjectCollection', $result);
75-
$this->assertEquals(0, count($result->getData()));
75+
$this->assertCount(0, $result->getData());
7676
}
7777

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

8282
$this->assertInstanceOf('\PropelObjectCollection', $result);
83-
$this->assertEquals(0, count($result->getData()));
83+
$this->assertCount(0, $result->getData());
8484
}
8585

8686
/**
@@ -101,7 +101,7 @@ public function testReverseTransformWithData()
101101
$this->assertInstanceOf('\PropelObjectCollection', $result);
102102

103103
$this->assertTrue(is_array($data));
104-
$this->assertEquals(2, count($data));
104+
$this->assertCount(2, $data);
105105
$this->assertEquals('foo', $data[0]);
106106
$this->assertEquals('bar', $data[1]);
107107
$this->assertsame($inputData, $data);

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/TemplateFinderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function ($template) { return $template->getLogicalName(); },
4646
$finder->findAllTemplates()
4747
);
4848

49-
$this->assertEquals(6, count($templates), '->findAllTemplates() find all templates in the bundles and global folders');
49+
$this->assertCount(6, $templates, '->findAllTemplates() find all templates in the bundles and global folders');
5050
$this->assertContains('BaseBundle::base.format.engine', $templates);
5151
$this->assertContains('BaseBundle::this.is.a.template.format.engine', $templates);
5252
$this->assertContains('BaseBundle:controller:base.format.engine', $templates);

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testMapperPassWithTwoTaggedLoaders()
7373

7474
$this->pass->process($this->builder);
7575
$calls = $this->chainLoader->getMethodCalls();
76-
$this->assertEquals(2, count($calls));
76+
$this->assertCount(2, $calls);
7777
$this->assertEquals('addLoader', $calls[0][0]);
7878
}
7979

src/Symfony/Component/Config/Tests/Definition/Builder/NodeBuilderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testAddingANewNodeType()
4545
->setNodeClass('newtype', $class)
4646
->node('', 'newtype');
4747

48-
$this->assertEquals(get_class($node), $class);
48+
$this->assertInstanceOf($class, $node);
4949
}
5050

5151
public function testOverridingAnExistingNodeType()
@@ -57,7 +57,7 @@ public function testOverridingAnExistingNodeType()
5757
->setNodeClass('variable', $class)
5858
->node('', 'variable');
5959

60-
$this->assertEquals(get_class($node), $class);
60+
$this->assertInstanceOf($class, $node);
6161
}
6262

6363
public function testNodeTypesAreNotCaseSensitive()
@@ -67,25 +67,25 @@ public function testNodeTypesAreNotCaseSensitive()
6767
$node1 = $builder->node('', 'VaRiAbLe');
6868
$node2 = $builder->node('', 'variable');
6969

70-
$this->assertEquals(get_class($node1), get_class($node2));
70+
$this->assertInstanceOf(get_class($node1), $node2);
7171

7272
$builder->setNodeClass('CuStOm', __NAMESPACE__.'\\SomeNodeDefinition');
7373

7474
$node1 = $builder->node('', 'CUSTOM');
7575
$node2 = $builder->node('', 'custom');
7676

77-
$this->assertEquals(get_class($node1), get_class($node2));
77+
$this->assertInstanceOf(get_class($node1), $node2);
7878
}
7979

8080
public function testNumericNodeCreation()
8181
{
8282
$builder = new NodeBuilder();
8383

8484
$node = $builder->integerNode('foo')->min(3)->max(5);
85-
$this->assertEquals('Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition', get_class($node));
85+
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition', $node);
8686

8787
$node = $builder->floatNode('bar')->min(3.0)->max(5.0);
88-
$this->assertEquals('Symfony\Component\Config\Definition\Builder\FloatNodeDefinition', get_class($node));
88+
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\FloatNodeDefinition', $node);
8989
}
9090
}
9191

src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public function testUsingACustomNodeBuilder()
2828

2929
$nodeBuilder = $root->children();
3030

31-
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder');
31+
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder', $nodeBuilder);
3232

3333
$nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();
3434

35-
$this->assertEquals(get_class($nodeBuilder), 'Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder');
35+
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\NodeBuilder', $nodeBuilder);
3636
}
3737

3838
public function testOverrideABuiltInNodeType()
@@ -42,7 +42,7 @@ public function testOverrideABuiltInNodeType()
4242

4343
$definition = $root->children()->variableNode('variable');
4444

45-
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition');
45+
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition', $definition);
4646
}
4747

4848
public function testAddANodeType()
@@ -52,7 +52,7 @@ public function testAddANodeType()
5252

5353
$definition = $root->children()->barNode('variable');
5454

55-
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Tests\Definition\Builder\BarNodeDefinition');
55+
$this->assertInstanceOf('Symfony\Component\Config\Tests\Definition\Builder\BarNodeDefinition', $definition);
5656
}
5757

5858
public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
@@ -62,7 +62,7 @@ public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
6262

6363
$definition = $root->children()->booleanNode('boolean');
6464

65-
$this->assertEquals(get_class($definition), 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition');
65+
$this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition', $definition);
6666
}
6767

6868
public function testPrototypedArrayNodeUseTheCustomNodeBuilder()

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public function testAll()
9797
{
9898
$application = new Application();
9999
$commands = $application->all();
100-
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($commands['help']), '->all() returns the registered commands');
100+
$this->assertInstanceOf('Symfony\\Component\\Console\\Command\\HelpCommand', $commands['help'], '->all() returns the registered commands');
101101

102102
$application->add(new \FooCommand());
103103
$commands = $application->all('foo');
104-
$this->assertEquals(1, count($commands), '->all() takes a namespace as its first argument');
104+
$this->assertCount(1, $commands, '->all() takes a namespace as its first argument');
105105
}
106106

107107
public function testRegister()
@@ -481,8 +481,8 @@ public function testRun()
481481
$application->run();
482482
ob_end_clean();
483483

484-
$this->assertSame('Symfony\Component\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
485-
$this->assertSame('Symfony\Component\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given');
484+
$this->assertInstanceOf('Symfony\Component\Console\Input\ArgvInput', $command->input, '->run() creates an ArgvInput by default if none is given');
485+
$this->assertInstanceOf('Symfony\Component\Console\Output\ConsoleOutput', $command->output, '->run() creates a ConsoleOutput by default if none is given');
486486

487487
$application = new Application();
488488
$application->setAutoExit(false);

src/Symfony/Component/CssSelector/Tests/Parser/ParserTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testPseudoElements($source, $element, $pseudo)
4747
{
4848
$parser = new Parser();
4949
$selectors = $parser->parse($source);
50-
$this->assertEquals(1, count($selectors));
50+
$this->assertCount(1, $selectors);
5151

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

6565
/** @var SelectorNode $selector */
6666
$selector = $selectors[0];
@@ -72,7 +72,7 @@ public function testParseSeries($series, $a, $b)
7272
{
7373
$parser = new Parser();
7474
$selectors = $parser->parse(sprintf(':nth-child(%s)', $series));
75-
$this->assertEquals(1, count($selectors));
75+
$this->assertCount(1, $selectors);
7676

7777
/** @var FunctionNode $function */
7878
$function = $selectors[0]->getTree();
@@ -84,7 +84,7 @@ public function testParseSeriesException($series)
8484
{
8585
$parser = new Parser();
8686
$selectors = $parser->parse(sprintf(':nth-child(%s)', $series));
87-
$this->assertEquals(1, count($selectors));
87+
$this->assertCount(1, $selectors);
8888

8989
/** @var FunctionNode $function */
9090
$function = $selectors[0]->getTree();

src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/ClassParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testParse($source, $representation)
2424
{
2525
$parser = new ClassParser();
2626
$selectors = $parser->parse($source);
27-
$this->assertEquals(1, count($selectors));
27+
$this->assertCount(1, $selectors);
2828

2929
/** @var SelectorNode $selector */
3030
$selector = $selectors[0];

src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/ElementParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testParse($source, $representation)
2424
{
2525
$parser = new ElementParser();
2626
$selectors = $parser->parse($source);
27-
$this->assertEquals(1, count($selectors));
27+
$this->assertCount(1, $selectors);
2828

2929
/** @var SelectorNode $selector */
3030
$selector = $selectors[0];

src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/EmptyStringParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function testParse()
2323
{
2424
$parser = new EmptyStringParser();
2525
$selectors = $parser->parse('');
26-
$this->assertEquals(1, count($selectors));
26+
$this->assertCount(1, $selectors);
2727

2828
/** @var SelectorNode $selector */
2929
$selector = $selectors[0];
3030
$this->assertEquals('Element[*]', (string) $selector->getTree());
3131

3232
$selectors = $parser->parse('this will produce an empty array');
33-
$this->assertEquals(0, count($selectors));
33+
$this->assertCount(0, $selectors);
3434
}
3535
}

src/Symfony/Component/CssSelector/Tests/Parser/Shortcut/HashParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testParse($source, $representation)
2424
{
2525
$parser = new HashParser();
2626
$selectors = $parser->parse($source);
27-
$this->assertEquals(1, count($selectors));
27+
$this->assertCount(1, $selectors);
2828

2929
/** @var SelectorNode $selector */
3030
$selector = $selectors[0];

src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function testFlattenHttpException(\Exception $exception, $statusCode)
113113

114114
$this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.');
115115
$this->assertEquals($exception->getCode(), $flattened->getCode(), 'The code is copied from the original exception.');
116-
$this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception');
116+
$this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
117117

118118
}
119119

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testParseFile()
8989
}
9090

9191
$xml = $m->invoke($loader, self::$fixturesPath.'/xml/services1.xml');
92-
$this->assertEquals('Symfony\\Component\\DependencyInjection\\SimpleXMLElement', get_class($xml), '->parseFile() returns an SimpleXMLElement object');
92+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\SimpleXMLElement', $xml, '->parseFile() returns an SimpleXMLElement object');
9393
}
9494

9595
public function testLoadParameters()
@@ -134,28 +134,28 @@ public function testLoadAnonymousServices()
134134
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
135135
$loader->load('services5.xml');
136136
$services = $container->getDefinitions();
137-
$this->assertEquals(4, count($services), '->load() attributes unique ids to anonymous services');
137+
$this->assertCount(4, $services, '->load() attributes unique ids to anonymous services');
138138

139139
// anonymous service as an argument
140140
$args = $services['foo']->getArguments();
141-
$this->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
142-
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($args[0]), '->load() converts anonymous services to references to "normal" services');
141+
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
142+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
143143
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
144144
$inner = $services[(string) $args[0]];
145145
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
146146

147147
// inner anonymous services
148148
$args = $inner->getArguments();
149-
$this->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
150-
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($args[0]), '->load() converts anonymous services to references to "normal" services');
149+
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
150+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
151151
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
152152
$inner = $services[(string) $args[0]];
153153
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
154154

155155
// anonymous service as a property
156156
$properties = $services['foo']->getProperties();
157157
$property = $properties['p'];
158-
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Reference', get_class($property), '->load() converts anonymous services to references to "normal" services');
158+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
159159
$this->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
160160
$inner = $services[(string) $property];
161161
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
@@ -168,7 +168,7 @@ public function testLoadServices()
168168
$loader->load('services6.xml');
169169
$services = $container->getDefinitions();
170170
$this->assertTrue(isset($services['foo']), '->load() parses <service> elements');
171-
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Definition', get_class($services['foo']), '->load() converts <service> element to Definition instances');
171+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts <service> element to Definition instances');
172172
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
173173
$this->assertEquals('container', $services['scope.container']->getScope());
174174
$this->assertEquals('custom', $services['scope.custom']->getScope());
@@ -361,11 +361,11 @@ public function testNoNamingConflictsForAnonymousServices()
361361
$loader1 = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml/extension1'));
362362
$loader1->load('services.xml');
363363
$services = $container->getDefinitions();
364-
$this->assertEquals(2, count($services), '->load() attributes unique ids to anonymous services');
364+
$this->assertCount(2, $services, '->load() attributes unique ids to anonymous services');
365365
$loader2 = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml/extension2'));
366366
$loader2->load('services.xml');
367367
$services = $container->getDefinitions();
368-
$this->assertEquals(4, count($services), '->load() attributes unique ids to anonymous services');
368+
$this->assertCount(4, $services, '->load() attributes unique ids to anonymous services');
369369

370370
$services = $container->getDefinitions();
371371
$args1 = $services['extension1.foo']->getArguments();

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function testLoadServices()
113113
$loader->load('services6.yml');
114114
$services = $container->getDefinitions();
115115
$this->assertTrue(isset($services['foo']), '->load() parses service elements');
116-
$this->assertEquals('Symfony\\Component\\DependencyInjection\\Definition', get_class($services['foo']), '->load() converts service element to Definition instances');
116+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts service element to Definition instances');
117117
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
118118
$this->assertEquals('container', $services['scope.container']->getScope());
119119
$this->assertEquals('custom', $services['scope.custom']->getScope());

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public function testGet()
584584
{
585585
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
586586

587-
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($form->get('bar')), '->get() returns the field object associated with the given name');
587+
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Field\\InputFormField', $form->get('bar'), '->get() returns the field object associated with the given name');
588588

589589
try {
590590
$form->get('foo');
@@ -599,8 +599,8 @@ public function testAll()
599599
$form = $this->createForm('<form method="post"><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
600600

601601
$fields = $form->all();
602-
$this->assertEquals(1, count($fields), '->all() return an array of form field objects');
603-
$this->assertEquals('Symfony\\Component\\DomCrawler\\Field\\InputFormField', get_class($fields['bar']), '->all() return an array of form field objects');
602+
$this->assertCount(1, $fields, '->all() return an array of form field objects');
603+
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Field\\InputFormField', $fields['bar'], '->all() return an array of form field objects');
604604
}
605605

606606
public function testSubmitWithoutAFormButton()

0 commit comments

Comments
 (0)