Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9b2436d

Browse filesBrowse 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
Copy full SHA for 9b2436d

File tree

Expand file treeCollapse file tree

5 files changed

+47
-31
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+47
-31
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
+22-11Lines 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()
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/composer.json
+2-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/Part/DataPartTest.php
+22-19Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.