Skip to content

Commit ae0be37

Browse files
Merge branch '2.7' into 2.8
* 2.7: Refactoring tests.
2 parents 8849cc2 + 1dd3a41 commit ae0be37

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

Tests/ContainerBuilderTest.php

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

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

5454
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
5555
$this->assertEquals(array_merge($definitions, $defs), $builder->getDefinitions(), '->addDefinitions() adds the service definitions');
@@ -189,7 +189,7 @@ public function testAliases()
189189
$this->assertFalse($builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
190190
$this->assertEquals('foo', (string) $builder->getAlias('bar'), '->getAlias() returns the aliased service');
191191
$this->assertTrue($builder->has('bar'), '->setAlias() defines a new service');
192-
$this->assertTrue($builder->get('bar') === $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
192+
$this->assertSame($builder->get('bar'), $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
193193

194194
try {
195195
$builder->setAlias('foobar', 'foobar');
@@ -234,8 +234,8 @@ public function testSetAliases()
234234
$builder->setAliases(array('bar' => 'foo', 'foobar' => 'foo'));
235235

236236
$aliases = $builder->getAliases();
237-
$this->assertTrue(isset($aliases['bar']));
238-
$this->assertTrue(isset($aliases['foobar']));
237+
$this->assertArrayHasKey('bar', $aliases);
238+
$this->assertArrayHasKey('foobar', $aliases);
239239
}
240240

241241
public function testAddAliases()
@@ -245,8 +245,8 @@ public function testAddAliases()
245245
$builder->addAliases(array('foobar' => 'foo'));
246246

247247
$aliases = $builder->getAliases();
248-
$this->assertTrue(isset($aliases['bar']));
249-
$this->assertTrue(isset($aliases['foobar']));
248+
$this->assertArrayHasKey('bar', $aliases);
249+
$this->assertArrayHasKey('foobar', $aliases);
250250
}
251251

252252
public function testSetReplacesAlias()
@@ -506,7 +506,7 @@ public function testMerge()
506506
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
507507

508508
$aliases = $container->getAliases();
509-
$this->assertTrue(isset($aliases['alias_for_foo']));
509+
$this->assertArrayHasKey('alias_for_foo', $aliases);
510510
$this->assertEquals('foo', (string) $aliases['alias_for_foo']);
511511

512512
$container = new ContainerBuilder();
@@ -657,7 +657,7 @@ public function testExtension()
657657
$container->setResourceTracking(false);
658658

659659
$container->registerExtension($extension = new \ProjectExtension());
660-
$this->assertTrue($container->getExtension('project') === $extension, '->registerExtension() registers an extension');
660+
$this->assertSame($container->getExtension('project'), $extension, '->registerExtension() registers an extension');
661661

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

Tests/ContainerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function testSetAlsoSetsScopedService()
177177
$c->set('foo', $foo = new \stdClass(), 'foo');
178178

179179
$scoped = $this->getField($c, 'scopedServices');
180-
$this->assertTrue(isset($scoped['foo']['foo']), '->set() sets a scoped service');
180+
$this->assertArrayHasKey('foo', $scoped['foo'], '->set() sets a scoped service');
181181
$this->assertSame($foo, $scoped['foo']['foo'], '->set() sets a scoped service');
182182
}
183183

@@ -400,14 +400,14 @@ public function testEnterLeaveScopeWithChildScopes()
400400
$container->set('a', $a, 'bar');
401401

402402
$scoped = $this->getField($container, 'scopedServices');
403-
$this->assertTrue(isset($scoped['bar']['a']));
403+
$this->assertArrayHasKey('a', $scoped['bar']);
404404
$this->assertSame($a, $scoped['bar']['a']);
405405
$this->assertTrue($container->has('a'));
406406

407407
$container->leaveScope('foo');
408408

409409
$scoped = $this->getField($container, 'scopedServices');
410-
$this->assertFalse(isset($scoped['bar']));
410+
$this->assertArrayNotHasKey('bar', $scoped);
411411
$this->assertFalse($container->isScopeActive('foo'));
412412
$this->assertFalse($container->has('a'));
413413
}
@@ -433,14 +433,14 @@ public function testEnterScopeRecursivelyWithInactiveChildScopes()
433433
$container->set('a', $a, 'foo');
434434

435435
$scoped = $this->getField($container, 'scopedServices');
436-
$this->assertTrue(isset($scoped['foo']['a']));
436+
$this->assertArrayHasKey('a', $scoped['foo']);
437437
$this->assertSame($a, $scoped['foo']['a']);
438438
$this->assertTrue($container->has('a'));
439439

440440
$container->enterScope('foo');
441441

442442
$scoped = $this->getField($container, 'scopedServices');
443-
$this->assertFalse(isset($scoped['a']));
443+
$this->assertArrayNotHasKey('a', $scoped);
444444
$this->assertTrue($container->isScopeActive('foo'));
445445
$this->assertFalse($container->isScopeActive('bar'));
446446
$this->assertFalse($container->has('a'));
@@ -475,14 +475,14 @@ public function testEnterChildScopeRecursively()
475475
$container->set('a', $a, 'bar');
476476

477477
$scoped = $this->getField($container, 'scopedServices');
478-
$this->assertTrue(isset($scoped['bar']['a']));
478+
$this->assertArrayHasKey('a', $scoped['bar']);
479479
$this->assertSame($a, $scoped['bar']['a']);
480480
$this->assertTrue($container->has('a'));
481481

