/
AbstractFileSystemLocatorTest.php
125 lines (105 loc) · 3.46 KB
/
AbstractFileSystemLocatorTest.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\Tests\Binary\Locator;
use Liip\ImagineBundle\Binary\Locator\FileSystemLocator;
use Liip\ImagineBundle\Binary\Locator\LocatorInterface;
use PHPUnit\Framework\TestCase;
abstract class AbstractFileSystemLocatorTest extends TestCase
{
public function testImplementsLocatorInterface()
{
$this->assertInstanceOf(LocatorInterface::class, new FileSystemLocator());
}
public function testThrowsIfEmptyRootPath()
{
$this->expectException(\Liip\ImagineBundle\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Root image path not resolvable');
$this->getFileSystemLocator('');
}
public function testThrowsIfRootPathDoesNotExist()
{
$this->expectException(\Liip\ImagineBundle\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Root image path not resolvable');
$this->getFileSystemLocator('/a/bad/root/path');
}
public function testThrowsIfFileDoesNotExist()
{
$this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class);
$this->expectExceptionMessage('Source image not resolvable');
$this->getFileSystemLocator(__DIR__)->locate('fileNotExist');
}
public function testThrowsIfRootPlaceholderInvalid()
{
$this->expectException(\Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException::class);
$this->expectExceptionMessage('Invalid root placeholder "@invalid-placeholder" for path');
$this->getFileSystemLocator(__DIR__)->locate('@invalid-placeholder:file.ext');
}
/**
* @return array[]
*/
public static function provideLoadCases()
{
return [];
}
/**
* @dataProvider provideLoadCases
*
* @param string $root
* @param string $path
*/
public function testLoad($root, $path)
{
$this->assertStringStartsWith(realpath($root.'/../'), $this->getFileSystemLocator($root)->locate($path));
}
/**
* @return array[]
*/
public static function provideMultipleRootLoadCases()
{
return [];
}
/**
* @dataProvider provideMultipleRootLoadCases
*
* @param string $root
* @param string $path
*/
public function testMultipleRootLoadCases($root, $path)
{
$this->assertNotNull($this->getFileSystemLocator($root)->locate($path));
}
/**
* @return array[]
*/
public function provideOutsideRootPathsData()
{
return [
['../Loader/../../Binary/Loader/../../../Resources/config/routing.yaml'],
['../../Binary/'],
];
}
/**
* @dataProvider provideOutsideRootPathsData
*
* @param string $path
*/
public function testThrowsIfRealPathOutsideRootPath($path)
{
$this->expectException(\Liip\ImagineBundle\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Root image path not resolvable');
$this->getFileSystemLocator($path)->locate($path);
}
/**
* @param string[]|string $paths
*
* @return LocatorInterface
*/
abstract protected function getFileSystemLocator($paths);
}