1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Tests\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\WebpackEntriesCompilerPass; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @group foo |
23
|
|
|
*/ |
24
|
|
|
class WebpackEntriesCompilerPassTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
private $container; |
27
|
|
|
|
28
|
|
|
private $definition; |
29
|
|
|
|
30
|
|
|
private $compilerPass; |
31
|
|
|
|
32
|
|
|
protected function setUp(): void |
33
|
|
|
{ |
34
|
|
|
$this->container = $this->createMock(ContainerBuilder::class); |
35
|
|
|
$this->definition = $this->createMock(Definition::class); |
36
|
|
|
|
37
|
|
|
$this->compilerPass = new WebpackEntriesCompilerPass(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testProcess(): void |
41
|
|
|
{ |
42
|
|
|
$expectedEntries = [ |
43
|
|
|
'app' => '%kernel.project_dir%/public/build', |
44
|
|
|
'sonata_admin' => '%kernel.project_dir%/public/bundles/sonataadmin/dist', |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
$webpackConfig = [ |
48
|
|
|
[ |
49
|
|
|
'output_path' => '%kernel.project_dir%/public/build', |
50
|
|
|
'builds' => [ |
51
|
|
|
'app' => '%kernel.project_dir%/public/build', |
52
|
|
|
], |
53
|
|
|
], |
54
|
|
|
[ |
55
|
|
|
'builds' => [ |
56
|
|
|
'sonata_admin' => '%kernel.project_dir%/public/bundles/sonataadmin/dist', |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
$this->container |
62
|
|
|
->expects($this->once()) |
63
|
|
|
->method('getExtensionConfig') |
64
|
|
|
->with('webpack_encore') |
65
|
|
|
->willReturn($webpackConfig); |
66
|
|
|
|
67
|
|
|
$this->definition |
68
|
|
|
->expects($this->once()) |
69
|
|
|
->method('addMethodCall') |
70
|
|
|
->with('addGlobal', ['sonata_admin_webpack_entries', $expectedEntries]) |
71
|
|
|
->willReturnSelf(); |
72
|
|
|
|
73
|
|
|
$this->container |
74
|
|
|
->expects($this->once()) |
75
|
|
|
->method('getDefinition') |
76
|
|
|
->with('twig') |
77
|
|
|
->willReturn($this->definition); |
78
|
|
|
|
79
|
|
|
$this->compilerPass->process($this->container); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testProcessBuildNotSet(): void |
83
|
|
|
{ |
84
|
|
|
$expectedEntries = [ |
85
|
|
|
'sonata_admin' => '%kernel.project_dir%/public/bundles/sonataadmin/dist', |
86
|
|
|
]; |
87
|
|
|
|
88
|
|
|
$webpackConfig = [ |
89
|
|
|
[ |
90
|
|
|
'output_path' => '%kernel.project_dir%/public/build', |
91
|
|
|
], |
92
|
|
|
[ |
93
|
|
|
'builds' => [ |
94
|
|
|
'sonata_admin' => '%kernel.project_dir%/public/bundles/sonataadmin/dist', |
95
|
|
|
], |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$this->container |
100
|
|
|
->expects($this->once()) |
101
|
|
|
->method('getExtensionConfig') |
102
|
|
|
->with('webpack_encore') |
103
|
|
|
->willReturn($webpackConfig); |
104
|
|
|
|
105
|
|
|
$this->definition |
106
|
|
|
->expects($this->once()) |
107
|
|
|
->method('addMethodCall') |
108
|
|
|
->with('addGlobal', ['sonata_admin_webpack_entries', $expectedEntries]) |
109
|
|
|
->willReturnSelf(); |
110
|
|
|
|
111
|
|
|
$this->container |
112
|
|
|
->expects($this->once()) |
113
|
|
|
->method('getDefinition') |
114
|
|
|
->with('twig') |
115
|
|
|
->willReturn($this->definition); |
116
|
|
|
|
117
|
|
|
$this->compilerPass->process($this->container); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testProcessEmptyEntries(): void |
121
|
|
|
{ |
122
|
|
|
$webpackConfig = []; |
123
|
|
|
|
124
|
|
|
$this->container |
125
|
|
|
->expects($this->once()) |
126
|
|
|
->method('getExtensionConfig') |
127
|
|
|
->with('webpack_encore') |
128
|
|
|
->willReturn($webpackConfig); |
129
|
|
|
|
130
|
|
|
$this->definition |
131
|
|
|
->expects($this->never()) |
132
|
|
|
->method('addMethodCall'); |
133
|
|
|
|
134
|
|
|
$this->container |
135
|
|
|
->expects($this->never()) |
136
|
|
|
->method('getDefinition'); |
137
|
|
|
|
138
|
|
|
$this->compilerPass->process($this->container); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|