482482
$container->enterScope('bar');
483483

484484
$scoped = $this->getField($container, 'scopedServices');
485-
$this->assertFalse(isset($scoped['a']));
485+
$this->assertArrayNotHasKey('a', $scoped);
486486
$this->assertTrue($container->isScopeActive('foo'));
487487
$this->assertTrue($container->isScopeActive('bar'));
488488
$this->assertFalse($container->has('a'));

Tests/Loader/XmlFileLoaderTest.php

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

9595
libxml_disable_entity_loader($disableEntities);
9696

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

100100
public function testLoadParameters()
@@ -182,7 +182,7 @@ public function testLoadAnonymousServices()
182182
$args = $services['foo']->getArguments();
183183
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
184184
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
185-
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
185+
$this->assertArrayHasKey((string) $args[0], $services, '->load() makes a reference to the created ones');
186186
$inner = $services[(string) $args[0]];
187187
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
188188
$this->assertFalse($inner->isPublic());
@@ -191,7 +191,7 @@ public function testLoadAnonymousServices()
191191
$args = $inner->getArguments();
192192
$this->assertCount(1, $args, '->load() references anonymous services as "normal" ones');
193193
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $args[0], '->load() converts anonymous services to references to "normal" services');
194-
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
194+
$this->assertArrayHasKey((string) $args[0], $services, '->load() makes a reference to the created ones');
195195
$inner = $services[(string) $args[0]];
196196
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
197197
$this->assertFalse($inner->isPublic());
@@ -200,7 +200,7 @@ public function testLoadAnonymousServices()
200200
$properties = $services['foo']->getProperties();
201201
$property = $properties['p'];
202202
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
203-
$this->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
203+
$this->assertArrayHasKey((string) $property, $services, '->load() makes a reference to the created ones');
204204
$inner = $services[(string) $property];
205205
$this->assertEquals('BuzClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
206206
$this->assertFalse($inner->isPublic());
@@ -252,7 +252,7 @@ public function testLoadServices()
252252
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
253253
$loader->load('services6.xml');
254254
$services = $container->getDefinitions();
255-
$this->assertTrue(isset($services['foo']), '->load() parses <service> elements');
255+
$this->assertArrayHasKey('foo', $services, '->load() parses <service> elements');
256256
$this->assertFalse($services['not_shared']->isShared(), '->load() parses shared flag');
257257
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts <service> element to Definition instances');
258258
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
@@ -268,10 +268,10 @@ public function testLoadServices()
268268
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
269269

270270
$aliases = $container->getAliases();
271-
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
271+
$this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses <service> elements');
272272
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
273273
$this->assertTrue($aliases['alias_for_foo']->isPublic());
274-
$this->assertTrue(isset($aliases['another_alias_for_foo']));
274+
$this->assertArrayHasKey('another_alias_for_foo', $aliases);
275275
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
276276
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
277277

@@ -383,8 +383,8 @@ public function testExtensions()
383383
$services = $container->getDefinitions();
384384
$parameters = $container->getParameterBag()->all();
385385

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

389389
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
390390
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
@@ -399,8 +399,8 @@ public function testExtensions()
399399
$services = $container->getDefinitions();
400400
$parameters = $container->getParameterBag()->all();
401401

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

405405
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
406406
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
@@ -521,8 +521,8 @@ public function testXmlNamespaces()
521521
$loader->load('namespaces.xml');
522522
$services = $container->getDefinitions();
523523

524-
$this->assertTrue(isset($services['foo']), '->load() parses <srv:service> elements');
525-
$this->assertEquals(1, count($services['foo']->getTag('foo.tag')), '->load parses <srv:tag> elements');
524+
$this->assertArrayHasKey('foo', $services, '->load() parses <srv:service> elements');
525+
$this->assertCount(1, $services['foo']->getTag('foo.tag'), '->load parses <srv:tag> elements');
526526
$this->assertEquals(array(array('setBar', array('foo'))), $services['foo']->getMethodCalls(), '->load() parses the <srv:call> tag');
527527
}
528528

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function testLoadServices()
145145
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
146146
$loader->load('services6.yml');
147147
$services = $container->getDefinitions();
148-
$this->assertTrue(isset($services['foo']), '->load() parses service elements');
148+
$this->assertArrayHasKey('foo', $services, '->load() parses service elements');
149149
$this->assertFalse($services['not_shared']->isShared(), '->load() parses the shared flag');
150150
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts service element to Definition instances');
151151
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
@@ -161,10 +161,10 @@ public function testLoadServices()
161161
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
162162

163163
$aliases = $container->getAliases();
164-
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses aliases');
164+
$this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses aliases');
165165
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
166166
$this->assertTrue($aliases['alias_for_foo']->isPublic());
167-
$this->assertTrue(isset($aliases['another_alias_for_foo']));
167+
$this->assertArrayHasKey('another_alias_for_foo', $aliases);
168168
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
169169
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
170170

@@ -194,8 +194,8 @@ public function testExtensions()
194194
$services = $container->getDefinitions();
195195
$parameters = $container->getParameterBag()->all();
196196

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

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

0 commit comments

Comments
 (0)