From 7f9342c0ce0cfc531e65d94a68b11d86f3d43ce1 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 21 Mar 2024 13:09:16 -0300 Subject: [PATCH] Prevent changes at initial dataProvider The vfsStream get crazy behavior when we run all tests. If we execute a test isolated, will work fine, if run together with all, the file don't will exstists. I identified that the dataProvider is started before all and maybe other tests that use vfs is affecting this tests and to prevent the problem, I created the vfs to each test. Signed-off-by: Vitor Mattos --- tests/Unit/Service/InstallServiceTest.php | 95 +++++++++++++---------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/tests/Unit/Service/InstallServiceTest.php b/tests/Unit/Service/InstallServiceTest.php index 0f2d0b9fb2..052a4843de 100644 --- a/tests/Unit/Service/InstallServiceTest.php +++ b/tests/Unit/Service/InstallServiceTest.php @@ -74,63 +74,78 @@ protected function getInstallService(): InstallService { /** * @dataProvider providerDownloadCli */ - public function testDownloadCli(string $url, string $filename, string $path, string $hash, string $algorithm, string $expectedOutput): void { + public function testDownloadCli(string $url, string $filename, string $content, string $hash, string $algorithm, string $expectedOutput): void { $installService = $this->getInstallService(); $output = new BufferedOutput(); $installService->setOutput($output); + + if ($content) { + vfsStream::setup('download'); + $path = 'vfs://download/dummy.svg'; + file_put_contents($path, $content); + } else { + $path = ''; + } + self::invokePrivate($installService, 'downloadCli', [$url, $filename, $path, $hash, $algorithm]); $actual = $output->fetch(); $this->assertEquals($expectedOutput, $actual); } public function providerDownloadCli(): array { - vfsStream::setup('download'); - - $pathInvalid = 'vfs://download/appInvalid.svg'; - file_put_contents($pathInvalid, 'invalidContent'); - $pathValid = 'vfs://download/validContent.svg'; - file_put_contents($pathValid, 'invalidContent'); return [ [ - "http://localhost/apps/libresign/img/app.svg", - 'app.svg', - 'vfs://download/app.svg', - '', - 'md5', - "Downloading app.svg...\n" . - " 0 [>---------------------------]\n". - "Failure on download app.svg, empty file, try again\n", + 'url' => 'http://localhost/apps/libresign/img/app.svg', + 'filename' => 'app.svg', + 'content' => '', + 'hash' => '', + 'algorithm' => 'md5', + 'expectedOutput' => <<---------------------------] + Failure on download app.svg, empty file, try again + + EXPECTEDOUTPUT ], [ - "http://localhost/apps/libresign/img/appInvalid.svg", - 'appInvalid.svg', - $pathInvalid, - 'hashInvalid', - 'md5', - "Downloading appInvalid.svg...\n" . - " 0 [>---------------------------]\n" . - "Failure on download appInvalid.svg try again\n" . - "Invalid md5\n", + 'url' => 'http://localhost/apps/libresign/img/appInvalid.svg', + 'filename' => 'appInvalid.svg', + 'content' => 'content', + 'hash' => 'invalidContent', + 'algorithm' => 'md5', + 'expectedOutput' => <<---------------------------] + Failure on download appInvalid.svg try again + Invalid md5 + + EXPECTEDOUTPUT ], [ - "http://localhost/apps/libresign/img/appInvalid.svg", - 'appInvalid.svg', - $pathInvalid, - 'hashInvalid', - 'sha256', - "Downloading appInvalid.svg...\n" . - " 0 [>---------------------------]\n" . - "Failure on download appInvalid.svg try again\n" . - "Invalid sha256\n", + 'url' => 'http://localhost/apps/libresign/img/appInvalid.svg', + 'filename' => 'appInvalid.svg', + 'content' => 'content', + 'hash' => 'invalidContent', + 'algorithm' => 'sha256', + 'expectedOutput' => <<---------------------------] + Failure on download appInvalid.svg try again + Invalid sha256 + + EXPECTEDOUTPUT ], [ - "http://localhost/apps/libresign/img/validContent.svg", - 'validContent.svg', - $pathValid, - hash_file('sha256', $pathValid), - 'sha256', - "Downloading validContent.svg...\n" . - " 0 [>---------------------------]\n", + 'url' => 'http://localhost/apps/libresign/img/validContent.svg', + 'filename' => 'validContent.svg', + 'content' => 'content', + 'hash' => hash('sha256', 'content'), + 'algorithm' => 'sha256', + 'expectedOutput' => <<---------------------------] + + EXPECTEDOUTPUT ], ]; }