Completed
Push — master ( e32202...083db4 )
by Alex
08:17
created

IndexActionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 73
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the PierstovalCharacterManagerBundle package.
5
 *
6
 * (c) Alexandre Rock Ancelet <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pierstoval\Bundle\CharacterManagerBundle\Tests\Controller\GeneratorController;
13
14
use Pierstoval\Bundle\CharacterManagerBundle\Resolver\StepResolver;
15
use Pierstoval\Bundle\CharacterManagerBundle\Tests\Controller\AbstractGeneratorControllerTest;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\Routing\RouterInterface;
19
20
class IndexActionTest extends AbstractGeneratorControllerTest
21
{
22
    /**
23
     * @expectedException \RuntimeException
24
     * @expectedExceptionMessage Session is mandatory when using the character generator.
25
     */
26
    public function test index needs session()
27
    {
28
        $controller = $this->createController();
29
        $request = new Request();
30
31
        $controller->indexAction($request);
32
    }
33
34
    /**
35
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
36
     * @expectedExceptionMessage No step found to start the generator.
37
     */
38
    public function test index with no configuration returns 404()
39
    {
40
        $stepsResolver = new StepResolver(['manager' => ['steps' => []]]);
41
42
        $controller = $this->createController($stepsResolver);
43
        $request = $this->createRequest();
44
45
        $controller->indexAction($request);
46
    }
47
48
    public function test index with no step in session redirects to first step()
49
    {
50
        $resolver = new StepResolver([
51
            'manager_one' => $this->createManagerConfiguration('manager_one'),
52
        ]);
53
54
        $router = $this->createMock(RouterInterface::class);
55
        $router->expects(self::once())
56
            ->method('generate')
57
            ->with('pierstoval_character_generator_step', ['requestStep' => '01'])
58
            ->willReturn('/generate/01')
59
        ;
60
61
        $controller = $this->createController($resolver, $router);
62
        $request = $this->createRequest();
63
64
        $response = $controller->indexAction($request);
65
66
        static::assertInstanceOf(RedirectResponse::class, $response);
67
        static::assertSame('/generate/01', $response->headers->get('Location'));
68
    }
69
70
    public function test index with manager in session redirects to first step with manager name()
71
    {
72
        $resolver = new StepResolver([
73
            'manager_one' => $this->createManagerConfiguration('manager_one'),
74
        ]);
75
76
        $router = $this->createMock(RouterInterface::class);
77
        $router->expects(self::once())
78
            ->method('generate')
79
            ->with('pierstoval_character_generator_step', ['requestStep' => '01', 'manager' => 'manager_one'])
80
            ->willReturn('/generate/manager_one/01')
81
        ;
82
83
        $controller = $this->createController($resolver, $router);
84
        $request = $this->createRequest();
85
86
        $response = $controller->indexAction($request, 'manager_one');
87
88
        static::assertInstanceOf(RedirectResponse::class, $response);
89
        static::assertSame('/generate/manager_one/01', $response->headers->get('Location'));
90
    }
91
92
}
93