1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\GBProd\AlgoliaSpecification; |
4
|
|
|
|
5
|
|
|
use GBProd\AlgoliaSpecification\Handler; |
6
|
|
|
use GBProd\AlgoliaSpecification\QueryFactory\AndXFactory; |
7
|
|
|
use GBProd\AlgoliaSpecification\QueryFactory\Factory; |
8
|
|
|
use GBProd\AlgoliaSpecification\QueryFactory\NotFactory; |
9
|
|
|
use GBProd\AlgoliaSpecification\QueryFactory\OrXFactory; |
10
|
|
|
use GBProd\AlgoliaSpecification\Registry; |
11
|
|
|
use GBProd\Specification\AndX; |
12
|
|
|
use GBProd\Specification\Not; |
13
|
|
|
use GBProd\Specification\OrX; |
14
|
|
|
use GBProd\Specification\Specification; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class HandlerTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Registry |
21
|
|
|
*/ |
22
|
|
|
private $registry; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Handler |
26
|
|
|
*/ |
27
|
|
|
private $handler; |
28
|
|
|
|
29
|
|
|
protected function setUp() |
30
|
|
|
{ |
31
|
|
|
$this->registry = new Registry(); |
32
|
|
|
$this->handler = new Handler($this->registry); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testConstructWillRegisterBaseFactoriess() |
36
|
|
|
{ |
37
|
|
|
$spec1 = $this->createMock(Specification::class); |
38
|
|
|
$spec2 = $this->createMock(Specification::class); |
39
|
|
|
|
40
|
|
|
$this->assertInstanceOf( |
41
|
|
|
AndXFactory::class, |
42
|
|
|
$this->registry->getFactory(new AndX($spec1, $spec2)) |
|
|
|
|
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$this->assertInstanceOf( |
46
|
|
|
OrXFactory::class, |
47
|
|
|
$this->registry->getFactory(new OrX($spec1, $spec2)) |
|
|
|
|
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf( |
51
|
|
|
NotFactory::class, |
52
|
|
|
$this->registry->getFactory(new Not($spec1)) |
|
|
|
|
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testRegisterFactoryAddFactoryInRegistry() |
57
|
|
|
{ |
58
|
|
|
$factory = $this->createMock(Factory::class); |
59
|
|
|
$spec = $this->createMock(Specification::class); |
60
|
|
|
|
61
|
|
|
$this->handler->registerFactory(get_class($spec), $factory); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->assertEquals( |
64
|
|
|
$factory, |
65
|
|
|
$this->registry->getFactory($spec) |
|
|
|
|
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testHandle() |
70
|
|
|
{ |
71
|
|
|
$this->handler = new Handler(new Registry()); |
72
|
|
|
|
73
|
|
|
$factory = $this->prophesize(Factory::class); |
74
|
|
|
|
75
|
|
|
$spec = $this->createMock(Specification::class); |
76
|
|
|
$this->handler->registerFactory(get_class($spec), $factory->reveal()); |
77
|
|
|
|
78
|
|
|
$factory |
79
|
|
|
->create($spec) |
80
|
|
|
->willReturn('query') |
81
|
|
|
->shouldBeCalled() |
82
|
|
|
; |
83
|
|
|
|
84
|
|
|
$this->assertEquals('query', $this->handler->handle($spec)); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: