1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
declare(strict_types=1); |
20
|
|
|
|
21
|
|
|
namespace ProxyManagerTest\Exception; |
22
|
|
|
|
23
|
|
|
use PHPUnit_Framework_TestCase; |
24
|
|
|
use ProxyManager\Exception\FileNotWritableException; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Tests for {@see \ProxyManager\Exception\FileNotWritableException} |
28
|
|
|
* |
29
|
|
|
* @author Marco Pivetta <[email protected]> |
30
|
|
|
* @license MIT |
31
|
|
|
* |
32
|
|
|
* @covers \ProxyManager\Exception\FileNotWritableException |
33
|
|
|
* @group Coverage |
34
|
|
|
*/ |
35
|
|
|
class FileNotWritableExceptionTest extends PHPUnit_Framework_TestCase |
36
|
|
|
{ |
37
|
|
|
public function testFromInvalidMoveOperation() |
38
|
|
|
{ |
39
|
|
|
$exception = FileNotWritableException::fromInvalidMoveOperation('/tmp/a', '/tmp/b'); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(FileNotWritableException::class, $exception); |
42
|
|
|
$this->assertSame( |
43
|
|
|
'Could not move file "/tmp/a" to location "/tmp/b": either the source file is not readable,' |
44
|
|
|
. ' or the destination is not writable', |
45
|
|
|
$exception->getMessage() |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testFromNotWritableLocationWithNonFilePath() |
50
|
|
|
{ |
51
|
|
|
$exception = FileNotWritableException::fromNonWritableLocation(__DIR__); |
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf(FileNotWritableException::class, $exception); |
54
|
|
|
$this->assertSame( |
55
|
|
|
'Could not write to path "' . __DIR__ . '": exists and is not a file', |
56
|
|
|
$exception->getMessage() |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testFromNotWritableLocationWithNonWritablePath() |
61
|
|
|
{ |
62
|
|
|
$path = sys_get_temp_dir() . '/' . uniqid('FileNotWritableExceptionTestNonWritable', true); |
63
|
|
|
|
64
|
|
|
mkdir($path, 0555); |
65
|
|
|
|
66
|
|
|
$exception = FileNotWritableException::fromNonWritableLocation($path); |
67
|
|
|
|
68
|
|
|
$this->assertInstanceOf(FileNotWritableException::class, $exception); |
69
|
|
|
$this->assertSame( |
70
|
|
|
'Could not write to path "' . $path . '": exists and is not a file, is not writable', |
71
|
|
|
$exception->getMessage() |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testFromNonExistingPath() |
76
|
|
|
{ |
77
|
|
|
$path = sys_get_temp_dir() . '/' . uniqid('FileNotWritableExceptionTestNonWritable', true); |
78
|
|
|
|
79
|
|
|
$exception = FileNotWritableException::fromNonWritableLocation($path . '/foo'); |
80
|
|
|
|
81
|
|
|
$this->assertInstanceOf(FileNotWritableException::class, $exception); |
82
|
|
|
$this->assertSame( |
83
|
|
|
'Could not write to path "' . $path . '/foo": path does not exist', |
84
|
|
|
$exception->getMessage() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|