Total Complexity | 4 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | class ChainFactoryTest extends TestCase |
||
14 | { |
||
15 | public function testCreate(): void |
||
16 | { |
||
17 | $expected = new ParsleyAssert\Required(); |
||
18 | |||
19 | $requiredFactory = $this->createMock(RequiredFactory::class); |
||
20 | $requiredFactory |
||
21 | ->expects($this->once()) |
||
22 | ->method('supports') |
||
23 | ->willReturn(true) |
||
24 | ; |
||
25 | $requiredFactory |
||
26 | ->expects($this->once()) |
||
27 | ->method('create') |
||
28 | ->willReturn($expected) |
||
29 | ; |
||
30 | |||
31 | $factory = $this->createFactory([ |
||
32 | $requiredFactory, |
||
33 | ]); |
||
34 | |||
35 | $constraint = $factory->create(new Assert\NotBlank()); |
||
36 | $this->assertSame($expected, $constraint); |
||
37 | } |
||
38 | |||
39 | public function testCreateUnsupported(): void |
||
40 | { |
||
41 | $this->expectException(ConstraintException::class); |
||
42 | $this->createFactory([])->create(new Assert\NotBlank()); |
||
43 | } |
||
44 | |||
45 | public function testSupports(): void |
||
46 | { |
||
47 | $factory = $this->createFactory([]); |
||
48 | |||
49 | $this->assertTrue($factory->supports(new Assert\NotBlank())); |
||
50 | $this->assertTrue($factory->supports(new Assert\Valid())); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param FactoryInterface[] $factories |
||
55 | * |
||
56 | * @return ChainFactory |
||
57 | */ |
||
58 | private function createFactory(array $factories): ChainFactory |
||
59 | { |
||
60 | return new ChainFactory($factories); |
||
61 | } |
||
63 |