1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* apparat-dev |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Server |
8
|
|
|
* @subpackage Apparat\Dev\Tests |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Apparat\Dev\Tests { |
38
|
|
|
|
39
|
|
|
use Apparat\Dev\Ports\Repository; |
40
|
|
|
use Apparat\Object\Ports\Object; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Repository test |
44
|
|
|
* |
45
|
|
|
* @package Apparat\Dev |
46
|
|
|
* @subpackage Apparat\Dev\Tests |
47
|
|
|
*/ |
48
|
|
|
class RepositoryTest extends AbstractTest |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* Tears down the fixture |
52
|
|
|
*/ |
53
|
|
|
public function tearDown() |
54
|
|
|
{ |
55
|
|
|
putenv('MOCK_MKDIR'); |
56
|
|
|
putenv('MOCK_TOUCH'); |
57
|
|
|
parent::tearDown(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test the generation of a test repository |
62
|
|
|
* |
63
|
|
|
* @expectedException \Apparat\Dev\Ports\InvalidArgumentsException |
64
|
|
|
* @expectedExceptionCode 1464974472 |
65
|
|
|
*/ |
66
|
|
|
public function testRepositoryBuildInvalidRoot() |
67
|
|
|
{ |
68
|
|
|
Repository::generate(null, []); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test the generation of a test repository with an empty object configuration |
73
|
|
|
* |
74
|
|
|
* @expectedException \Apparat\Dev\Ports\InvalidArgumentsException |
75
|
|
|
* @expectedExceptionCode 1464974779 |
76
|
|
|
*/ |
77
|
|
|
public function testRepositoryBuildInvalidObjectConfig() |
78
|
|
|
{ |
79
|
|
|
Repository::generate($this->createTemporaryFileName(), [], Repository::FLAG_CREATE_ROOT_DIRECTORY); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Test the generation of a test repository with zero object count |
84
|
|
|
* |
85
|
|
|
* @expectedException \Apparat\Dev\Ports\InvalidArgumentsException |
86
|
|
|
* @expectedExceptionCode 1464975382 |
87
|
|
|
*/ |
88
|
|
|
public function testRepositoryBuildEmptyObjectCount() |
89
|
|
|
{ |
90
|
|
|
$objectConfig = [ |
91
|
|
|
Object::ARTICLE => [] |
92
|
|
|
]; |
93
|
|
|
Repository::generate($this->createTemporaryFileName(), $objectConfig, |
94
|
|
|
Repository::FLAG_CREATE_ROOT_DIRECTORY); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Test the generation of a test repository |
99
|
|
|
*/ |
100
|
|
|
public function testRepositoryBuild() |
101
|
|
|
{ |
102
|
|
|
$objectConfig = [ |
103
|
|
|
Object::ARTICLE => [ |
104
|
|
|
Repository::COUNT => 100, |
105
|
|
|
Repository::HIDDEN => true, |
106
|
|
|
Repository::DRAFTS => true, |
107
|
|
|
], |
108
|
|
|
Object::EVENT => [ |
109
|
|
|
Repository::COUNT => 100, |
110
|
|
|
], |
111
|
|
|
Object::CONTACT => [ |
112
|
|
|
Repository::COUNT => 100, |
113
|
|
|
Repository::REVISIONS => -3, |
114
|
|
|
Repository::DRAFTS => true, |
115
|
|
|
] |
116
|
|
|
]; |
117
|
|
|
Repository::generate( |
118
|
|
|
sys_get_temp_dir().DIRECTORY_SEPARATOR.'apparat-test', |
119
|
|
|
$objectConfig, |
120
|
|
|
Repository::FLAG_CREATE_ROOT_DIRECTORY | Repository::FLAG_EMPTY_FILES |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Test the repository generation with failing mkdir() |
126
|
|
|
* |
127
|
|
|
* @expectedException \Apparat\Dev\Ports\RuntimeException |
128
|
|
|
* @expectedExceptionCode 1464997310 |
129
|
|
|
*/ |
130
|
|
|
public function testRepositoryBuildFailingMkdir() |
131
|
|
|
{ |
132
|
|
|
putenv('MOCK_MKDIR=1'); |
133
|
|
|
$this->testRepositoryBuild(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Test the repository generation with failing touch() |
138
|
|
|
* |
139
|
|
|
* @expectedException \Apparat\Dev\Ports\RuntimeException |
140
|
|
|
* @expectedExceptionCode 1464997761 |
141
|
|
|
*/ |
142
|
|
|
public function testRepositoryBuildFailingTouch() |
143
|
|
|
{ |
144
|
|
|
putenv('MOCK_TOUCH=1'); |
145
|
|
|
$this->testRepositoryBuild(); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
namespace Apparat\Dev\Infrastructure\Factory { |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Create a directory |
154
|
|
|
* |
155
|
|
|
* @param string $pathname Path name |
156
|
|
|
* @param int $mode File mode |
157
|
|
|
* @param bool $recursive Create parent directories |
158
|
|
|
* @return bool Success |
159
|
|
|
*/ |
160
|
|
|
function mkdir($pathname, $mode = 0777, $recursive = false) |
161
|
|
|
{ |
162
|
|
|
return (getenv('MOCK_MKDIR') != 1) ? \mkdir($pathname, $mode, $recursive) : false; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Sets access and modification time of file |
167
|
|
|
* |
168
|
|
|
* @param string $filename File name |
169
|
|
|
* @param null $time Modification time |
170
|
|
|
* @param null $atime Access time |
171
|
|
|
* @return bool Success |
172
|
|
|
*/ |
173
|
|
|
function touch($filename, $time = null, $atime = null) |
174
|
|
|
{ |
175
|
|
|
return (getenv('MOCK_TOUCH') != 1) ? \touch($filename, $time, $atime) : false; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|