|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\InformationCollectionBundle\Tests\FieldHandler; |
|
4
|
|
|
|
|
5
|
|
|
use eZ\Publish\Core\FieldType\Integer\Value as TestValue; |
|
6
|
|
|
use Netgen\Bundle\InformationCollectionBundle\FieldHandler\Custom\CustomFieldHandlerInterface; |
|
7
|
|
|
use Netgen\Bundle\InformationCollectionBundle\FieldHandler\FieldHandlerRegistry; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class FieldHandlerRegistryTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var FieldHandlerRegistry |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $registry; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $customHandler1; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $customHandler2; |
|
26
|
|
|
|
|
27
|
|
|
public function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->registry = new FieldHandlerRegistry(); |
|
30
|
|
|
$this->customHandler1 = $this->getMockBuilder(CustomFieldHandlerInterface::class) |
|
31
|
|
|
->disableOriginalConstructor() |
|
32
|
|
|
->setMethods(array('supports', 'toString')) |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
|
|
35
|
|
|
$this->customHandler2 = $this->getMockBuilder(CustomFieldHandlerInterface::class) |
|
36
|
|
|
->disableOriginalConstructor() |
|
37
|
|
|
->setMethods(array('supports', 'toString')) |
|
38
|
|
|
->getMock(); |
|
39
|
|
|
|
|
40
|
|
|
parent::setUp(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testAddingHandlers() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->registry->addHandler($this->customHandler1); |
|
46
|
|
|
$this->registry->addHandler($this->customHandler2); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testItReturnsProperHandler() |
|
50
|
|
|
{ |
|
51
|
|
|
$value = new TestValue(2); |
|
52
|
|
|
|
|
53
|
|
|
$this->registry->addHandler($this->customHandler1); |
|
54
|
|
|
$this->registry->addHandler($this->customHandler2); |
|
55
|
|
|
|
|
56
|
|
|
$this->customHandler1->expects($this->once()) |
|
57
|
|
|
->method('supports') |
|
58
|
|
|
->willReturn(false); |
|
59
|
|
|
|
|
60
|
|
|
$this->customHandler2->expects($this->once()) |
|
61
|
|
|
->method('supports') |
|
62
|
|
|
->willReturn(true); |
|
63
|
|
|
|
|
64
|
|
|
$handler = $this->registry->handle($value); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertSame($this->customHandler2, $handler); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testItReturnsNullWhenSupportedHandlerNotFound() |
|
70
|
|
|
{ |
|
71
|
|
|
$value = new TestValue(2); |
|
72
|
|
|
|
|
73
|
|
|
$handler = $this->registry->handle($value); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertNull($handler); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|