10000 Refactoring tests. · symfony/dependency-injection@1dd3a41 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1dd3a41

Browse files
committed
Refactoring tests.
1 parent db888ba commit 1dd3a41

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');
@@ -163,7 +163,7 @@ public function testAliases()
163163
$this->assertFalse($builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
164164
$this->assertEquals('foo', (string) $builder->getAlias('bar'), '->getAlias() returns the aliased service');
165165
$this->assertTrue($builder->has('bar'), '->setAlias() defines a new service');
166-
$this->assertTrue($builder->get('bar') === $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
166+
$this->assertSame($builder->get('bar'), $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
167167

168168
try {
169169
$builder->setAlias('foobar', 'foobar');
@@ -208,8 +208,8 @@ public function testSetAliases()
208208
$builder->setAliases(array('bar' => 'foo', 'foobar' => 'foo'));
209209

210210
$aliases = $builder->getAliases();
211-
$this->assertTrue(isset($aliases['bar']));
212-
$this->assertTrue(isset($aliases['foobar']));
211+
$this->assertArrayHasKey('bar', $aliases);
212+
$this->assertArrayHasKey('foobar', $aliases);
213213
}
214214

215215
public function testAddAliases()
@@ -219,8 +219,8 @@ public function testAddAliases()
219219
$builder->addAliases(array('foobar' => 'foo'));
220220

221221
$aliases = $builder->getAliases();
222-
$this->assertTrue(isset($aliases['bar']));
223-
$this->assertTrue(isset($aliases['foobar']));
222+
$this->assertArrayHasKey('bar', $aliases);
223+
$this->assertArrayHasKey('foobar', $aliases);
224224
}
225225

226226
public function testSetReplacesAlias()
@@ -480,7 +480,7 @@ public function testMerge()
480480
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
481481

482482
$aliases = $container->getAliases();
483-
$this->assertTrue(isset($aliases['alias_for_foo']));
483+
$this->assertArrayHasKey('alias_for_foo', $aliases);
484484
$this->assertEquals('foo', (string) $aliases['alias_for_foo']);
485485

486486
$container = new ContainerBuilder();
@@ -619,7 +619,7 @@ public function testExtension()
619619
$container->setResourceTracking(false);
620620

621621
$container->registerExtension($extension = new \ProjectExtension());
622-
$this->assertTrue($container->getExtension('project') === $extension, '->registerExtension() registers an extension');
622+
$this->assertSame($container->getExtension('project'), $extension, '->registerExtension() registers an extension');
623623

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

Tests/ContainerTest.php

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

174174
$scoped = $this->getField($c, 'scopedServices');
175-
$this->assertTrue(isset($scoped['foo']['foo']), '->set() sets a scoped service');
175+
$this->assertArrayHasKey('foo', $scoped['foo'], '->set() sets a scoped service');
176176
$this->assertSame($foo, $scoped['foo']['foo'], '->set() sets a scoped service');
177177
}
178178

@@ -340,14 +340,14 @@ public function testEnterLeaveScopeWithChildScopes()
340340
$container->set('a', $a, 'bar');
341341

342342
$scoped = $this->getField($container, 'scopedServices');
343-
$this->assertTrue(isset($scoped['bar']['a']));
343+
$this->assertArrayHasKey('a', $scoped['bar']);
344344
$this->assertSame($a, $scoped['bar']['a']);
345345
$this->assertTrue($container->has('a'));
346346

347347
$container->leaveScope('foo');
348348

349349
$scoped = $this->getField($container, 'scopedServices');
350-
$this->assertFalse(isset($scoped['bar']));
350+
$this->assertArrayNotHasKey('bar', $scoped);
351351
$this->assertFalse($container->isScopeActive('foo'));
352352
$this->assertFalse($container->has('a'));
353353
}
@@ -370,14 +370,14 @@ public function testEnterScopeRecursivelyWithInactiveChildScopes()
370370
$container->set('a', $a, 'foo');
371371

372372
$scoped = $this->getField($container, 'scopedServices');
373-
$this->assertTrue(isset($scoped['foo']['a']));
373+
$this->assertArrayHasKey('a', $scoped['foo']);
374374
$this->assertSame($a, $scoped['foo']['a']);
375375
$this->assertTrue($container->has('a'));
376376

377377
$container->enterScope('foo');
378378

