1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JBen87\ParsleyBundle\Tests; |
4
|
|
|
|
5
|
|
|
use JBen87\ParsleyBundle\DependencyInjection\Configuration; |
6
|
|
|
use JBen87\ParsleyBundle\JBen87ParsleyBundle; |
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
10
|
|
|
|
11
|
|
|
class JBen87ParsleyBundleTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testContainerExtension(): void |
14
|
|
|
{ |
15
|
|
|
$container = $this->createMock(ContainerBuilder::class); |
16
|
|
|
$this->setUpContainer($container); |
17
|
|
|
|
18
|
|
|
$container |
19
|
|
|
->expects($this->exactly(5)) |
20
|
|
|
->method('setParameter') |
21
|
|
|
->withConsecutive( |
22
|
|
|
['jben87_parsley.enabled', true], |
23
|
|
|
['jben87_parsley.trigger_event', 'blur'], |
24
|
|
|
['jben87_parsley.date_pattern', '\d{4}-\d{2}-\d{2}'], |
25
|
|
|
['jben87_parsley.time_pattern', '\d{2}:\d{2}'], |
26
|
|
|
['jben87_parsley.datetime_pattern', '\d{4}-\d{2}-\d{2} \d{2}:\d{2}'] |
27
|
|
|
) |
28
|
|
|
; |
29
|
|
|
|
30
|
|
|
$bundle = new JBen87ParsleyBundle(); |
31
|
|
|
$extension = $bundle->getContainerExtension(); |
32
|
|
|
$extension->load([], $container); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testContainerExtensionAlternative(): void |
36
|
|
|
{ |
37
|
|
|
$container = $this->createMock(ContainerBuilder::class); |
38
|
|
|
$this->setUpContainer($container); |
39
|
|
|
|
40
|
|
|
$container |
41
|
|
|
->expects($this->exactly(5)) |
42
|
|
|
->method('setParameter') |
43
|
|
|
->withConsecutive( |
44
|
|
|
['jben87_parsley.enabled', false], |
45
|
|
|
['jben87_parsley.trigger_event', 'click'], |
46
|
|
|
['jben87_parsley.date_pattern', '\d{2}/\d{2}/\d{4}'], |
47
|
|
|
['jben87_parsley.time_pattern', '\d{2}:\d{2}'], |
48
|
|
|
['jben87_parsley.datetime_pattern', '\d{2}/\d{2}/\d{4} \d{2}:\d{2}'] |
49
|
|
|
) |
50
|
|
|
; |
51
|
|
|
|
52
|
|
|
$bundle = new JBen87ParsleyBundle(); |
53
|
|
|
$extension = $bundle->getContainerExtension(); |
54
|
|
|
$extension->load( |
55
|
|
|
[ |
56
|
|
|
'jben87_parsley' => [ |
57
|
|
|
'enabled' => false, |
58
|
|
|
'trigger_event' => 'click', |
59
|
|
|
'date_pattern' => ['fr' => '\d{2}/\d{2}/\d{4}'], |
60
|
|
|
'time_pattern' => ['fr' => '\d{2}:\d{2}'], |
61
|
|
|
'datetime_pattern' => ['fr' => '\d{2}/\d{2}/\d{4} \d{2}:\d{2}'], |
62
|
|
|
], |
63
|
|
|
], |
64
|
|
|
$container |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param MockObject $container |
70
|
|
|
*/ |
71
|
|
|
private function setUpContainer(MockObject $container): void |
72
|
|
|
{ |
73
|
|
|
$container |
74
|
|
|
->expects($this->once()) |
75
|
|
|
->method('getReflectionClass') |
76
|
|
|
->with(Configuration::class) |
77
|
|
|
->willReturn(new \ReflectionClass(Configuration::class)) |
78
|
|
|
; |
79
|
|
|
|
80
|
|
|
$container |
81
|
|
|
->expects($this->once()) |
82
|
|
|
->method('getParameter') |
83
|
|
|
->with('locale') |
84
|
|
|
->willReturn('fr') |
85
|
|
|
; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|