@@ 11-83 (lines=73) @@ | ||
8 | use GBProd\Specification\AndX; |
|
9 | use GBProd\Specification\Specification; |
|
10 | ||
11 | class AndXFactoryTest extends \PHPUnit_Framework_TestCase |
|
12 | { |
|
13 | public function testConstruct() |
|
14 | { |
|
15 | $factory = new AndXFactory(new Registry()); |
|
16 | ||
17 | $this->assertInstanceOf(AndXFactory::class, $factory); |
|
18 | } |
|
19 | ||
20 | public function testCreateReturnsAndxQuery() |
|
21 | { |
|
22 | $andx = $this->createAndX(); |
|
23 | $registry = $this->createRegistry($andx); |
|
24 | ||
25 | $factory = new AndXFactory($registry); |
|
26 | ||
27 | $query = $factory->create($andx); |
|
28 | ||
29 | $this->assertEquals('(first_part) AND (second_part)', $query); |
|
30 | } |
|
31 | ||
32 | /** |
|
33 | * @return AndX |
|
34 | */ |
|
35 | private function createAndX() |
|
36 | { |
|
37 | return new AndX( |
|
38 | $this->prophesize(Specification::class)->reveal(), |
|
39 | $this->prophesize(Specification::class)->reveal() |
|
40 | ); |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * @param AndX $andx |
|
45 | * |
|
46 | * @return Registry |
|
47 | */ |
|
48 | private function createRegistry($andx) |
|
49 | { |
|
50 | $firstFactory = $this->createMock(Factory::class); |
|
51 | $firstFactory |
|
52 | ->expects($this->any()) |
|
53 | ->method('create') |
|
54 | ->willReturn('first_part') |
|
55 | ; |
|
56 | ||
57 | $secondFactory = $this->createMock(Factory::class); |
|
58 | $secondFactory |
|
59 | ->expects($this->any()) |
|
60 | ->method('create') |
|
61 | ->willReturn('second_part') |
|
62 | ; |
|
63 | ||
64 | $registry = new Registry(); |
|
65 | ||
66 | $registry->register(get_class($andx->getFirstPart()), $firstFactory); |
|
67 | $registry->register(get_class($andx->getSecondPart()), $secondFactory); |
|
68 | ||
69 | return $registry; |
|
70 | } |
|
71 | ||
72 | ||
73 | public function testCreateThrowExceptionIfNotAndXSpecification() |
|
74 | { |
|
75 | $spec = $this->createMock(Specification::class); |
|
76 | $registry = new Registry(); |
|
77 | $factory = new AndXFactory($registry); |
|
78 | ||
79 | $this->expectException(\InvalidArgumentException::class); |
|
80 | ||
81 | $factory->create($spec); |
|
82 | } |
|
83 | } |
|
84 |
@@ 11-83 (lines=73) @@ | ||
8 | use GBProd\Specification\OrX; |
|
9 | use GBProd\Specification\Specification; |
|
10 | ||
11 | class OrXFactoryTest extends \PHPUnit_Framework_TestCase |
|
12 | { |
|
13 | public function testConstruct() |
|
14 | { |
|
15 | $factory = new OrXFactory(new Registry()); |
|
16 | ||
17 | $this->assertInstanceOf(OrXFactory::class, $factory); |
|
18 | } |
|
19 | ||
20 | public function testCreateReturnsAndxQuery() |
|
21 | { |
|
22 | $andx = $this->createOrX(); |
|
23 | $registry = $this->createRegistry($andx); |
|
24 | ||
25 | $factory = new OrXFactory($registry); |
|
26 | ||
27 | $query = $factory->create($andx); |
|
28 | ||
29 | $this->assertEquals('(first_part) OR (second_part)', $query); |
|
30 | } |
|
31 | ||
32 | /** |
|
33 | * @return OrX |
|
34 | */ |
|
35 | private function createOrX() |
|
36 | { |
|
37 | return new OrX( |
|
38 | $this->prophesize(Specification::class)->reveal(), |
|
39 | $this->prophesize(Specification::class)->reveal() |
|
40 | ); |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * @param OrX $andx |
|
45 | * |
|
46 | * @return Registry |
|
47 | */ |
|
48 | private function createRegistry($andx) |
|
49 | { |
|
50 | $firstFactory = $this->createMock(Factory::class); |
|
51 | $firstFactory |
|
52 | ->expects($this->any()) |
|
53 | ->method('create') |
|
54 | ->willReturn('first_part') |
|
55 | ; |
|
56 | ||
57 | $secondFactory = $this->createMock(Factory::class); |
|
58 | $secondFactory |
|
59 | ->expects($this->any()) |
|
60 | ->method('create') |
|
61 | ->willReturn('second_part') |
|
62 | ; |
|
63 | ||
64 | $registry = new Registry(); |
|
65 | ||
66 | $registry->register(get_class($andx->getFirstPart()), $firstFactory); |
|
67 | $registry->register(get_class($andx->getSecondPart()), $secondFactory); |
|
68 | ||
69 | return $registry; |
|
70 | } |
|
71 | ||
72 | ||
73 | public function testCreateThrowExceptionIfNotOrXSpecification() |
|
74 | { |
|
75 | $spec = $this->createMock(Specification::class); |
|
76 | $registry = new Registry(); |
|
77 | $factory = new OrXFactory($registry); |
|
78 | ||
79 | $this->expectException(\InvalidArgumentException::class); |
|
80 | ||
81 | $factory->create($spec); |
|
82 | } |
|
83 | } |
|
84 |