Skip to content

Commit 52f8dc7

Browse files
committed
Merge branch '2.3' into 2.4
* 2.3: changed some PHPUnit assertions to more specific ones fixed Kernel::stripComments() normalizing new-lines added a BC comment Update FileLoader to fix issue symfony#10339
2 parents dde2365 + 0ccf5bc commit 52f8dc7

File tree

23 files changed

+108
-69
lines changed

23 files changed

+108
-69
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
@@ -29,15 +29,15 @@ public function testTransform()
2929
$result = $this->transformer->transform(new PropelObjectCollection());
3030

3131
$this->assertTrue(is_array($result));
32-
$this->assertEquals(0, count($result));
32+
$this->assertCount(0, $result);
3333
}
3434

3535
public function testTransformWithNull()
3636
{
3737
$result = $this->transformer->transform(null);
3838

3939
$this->assertTrue(is_array($result));
40-
$this->assertEquals(0, count($result));
40+
$this->assertCount(0, $result);
4141
}
4242

4343
/**
@@ -56,7 +56,7 @@ public function testTransformWithData()
5656
$result = $this->transformer->transform($coll);
5757

5858
$this->assertTrue(is_array($result));
59-
$this->assertEquals(2, count($result));
59+
$this->assertCount(2, $result);
6060
$this->assertEquals('foo', $result[0]);
6161
$this->assertEquals('bar', $result[1]);
6262
}
@@ -66,15 +66,15 @@ public function testReverseTransformWithNull()
6666
$result = $this->transformer->reverseTransform(null);
6767

6868
$this->assertInstanceOf('\PropelObjectCollection', $result);
69-
$this->assertEquals(0, count($result->getData()));
69+
$this->assertCount(0, $result->getData());
7070
}
7171

7272
public function testReverseTransformWithEmptyString()
7373
{
7474
$result = $this->transformer->reverseTransform('');
7575

7676
$this->assertInstanceOf('\PropelObjectCollection', $result);
77-
$this->assertEquals(0, count($result->getData()));
77+
$this->assertCount(0, $result->getData());
7878
}
7979

8080
/**
@@ -95,7 +95,7 @@ public function testReverseTransformWithData()
9595
$this->assertInstanceOf('\PropelObjectCollection', $result);
9696

9797
$this->assertTrue(is_array($data));
98-
$this->assertEquals(2, count($data));
98+
$this->assertCount(2, $data);
9999
$this->assertEquals('foo', $data[0]);
100100
$this->assertEquals('bar', $data[1]);
101101
$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/Loader/FileLoader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
6767
$loader = $this->resolve($resource, $type);
6868

6969
if ($loader instanceof FileLoader && null !== $this->currentDir) {
70-
$resource = $this->locator->locate($resource, $this->currentDir, false);
70+
// we fallback to the current locator to keep BC
71+
// as some some loaders do not call the parent __construct()
72+
// @deprecated should be removed in 3.0
73+
$locator = $loader->getLocator() ?: $this->locator;
74+
$resource = $locator->locate($resource, $this->currentDir, false);
7175
}
7276

7377
$resources = is_array($resource) ? $resource : array($resource);

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/Config/Tests/Loader/FileLoaderTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class FileLoaderTest extends \PHPUnit_Framework_TestCase
2020
/**
2121
* @covers Symfony\Component\Config\Loader\FileLoader
2222
*/
23-
public function testImport()
23+
public function testImportWithFileLocatorDelegation()
2424
{
2525
$locatorMock = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
26-
$locatorMock->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
26+
27+
$locatorMockForAdditionalLoader = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
28+
$locatorMockForAdditionalLoader->expects($this->any())->method('locate')->will($this->onConsecutiveCalls(
2729
array('path/to/file1'), // Default
2830
array('path/to/file1', 'path/to/file2'), // First is imported
2931
array('path/to/file1', 'path/to/file2'), // Second is imported
@@ -32,8 +34,13 @@ public function testImport()
3234
));
3335

3436
$fileLoader = new TestFileLoader($locatorMock);
37+
$fileLoader->setSupports(false);
3538
$fileLoader->setCurrentDir('.');
36-
$fileLoader->setResolver($loaderResolver = new LoaderResolver(array($fileLoader)));
39+
40+
$additionalLoader = new TestFileLoader($locatorMockForAdditionalLoader);
41+
$additionalLoader->setCurrentDir('.');
42+
43+
$fileLoader->setResolver($loaderResolver = new LoaderResolver(array($fileLoader, $additionalLoader)));
3744

3845
// Default case
3946
$this->assertSame('path/to/file1', $fileLoader->import('my_resource'));
@@ -66,14 +73,16 @@ public function testImport()
6673

6774
class TestFileLoader extends FileLoader
6875
{
76+
private $supports = true;
77+
6978
public function load($resource, $type = null)
7079
{
7180
return $resource;
7281
}
7382

7483
public function supports($resource, $type = null)
7584
{
76-
return true;
85+
return $this->supports;
7786
}
7887

7988
public function addLoading($resource)
@@ -90,4 +99,9 @@ public function clearLoading()
9099
{
91100
self::$loading = array();
92101
}
102+
103+
public function setSupports($supports)
104+
{
105+
$this->supports = $supports;
106+
}
93107
}

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

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

107107
$application->add(new \FooCommand());
108108
$commands = $application->all('foo');
109-
$this->assertEquals(1, count($commands), '->all() takes a namespace as its first argument');
109+
$this->assertCount(1, $commands, '->all() takes a namespace as its first argument');
110110
}
111111

112112
public function testRegister()
@@ -535,8 +535,8 @@ public function testRun()
535535
$application->run();
536536
ob_end_clean();
537537

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

541541
$application = new Application();
542542
$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

0 commit comments

Comments
 (0)