Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c235db

Browse filesBrowse files
committed
Add more tests
1 parent 2ed7297 commit 4c235db
Copy full SHA for 4c235db

File tree

Expand file treeCollapse file tree

10 files changed

+115
-19
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+115
-19
lines changed
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity;
13+
14+
class Person
15+
{
16+
public $name;
17+
public $age;
18+
19+
public function __construct(string $name, string $age)
20+
{
21+
$this->name = $name;
22+
$this->age = $age;
23+
}
24+
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class LegacyBundle extends Bundle
17+
{
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity\Person:
2+
attributes:
3+
name:
4+
serialized_name: 'full_name'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity\Person:
2+
properties:
3+
age:
4+
- GreaterThan:
5+
value: 18

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/LegacyBundle/Resources/public/legacy.css

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/LegacyBundle/Resources/public/legacy.css
Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ok_label: OK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php
+57-19Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand;
1515
use Symfony\Bundle\FrameworkBundle\Console\Application;
16-
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src\Entity\Person;
1716
use Symfony\Component\Console\Tester\CommandTester;
1817
use Symfony\Component\Filesystem\Filesystem;
1918

2019
class BundlePathsTest extends AbstractWebTestCase
2120
{
22-
public function testDefaultBundlePaths()
21+
public function testLegacyBundleDir()
2322
{
2423
static::bootKernel(['test_case' => 'BundlePaths']);
2524
$bundlesMetadata = static::$container->getParameter('kernel.bundles_metadata');
26-
$bundlePath = $bundlesMetadata['FrameworkBundle']['path'];
25+
$bundlePath = $bundlesMetadata['LegacyBundle']['path'];
2726

28-
$this->assertSame($bundlePath, $bundlesMetadata['FrameworkBundle']['dir']);
27+
$this->assertSame($bundlePath, $bundlesMetadata['LegacyBundle']['dir']);
2928
}
3029

31-
public function testCustomBundlePaths()
30+
public function testBundleDir()
3231
{
3332
static::bootKernel(['test_case' => 'BundlePaths']);
3433
$bundlesMetadata = static::$container->getParameter('kernel.bundles_metadata');
@@ -37,56 +36,95 @@ public function testCustomBundlePaths()
3736
$this->assertSame(\dirname($bundlePath), $bundlesMetadata['ModernBundle']['dir']);
3837
}
3938

40-
public function testCustomBundlePublicPath()
39+
/**
40+
* @dataProvider getPublicDirProvider
41+
*/
42+
public function testBundlePublicDir(string $expectedFilename)
4143
{
4244
$kernel = static::bootKernel(['test_case' => 'BundlePaths']);
43-
$projectDir = sys_get_temp_dir().'/'.uniqid('sf_modern', true);
45+
$projectDir = sys_get_temp_dir().'/'.uniqid('sf_project', true);
4446

4547
$fs = new Filesystem();
4648
$fs->mkdir($projectDir.'/public');
4749
$command = (new Application($kernel))->add(new AssetsInstallCommand($fs, $projectDir));
4850
$commandTester = new CommandTester($command);
4951

5052
$this->assertSame(0, $commandTester->execute(['target' => $projectDir.'/public']));
51-
$this->assertFileExists($projectDir.'/public/bundles/modern/modern.css');
53+
$this->assertFileExists($projectDir.$expectedFilename);
5254

5355
$fs->remove($projectDir);
5456
}
5557

56-
public function testCustomBundleTwigTemplatesPath()
58+
/**
59+
* @dataProvider getTemplatesDirProvider
60+
*/
61+
public function testBundleTwigTemplatesDir(string $bundleName, string $twigNamespace, string $templateDir, string $twigTemplate)
5762
{
5863
static::bootKernel(['test_case' => 'BundlePaths']);
5964
$bundlesMetadata = static::$container->getParameter('kernel.bundles_metadata');
60-
$bundleDir = $bundlesMetadata['ModernBundle']['dir'];
65+
$bundleDir = $bundlesMetadata[$bundleName]['dir'];
6166

6267
$twig = static::$container->get('twig');
63-
$this->assertSame([$bundleDir.'/templates'], $twig->getLoader()->getPaths('Modern'));
64-
$this->assertSame("OK\n", $twig->render('@Modern/index.html.twig'));
68+
$this->assertSame([$bundleDir.$templateDir], $twig->getLoader()->getPaths($twigNamespace));
69+
$this->assertSame("OK\n", $twig->render($twigTemplate));
6570
}
6671

67-
public function testCustomBundleTranslationsPath()
72+
/**
73+
* @dataProvider getTranslationsDirProvider
74+
*/
75+
public function testBundleTranslationsDir(string $translationDomain)
6876
{
6977
static::bootKernel(['test_case' => 'BundlePaths']);
7078

7179
$translator = static::$container->get('translator');
72-
$this->assertSame('OK', $translator->trans('ok_label', [], 'modern'));
80+
$this->assertSame('OK', $translator->trans('ok_label', [], $translationDomain));
7381
}
7482

75-
public function testCustomBundleValidationConfigPath()
83+
/**
84+
* @dataProvider getConfigDirProvider
85+
*/
86+
public function testBundleValidationConfigDir(string $personClass)
7687
{
7788
static::bootKernel(['test_case' => 'BundlePaths']);
7889

7990
$validator = static::$container->get('validator');
80-
$this->assertTrue($validator->hasMetadataFor(Person::class));
81-
$this->assertCount(1, $constraintViolationList = $validator->validate(new Person('john', 5)));
91+
$this->assertTrue($validator->hasMetadataFor($personClass));
92+
$this->assertCount(1, $constraintViolationList = $validator->validate(new $personClass('john', 5)));
8293
$this->assertSame('This value should be greater than 18.', $constraintViolationList->get(0)->getMessage());
8394
}
8495

85-
public function testCustomBundleSerializationConfigPath()
96+
/**
97+
* @dataProvider getConfigDirProvider
98+
*/
99+
public function testBundleSerializationConfigDir(string $personClass)
86100
{
87101
static::bootKernel(['test_case' => 'BundlePaths']);
88102

89103
$serializer = static::$container->get('serializer');
90-
$this->assertEquals(['full_name' => 'john', 'age' => 5], $serializer->normalize(new Person('john', 5), 'json'));
104+
$this->assertEquals(['full_name' => 'john', 'age' => 5], $serializer->normalize(new $personClass('john', 5), 'json'));
105+
}
106+
107+
public function getPublicDirProvider()
108+
{
109+
yield ['/public/bundles/modern/modern.css'];
110+
yield ['/public/bundles/legacy/legacy.css'];
111+
}
112+
113+
public function getTemplatesDirProvider()
114+
{
115+
yield ['ModernBundle', 'Modern', '/templates', '@Modern/index.html.twig'];
116+
yield ['LegacyBundle', 'Legacy', '/Resources/views', '@Legacy/index.html.twig'];
117+
}
118+
119+
public function getTranslationsDirProvider()
120+
{
121+
yield ['modern'];
122+
yield ['legacy'];
123+
}
124+
125+
public function getConfigDirProvider()
126+
{
127+
yield [\Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src\Entity\Person::class];
128+
yield [\Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity\Person::class];
91129
}
92130
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/BundlePaths/bundles.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/BundlePaths/bundles.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
*/
1111

1212
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\LegacyBundle;
1314
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src\ModernBundle;
1415
use Symfony\Bundle\TwigBundle\TwigBundle;
1516

1617
return [
1718
new FrameworkBundle(),
1819
new TwigBundle(),
1920
new ModernBundle(),
21+
new LegacyBundle(),
2022
];

‎src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Bundle/Bundle.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public function getPath()
117117
return $this->path;
118118
}
119119

120+
/**
121+
* {@inheritdoc}
122+
*/
120123
public function getBundleDir(): string
121124
{
122125
return $this->getPath();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.