1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the IrishDan\ResponsiveImageBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) Daniel Byrne <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE file that was distributed with this source |
8
|
|
|
* code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace IrishDan\ResponsiveImageBundle; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\HttpKernel\Config\FileLocator; |
14
|
|
|
|
15
|
|
|
class ImageEntityClassLocatorTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
public function getBundleDirectory() |
18
|
|
|
{ |
19
|
|
|
return $directory = __DIR__ . '/../'; |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
View Code Duplication |
public function testItCanFindTheClassWhenPresent() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
// Mock the FileLocator to return the mock of the repository |
25
|
|
|
$fileLocator = $this->getMockBuilder(FileLocator::class) |
26
|
|
|
->disableOriginalConstructor() |
27
|
|
|
->getMock(); |
28
|
|
|
|
29
|
|
|
$fileLocator->expects($this->any()) |
30
|
|
|
->method('locate') |
31
|
|
|
->will($this->returnValue($this->getBundleDirectory())); |
32
|
|
|
|
33
|
|
|
$bundles = [ |
34
|
|
|
'ResponsiveImageBundle' => 'IrishDan\ResponsiveImageBundle\ResponsiveImageBundle', |
35
|
|
|
'TwigBundle' => "Symfony\Bundle\TwigBundle\TwigBundle", |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
$locator = new ImageEntityClassLocator($bundles, $fileLocator); |
39
|
|
|
|
40
|
|
|
$locator->setEntityDirectory('Tests/Entity'); |
41
|
|
|
|
42
|
|
|
$this->assertEquals('IrishDan\ResponsiveImageBundle\Tests\Entity\TestImage', $locator->getClassName()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function testItCantFindTheClassWhenNotPresent() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
// Mock the EntityManager to return the mock of the repository |
48
|
|
|
$fileLocator = $this->getMockBuilder(FileLocator::class) |
49
|
|
|
->disableOriginalConstructor() |
50
|
|
|
->getMock(); |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
$fileLocator->expects($this->any()) |
54
|
|
|
->method('locate') |
55
|
|
|
->will($this->returnValue($this->getBundleDirectory())); |
56
|
|
|
|
57
|
|
|
$bundles = [ |
58
|
|
|
'ResponsiveImageBundle' => 'IrishDan\ResponsiveImageBundle\ResponsiveImageBundle', |
59
|
|
|
'TwigBundle' => 'Symfony\Bundle\TwigBundle\TwigBundle', |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
$locator = new ImageEntityClassLocator($bundles, $fileLocator); |
63
|
|
|
|
64
|
|
|
$this->assertNull($locator->getClassName()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.