-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathBundlePathsTest.php
84 lines (67 loc) · 3.67 KB
/
BundlePathsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\LegacyBundle\Entity\LegacyPerson;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ModernBundle\src\Entity\ModernPerson;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
class BundlePathsTest extends AbstractWebTestCase
{
public function testBundlePublicDir()
{
$kernel = static::bootKernel(['test_case' => 'BundlePaths']);
$projectDir = sys_get_temp_dir().'/'.uniqid('sf_bundle_paths', true);
$fs = new Filesystem();
$fs->mkdir($projectDir.'/public');
$command = (new Application($kernel))->add(new AssetsInstallCommand($fs, $projectDir));
$exitCode = (new CommandTester($command))->execute(['target' => $projectDir.'/public']);
$this->assertSame(0, $exitCode);
$this->assertFileExists($projectDir.'/public/bundles/modern/modern.css');
$this->assertFileExists($projectDir.'/public/bundles/legacy/legacy.css');
$fs->remove($projectDir);
}
public function testBundleTwigTemplatesDir()
{
static::bootKernel(['test_case' => 'BundlePaths']);
$twig = static::getContainer()->get('twig.alias');
$bundlesMetadata = static::getContainer()->getParameter('kernel.bundles_metadata');
$this->assertSame([$bundlesMetadata['LegacyBundle']['path'].'/Resources/views'], $twig->getLoader()->getPaths('Legacy'));
$this->assertSame("OK\n", $twig->render('@Legacy/index.html.twig'));
$this->assertSame([$bundlesMetadata['ModernBundle']['path'].'/templates'], $twig->getLoader()->getPaths('Modern'));
$this->assertSame("OK\n", $twig->render('@Modern/index.html.twig'));
}
public function testBundleTranslationsDir()
{
static::bootKernel(['test_case' => 'BundlePaths']);
$translator = static::getContainer()->get('translator.alias');
$this->assertSame('OK', $translator->trans('ok_label', [], 'legacy'));
$this->assertSame('OK', $translator->trans('ok_label', [], 'modern'));
}
public function testBundleValidationConfigDir()
{
static::bootKernel(['test_case' => 'BundlePaths']);
$validator = static::getContainer()->get('validator.alias');
$this->assertTrue($validator->hasMetadataFor(LegacyPerson::class));
$this->assertCount(1, $constraintViolationList = $validator->validate(new LegacyPerson('john', 5)));
$this->assertSame('This value should be greater than 18.', $constraintViolationList->get(0)->getMessage());
$this->assertTrue($validator->hasMetadataFor(ModernPerson::class));
$this->assertCount(1, $constraintViolationList = $validator->validate(new ModernPerson('john', 5)));
$this->assertSame('This value should be greater than 18.', $constraintViolationList->get(0)->getMessage());
}
public function testBundleSerializationConfigDir()
{
static::bootKernel(['test_case' => 'BundlePaths']);
$serializer = static::getContainer()->get('serializer.alias');
$this->assertEquals(['full_name' => 'john', 'age' => 5], $serializer->normalize(new LegacyPerson('john', 5), 'json'));
$this->assertEquals(['full_name' => 'john', 'age' => 5], $serializer->normalize(new ModernPerson('john', 5), 'json'));
}
}