Skip to content

Commit ba5672f

Browse files
committed
use local PHP web server to test HTTP stream wrappers
1 parent 5a3a72f commit ba5672f

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 20 additions & 6 deletions
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,15 +164,27 @@ 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';
172+
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');
176+
177+
register_shutdown_function(static function () use ($process) {
178+
$process->stop();
179+
});
180+
181+
$process->start();
182+
183+
do {
184+
usleep(50000);
185+
} while (!@fopen('http://127.0.0.1:8057', 'r'));
186+
187+
$sourceFilePath = 'http://localhost:8057/logo_symfony_header.png';
174188
$targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file';
175189

176190
file_put_contents($targetFilePath, 'TARGET FILE');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php
1.58 KB
Loading

src/Symfony/Component/Filesystem/composer.json

Lines changed: 2 additions & 1 deletion
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\\": "" },

src/Symfony/Component/Mime/Tests/Part/DataPartTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@ public function testFromPathWithNotAFile()
138138

139139
public function testFromPathWithUrl()
140140
{
141-
if (!\in_array('https', stream_get_wrappers())) {
142-
$this->markTestSkipped('"https" stream wrapper is not enabled.');
141+
if (!\in_array('http', stream_get_wrappers())) {
142+
$this->markTestSkipped('"http" stream wrapper is not enabled.');
143143
}
144144

145145
$finder = new PhpExecutableFinder();
146146
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
147147
$process->setWorkingDirectory(__DIR__.'/../Fixtures/web');
148+
149+
register_shutdown_function(static function () use ($process) {
150+
$process->stop();
151+
});
152+
148153
$process->start();
149154

150155
do {

0 commit comments

Comments
 (0)