Skip to content

Commit

Permalink
use local PHP web server to test HTTP stream wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Mar 21, 2024
1 parent 2d3300e commit a28330f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Mime/Tests/Fixtures/web/index.php
@@ -0,0 +1 @@
<?php
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions src/Symfony/Component/Mime/Tests/Part/DataPartTest.php
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Mime\Header\ParameterizedHeader;
use Symfony\Component\Mime\Header\UnstructuredHeader;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

class DataPartTest extends TestCase
{
Expand Down Expand Up @@ -134,17 +136,24 @@ public function testFromPathWithNotAFile()
DataPart::fromPath(__DIR__.'/../Fixtures/mimetypes/');
}

/**
* @group network
*/
public function testFromPathWithUrl()
{
if (!\in_array('https', stream_get_wrappers())) {
$this->markTestSkipped('"https" stream wrapper is not enabled.');
}

$p = DataPart::fromPath($file = 'https://symfony.com/images/common/logo/logo_symfony_header.png');
$finder = new PhpExecutableFinder();
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:8057']));
$process->setWorkingDirectory(__DIR__.'/../Fixtures/web');
$process->start();

do {
usleep(50000);
} while (!@fopen('http://127.0.0.1:8057', 'r'));

$p = DataPart::fromPath($file = 'http://localhost:8057/logo_symfony_header.png');
$content = file_get_contents($file);
file_put_contents(__DIR__ . '/../Fixtures/web/logo_symfony_header.png', $content);
$this->assertEquals($content, $p->getBody());
$maxLineLength = 76;
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr($p->bodyToString(), 0, $maxLineLength));
Expand Down

0 comments on commit a28330f

Please sign in to comment.