8000 minor #54388 [Filesystem] use local PHP web server to test HTTP strea… · symfony/symfony@9b2436d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b2436d

Browse files
committed
minor #54388 [Filesystem] use local PHP web server to test HTTP stream wrappers (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [Filesystem] use local PHP web server to test HTTP stream wrappers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT same approach as #54360 (see https://github.com/symfony/symfony/actions/runs/8387183697/job/22968895866#step:8:2558 for a failure) Commits ------- 8a7813b use local PHP web server to test HTTP stream wrappers
2 parents 50268e6 + 8a7813b commit 9b2436d

File tree

5 files changed

+47
-31
lines changed

5 files changed

+47
-31
lines changed

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

Lines changed: 22 additions & 11 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,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()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php
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: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,35 @@ 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');
148148
$process->start();
149149

150-
do {
151-
usleep(50000);
152-
} while (!@fopen('http://127.0.0.1:8057', 'r'));
153-
154-
$p = DataPart::fromPath($file = 'http://localhost:8057/logo_symfony_header.png');
155-
$content = file_get_contents($file);
156-
$this->assertEquals($content, $p->getBody());
157-
$maxLineLength = 76;
158-
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr($p->bodyToString(), 0, $maxLineLength));
159-
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr(implode('', iterator_to_array($p->bodyToIterable())), 0, $maxLineLength));
160-
$this->assertEquals('image', $p->getMediaType());
161-
$this->assertEquals('png', $p->getMediaSubType());
162-
$this->assertEquals(new Headers(
163-
new ParameterizedHeader('Content-Type', 'image/png', ['name' => 'logo_symfony_header.png']),
164-
new UnstructuredHeader('Content-Transfer-Encoding', 'base64'),
165-
new ParameterizedHeader('Content-Disposition', 'attachment', ['name' => 'logo_symfony_header.png', 'filename' => 'logo_symfony_header.png'])
166-
), $p->getPreparedHeaders());
150+
try {
151+
do {
152+
usleep(50000);
153+
} while (!@fopen('http://127.0.0.1:8057', 'r'));
154+
$p = DataPart::fromPath($file = 'http://localhost:8057/logo_symfony_header.png');
155+
$content = file_get_contents($file);
156+
$this->assertEquals($content, $p->getBody());
157+
$maxLineLength = 76;
158+
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr($p->bodyToString(), 0, $maxLineLength));
159+
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr(implode('', iterator_to_array($p->bodyToIterable())), 0, $maxLineLength));
160+
$this->assertEquals('image', $p->getMediaType());
161+
$this->assertEquals('png', $p->getMediaSubType());
162+
$this->assertEquals(new Headers(
163+
new ParameterizedHeader('Content-Type', 'image/png', ['name' => 'logo_symfony_header.png']),
164+
new UnstructuredHeader('Content-Transfer-Encoding', 'base64'),
165+
new ParameterizedHeader('Content-Disposition', 'attachment', ['name' => 'logo_symfony_header.png', 'filename' => 'logo_symfony_header.png'])
166+
), $p->getPreparedHeaders());
167+
} finally {
168+
$process->stop();
169+
}
167170
}
168171

169172
public function testHasContentId()

0 commit comments

Comments
 (0)
0