Completed
Push — master ( 117216...05d77e )
by Pavel
05:39 queued 11s
created

ProcessorTest::getItems()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 0
1
<?php
2
3
namespace Bankiru\Seo\Tests;
4
5
use Bankiru\Seo\Destination;
6
use Bankiru\Seo\DestinationInterface;
7
use Bankiru\Seo\Entity\TargetDefinition;
8
use Bankiru\Seo\Exception\ProcessingException;
9
use Bankiru\Seo\Integration\Local\ExactCondition;
10
use Bankiru\Seo\Page\SeoPageBuilder;
11
use Bankiru\Seo\PageRepositoryInterface;
12
use Bankiru\Seo\Processor;
13
use Bankiru\Seo\TargetDefinitionInterface;
14
use Bankiru\Seo\TargetRepositoryInterface;
15
use Prophecy\Argument;
16
17
class ProcessorTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function getItems()
20
    {
21
        $route = 'any_random_route_id';
22
        $c1    = new ExactCondition('1');
23
        $c2    = new ExactCondition(2);
24
25
        $d1      = new TargetDefinition($route);
26
        $d2      = new TargetDefinition($route);
27
        $d3      = new TargetDefinition($route);
28
        $d4      = new TargetDefinition($route);
29
        $targets = [$d1, $d2, $d3, $d4];
30
31
        foreach ($targets as $target) {
32
            $c1->attach($target, 'arg1');
33
            $c2->attach($target, 'arg2');
34
        }
35
36
        return [
37
            'exact match'   => [$route, $targets, ['arg1' => '1', 'arg2' => 2], true],
38
            'arg1 no match' => [$route, $targets, ['arg1' => 2, 'arg2' => 2], false],
39
            'arg2 no match' => [$route, $targets, ['arg1' => '1', 'arg2' => 1], false],
40
            'no match'      => [$route, $targets, ['arg1' => '5', 'arg2' => 3], false],
41
        ];
42
    }
43
44
    /**
45
     * @dataProvider getItems
46
     *
47
     * @param string $route
48
     * @param array  $targets
49
     * @param array  $items
50
     *
51
     * @internal     param $route
52
     */
53
    public function testProcessing($route, array $targets, array $items, $match)
54
    {
55
56
        $page = (new SeoPageBuilder())
57
            ->setTitle('Test Page')
58
            ->getSeoPage();
59
60
        $targetRepository = $this->prophesize(TargetRepositoryInterface::class);
61
        $targetRepository->findByRoute(Argument::exact($route))->willReturn($targets);
62
        $targetRepository = $targetRepository->reveal();
63
64
        $pageRepository = $this->prophesize(PageRepositoryInterface::class);
65
        $pageRepository
66
            ->getByTargetDestination(
67
                Argument::type(TargetDefinitionInterface::class),
68
                Argument::type(DestinationInterface::class)
69
            )
70
            ->willReturn($page);
71
        $pageRepository = $pageRepository->reveal();
72
73
        $processor = new Processor($targetRepository, $pageRepository);
74
75
        $destination = new Destination($route, $items);
76
77
        try {
78
            $seoPage = $processor->process($destination);
79
            if (!$match) {
80
                self::fail('Should not match');
81
            }
82
            self::assertEquals($page, $seoPage);
83
        } catch (ProcessingException $exception) {
84
            if ($match) {
85
                throw $exception;
86
            }
87
        }
88
    }
89
}
90