1 |
cd5c298a
|
Geoffroy Desvernay
|
<?php
|
2 |
|
|
namespace TYPO3\PharStreamWrapper;
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
class Behavior implements Assertable
|
15 |
|
|
{
|
16 |
|
|
const COMMAND_DIR_OPENDIR = 'dir_opendir';
|
17 |
|
|
const COMMAND_MKDIR = 'mkdir';
|
18 |
|
|
const COMMAND_RENAME = 'rename';
|
19 |
|
|
const COMMAND_RMDIR = 'rmdir';
|
20 |
|
|
const COMMAND_STEAM_METADATA = 'stream_metadata';
|
21 |
|
|
const COMMAND_STREAM_OPEN = 'stream_open';
|
22 |
|
|
const COMMAND_UNLINK = 'unlink';
|
23 |
|
|
const COMMAND_URL_STAT = 'url_stat';
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
private $availableCommands = array(
|
29 |
|
|
self::COMMAND_DIR_OPENDIR,
|
30 |
|
|
self::COMMAND_MKDIR,
|
31 |
|
|
self::COMMAND_RENAME,
|
32 |
|
|
self::COMMAND_RMDIR,
|
33 |
|
|
self::COMMAND_STEAM_METADATA,
|
34 |
|
|
self::COMMAND_STREAM_OPEN,
|
35 |
|
|
self::COMMAND_UNLINK,
|
36 |
|
|
self::COMMAND_URL_STAT,
|
37 |
|
|
);
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
private $assertions;
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
public function withAssertion(Assertable $assertable)
|
49 |
|
|
{
|
50 |
|
|
$commands = func_get_args();
|
51 |
|
|
array_shift($commands);
|
52 |
|
|
$this->assertCommands($commands);
|
53 |
|
|
$commands = $commands ?: $this->availableCommands;
|
54 |
|
|
|
55 |
|
|
$target = clone $this;
|
56 |
|
|
foreach ($commands as $command) {
|
57 |
|
|
$target->assertions[$command] = $assertable;
|
58 |
|
|
}
|
59 |
|
|
return $target;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
public function assert($path, $command)
|
68 |
|
|
{
|
69 |
|
|
$this->assertCommand($command);
|
70 |
|
|
$this->assertAssertionCompleteness();
|
71 |
|
|
|
72 |
|
|
return $this->assertions[$command]->assert($path, $command);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
private function assertCommands(array $commands)
|
79 |
|
|
{
|
80 |
|
|
$unknownCommands = array_diff($commands, $this->availableCommands);
|
81 |
|
|
if (empty($unknownCommands)) {
|
82 |
|
|
return;
|
83 |
|
|
}
|
84 |
|
|
throw new \LogicException(
|
85 |
|
|
sprintf(
|
86 |
|
|
'Unknown commands: %s',
|
87 |
|
|
implode(', ', $unknownCommands)
|
88 |
|
|
),
|
89 |
|
|
1535189881
|
90 |
|
|
);
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
private function assertCommand($command)
|
94 |
|
|
{
|
95 |
|
|
if (in_array($command, $this->availableCommands, true)) {
|
96 |
|
|
return;
|
97 |
|
|
}
|
98 |
|
|
throw new \LogicException(
|
99 |
|
|
sprintf(
|
100 |
|
|
'Unknown command "%s"',
|
101 |
|
|
$command
|
102 |
|
|
),
|
103 |
|
|
1535189882
|
104 |
|
|
);
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
private function assertAssertionCompleteness()
|
108 |
|
|
{
|
109 |
|
|
$undefinedAssertions = array_diff(
|
110 |
|
|
$this->availableCommands,
|
111 |
|
|
array_keys($this->assertions)
|
112 |
|
|
);
|
113 |
|
|
if (empty($undefinedAssertions)) {
|
114 |
|
|
return;
|
115 |
|
|
}
|
116 |
|
|
throw new \LogicException(
|
117 |
|
|
sprintf(
|
118 |
|
|
'Missing assertions for commands: %s',
|
119 |
|
|
implode(', ', $undefinedAssertions)
|
120 |
|
|
),
|
121 |
|
|
1535189883
|
122 |
|
|
);
|
123 |
|
|
}
|
124 |
|
|
} |