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

SeoPageTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 9
dl 0
loc 61
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getKernelClass() 0 4 1
A getRoutes() 0 8 1
B testControllerEvents() 0 32 4
A setUp() 0 4 1
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