|
18 | 18 |
|
19 | 19 | namespace Composer\ClassMapGenerator;
|
20 | 20 |
|
21 |
| -use Composer\ClassMapGenerator\ClassMapGenerator; |
22 | 21 | use PHPUnit\Framework\TestCase;
|
23 | 22 | use Symfony\Component\Finder\Finder;
|
24 | 23 | use Symfony\Component\Filesystem\Filesystem;
|
@@ -150,6 +149,86 @@ public function testCreateMapFinderSupport(): void
|
150 | 149 | ), ClassMapGenerator::createMap($finder));
|
151 | 150 | }
|
152 | 151 |
|
| 152 | + /** |
| 153 | + * @see ClassMapGenerator::isStreamWrapper() |
| 154 | + */ |
| 155 | + public function testStreamWrapperSupport(): void { |
| 156 | + |
| 157 | + /** |
| 158 | + * A stream wrapper that given `test://myfile.php` will read `test://path/to/myfile.php` where `path/to` is |
| 159 | + * set on the `$rootPath` static variable. |
| 160 | + */ |
| 161 | + $testProxyStreamWrapper = new class() { |
| 162 | + /** |
| 163 | + * @var string |
| 164 | + */ |
| 165 | + public static $rootPath; |
| 166 | + |
| 167 | + /** |
| 168 | + * @var string |
| 169 | + */ |
| 170 | + protected $real; |
| 171 | + |
| 172 | + /** |
| 173 | + * @var resource|false |
| 174 | + */ |
| 175 | + protected $resource; |
| 176 | + |
| 177 | + /** |
| 178 | + * @param string $path |
| 179 | + * @param string $mode |
| 180 | + * @param int $options |
| 181 | + * @param ?string $opened_path |
| 182 | + * |
| 183 | + * @return bool |
| 184 | + */ |
| 185 | + public function stream_open($path, $mode, $options, &$opened_path) { |
| 186 | + $scheme = parse_url($path, PHP_URL_SCHEME); |
| 187 | + $varname = str_replace($scheme . '://', '', $path); |
| 188 | + |
| 189 | + $this->real = 'file://' . self::$rootPath . '/' . $varname; |
| 190 | + |
| 191 | + $this->resource = fopen($this->real, $mode); |
| 192 | + |
| 193 | + return (bool) $this->resource; |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * @param int<0, max>|null $count |
| 198 | + * |
| 199 | + * @return false|string |
| 200 | + */ |
| 201 | + public function stream_read($count) { |
| 202 | + return $this->resource === false ? false : fgets($this->resource, (int) $count); |
| 203 | + } |
| 204 | + |
| 205 | + /** |
| 206 | + * @return array<int|string, int>|false |
| 207 | + */ |
| 208 | + public function stream_stat() { |
| 209 | + return $this->resource === false ? false : fstat($this->resource); |
| 210 | + } |
| 211 | + }; |
| 212 | + |
| 213 | + $testProxyStreamWrapper::$rootPath = realpath(__DIR__) . '/Fixtures/classmap'; |
| 214 | + stream_wrapper_register('test', get_class($testProxyStreamWrapper)); |
| 215 | + |
| 216 | + $arrayOfSplFileInfoStreamPaths = [ |
| 217 | + new \SplFileInfo('test://BackslashLineEndingString.php'), |
| 218 | + new \SplFileInfo('test://InvalidUnicode.php'), |
| 219 | + ]; |
| 220 | + |
| 221 | + self::assertSame( |
| 222 | + [ |
| 223 | + 'Foo\\SlashedA' => 'test://BackslashLineEndingString.php', |
| 224 | + 'Foo\\SlashedB' => 'test://BackslashLineEndingString.php', |
| 225 | + 'Smarty_Internal_Compile_Block' => 'test://InvalidUnicode.php', |
| 226 | + 'Smarty_Internal_Compile_Blockclose' => 'test://InvalidUnicode.php', |
| 227 | + ], |
| 228 | + ClassMapGenerator::createMap($arrayOfSplFileInfoStreamPaths) |
| 229 | + ); |
| 230 | + } |
| 231 | + |
153 | 232 | public function testAmbiguousReference(): void
|
154 | 233 | {
|
155 | 234 | $tempDir = self::getUniqueTmpDirectory();
|
|
0 commit comments