diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 7280d51357bb..47c89995f789 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -14,6 +14,8 @@ use Symfony\Component\Filesystem\Exception\InvalidArgumentException; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Path; +use Symfony\Component\Process\PhpExecutableFinder; +use Symfony\Component\Process\Process; /** * Test class for Filesystem. @@ -162,23 +164,32 @@ public function testCopyCreatesTargetDirectoryIfItDoesNotExist() $this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE'); } - /** - * @group network - */ public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToCopy() { - 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.'); } - $sourceFilePath = 'https://symfony.com/images/common/logo/logo_symfony_header.png'; - $targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file'; - file_put_contents($targetFilePath, 'TARGET FILE'); + $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'); - $this->filesystem->copy($sourceFilePath, $targetFilePath, false); + $process->start(); - $this->assertFileExists($targetFilePath); - $this->assertEquals(file_get_contents($sourceFilePath), file_get_contents($targetFilePath)); + do { + usleep(50000); + } while (!@fopen('http://127.0.0.1:8057', 'r')); + + try { + $sourceFilePath = 'http://localhost:8057/logo_symfony_header.png'; + $targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file'; + file_put_contents($targetFilePath, 'TARGET FILE'); + $this->filesystem->copy($sourceFilePath, $targetFilePath, false); + $this->assertFileExists($targetFilePath); + $this->assertEquals(file_get_contents($sourceFilePath), file_get_contents($targetFilePath)); + } finally { + $process->stop(); + } } public function testMkdirCreatesDirectoriesRecursively() diff --git a/src/Symfony/Component/Filesystem/Tests/Fixtures/web/index.php b/src/Symfony/Component/Filesystem/Tests/Fixtures/web/index.php new file mode 100644 index 000000000000..b3d9bbc7f371 --- /dev/null +++ b/src/Symfony/Component/Filesystem/Tests/Fixtures/web/index.php @@ -0,0 +1 @@ +=7.2.5", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.8", - "symfony/polyfill-php80": "^1.16" + "symfony/polyfill-php80": "^1.16", + "symfony/process": "^5.4|^6.4" }, "autoload": { "psr-4": { "Symfony\\Component\\Filesystem\\": "" }, diff --git a/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php b/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php index d0a692761fdf..361bb00be5d1 100644 --- a/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php +++ b/src/Symfony/Component/Mime/Tests/Part/DataPartTest.php @@ -138,8 +138,8 @@ 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(); @@ -147,23 +147,26 @@ public function testFromPathWithUrl() $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()