Completed
Push — master ( 99533f...82ed85 )
by Pavel
03:26
created

SeoPageTest::testControllerEvents()   B

Complexity

Conditions 4
Paths 12

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 31
rs 8.5806
c 1
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
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13
class SeoPageTest extends WebTestCase
14
{
15
    protected static function getKernelClass()
16
    {
17
        return SeoKernel::class;
18
    }
19
20
    public function getRoutes()
21
    {
22
        return [
23
            'event match'    => ['event_controller_match', 'test/match', 'Title'],
24
            'event no match' => ['event_controller_match', 'test/no_match', false],
25
            'event no seo'   => ['event_controller_match', 'test/no_seo', 'not_found'],
26
        ];
27
    }
28
29
    /**
30
     * @dataProvider getRoutes
31
     *
32
     * @param string       $route
33
     * @param string       $path
34
     * @param string|false $response
35
     */
36
    public function testControllerEvents($route, $path, $response)
37
    {
38
        $client    = static::createClient();
39
        $container = static::$kernel->getContainer();
40
41
        $target = new TargetDefinition($route);
42
        $page   = (new SeoPageBuilder())->setTitle('Title')->getSeoPage();
43
44
        $targetRepo = new StaticTargetRepository();
45
        $pageRepo   = new StaticPageRepository();
46
        $container->set('bankiru.seo.target_repository', $targetRepo);
47
        $container->set('bankiru.seo.page_repository', $pageRepo);
48
49
        $targetRepo->add($target);
50
        $pageRepo->add($target, $page);
51
52
        try {
53
            $client->request('GET', $path);
54
            $serverResponse = $client->getResponse()->getContent();
55
56
            if (false === $response) {
57
                self::fail(sprintf('Should fail with match exception. Received "%s"', $serverResponse));
58
            }
59
60
            self::assertSame($response, $serverResponse);
61
        } catch (NotFoundHttpException $exception) {
62
            if (false !== $response) {
63
                throw $exception;
64
            }
65
        }
66
    }
67
68
    protected function setUp()
69
    {
70
        self::bootKernel();
71
    }
72
}
73