8000 Refactoring tests. · symfony/symfony@567e0ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 567e0ab

Browse files
committed
Refactoring tests.
1 parent 9ac08e8 commit 567e0ab
  • Util
  • Locale/Tests/Stub
  • OptionsResolver/Tests
  • Process/Tests
  • Security
  • Templating/Tests
  • Translation/Tests/Dumper
  • Validator/Tests
  • Some content is hidden

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

    62 files changed

    +192
    -195
    lines changed

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

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -143,7 +143,7 @@ public function testAccess()
    143143
    list($matcherId, $attributes, $channel) = $rule;
    144144
    $requestMatcher = $container->getDefinition($matcherId);
    145145

    146-
    $this->assertFalse(isset($matcherIds[$matcherId]));
    146+
    $this->assertArrayNotHasKey($matcherId, $matcherIds);
    147147
    $matcherIds[$matcherId] = true;
    148148

    149149
    $i = count($matcherIds);

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

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -84,9 +84,9 @@ public function testCsrfAliases()
    8484
    $processor = new Processor();
    8585
    $configuration = new MainConfiguration(array(), array());
    8686
    $processedConfig = $processor->processConfiguration($configuration, array($config));
    87-
    $this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_generator']));
    87+
    $this->assertArrayHasKey('csrf_token_generator', $processedConfig['firewalls']['stub']['logout']);
    8888
    $this->assertEquals('a_token_generator', $processedConfig['firewalls']['stub']['logout']['csrf_token_generator']);
    89-
    $this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_id']));
    89+
    $this->assertArrayHasKey('csrf_token_id', $processedConfig['firewalls']['stub']['logout']);
    9090
    $this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
    9191
    }
    9292

    src/Symfony/Component/Config/Tests/ConfigCacheTest.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -112,7 +112,7 @@ public function testWriteDumpsFile()
    112112
    $cache->write('FOOBAR');
    113113

    114114
    $this->assertFileExists($this->cacheFile, 'Cache file is created');
    115-
    $this->assertSame('FOOBAR', file_get_contents($this->cacheFile));
    115+
    $this->assertStringEqualsFile($this->cacheFile, 'FOOBAR');
    116116
    $this->assertFileNotExists($this->metaFile, 'Meta file is not created');
    117117
    }
    118118

    @@ -128,7 +128,7 @@ public function testWriteDumpsMetaFileWithDebugEnabled()
    128128

    129129
    $this->assertFileExists($this->cacheFile, 'Cache file is created');
    130130
    $this->assertFileExists($this->metaFile, 'Meta file is created');
    131-
    $this->assertSame(serialize($metadata), file_get_contents($this->metaFile));
    131+
    $this->assertStringEqualsFile($this->metaFile, serialize($metadata));
    132132
    }
    133133

    134134
    private function makeCacheFresh()

    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
    @@ -164,6 +164,6 @@ public function testResourcesWithDifferentPatternsAreDifferent()
    164164
    $resourceA = new DirectoryResource($this->directory, '/.xml$/');
    165165
    $resourceB = new DirectoryResource($this->directory, '/.yaml$/');
    166166

    167-
    $this->assertEquals(2, count(array_unique(array($resourceA, $resourceB))));
    167+
    $this->assertCount(2, array_unique(array($resourceA, $resourceB)));
    168168
    }
    169169
    }

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

    src/Symfony/Component/DependencyInjection/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'));

    src/Symfony/Component/DependencyInjection/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());
    @@ -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

    src/Symfony/Component/DependencyInjection/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');

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

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -172,7 +172,7 @@ public function testAddXmlContentWithErrors()
    172172
    EOF
    173173
    , 'UTF-8');
    174174

    175-
    $this->assertTrue(count(libxml_get_errors()) > 1);
    175+
    $this->assertGreaterThan(1, libxml_get_errors());
    176176

    177177
    libxml_clear_errors();
    178178
    libxml_use_internal_errors($internalErrors);

    0 commit comments

    Comments
     (0)
    0