-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
IntegrationTest.php
136 lines (121 loc) · 4.31 KB
/
IntegrationTest.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Symfony\WebpackEncoreBundle\Tests;
use Symfony\WebpackEncoreBundle\WebpackEncoreBundle;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
class IntegrationTest extends TestCase
{
public function testTwigIntegration()
{
$kernel = new WebpackEncoreIntegrationTestKernel(true);
$kernel->boot();
$container = $kernel->getContainer();
$html1 = $container->get('twig')->render('@integration_test/template.twig');
$this->assertContains(
'<script src="/build/file1.js" integrity="sha384-Q86c+opr0lBUPWN28BLJFqmLhho+9ZcJpXHorQvX6mYDWJ24RQcdDarXFQYN8HLc"></script>',
$html1
);
$this->assertContains(
'<link rel="stylesheet" href="/build/styles.css" integrity="sha384-4g+Zv0iELStVvA4/B27g4TQHUMwZttA5TEojjUyB8Gl5p7sarU4y+VTSGMrNab8n">' .
'<link rel="stylesheet" href="/build/styles2.css" integrity="sha384-hfZmq9+2oI5Cst4/F4YyS2tJAAYdGz7vqSMP8cJoa8bVOr2kxNRLxSw6P8UZjwUn">',
$html1
);
$this->assertContains(
'<script src="/build/other3.js"></script>',
$html1
);
$this->assertContains(
'<link rel="stylesheet" href="/build/styles3.css">'.
'<link rel="stylesheet" href="/build/styles4.css">',
$html1
);
$html2 = $container->get('twig')->render('@integration_test/manual_template.twig');
$this->assertContains(
'<script src="/build/file3.js"></script>',
$html2
);
$this->assertContains(
'<script src="/build/other4.js"></script>',
$html2
);
}
public function testEntriesAreNotRepeteadWhenAlreadyOutputIntegration()
{
$kernel = new WebpackEncoreIntegrationTestKernel(true);
$kernel->boot();
$container = $kernel->getContainer();
$html1 = $container->get('twig')->render('@integration_test/template.twig');
$html2 = $container->get('twig')->render('@integration_test/manual_template.twig');
$this->assertContains(
'<script src="/build/file3.js"></script>',
$html2
);
// file1.js is not repeated
$this->assertNotContains(
'<script src="/build/file1.js"></script>',
$html2
);
// styles3.css is not repeated
$this->assertNotContains(
'<link rel="stylesheet" href="/build/styles3.css">',
$html2
);
// styles4.css is not repeated
$this->assertNotContains(
'<link rel="stylesheet" href="/build/styles4.css">',
$html2
);
}
}
class WebpackEncoreIntegrationTestKernel extends Kernel
{
private $enableAssets;
public function __construct($enableAssets)
{
parent::__construct('test', true);
$this->enableAssets = $enableAssets;
}
public function registerBundles()
{
return [
new FrameworkBundle(),
new TwigBundle(),
new WebpackEncoreBundle(),
];
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function(ContainerBuilder $container) {
$container->loadFromExtension('framework', [
'secret' => 'foo',
'assets' => [
'enabled' => $this->enableAssets,
],
]);
$container->loadFromExtension('twig', [
'paths' => [
__DIR__.'/fixtures' => 'integration_test'
],
'strict_variables' => true,
]);
$container->loadFromExtension('webpack_encore', [
'output_path' => __DIR__.'/fixtures/build',
'builds' => [
'different_build' => __DIR__.'/fixtures/different_build'
]
]);
});
}
public function getCacheDir()
{
return sys_get_temp_dir().'/cache'.spl_object_hash($this);
}
public function getLogDir()
{
return sys_get_temp_dir().'/logs'.spl_object_hash($this);
}
}