forked from sonata-project/SonataAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControllerGeneratorTest.php
92 lines (78 loc) · 2.72 KB
/
ControllerGeneratorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Tests\Generator;
use Sonata\AdminBundle\Generator\ControllerGenerator;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
/**
* @author Marek Stipek <[email protected]>
*/
class ControllerGeneratorTest extends \PHPUnit_Framework_TestCase
{
/** @var ControllerGenerator */
private $controllerGenerator;
/** @var BundleInterface|\PHPUnit_Framework_MockObject_MockObject */
private $bundleMock;
/** @var string */
private $bundlePath;
/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->controllerGenerator = new ControllerGenerator(__DIR__ . '/../../Resources/skeleton');
$this->bundleMock = $this->createBundleMock();
$this->bundlePath = $this->bundleMock->getPath();
}
/**
* {@inheritDoc}
*/
protected function tearDown()
{
$filesystem = new Filesystem();
$filesystem->remove($this->bundlePath);
}
public function testGenerate()
{
$this->controllerGenerator->generate($this->bundleMock, 'ModelAdminController');
$file = $this->controllerGenerator->getFile();
$this->assertEquals(
'Sonata\AdminBundle\Tests\Fixtures\Controller\ModelAdminController',
$this->controllerGenerator->getClass()
);
$this->assertEquals('ModelAdminController.php', basename($file));
$this->assertFileEquals(__DIR__ . '/../Fixtures/Controller/ModelAdminController.php', $file);
try {
$this->controllerGenerator->generate($this->bundleMock, 'ModelAdminController');
} catch (\RuntimeException $e) {
$this->assertContains('already exists', $e->getMessage());
return;
}
$this->fail('Failed asserting that exception of type "\RuntimeException" is thrown.');
}
/**
* @return BundleInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private function createBundleMock()
{
$bundleMock = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
$bundleMock
->expects($this->any())
->method('getNamespace')
->will($this->returnValue('Sonata\AdminBundle\Tests\Fixtures'))
;
$bundleMock
->expects($this->any())
->method('getPath')
->will($this->returnValue(sprintf('%s/%s', sys_get_temp_dir(), lcg_value())))
;
return $bundleMock;
}
}