Completed
Push — master ( 51af85...b489fc )
by Pavel
06:35
created

SeoPageTest::testControllerEvents()   B

Complexity

Conditions 4
Paths 12

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 20
nc 12
nop 3
1
<?php
2
3
namespace Bankiru\Seo\Tests\Bundle;
4
5
use Bankiru\Seo\Entity\TargetDefinition;
6
use Bankiru\Seo\Exception\MatchingException;
7
use Bankiru\Seo\Integration\Local\StaticPageRepository;
8
use Bankiru\Seo\Integration\Local\StaticTargetRepository;
9
use Bankiru\Seo\Page\SeoPageBuilder;
10
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
11
12
abstract class SeoPageTest extends WebTestCase
13
{
14
    protected static function getKernelClass()
15
    {
16
        return SeoKernel::class;
17
    }
18
19
    public function getRoutes()
20
    {
21
        return [
22
            'event match'    => ['event_controller_match', 'test/match', 'Title'],
23
            'event no match' => ['event_controller_no_match', 'test/no_match', false],
24
            'event no seo'   => ['event_controller_no_seo', 'test/no_seo', 'not_found'],
25
        ];
26
    }
27
28
    /**
29
     * @dataProvider getRoutes
30
     *
31
     * @param string       $route
32
     * @param string       $path
33
     * @param string|false $response
34
     */
35
    public function testControllerEvents($route, $path, $response)
36
    {
37
        $container = static::$kernel->getContainer();
38
39
        $target = new TargetDefinition($route);
40
        $page   = (new SeoPageBuilder())->setTitle('Title')->getSeoPage();
41
42
        $targetRepo = new StaticTargetRepository();
43
        $pageRepo   = new StaticPageRepository();
44
        $container->set('bankiru.seo.target_repository', $targetRepo);
45
        $container->set('bankiru.seo.page_repository', $pageRepo);
46
47
        $targetRepo->add($target);
48
        $pageRepo->add($target, $page);
49
50
        $client = static::createClient();
51
52
        try {
53
            $client->request('GET', $path);
54
            $serverResponse = $client->getResponse()->getContent();
55
56
            if (false === $response) {
57
                self::fail('Should fail with match exception. '.$serverResponse);
58
            }
59
60
            self::assertSame($response, $serverResponse);
61
        } catch (MatchingException $exception) {
62
            if (false !== $response) {
63
                throw $exception;
64
            }
65
        }
66
    }
67
68
    protected function setUp()
69
    {
70
        self::bootKernel();
71
    }
72
}
73