From ce8622e3bcbc17c30127884a7a1fb31a8a1fe856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 10 Dec 2023 14:26:38 +0100 Subject: [PATCH] fix --- infection.json.dist | 4 ++ phpunit.xml.dist | 5 ++ src/Test/FileSystemTestCase.php | 8 ++- tests/Test/FilesystemTestCaseTest.php | 2 + tests/Test/SkippedFilesystemTest.php | 72 +++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 tests/Test/SkippedFilesystemTest.php diff --git a/infection.json.dist b/infection.json.dist index fcf5e00..c817f85 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -14,6 +14,10 @@ "@default": true, "MBString": false, + "global-ignore": [ + "Fidry\\FileSystem\\Test\\FileSystemTestCase::tearDown" + ], + "FunctionCallRemoval": false, "MethodCallRemoval": false, "PublicVisibility": false, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 28c8fd1..46f544d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,6 +5,11 @@ bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerNotices="true" + displayDetailsOnTestsThatTriggerWarnings="true" + displayDetailsOnTestsThatTriggerErrors="true" + executionOrder="duration" cacheResultFile="dist/.phpunit.result.cache"> diff --git a/src/Test/FileSystemTestCase.php b/src/Test/FileSystemTestCase.php index 1a50772..8403d47 100644 --- a/src/Test/FileSystemTestCase.php +++ b/src/Test/FileSystemTestCase.php @@ -85,8 +85,12 @@ protected function setUp(): void protected function tearDown(): void { - chdir($this->cwd); - FS::remove($this->tmp); + $wasSetupSkipped = '' === $this->cwd && '' === $this->tmp; + + if (!$wasSetupSkipped) { + chdir($this->cwd); + FS::remove($this->tmp); + } } /** diff --git a/tests/Test/FilesystemTestCaseTest.php b/tests/Test/FilesystemTestCaseTest.php index 241ad65..b0271f6 100644 --- a/tests/Test/FilesystemTestCaseTest.php +++ b/tests/Test/FilesystemTestCaseTest.php @@ -39,6 +39,7 @@ use Fidry\FileSystem\FS; use Fidry\FileSystem\Test\FileSystemTestCase; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Small; use Symfony\Component\Finder\Finder; use function getenv; use function is_string; @@ -47,6 +48,7 @@ * @internal */ #[CoversClass(FileSystemTestCase::class)] +#[Small] final class FilesystemTestCaseTest extends FileSystemTestCase { public static function getTmpDirNamespace(): string diff --git a/tests/Test/SkippedFilesystemTest.php b/tests/Test/SkippedFilesystemTest.php new file mode 100644 index 0000000..8356586 --- /dev/null +++ b/tests/Test/SkippedFilesystemTest.php @@ -0,0 +1,72 @@ + + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +declare(strict_types=1); + +namespace Fidry\FileSystem\Tests\Test; + +use Fidry\FileSystem\Test\FileSystemTestCase; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Medium; +use function getenv; +use function is_string; + +/** + * @internal + */ +#[CoversNothing] +#[Medium] +final class SkippedFilesystemTest extends FileSystemTestCase +{ + public static function getTmpDirNamespace(): string + { + $threadId = getenv('TEST_TOKEN'); + + if (!is_string($threadId)) { + $threadId = ''; + } + + return 'FidryFilesystem'.$threadId; + } + + protected function setUp(): void + { + self::markTestSkipped(); + } + + public function test_empty_test(): void + { + $this->addToAssertionCount(1); + } +}