Skip to content

Commit 05ab1cd

Browse files
Merge branch '2.8' into 3.3
* 2.8: Refactoring tests.
2 parents 33f1698 + 263eda3 commit 05ab1cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+146
-146
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function testAccess()
225225
foreach ($rules as list($matcherId, $attributes, $channel)) {
226226
$requestMatcher = $container->getDefinition($matcherId);
227227

228-
$this->assertFalse(isset($matcherIds[$matcherId]));
228+
$this->assertArrayNotHasKey($matcherId, $matcherIds);
229229
$matcherIds[$matcherId] = true;
230230

231231
$i = count($matcherIds);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testAppendingSomeNode()
3232
->append($child);
3333

3434
$this->assertCount(3, $this->getField($parent, 'children'));
35-
$this->assertTrue(in_array($child, $this->getField($parent, 'children')));
35+
$this->assertContains($child, $this->getField($parent, 'children'));
3636
}
3737

3838
/**

src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ public function testResourcesWithDifferentPatternsAreDifferent()
178178
$resourceA = new DirectoryResource($this->directory, '/.xml$/');
179179
$resourceB = new DirectoryResource($this->directory, '/.yaml$/');
180180

181-
$this->assertEquals(2, count(array_unique(array($resourceA, $resourceB))));
181+
$this->assertCount(2, array_unique(array($resourceA, $resourceB)));
182182
}
183183
}

src/Symfony/Component/CssSelector/Tests/XPath/TranslatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testXmlLang($css, array $elementsId)
3737
$translator = new Translator();
3838
$document = new \SimpleXMLElement(file_get_contents(__DIR__.'/Fixtures/lang.xml'));
3939
$elements = $document->xpath($translator->cssToXPath($css));
40-
$this->assertEquals(count($elementsId), count($elements));
40+
$this->assertCount(count($elementsId), $elements);
4141
foreach ($elements as $element) {
4242
$this->assertTrue(in_array($element->attributes()->id, $elementsId));
4343
}

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testDefinitions()
7272

7373
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
7474
$this->assertEquals($foo, $builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
75-
$this->assertTrue($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fluid interface by returning the service reference');
75+
$this->assertSame($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')), $foo, '->setDefinition() implements a fluid interface by returning the service reference');
7676

7777
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
7878
$this->assertEquals(array_merge($definitions, $defs), $builder->getDefinitions(), '->addDefinitions() adds the service definitions');
@@ -241,7 +241,7 @@ public function testAliases()
241241
$this->assertFalse($builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
242242
$this->assertEquals('foo', (string) $builder->getAlias('bar'), '->getAlias() returns the aliased service');
243243
$this->assertTrue($builder->has('bar'), '->setAlias() defines a new service');
244-
$this->assertTrue($builder->get('bar') === $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
244+
$this->assertSame($builder->get('bar'), $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
245245

246246
try {
247247
$builder->setAlias('foobar', 'foobar');
@@ -286,8 +286,8 @@ public function testSetAliases()
286286
$builder->setAliases(array('bar' => 'foo', 'foobar' => 'foo'));
287287

288288
$aliases = $builder->getAliases();
289-
$this->assertTrue(isset($aliases['bar']));
290-
$this->assertTrue(isset($aliases['foobar']));
289+
$this->assertArrayHasKey('bar', $aliases);
290+
$this->assertArrayHasKey('foobar', $aliases);
291291
}
292292

293293
public function testAddAliases()
@@ -297,8 +297,8 @@ public function testAddAliases()
297297
$builder->addAliases(array('foobar' => 'foo'));
298298

299299
$aliases = $builder->getAliases();
300-
$this->assertTrue(isset($aliases['bar']));
301-
$this->assertTrue(isset($aliases['foobar']));
300+
$this->assertArrayHasKey('bar', $aliases);
301+
$this->assertArrayHasKey('foobar', $aliases);
302302
}
303303

304304
public function testSetReplacesAlias()
@@ -561,7 +561,7 @@ public function testMerge()
561561
$this->assertEquals(array('service_container', 'foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
562562

563563
$aliases = $container->getAliases();
564-
$this->assertTrue(isset($aliases['alias_for_foo']));
564+
$this->assertArrayHasKey('alias_for_foo', $aliases);
565565
$this->assertEquals('foo', (string) $aliases['alias_for_foo']);
566566

567567
$container = new ContainerBuilder();
@@ -891,7 +891,7 @@ public function testExtension()
891891
$container->setResourceTracking(false);
892892

893893
$container->registerExtension($extension = new \ProjectExtension());
894-
$this->assertTrue($container->getExtension('project') === $extension, '->registerExtension() registers an extension');
894+
$this->assertSame($container->getExtension('project'), $extension, '->registerExtension() registers an extension');
895895

896896
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException');
897897
$container->getExtension('no_registered');

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testLoadWithExternalEntitiesDisabled()
9999

100100
libxml_disable_entity_loader($disableEntities);
101101

102-
$this->assertTrue(count($containerBuilder->getParameterBag()->all()) > 0, 'Parameters can be read from the config file.');
102+
$this->assertGreaterThan(0, $containerBuilder->getParameterBag()->all(), 'Parameters can be read from the config file.');
103103
}
104104

105105
public function testLoadParameters()
@@ -189,7 +189,7 @@ public function testLoadAnonymousServices()
189189
$args = $services['foo']->getArguments();
190190
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
191191
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
192-
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
192+
$this->assertArrayHasKey((string) $args[0], $services, '->load() makes a reference to the created ones');
193193
$inner = $services[(string) $args[0]];
194194
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
195195
$this->assertFalse($inner->isPublic());
@@ -198,7 +198,7 @@ public function testLoadAnonymousServices()
198198
$args = $inner->getArguments();
199199
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
200200
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
201-
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
201+
$this->assertArrayHasKey((string) $args[0], $services, '->load() makes a reference to the created ones');
202202
$inner = $services[(string) $args[0]];
203203
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
204204
$this->assertFalse($inner->isPublic());
@@ -207,7 +207,7 @@ public function testLoadAnonymousServices()
207207
$properties = $services['foo']->getProperties();
208208
$property = $properties['p'];
209209
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
210-
$this->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
210+
$this->assertArrayHasKey((string) $property, $services, '->load() makes a reference to the created ones');
211211
$inner = $services[(string) $property];
212212
$this->assertEquals('BuzClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
213213
$this->assertFalse($inner->isPublic());
@@ -236,7 +236,7 @@ public function testLoadServices()
236236
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
237237
$loader->load('services6.xml');
238238
$services = $container->getDefinitions();
239-
$this->assertTrue(isset($services['foo']), '->load() parses <service> elements');
239+
$this->assertArrayHasKey('foo', $services, '->load() parses <service> elements');
240240
$this->assertFalse($services['not_shared']->isShared(), '->load() parses shared flag');
241241
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts <service> element to Definition instances');
242242
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
@@ -253,10 +253,10 @@ public function testLoadServices()
253253
$this->assertSame(array(null, 'getInstance'), $services['new_factory4']->getFactory(), '->load() accepts factory tag without class');
254254

255255
$aliases = $container->getAliases();
256-
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
256+
$this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses <service> elements');
257257
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
258258
$this->assertTrue($aliases['alias_for_foo']->isPublic());
259-
$this->assertTrue(isset($aliases['another_alias_for_foo']));
259+
$this->assertArrayHasKey('another_alias_for_foo', $aliases);
260260
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
261261
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
262262

@@ -379,8 +379,8 @@ public function testExtensions()
379379
$services = $container->getDefinitions();
380380
$parameters = $container->getParameterBag()->all();
381381

382-
$this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
383-
$this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
382+
$this->assertArrayHasKey('project.service.bar', $services, '->load() parses extension elements');
383+
$this->assertArrayHasKey('project.parameter.bar', $parameters, '->load() parses extension elements');
384384

385385
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
386386
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
@@ -395,8 +395,8 @@ public function testExtensions()
395395
$services = $container->getDefinitions();
396396
$parameters = $container->getParameterBag()->all();
397397

398-
$this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
399-
$this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
398+
$this->assertArrayHasKey('project.service.bar', $services, '->load() parses extension elements');
399+
$this->assertArrayHasKey('project.parameter.bar', $parameters, '->load() parses extension elements');
400400

401401
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
402402
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
@@ -518,8 +518,8 @@ public function testXmlNamespaces()
518518
$loader->load('namespaces.xml');
519519
$services = $container->getDefinitions();
520520

521-
$this->assertTrue(isset($services['foo']), '->load() parses <srv:service> elements');
522-
$this->assertEquals(1, count($services['foo']->getTag('foo.tag')), '->load parses <srv:tag> elements');
521+
$this->assertArrayHasKey('foo', $services, '->load() parses <srv:service> elements');
522+
$this->assertCount(1, $services['foo']->getTag('foo.tag'), '->load parses <srv:tag> elements');
523523
$this->assertEquals(array(array('setBar', array('foo'))), $services['foo']->getMethodCalls(), '->load() parses the <srv:call> tag');
524524
}
525525

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function testLoadServices()
139139
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
140140
$loader->load('services6.yml');
141141
$services = $container->getDefinitions();
142-
$this->assertTrue(isset($services['foo']), '->load() parses service elements');
142+
$this->assertArrayHasKey('foo', $services, '->load() parses service elements');
143143
$this->assertFalse($services['not_shared']->isShared(), '->load() parses the shared flag');
144144
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts service element to Definition instances');
145145
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
@@ -157,10 +157,10 @@ public function testLoadServices()
157157
$this->assertEquals(array('foo', new Reference('baz')), $services['Acme\WithShortCutArgs']->getArguments(), '->load() parses short service definition');
158158

159159
$aliases = $container->getAliases();
160-
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses aliases');
160+
$this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses aliases');
161161
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
162162
$this->assertTrue($aliases['alias_for_foo']->isPublic());
163-
$this->assertTrue(isset($aliases['another_alias_for_foo']));
163+
$this->assertArrayHasKey('another_alias_for_foo', $aliases);
164164
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
165165
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
166166
$this->assertTrue(isset($aliases['another_third_alias_for_foo']));
@@ -204,8 +204,8 @@ public function testExtensions()
204204
$services = $container->getDefinitions();
205205
$parameters = $container->getParameterBag()->all();
206206

207-
$this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements');
208-
$this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements');
207+
$this->assertArrayHasKey('project.service.bar', $services, '->load() parses extension elements');
208+
$this->assertArrayHasKey('project.parameter.bar', $parameters, '->load() parses extension elements');
209209

210210
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
211211
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function testAddXmlContentWithErrors()
204204
EOF
205205
, 'UTF-8');
206206

207-
$this->assertTrue(count(libxml_get_errors()) > 1);
207+
$this->assertGreaterThan(1, libxml_get_errors());
208208

209209
libxml_clear_errors();
210210
libxml_use_internal_errors($internalErrors);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,15 @@ public function testOffsetUnset()
376376
{
377377
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
378378
unset($form['foo']);
379-
$this->assertFalse(isset($form['foo']), '->offsetUnset() removes a field');
379+
$this->assertArrayNotHasKey('foo', $form, '->offsetUnset() removes a field');
380380
}
381381

382382
public function testOffsetExists()
383383
{
384384
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
385385

386-
$this->assertTrue(isset($form['foo']), '->offsetExists() return true if the field exists');
387-
$this->assertFalse(isset($form['bar']), '->offsetExists() return false if the field does not exist');
386+
$this->assertArrayHasKey('foo', $form, '->offsetExists() return true if the field exists');
387+
$this->assertArrayNotHasKey('bar', $form, '->offsetExists() return false if the field does not exist');
388388
}
389389

390390
public function testGetValues()

src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function testGetListenersOnLazyLoad()
143143

144144
$listeners = $dispatcher->getListeners();
145145

146-
$this->assertTrue(isset($listeners['onEvent']));
146+
$this->assertArrayHasKey('onEvent', $listeners);
147147

148148
$this->assertCount(1, $dispatcher->getListeners('onEvent'));
149149
}

0 commit comments

Comments
 (0)