1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BestIt\KitchensinkBundle\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use BestIt\KitchensinkBundle\Controller\KitchensinkController; |
6
|
|
|
use BestIt\KitchensinkBundle\DataProviderInterface; |
7
|
|
|
use BestIt\KitchensinkBundle\Tests\ContainerProviderTrait; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class KitchensinkControllerTest |
15
|
|
|
* @author blange <[email protected]> |
16
|
|
|
* @category Tests |
17
|
|
|
* @package BestIt\KitchensinkBundle |
18
|
|
|
* @subpackage Controller |
19
|
|
|
* @version $id$ |
20
|
|
|
*/ |
21
|
|
|
class KitchensinkControllerTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
use ContainerProviderTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The used container. |
27
|
|
|
* @var ContainerBuilder |
28
|
|
|
*/ |
29
|
|
|
private $container = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The tested class. |
33
|
|
|
* @var KitchensinkController |
34
|
|
|
*/ |
35
|
|
|
private $fixture = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Sets up the test. |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function setUp() |
42
|
|
|
{ |
43
|
|
|
$this->fixture = new KitchensinkController(); |
44
|
|
|
|
45
|
|
|
$this->fixture->setContainer($this->container = $this->getFullyLoadedContainer()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Checks if the response can be rendered. |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function testIndexAction() |
53
|
|
|
{ |
54
|
|
|
$this->container->set('templating', $mock = static::createMock(EngineInterface::class)); |
55
|
|
|
|
56
|
|
|
$mock |
57
|
|
|
->method('renderResponse') |
58
|
|
|
->with( |
59
|
|
|
$this->fixture->getTemplateName(), |
60
|
|
|
[ |
61
|
|
|
'foo' => 'BestIt\KitchensinkBundle\Tests\DataProviderFake::bar', |
62
|
|
|
'foobar' => 'BestIt\KitchensinkBundle\Tests\DataProviderFake::getFoobar', |
63
|
|
|
'foobarBaz' => 'BestIt\KitchensinkBundle\Tests\DataProviderFake::getFoobarBaz' |
64
|
|
|
] |
65
|
|
|
) |
66
|
|
|
->willReturn($response = static::createMock(Response::class)); |
67
|
|
|
|
68
|
|
|
static::assertSame($response, $this->fixture->indexAction()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Checks the getter and setter for the template name. |
73
|
|
|
* @covers KitchensinkController::getDataProvider() |
74
|
|
|
* @covers KitchensinkController::setDataProvider() |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function testSetAndGetDataProvider() |
78
|
|
|
{ |
79
|
|
|
static::assertInstanceOf( |
80
|
|
|
DataProviderInterface::class, |
81
|
|
|
$this->fixture->getDataProvider(), |
82
|
|
|
'Wrong default return.' |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
static::assertSame( |
86
|
|
|
$this->fixture, |
87
|
|
|
$this->fixture->setDataProvider($mock = static::createMock(DataProviderInterface::class)), |
88
|
|
|
'Fluent interface broken.' |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
static::assertSame($mock, $this->fixture->getDataProvider(), 'Value not saved.'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Checks the getter and setter for the template name. |
96
|
|
|
* @covers KitchensinkController::getTemplateName() |
97
|
|
|
* @covers KitchensinkController::setTemplateName() |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
public function testSetAndGetTemplateName() |
101
|
|
|
{ |
102
|
|
|
static::assertSame('kitchensink/index.html.twig', $this->fixture->getTemplateName(), 'Wrong default return.'); |
103
|
|
|
|
104
|
|
|
static::assertSame( |
105
|
|
|
$this->fixture, |
106
|
|
|
$this->fixture->setTemplateName($mock = uniqid()), |
107
|
|
|
'Fluent interface broken.' |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
static::assertSame($mock, $this->fixture->getTemplateName(), 'Value not saved.'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|