Skip to content

Commit 4303603

Browse files
committed
use local PHP web server to test HTTP stream wrappers
1 parent 899330a commit 4303603

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

Diff for: Tests/FilesystemTest.php

+22-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Filesystem\Exception\InvalidArgumentException;
1515
use Symfony\Component\Filesystem\Exception\IOException;
1616
use Symfony\Component\Filesystem\Path;
17+
use Symfony\Component\Process\PhpExecutableFinder;
18+
use Symfony\Component\Process\Process;
1719

1820
/**
1921
* Test class for Filesystem.
@@ -162,23 +164,32 @@ public function testCopyCreatesTargetDirectoryIfItDoesNotExist()
162164
$this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
163165
}
164166

165-
/**
166-
* @group network
167-
*/
168167
public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToCopy()
169168
{
170-
if (!\in_array('https', stream_get_wrappers())) {
171-
$this->markTestSkipped('"https" stream wrapper is not enabled.');
169+
if (!\in_array('http', stream_get_wrappers())) {
170+
$this->markTestSkipped('"http" stream wrapper is not enabled.');
172171
}
173-
$sourceFilePath = 'https://symfony.com/images/common/logo/logo_symfony_header.png';
174-
$targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file';
175172

176-
file_put_contents($targetFilePath, 'TARGET FILE');
173+
$finder = new PhpExecutableFinder();
174+
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
175+
$process->setWorkingDirectory(__DIR__.'/Fixtures/web');
177176

178-
$this->filesystem->copy($sourceFilePath, $targetFilePath, false);
177+
$process->start();
179178

180-
$this->assertFileExists($targetFilePath);
181-
$this->assertEquals(file_get_contents($sourceFilePath), file_get_contents($targetFilePath));
179+
do {
180+
usleep(50000);
181+
} while (!@fopen('http://127.0.0.1:8057', 'r'));
182+
183+
try {
184+
$sourceFilePath = 'http://localhost:8057/logo_symfony_header.png';
185+
$targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file';
186+
file_put_contents($targetFilePath, 'TARGET FILE');
187+
$this->filesystem->copy($sourceFilePath, $targetFilePath, false);
188+
$this->assertFileExists($targetFilePath);
189+
$this->assertEquals(file_get_contents($sourceFilePath), file_get_contents($targetFilePath));
190+
} finally {
191+
$process->stop();
192+
}
182193
}
183194

184195
public function testMkdirCreatesDirectoriesRecursively()

Diff for: Tests/Fixtures/web/index.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

Diff for: Tests/Fixtures/web/logo_symfony_header.png

1.58 KB
Loading

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"php": ">=7.2.5",
2020
"symfony/polyfill-ctype": "~1.8",
2121
"symfony/polyfill-mbstring": "~1.8",
22-
"symfony/polyfill-php80": "^1.16"
22+
"symfony/polyfill-php80": "^1.16",
23+
"symfony/process": "^5.4|^6.4"
2324
},
2425
"autoload": {
2526
"psr-4": { "Symfony\\Component\\Filesystem\\": "" },

0 commit comments

Comments
 (0)