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 Apr 3, 2024
1 parent 82fa6be commit 31acbc4
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions Tests/Part/DataPartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,35 @@ public function testFromPathWithNotAFile()

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

$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);
$this->assertEquals($content, $p->getBody());
$maxLineLength = 76;
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr($p->bodyToString(), 0, $maxLineLength));
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr(implode('', iterator_to_array($p->bodyToIterable())), 0, $maxLineLength));
$this->assertEquals('image', $p->getMediaType());
$this->assertEquals('png', $p->getMediaSubType());
$this->assertEquals(new Headers(
new ParameterizedHeader('Content-Type', 'image/png', ['name' => 'logo_symfony_header.png']),
new UnstructuredHeader('Content-Transfer-Encoding', 'base64'),
new ParameterizedHeader('Content-Disposition', 'attachment', ['name' => 'logo_symfony_header.png', 'filename' => 'logo_symfony_header.png'])
), $p->getPreparedHeaders());
try {
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);
$this->assertEquals($content, $p->getBody());
$maxLineLength = 76;
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr($p->bodyToString(), 0, $maxLineLength));
$this->assertEquals(substr(base64_encode($content), 0, $maxLineLength), substr(implode('', iterator_to_array($p->bodyToIterable())), 0, $maxLineLength));
$this->assertEquals('image', $p->getMediaType());
$this->assertEquals('png', $p->getMediaSubType());
$this->assertEquals(new Headers(
new ParameterizedHeader('Content-Type', 'image/png', ['name' => 'logo_symfony_header.png']),
new UnstructuredHeader('Content-Transfer-Encoding', 'base64'),
new ParameterizedHeader('Content-Disposition', 'attachment', ['name' => 'logo_symfony_header.png', 'filename' => 'logo_symfony_header.png'])
), $p->getPreparedHeaders());
} finally {
$process->stop();
}
}

public function testHasContentId()
Expand Down

0 comments on commit 31acbc4

Please sign in to comment.