|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bankiru\Seo\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Bankiru\Seo\Exception\DestinationException; |
|
6
|
|
|
use Bankiru\Seo\Generator\DestinationGenerator; |
|
7
|
|
|
use Bankiru\Seo\Integration\Local\CallbackFiller; |
|
8
|
|
|
use Bankiru\Seo\Integration\Local\CollectionSource; |
|
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
10
|
|
|
|
|
11
|
|
|
class DestinationGeneratorTest extends \PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testGeneratorCircularityException() |
|
14
|
|
|
{ |
|
15
|
|
|
$source = new CollectionSource(new ArrayCollection([1, 2, 3])); |
|
16
|
|
|
|
|
17
|
|
|
$generator = new DestinationGenerator(); |
|
18
|
|
|
try { |
|
19
|
|
|
$generator->generate( |
|
20
|
|
|
'random_route_id', |
|
21
|
|
|
[ |
|
22
|
|
|
'source_arg' => $source, |
|
23
|
|
|
], |
|
24
|
|
|
[ |
|
25
|
|
|
'filler_1' => $this->createCloneFiller(['filler_2']), |
|
26
|
|
|
'filler_2' => $this->createCloneFiller(['filler_3']), |
|
27
|
|
|
'filler_3' => $this->createCloneFiller(['filler_1']), |
|
28
|
|
|
] |
|
29
|
|
|
); |
|
30
|
|
|
} catch (DestinationException $exception) { |
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
self::fail('Circular dependency was not detected'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGeneratorInference() |
|
38
|
|
|
{ |
|
39
|
|
|
$route = 'random_route_id'; |
|
40
|
|
|
$source = new CollectionSource(new ArrayCollection([1, 2, 3])); |
|
41
|
|
|
|
|
42
|
|
|
$generator = new DestinationGenerator(); |
|
43
|
|
|
|
|
44
|
|
|
$destinations = $generator->generate( |
|
45
|
|
|
$route, |
|
46
|
|
|
['source_arg' => $source], |
|
47
|
|
|
['filler_1' => $this->createCloneFiller(['source_arg'])] |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
self::assertCount(3, $destinations); |
|
51
|
|
|
foreach ($destinations as $destination) { |
|
52
|
|
|
self::assertSame($route, $destination->getRoute()); |
|
53
|
|
|
self::assertNotNull($destination->resolve('source_arg')); |
|
54
|
|
|
self::assertNotNull($destination->resolve('filler_1')); |
|
55
|
|
|
self::assertSame($destination->resolve('source_arg'), $destination->resolve('filler_1')); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function createCloneFiller(array $dependencies) |
|
60
|
|
|
{ |
|
61
|
|
|
return new CallbackFiller( |
|
62
|
|
|
$dependencies, function ($items) { |
|
63
|
|
|
return array_shift($items); |
|
64
|
|
|
} |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|