379379
$scoped = $this->getField($container, 'scopedServices');
380-
$this->assertFalse(isset($scoped['a']));
380+
$this->assertArrayNotHasKey('a', $scoped);
381381
$this->assertTrue($container->isScopeActive('foo'));
382382
$this->assertFalse($container->isScopeActive('bar'));
383383
$this->assertFalse($container->has('a'));
@@ -409,14 +409,14 @@ public function testEnterChildScopeRecursively()
409409
$container->set('a', $a, 'bar');
410410

411411
$scoped = $this->getField($container, 'scopedServices');
412-
$this->assertTrue(isset($scoped['bar']['a']));
412+
$this->assertArrayHasKey('a', $scoped['bar']);
413413
$this->assertSame($a, $scoped['bar']['a']);
414414
$this->assertTrue($container->has('a'));
415415

416416
$container->enterScope('bar');
417417

418418
$scoped = $this->getField($container, 'scopedServices');
419-
$this->assertFalse(isset($scoped['a']));
419+
$this->assertArrayNotHasKey('a', $scoped);
420420
$this->assertTrue($container->isScopeActive('foo'));
421421
$this->assertTrue($container->isScopeActive('bar'));
422422
$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 57AE 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());
@@ -249,7 +249,7 @@ public function testLoadServices()
249249
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
250250
$loader->load('services6.xml');
251251
$services = $container->getDefinitions();
252-
$this->assertTrue(isset($services['foo']), '->load() parses <service> elements');
252+
$this->assertArrayHasKey('foo', $services, '->load() parses <service> elements');
253253
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts <service> element to Definition instances');
254254
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
255255
$this->assertEquals('container', $services['scope.container']->getScope());
@@ -267,10 +267,10 @@ public function testLoadServices()
267267
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
268268

269269
$aliases = $container->getAliases();
270-
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
270+
$this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses <service> elements');
271271
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
272272
$this->assertTrue($aliases['alias_for_foo']->isPublic());
273-
$this->assertTrue(isset($aliases['another_alias_for_foo']));
273+
$this->assertArrayHasKey('another_alias_for_foo', $aliases);
274274
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
275275
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
276276

@@ -366,8 +366,8 @@ public function testExtensions()
366366
$services = $container->getDefinitions();
367367
$parameters = $container->getParameterBag()->all();
368368

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

372372
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
373373
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
@@ -382,8 +382,8 @@ public function testExtensions()
382382
$services = $container->getDefinitions();
383383
$parameters = $container->getParameterBag()->all();
384384

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

388388
$this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements');
389389
$this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements');
@@ -504,8 +504,8 @@ public function testXmlNamespaces()
504504
$loader->load('namespaces.xml');
505505
$services = $container->getDefinitions();
506506

507-
$this->assertTrue(isset($services['foo']), '->load() parses <srv:service> elements');
508-
$this->assertEquals(1, count($services['foo']->getTag('foo.tag')), '->load parses <srv:tag> elements');
507+
$this->assertArrayHasKey('foo', $services, '->load() parses <srv:service> elements');
508+
$this->assertCount(1, $services['foo']->getTag('foo.tag'), '->load parses <srv:tag> elements');
509509
$this->assertEquals(array(array('setBar', array('foo'))), $services['foo']->getMethodCalls(), '->load() parses the <srv:call> tag');
510510
}
511511

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testLoadServices()
142142
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
143143
$loader->load('services6.yml');
144144
$services = $container->getDefinitions();
145-
$this->assertTrue(isset($services['foo']), '->load() parses service elements');
145+
$this->assertArrayHasKey('foo', $services, '->load() parses service elements');
146146
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts service element to Definition instances');
147147
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
148148
$this->assertEquals('container', $services['scope.container']->getScope());
@@ -160,10 +160,10 @@ public function testLoadServices()
160160
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
161161

162162
$aliases = $container->getAliases();
163-
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses aliases');
163+
$this->assertArrayHasKey('alias_for_foo', $aliases, '->load() parses aliases');
164164
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
165165
$this->assertTrue($aliases['alias_for_foo']->isPublic());
166-
$this->assertTrue(isset($aliases['another_alias_for_foo']));
166+
$this->assertArrayHasKey('another_alias_for_foo', $aliases);
167167
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
168168
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
169169

@@ -192,8 +192,8 @@ public function testExtensions()
192192
$services = $container->getDefinitions();
193193
$parameters = $container->getParameterBag()->all();
194194

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

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

0 commit comments

Comments
 (0)
0