From 0730780cd9bb68d7d524eb990f490e77f280b598 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 04:48:34 -0400 Subject: [PATCH 01/75] Little consistency improvement. --- tests/PHPBench/TestUtils/FixtureHelper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/PHPBench/TestUtils/FixtureHelper.php b/tests/PHPBench/TestUtils/FixtureHelper.php index c5e4efb9d..262cb87cf 100644 --- a/tests/PHPBench/TestUtils/FixtureHelper.php +++ b/tests/PHPBench/TestUtils/FixtureHelper.php @@ -10,7 +10,6 @@ final class FixtureHelper { - private const REPOSITORY_ROOT = '../../..'; private const TEST_ENV = 'var/phpbench'; private const FIXTURES_DIR = 'fixtures'; private const WORKING_DIR = 'working-dir'; @@ -30,7 +29,7 @@ public static function ensureFixtures(): void public static function repositoryRootAbsolute(): string { - return SymfonyPath::makeAbsolute(self::REPOSITORY_ROOT, __DIR__); + return dirname(__DIR__, 3); } public static function workingDirAbsolute(): string From 28bba01ef6986dad1cdac61e57d5353207af6709 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 04:50:28 -0400 Subject: [PATCH 02/75] Replace Tests\TestCase::TEST_WORKING_DIR_ABSOLUTE with Tests\TestUtils\PathHelper::testWorkingDirAbsolute(). --- tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php | 3 ++- .../Service/LinkPreconditionsFunctionalTestCase.php | 7 ++++++- .../NoSymlinksPointOutsideTheCodebaseFunctionalTest.php | 5 +++-- .../Service/NoSymlinksPointToADirectoryFunctionalTest.php | 5 +++-- tests/PHPUnit/TestCase.php | 3 +-- tests/PHPUnit/TestUtils/PathHelper.php | 3 +-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php index 681d73763..928d10308 100644 --- a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php +++ b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php @@ -7,6 +7,7 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Finder\Service\FileFinder @@ -157,7 +158,7 @@ private function normalizePaths(array $paths): array $path = implode( DIRECTORY_SEPARATOR, [ - self::TEST_WORKING_DIR_ABSOLUTE, + PathHelper::testWorkingDirAbsolute(), self::ACTIVE_DIR_RELATIVE, $path, ], diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php index 974000347..80272e1a5 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php @@ -6,6 +6,8 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; +use Symfony\Component\Filesystem\Path as SymfonyPath; abstract class LinkPreconditionsFunctionalTestCase extends TestCase { @@ -44,7 +46,10 @@ final protected function doTestFulfilledDirectoryDoesNotExist(string $activeDir, final public function providerFulfilledDirectoryDoesNotExist(): array { - $nonexistentDir = self::TEST_WORKING_DIR_ABSOLUTE . '/65eb69a274470dd84e9b5371f7e1e8c8'; + $nonexistentDir = SymfonyPath::makeAbsolute( + '65eb69a274470dd84e9b5371f7e1e8c8', + PathHelper::testWorkingDirAbsolute(), + ); return [ 'Active directory' => [ diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index b74ea1bf9..9146d6e70 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase @@ -110,12 +111,12 @@ public function providerUnfulfilled(): array { return [ 'In active directory' => [ - 'targetDir' => self::TEST_WORKING_DIR_ABSOLUTE, + 'targetDir' => PathHelper::testWorkingDirAbsolute(), 'linkDir' => self::ACTIVE_DIR_RELATIVE, 'linkDirName' => 'active', ], 'In staging directory' => [ - 'targetDir' => self::TEST_WORKING_DIR_ABSOLUTE, + 'targetDir' => PathHelper::testWorkingDirAbsolute(), 'linkDir' => self::STAGING_DIR_RELATIVE, 'linkDirName' => 'staging', ], diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index e59080589..3ffb4eac3 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -9,6 +9,7 @@ use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory @@ -85,12 +86,12 @@ public function providerUnfulfilled(): array { return [ 'In active directory' => [ - 'targetDir' => self::TEST_WORKING_DIR_ABSOLUTE, + 'targetDir' => PathHelper::testWorkingDirAbsolute(), 'linkDir' => self::ACTIVE_DIR_RELATIVE, 'linkDirName' => 'active', ], 'In staging directory' => [ - 'targetDir' => self::TEST_WORKING_DIR_ABSOLUTE, + 'targetDir' => PathHelper::testWorkingDirAbsolute(), 'linkDir' => self::STAGING_DIR_RELATIVE, 'linkDirName' => 'staging', ], diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index 2249ce7f3..7950b1a25 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -27,7 +27,6 @@ abstract class TestCase extends PHPUnitTestCase use ProphecyTrait; protected const TEST_ENV_ABSOLUTE = __DIR__ . '/../../var/phpunit/test-env'; - protected const TEST_WORKING_DIR_ABSOLUTE = self::TEST_ENV_ABSOLUTE . '/working-dir'; protected const ACTIVE_DIR_RELATIVE = 'active-dir'; protected const STAGING_DIR_RELATIVE = 'staging-dir'; protected const ORIGINAL_CONTENT = ''; @@ -41,7 +40,7 @@ abstract class TestCase extends PHPUnitTestCase protected static function testWorkingDirPath(): PathInterface { - return PathFactory::create(self::TEST_WORKING_DIR_ABSOLUTE); + return PathFactory::create(PathHelper::testWorkingDirAbsolute()); } protected static function activeDirPath(): PathInterface diff --git a/tests/PHPUnit/TestUtils/PathHelper.php b/tests/PHPUnit/TestUtils/PathHelper.php index 9e649ebe3..ae2be405b 100644 --- a/tests/PHPUnit/TestUtils/PathHelper.php +++ b/tests/PHPUnit/TestUtils/PathHelper.php @@ -8,7 +8,6 @@ final class PathHelper { - private const REPOSITORY_ROOT = '../../..'; private const TEST_ENV = 'var/phpunit/test-env'; private const WORKING_DIR = 'working-dir'; private const ACTIVE_DIR = 'active-dir'; @@ -16,7 +15,7 @@ final class PathHelper public static function repositoryRootAbsolute(): string { - return SymfonyPath::makeAbsolute(self::REPOSITORY_ROOT, __DIR__); + return dirname(__DIR__, 3); } public static function testEnvAbsolute(): string From 27fa7dcc99886b1135d2d3651e594b1510e1b771 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 05:09:45 -0400 Subject: [PATCH 03/75] Replace Tests\FileSyncer\Service\FileSyncerFunctionalTestCase::SOURCE_DIR with ::sourcePath(). --- .../Service/FileSyncerFunctionalTestCase.php | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php index 4790f4e39..b572ee654 100644 --- a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -7,22 +7,31 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; +use Symfony\Component\Filesystem\Path as SymfonyPath; abstract class FileSyncerFunctionalTestCase extends TestCase { - private const SOURCE_DIR = self::TEST_ENV_ABSOLUTE . DIRECTORY_SEPARATOR . 'source'; private const DESTINATION_DIR = self::TEST_ENV_ABSOLUTE . DIRECTORY_SEPARATOR . 'destination'; private PathInterface $destination; - private PathInterface $source; + + private static function sourceDirAbsolute(): string + { + return SymfonyPath::makeAbsolute('source', PathHelper::testEnvAbsolute()); + } + + private static function sourcePath(): PathInterface + { + return PathFactory::create(self::sourceDirAbsolute()); + } protected function setUp(): void { - $this->source = PathFactory::create(self::SOURCE_DIR); $this->destination = PathFactory::create(self::DESTINATION_DIR); FilesystemHelper::createDirectories([ - $this->source->absolute(), + self::sourceDirAbsolute(), $this->destination->absolute(), ]); } @@ -54,7 +63,7 @@ public function testSyncTimeout(?int $givenTimeout, int $expectedTimeout): void { $sut = $this->createSut(); - $sut->sync($this->source, $this->destination, null, null, $givenTimeout); + $sut->sync(self::sourcePath(), $this->destination, null, null, $givenTimeout); self::assertSame((string) $expectedTimeout, ini_get('max_execution_time'), 'Correctly set process timeout.'); } @@ -76,15 +85,15 @@ public function providerSyncTimeout(): array /** @covers ::sync */ public function testSyncWithDirectorySymlinks(): void { - $link = PathFactory::create('link', $this->source); - $target = PathFactory::create('directory', $this->source); - FilesystemHelper::createDirectories($target->absolute()); - $file = PathFactory::create('directory/file.txt', $this->source)->absolute(); + $link = SymfonyPath::makeAbsolute('link', self::sourceDirAbsolute()); + $target = SymfonyPath::makeAbsolute('directory', self::sourceDirAbsolute()); + FilesystemHelper::createDirectories($target); + $file = SymfonyPath::makeAbsolute('directory/file.txt', self::sourceDirAbsolute()); touch($file); - symlink($target->absolute(), $link->absolute()); + symlink($target, $link); $sut = $this->createSut(); - $sut->sync($this->source, $this->destination); + $sut->sync(self::sourcePath(), $this->destination); self::assertDirectoryListing($this->destination->absolute(), [ 'link', From e187aa6e08bc9861f797055e94a5bf1470fc567c Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 05:17:27 -0400 Subject: [PATCH 04/75] Replace Tests\FileSyncer\Service\FileSyncerFunctionalTestCase::DESTINATION_DIR with ::destinationPath(). --- .../Service/FileSyncerFunctionalTestCase.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php index b572ee654..7e90b72e4 100644 --- a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -12,10 +12,6 @@ abstract class FileSyncerFunctionalTestCase extends TestCase { - private const DESTINATION_DIR = self::TEST_ENV_ABSOLUTE . DIRECTORY_SEPARATOR . 'destination'; - - private PathInterface $destination; - private static function sourceDirAbsolute(): string { return SymfonyPath::makeAbsolute('source', PathHelper::testEnvAbsolute()); @@ -26,13 +22,21 @@ private static function sourcePath(): PathInterface return PathFactory::create(self::sourceDirAbsolute()); } - protected function setUp(): void + public static function destinationDirAbsolute(): string { - $this->destination = PathFactory::create(self::DESTINATION_DIR); + return SymfonyPath::makeAbsolute('destination', PathHelper::testEnvAbsolute()); + } + private static function destinationPath(): PathInterface + { + return PathFactory::create(self::destinationDirAbsolute()); + } + + protected function setUp(): void + { FilesystemHelper::createDirectories([ self::sourceDirAbsolute(), - $this->destination->absolute(), + self::destinationDirAbsolute(), ]); } @@ -63,7 +67,7 @@ public function testSyncTimeout(?int $givenTimeout, int $expectedTimeout): void { $sut = $this->createSut(); - $sut->sync(self::sourcePath(), $this->destination, null, null, $givenTimeout); + $sut->sync(self::sourcePath(), self::destinationPath(), null, null, $givenTimeout); self::assertSame((string) $expectedTimeout, ini_get('max_execution_time'), 'Correctly set process timeout.'); } @@ -93,9 +97,9 @@ public function testSyncWithDirectorySymlinks(): void symlink($target, $link); $sut = $this->createSut(); - $sut->sync(self::sourcePath(), $this->destination); + $sut->sync(self::sourcePath(), self::destinationPath()); - self::assertDirectoryListing($this->destination->absolute(), [ + self::assertDirectoryListing(self::destinationDirAbsolute(), [ 'link', 'directory/file.txt', ], '', 'Correctly synced files, including a symlink to a directory.'); From ae8849c959fa696cc428d3a3664dadcac042c414 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 05:39:44 -0400 Subject: [PATCH 05/75] Replace Tests\TestCase::TEST_ENV_ABSOLUTE with Tests\TestUtils\PathHelper::testEnvAbsolute(). --- .../Filesystem/Service/FilesystemFunctionalTest.php | 9 +++++---- tests/PHPUnit/TestCase.php | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php b/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php index 26f67435f..f34d8f398 100644 --- a/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php +++ b/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php @@ -8,6 +8,7 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use Symfony\Component\Filesystem\Exception\IOException as SymfonyIOException; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; @@ -16,12 +17,12 @@ final class FilesystemFunctionalTest extends TestCase { private static function sourceDir(): PathInterface { - return PathFactory::create(self::TEST_ENV_ABSOLUTE . '/source'); + return PathFactory::create(PathHelper::testEnvAbsolute() . '/source'); } private static function destinationDir(): PathInterface { - return PathFactory::create(self::TEST_ENV_ABSOLUTE . '/destination'); + return PathFactory::create(PathHelper::testEnvAbsolute() . '/destination'); } protected function setUp(): void @@ -67,7 +68,7 @@ public function testCopy(): void /** @covers ::isDirEmpty */ public function testIsDirEmptyTrue(): void { - $directory = PathFactory::create(self::TEST_ENV_ABSOLUTE . '/empty'); + $directory = PathFactory::create(PathHelper::testEnvAbsolute() . '/empty'); FilesystemHelper::createDirectories($directory->absolute()); $sut = $this->createSut(); @@ -86,7 +87,7 @@ public function testIsDirEmptyFalse(): void /** @covers ::isDirEmpty */ public function testIsDirEmptyErrorIsNotADirectory(): void { - $path = PathFactory::create(self::TEST_ENV_ABSOLUTE); + $path = PathFactory::create(PathHelper::testEnvAbsolute()); $file = PathFactory::create('file.txt', $path); touch($file->absolute()); $message = sprintf( diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index 7950b1a25..8810d9338 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -26,7 +26,6 @@ abstract class TestCase extends PHPUnitTestCase use AssertTrait; use ProphecyTrait; - protected const TEST_ENV_ABSOLUTE = __DIR__ . '/../../var/phpunit/test-env'; protected const ACTIVE_DIR_RELATIVE = 'active-dir'; protected const STAGING_DIR_RELATIVE = 'staging-dir'; protected const ORIGINAL_CONTENT = ''; @@ -79,12 +78,12 @@ protected static function removeTestEnvironment(): void { $filesystem = new Filesystem(); - if (!$filesystem->exists(self::TEST_ENV_ABSOLUTE)) { + if (!$filesystem->exists(PathHelper::testEnvAbsolute())) { return; } try { - $filesystem->remove(self::TEST_ENV_ABSOLUTE); + $filesystem->remove(PathHelper::testEnvAbsolute()); } catch (IOException) { // @todo Windows chokes on this every time, e.g., // | Failed to remove directory From 822003add3eeaeeaf75b1041db1af06a9a1fa307 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 12:44:23 -0400 Subject: [PATCH 06/75] Replace Tests\TestCase::ACTIVE_DIR_RELATIVE with Tests\TestUtils\PathHelper::activeDirRelative(). --- tests/PHPUnit/Core/BeginnerUnitTest.php | 3 ++- tests/PHPUnit/Core/CleanerUnitTest.php | 3 ++- tests/PHPUnit/Core/CommitterUnitTest.php | 3 ++- tests/PHPUnit/Core/StagerUnitTest.php | 2 +- tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php | 3 ++- .../PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php | 3 ++- tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php | 3 ++- tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php | 2 +- .../Service/ComposerIsAvailableFunctionalTest.php | 3 ++- .../Service/LinkPreconditionsFunctionalTestCase.php | 2 +- .../Service/NoAbsoluteSymlinksExistFunctionalTest.php | 3 ++- .../Service/NoHardLinksExistFunctionalTest.php | 3 ++- .../NoSymlinksPointOutsideTheCodebaseFunctionalTest.php | 2 +- .../Service/NoSymlinksPointToADirectoryFunctionalTest.php | 2 +- .../PHPUnit/Precondition/Service/PreconditionTestCase.php | 3 ++- tests/PHPUnit/TestCase.php | 7 ++++--- 16 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tests/PHPUnit/Core/BeginnerUnitTest.php b/tests/PHPUnit/Core/BeginnerUnitTest.php index 3b2ab9340..554c30bb4 100644 --- a/tests/PHPUnit/Core/BeginnerUnitTest.php +++ b/tests/PHPUnit/Core/BeginnerUnitTest.php @@ -17,6 +17,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -33,7 +34,7 @@ final class BeginnerUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->activeDir = new TestPath(PathHelper::activeDirRelative()); $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); $this->preconditions = $this->prophesize(BeginnerPreconditionsInterface::class); $this->fileSyncer = $this->prophesize(FileSyncerInterface::class); diff --git a/tests/PHPUnit/Core/CleanerUnitTest.php b/tests/PHPUnit/Core/CleanerUnitTest.php index dde949e7c..d91e05d48 100644 --- a/tests/PHPUnit/Core/CleanerUnitTest.php +++ b/tests/PHPUnit/Core/CleanerUnitTest.php @@ -13,6 +13,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -29,7 +30,7 @@ final class CleanerUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->activeDir = new TestPath(PathHelper::activeDirRelative()); $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); $this->preconditions = $this->prophesize(CleanerPreconditionsInterface::class); $this->filesystem = $this->prophesize(FilesystemInterface::class); diff --git a/tests/PHPUnit/Core/CommitterUnitTest.php b/tests/PHPUnit/Core/CommitterUnitTest.php index ca2fa09e2..839461cd7 100644 --- a/tests/PHPUnit/Core/CommitterUnitTest.php +++ b/tests/PHPUnit/Core/CommitterUnitTest.php @@ -17,6 +17,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -33,7 +34,7 @@ final class CommitterUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->activeDir = new TestPath(PathHelper::activeDirRelative()); $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); $this->preconditions = $this->prophesize(CommitterPreconditionsInterface::class); $this->fileSyncer = $this->prophesize(FileSyncerInterface::class); diff --git a/tests/PHPUnit/Core/StagerUnitTest.php b/tests/PHPUnit/Core/StagerUnitTest.php index 81164c287..f9b91b207 100644 --- a/tests/PHPUnit/Core/StagerUnitTest.php +++ b/tests/PHPUnit/Core/StagerUnitTest.php @@ -37,7 +37,7 @@ final class StagerUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->activeDir = new TestPath(PathHelper::activeDirRelative()); $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); $this->composerRunner = $this->prophesize(ComposerProcessRunnerInterface::class); $this->preconditions = $this->prophesize(StagerPreconditionsInterface::class); diff --git a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php index 72f6fc346..88f5bab1d 100644 --- a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php +++ b/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php @@ -14,6 +14,7 @@ use PhpTuf\ComposerStager\Internal\Host\Service\Host; use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Argument; @@ -35,7 +36,7 @@ final class PhpFileSyncerUnitTest extends TestCase protected function setUp(): void { - $this->source = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->source = new TestPath(PathHelper::activeDirRelative()); $this->destination = new TestPath(self::STAGING_DIR_RELATIVE); $this->fileFinder = $this->prophesize(FileFinderInterface::class); $this->filesystem = $this->prophesize(FilesystemInterface::class); diff --git a/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php b/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php index 8b2c184bd..7eb140e9b 100644 --- a/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php +++ b/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php @@ -16,6 +16,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Argument; @@ -45,7 +46,7 @@ final class RsyncFileSyncerUnitTest extends TestCase protected function setUp(): void { - $this->source = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->source = new TestPath(PathHelper::activeDirRelative()); $this->destination = new TestPath(self::STAGING_DIR_RELATIVE); $this->filesystem = $this->prophesize(FilesystemInterface::class); $this->filesystem diff --git a/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php b/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php index a6a9164bc..f7e12aba0 100644 --- a/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php +++ b/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -29,7 +30,7 @@ final class FilesystemUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->activeDir = new TestPath(PathHelper::activeDirRelative()); $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); $this->pathFactory = $this->prophesize(PathFactoryInterface::class); $this->symfonyFilesystem = $this->prophesize(SymfonyFilesystem::class); diff --git a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php index 928d10308..898c4ebcf 100644 --- a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php +++ b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php @@ -159,7 +159,7 @@ private function normalizePaths(array $paths): array DIRECTORY_SEPARATOR, [ PathHelper::testWorkingDirAbsolute(), - self::ACTIVE_DIR_RELATIVE, + PathHelper::activeDirRelative(), $path, ], ); diff --git a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php index 6e53a262d..5d563fb8f 100644 --- a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; use Symfony\Component\DependencyInjection\Definition; @@ -23,7 +24,7 @@ protected function setUp(): void self::createTestEnvironment(); FilesystemHelper::createDirectories(self::STAGING_DIR_RELATIVE); - $this->activeDir = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->activeDir = new TestPath(PathHelper::activeDirRelative()); $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); $this->executableFinderClass = ExecutableFinder::class; } diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php index 80272e1a5..d25a55e46 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php @@ -57,7 +57,7 @@ final public function providerFulfilledDirectoryDoesNotExist(): array 'stagingDir' => self::STAGING_DIR_RELATIVE, ], 'Staging directory' => [ - 'activeDir' => self::ACTIVE_DIR_RELATIVE, + 'activeDir' => PathHelper::activeDirRelative(), 'stagingDir' => $nonexistentDir, ], ]; diff --git a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index ecec27cea..546d82440 100644 --- a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist @@ -37,7 +38,7 @@ protected function createSut(): NoAbsoluteSymlinksExist */ public function testDoesNotContainLinks(array $files): void { - self::createFiles(self::ACTIVE_DIR_RELATIVE, $files); + self::createFiles(PathHelper::activeDirRelative(), $files); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath()); diff --git a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php index 7986e95b3..67f48d50f 100644 --- a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist @@ -84,7 +85,7 @@ public function providerUnfulfilled(): array { return [ 'In active directory' => [ - 'directory' => self::ACTIVE_DIR_RELATIVE, + 'directory' => PathHelper::activeDirRelative(), 'dirName' => 'active', ], 'In staging directory' => [ diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index 9146d6e70..23335b0af 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -112,7 +112,7 @@ public function providerUnfulfilled(): array return [ 'In active directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => self::ACTIVE_DIR_RELATIVE, + 'linkDir' => PathHelper::activeDirRelative(), 'linkDirName' => 'active', ], 'In staging directory' => [ diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index 3ffb4eac3..dbb0eef9a 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -87,7 +87,7 @@ public function providerUnfulfilled(): array return [ 'In active directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => self::ACTIVE_DIR_RELATIVE, + 'linkDir' => PathHelper::activeDirRelative(), 'linkDirName' => 'active', ], 'In staging directory' => [ diff --git a/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php b/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php index b43d217be..bd8bcf969 100644 --- a/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php +++ b/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php @@ -8,6 +8,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; abstract class PreconditionTestCase extends TestCase { @@ -17,7 +18,7 @@ abstract class PreconditionTestCase extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(self::ACTIVE_DIR_RELATIVE); + $this->activeDir = new TestPath(PathHelper::activeDirRelative()); $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); $this->exclusions = new TestPathList(); } diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index 8810d9338..7326df931 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -26,7 +26,6 @@ abstract class TestCase extends PHPUnitTestCase use AssertTrait; use ProphecyTrait; - protected const ACTIVE_DIR_RELATIVE = 'active-dir'; protected const STAGING_DIR_RELATIVE = 'staging-dir'; protected const ORIGINAL_CONTENT = ''; protected const CHANGED_CONTENT = 'changed'; @@ -44,7 +43,7 @@ protected static function testWorkingDirPath(): PathInterface protected static function activeDirPath(): PathInterface { - return PathFactory::create(self::ACTIVE_DIR_RELATIVE, self::testWorkingDirPath()); + return PathFactory::create(PathHelper::activeDirRelative(), self::testWorkingDirPath()); } protected static function stagingDirPath(): PathInterface @@ -62,8 +61,10 @@ public function container(): ContainerBuilder return $container; } - protected static function createTestEnvironment(string $activeDir = self::ACTIVE_DIR_RELATIVE): void + protected static function createTestEnvironment(?string $activeDir = null): void { + $activeDir ??= PathHelper::activeDirRelative(); + self::removeTestEnvironment(); // Create the active directory only. The staging directory is created From 8bc709fc624d06446d8521ac2eb6451bb150508c Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 12:57:20 -0400 Subject: [PATCH 07/75] Replace Tests\TestCase::STAGING_DIR_RELATIVE with Tests\TestUtils\PathHelper::stagingDirRelative(). --- tests/PHPUnit/Core/BeginnerUnitTest.php | 2 +- tests/PHPUnit/Core/CleanerUnitTest.php | 2 +- tests/PHPUnit/Core/CommitterUnitTest.php | 2 +- tests/PHPUnit/Core/StagerUnitTest.php | 4 ++-- tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php | 2 +- tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php | 2 +- tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php | 2 +- .../Service/ComposerIsAvailableFunctionalTest.php | 4 ++-- .../Service/LinkPreconditionsFunctionalTestCase.php | 4 ++-- .../Precondition/Service/NoHardLinksExistFunctionalTest.php | 2 +- .../NoSymlinksPointOutsideTheCodebaseFunctionalTest.php | 2 +- .../Service/NoSymlinksPointToADirectoryFunctionalTest.php | 2 +- tests/PHPUnit/Precondition/Service/PreconditionTestCase.php | 2 +- tests/PHPUnit/TestCase.php | 3 +-- 14 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/PHPUnit/Core/BeginnerUnitTest.php b/tests/PHPUnit/Core/BeginnerUnitTest.php index 554c30bb4..98b23ba6e 100644 --- a/tests/PHPUnit/Core/BeginnerUnitTest.php +++ b/tests/PHPUnit/Core/BeginnerUnitTest.php @@ -35,7 +35,7 @@ final class BeginnerUnitTest extends TestCase protected function setUp(): void { $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); + $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->preconditions = $this->prophesize(BeginnerPreconditionsInterface::class); $this->fileSyncer = $this->prophesize(FileSyncerInterface::class); } diff --git a/tests/PHPUnit/Core/CleanerUnitTest.php b/tests/PHPUnit/Core/CleanerUnitTest.php index d91e05d48..ab7ad5e0f 100644 --- a/tests/PHPUnit/Core/CleanerUnitTest.php +++ b/tests/PHPUnit/Core/CleanerUnitTest.php @@ -31,7 +31,7 @@ final class CleanerUnitTest extends TestCase protected function setUp(): void { $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); + $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->preconditions = $this->prophesize(CleanerPreconditionsInterface::class); $this->filesystem = $this->prophesize(FilesystemInterface::class); } diff --git a/tests/PHPUnit/Core/CommitterUnitTest.php b/tests/PHPUnit/Core/CommitterUnitTest.php index 839461cd7..bf1f9fbea 100644 --- a/tests/PHPUnit/Core/CommitterUnitTest.php +++ b/tests/PHPUnit/Core/CommitterUnitTest.php @@ -35,7 +35,7 @@ final class CommitterUnitTest extends TestCase protected function setUp(): void { $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); + $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->preconditions = $this->prophesize(CommitterPreconditionsInterface::class); $this->fileSyncer = $this->prophesize(FileSyncerInterface::class); } diff --git a/tests/PHPUnit/Core/StagerUnitTest.php b/tests/PHPUnit/Core/StagerUnitTest.php index f9b91b207..569aa8c66 100644 --- a/tests/PHPUnit/Core/StagerUnitTest.php +++ b/tests/PHPUnit/Core/StagerUnitTest.php @@ -38,7 +38,7 @@ final class StagerUnitTest extends TestCase protected function setUp(): void { $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); + $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->composerRunner = $this->prophesize(ComposerProcessRunnerInterface::class); $this->preconditions = $this->prophesize(StagerPreconditionsInterface::class); } @@ -59,7 +59,7 @@ public function testStageWithMinimumParams(): void ->assertIsFulfilled($this->activeDir, $this->stagingDir) ->shouldBeCalledOnce(); $expectedCommand = [ - '--working-dir=' . self::STAGING_DIR_RELATIVE, + '--working-dir=' . PathHelper::stagingDirRelative(), self::INERT_COMMAND, ]; $this->composerRunner diff --git a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php index 88f5bab1d..19a9d80bc 100644 --- a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php +++ b/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php @@ -37,7 +37,7 @@ final class PhpFileSyncerUnitTest extends TestCase protected function setUp(): void { $this->source = new TestPath(PathHelper::activeDirRelative()); - $this->destination = new TestPath(self::STAGING_DIR_RELATIVE); + $this->destination = new TestPath(PathHelper::stagingDirRelative()); $this->fileFinder = $this->prophesize(FileFinderInterface::class); $this->filesystem = $this->prophesize(FilesystemInterface::class); $this->filesystem diff --git a/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php b/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php index 7eb140e9b..86f6de948 100644 --- a/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php +++ b/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php @@ -47,7 +47,7 @@ final class RsyncFileSyncerUnitTest extends TestCase protected function setUp(): void { $this->source = new TestPath(PathHelper::activeDirRelative()); - $this->destination = new TestPath(self::STAGING_DIR_RELATIVE); + $this->destination = new TestPath(PathHelper::stagingDirRelative()); $this->filesystem = $this->prophesize(FilesystemInterface::class); $this->filesystem ->exists(Argument::any()) diff --git a/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php b/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php index f7e12aba0..2eefa47b5 100644 --- a/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php +++ b/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php @@ -31,7 +31,7 @@ final class FilesystemUnitTest extends TestCase protected function setUp(): void { $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); + $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->pathFactory = $this->prophesize(PathFactoryInterface::class); $this->symfonyFilesystem = $this->prophesize(SymfonyFilesystem::class); } diff --git a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php index 5d563fb8f..6be3cb1f3 100644 --- a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php @@ -22,10 +22,10 @@ final class ComposerIsAvailableFunctionalTest extends TestCase protected function setUp(): void { self::createTestEnvironment(); - FilesystemHelper::createDirectories(self::STAGING_DIR_RELATIVE); + FilesystemHelper::createDirectories(PathHelper::stagingDirRelative()); $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); + $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->executableFinderClass = ExecutableFinder::class; } diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php index d25a55e46..bc5f4ec53 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php @@ -14,7 +14,7 @@ abstract class LinkPreconditionsFunctionalTestCase extends TestCase protected function setUp(): void { self::createTestEnvironment(); - FilesystemHelper::createDirectories(self::STAGING_DIR_RELATIVE); + FilesystemHelper::createDirectories(PathHelper::stagingDirRelative()); $this->activeDir = self::activeDirPath(); $this->stagingDir = self::stagingDirPath(); @@ -54,7 +54,7 @@ final public function providerFulfilledDirectoryDoesNotExist(): array return [ 'Active directory' => [ 'activeDir' => $nonexistentDir, - 'stagingDir' => self::STAGING_DIR_RELATIVE, + 'stagingDir' => PathHelper::stagingDirRelative(), ], 'Staging directory' => [ 'activeDir' => PathHelper::activeDirRelative(), diff --git a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php index 67f48d50f..4a4695583 100644 --- a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -89,7 +89,7 @@ public function providerUnfulfilled(): array 'dirName' => 'active', ], 'In staging directory' => [ - 'directory' => self::STAGING_DIR_RELATIVE, + 'directory' => PathHelper::stagingDirRelative(), 'dirName' => 'staging', ], ]; diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index 23335b0af..b66bcc0cd 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -117,7 +117,7 @@ public function providerUnfulfilled(): array ], 'In staging directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => self::STAGING_DIR_RELATIVE, + 'linkDir' => PathHelper::stagingDirRelative(), 'linkDirName' => 'staging', ], ]; diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index dbb0eef9a..6c0d0f09a 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -92,7 +92,7 @@ public function providerUnfulfilled(): array ], 'In staging directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => self::STAGING_DIR_RELATIVE, + 'linkDir' => PathHelper::stagingDirRelative(), 'linkDirName' => 'staging', ], ]; diff --git a/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php b/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php index bd8bcf969..31ded5c89 100644 --- a/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php +++ b/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php @@ -19,7 +19,7 @@ abstract class PreconditionTestCase extends TestCase protected function setUp(): void { $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(self::STAGING_DIR_RELATIVE); + $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->exclusions = new TestPathList(); } diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index 7326df931..20a9f614c 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -26,7 +26,6 @@ abstract class TestCase extends PHPUnitTestCase use AssertTrait; use ProphecyTrait; - protected const STAGING_DIR_RELATIVE = 'staging-dir'; protected const ORIGINAL_CONTENT = ''; protected const CHANGED_CONTENT = 'changed'; final public const DOMAIN_DEFAULT = 'messages'; @@ -48,7 +47,7 @@ protected static function activeDirPath(): PathInterface protected static function stagingDirPath(): PathInterface { - return PathFactory::create(self::STAGING_DIR_RELATIVE, self::testWorkingDirPath()); + return PathFactory::create(PathHelper::stagingDirRelative(), self::testWorkingDirPath()); } public function container(): ContainerBuilder From b46ed19badb58cb3dc5e38ec16e0cb5a476c9220 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 14:51:48 -0400 Subject: [PATCH 08/75] Eliminate Tests\TestCase::$activeDir and $stagingDir. --- tests/PHPUnit/Core/BeginnerUnitTest.php | 18 +++---- tests/PHPUnit/Core/CleanerUnitTest.php | 22 ++++---- tests/PHPUnit/Core/CommitterUnitTest.php | 26 +++++---- tests/PHPUnit/Core/StagerUnitTest.php | 45 ++++++++-------- .../Service/FileSyncerFunctionalTestCase.php | 11 ++-- .../Service/PhpFileSyncerUnitTest.php | 14 +++-- .../Filesystem/Service/FilesystemUnitTest.php | 38 ++++++------- ...tractFileIteratingPreconditionUnitTest.php | 8 ++- .../Service/AbstractPreconditionUnitTest.php | 30 +++++++---- .../AbstractPreconditionsTreeUnitTest.php | 19 ++++--- ...tiveAndStagingDirsAreDifferentUnitTest.php | 22 ++++---- .../Service/ActiveDirExistsUnitTest.php | 5 +- .../Service/ActiveDirIsReadyUnitTest.php | 13 +++-- .../Service/ActiveDirIsWritableUnitTest.php | 5 +- .../Service/BeginnerPreconditionsUnitTest.php | 15 ++++-- .../Service/CleanerPreconditionsUnitTest.php | 13 +++-- .../CommitterPreconditionsUnitTest.php | 15 ++++-- .../Service/CommonPreconditionsUnitTest.php | 17 ++++-- .../ComposerIsAvailableFunctionalTest.php | 11 ++-- .../Service/ComposerIsAvailableUnitTest.php | 37 ++++++++----- .../FileIteratingPreconditionUnitTestCase.php | 40 +++++++++----- ...SupportsRunningProcessesFunctionalTest.php | 9 +--- .../LinkPreconditionsFunctionalTestCase.php | 24 ++++----- .../NoAbsoluteSymlinksExistFunctionalTest.php | 2 +- .../NoHardLinksExistFunctionalTest.php | 20 +++---- .../NoLinksExistOnWindowsFunctionalTest.php | 35 ++++++------ .../Service/NoLinksExistOnWindowsUnitTest.php | 8 ++- ...sPointOutsideTheCodebaseFunctionalTest.php | 54 ++++++++++++------- ...ymlinksPointToADirectoryFunctionalTest.php | 23 ++++---- .../NoSymlinksPointToADirectoryUnitTest.php | 8 ++- .../NoUnsupportedLinksExistUnitTest.php | 25 +++++---- .../Service/PreconditionTestCase.php | 27 ++++++---- .../Service/StagerPreconditionsUnitTest.php | 19 ++++--- .../StagingDirDoesNotExistUnitTest.php | 5 +- .../Service/StagingDirExistsUnitTest.php | 7 ++- .../Service/StagingDirIsReadyUnitTest.php | 19 ++++--- .../Service/StagingDirIsWritableUnitTest.php | 5 +- tests/PHPUnit/TestCase.php | 7 +-- tests/PHPUnit/TestUtils/FilesystemHelper.php | 7 ++- tests/PHPUnit/TestUtils/PathHelper.php | 27 ++++++++-- 40 files changed, 456 insertions(+), 299 deletions(-) diff --git a/tests/PHPUnit/Core/BeginnerUnitTest.php b/tests/PHPUnit/Core/BeginnerUnitTest.php index 98b23ba6e..222f25103 100644 --- a/tests/PHPUnit/Core/BeginnerUnitTest.php +++ b/tests/PHPUnit/Core/BeginnerUnitTest.php @@ -34,8 +34,6 @@ final class BeginnerUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->preconditions = $this->prophesize(BeginnerPreconditionsInterface::class); $this->fileSyncer = $this->prophesize(FileSyncerInterface::class); } @@ -52,14 +50,14 @@ private function createSut(): Beginner public function testBeginWithMinimumParams(): void { $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, null) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null) ->shouldBeCalledOnce(); $this->fileSyncer - ->sync($this->activeDir, $this->stagingDir, null, null, ProcessInterface::DEFAULT_TIMEOUT) + ->sync(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null, null, ProcessInterface::DEFAULT_TIMEOUT) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->begin($this->activeDir, $this->stagingDir); + $sut->begin(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); } /** @@ -113,12 +111,12 @@ public function testBeginPreconditionsUnfulfilled(): void $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, Argument::cetera()) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), Argument::cetera()) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->begin($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->begin(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class, $previous->getTranslatableMessage()); } @@ -134,8 +132,8 @@ public function testExceptions(ExceptionInterface $exception): void ->willThrow($exception); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->begin($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->begin(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, RuntimeException::class, $exception->getMessage(), $exception::class); } diff --git a/tests/PHPUnit/Core/CleanerUnitTest.php b/tests/PHPUnit/Core/CleanerUnitTest.php index ab7ad5e0f..bf69a9b15 100644 --- a/tests/PHPUnit/Core/CleanerUnitTest.php +++ b/tests/PHPUnit/Core/CleanerUnitTest.php @@ -30,8 +30,6 @@ final class CleanerUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->preconditions = $this->prophesize(CleanerPreconditionsInterface::class); $this->filesystem = $this->prophesize(FilesystemInterface::class); } @@ -48,14 +46,14 @@ private function createSut(): Cleaner public function testCleanWithMinimumParams(): void { $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, null) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null) ->shouldBeCalledOnce(); $this->filesystem - ->remove($this->stagingDir, null, ProcessInterface::DEFAULT_TIMEOUT) + ->remove(PathHelper::stagingDirPath(), null, ProcessInterface::DEFAULT_TIMEOUT) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->clean($this->activeDir, $this->stagingDir); + $sut->clean(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); } /** @@ -67,14 +65,14 @@ public function testCleanWithOptionalParams(string $path, ?OutputCallbackInterfa { $path = new TestPath($path); $this->preconditions - ->assertIsFulfilled($this->activeDir, $path) + ->assertIsFulfilled(PathHelper::activeDirPath(), $path) ->shouldBeCalledOnce(); $this->filesystem ->remove($path, $callback, $timeout) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->clean($this->activeDir, $path, $callback, $timeout); + $sut->clean(PathHelper::activeDirPath(), $path, $callback, $timeout); } public function providerCleanWithOptionalParams(): array @@ -99,12 +97,12 @@ public function testCleanPreconditionsUnfulfilled(): void $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, Argument::cetera()) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), Argument::cetera()) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->clean($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->clean(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class, $previous->getTranslatableMessage()); } @@ -118,8 +116,8 @@ public function testCleanFailToRemove(): void ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->clean($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->clean(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, RuntimeException::class, $message, $previous::class); } } diff --git a/tests/PHPUnit/Core/CommitterUnitTest.php b/tests/PHPUnit/Core/CommitterUnitTest.php index bf1f9fbea..da99eb0ce 100644 --- a/tests/PHPUnit/Core/CommitterUnitTest.php +++ b/tests/PHPUnit/Core/CommitterUnitTest.php @@ -34,8 +34,6 @@ final class CommitterUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->preconditions = $this->prophesize(CommitterPreconditionsInterface::class); $this->fileSyncer = $this->prophesize(FileSyncerInterface::class); } @@ -52,14 +50,14 @@ private function createSut(): Committer public function testCommitWithMinimumParams(): void { $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, null) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null) ->shouldBeCalledOnce(); $this->fileSyncer - ->sync($this->stagingDir, $this->activeDir, null, null, ProcessInterface::DEFAULT_TIMEOUT) + ->sync(PathHelper::stagingDirPath(), PathHelper::activeDirPath(), null, null, ProcessInterface::DEFAULT_TIMEOUT) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->commit($this->stagingDir, $this->activeDir); + $sut->commit(PathHelper::stagingDirPath(), PathHelper::activeDirPath()); } /** @@ -110,16 +108,19 @@ public function providerCommitWithOptionalParams(): array /** @covers ::commit */ public function testCommitPreconditionsUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, Argument::cetera()) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, Argument::cetera()) ->shouldBeCalled() ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->commit($this->stagingDir, $this->activeDir); + self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->commit($stagingDirPath, $activeDirPath); }, PreconditionException::class, $previous->getTranslatableMessage()); } @@ -130,13 +131,16 @@ public function testCommitPreconditionsUnfulfilled(): void */ public function testExceptions(ExceptionInterface $exception, string $message): void { + $stagingDirPath = PathHelper::stagingDirPath(); + $activeDirPath = PathHelper::activeDirPath(); + $this->fileSyncer - ->sync($this->stagingDir, $this->activeDir, Argument::cetera()) + ->sync($stagingDirPath, $activeDirPath, Argument::cetera()) ->willThrow($exception); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->commit($this->stagingDir, $this->activeDir); + self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->commit($stagingDirPath, $activeDirPath); }, RuntimeException::class, $message, $exception::class); } diff --git a/tests/PHPUnit/Core/StagerUnitTest.php b/tests/PHPUnit/Core/StagerUnitTest.php index 569aa8c66..477cb27b8 100644 --- a/tests/PHPUnit/Core/StagerUnitTest.php +++ b/tests/PHPUnit/Core/StagerUnitTest.php @@ -13,7 +13,6 @@ use PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface; use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\Internal\Core\Stager; -use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -37,8 +36,6 @@ final class StagerUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->composerRunner = $this->prophesize(ComposerProcessRunnerInterface::class); $this->preconditions = $this->prophesize(StagerPreconditionsInterface::class); } @@ -55,11 +52,14 @@ private function createSut(): Stager /** @covers ::stage */ public function testStageWithMinimumParams(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir) + ->assertIsFulfilled($activeDirPath, $stagingDirPath) ->shouldBeCalledOnce(); $expectedCommand = [ - '--working-dir=' . PathHelper::stagingDirRelative(), + '--working-dir=' . PathHelper::stagingDirAbsolute(), self::INERT_COMMAND, ]; $this->composerRunner @@ -67,7 +67,7 @@ public function testStageWithMinimumParams(): void ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->stage([self::INERT_COMMAND], $this->activeDir, $this->stagingDir); + $sut->stage([self::INERT_COMMAND], $activeDirPath, $stagingDirPath); } /** @dataProvider providerStageWithOptionalParams */ @@ -77,15 +77,18 @@ public function testStageWithOptionalParams( ?OutputCallbackInterface $callback, ?int $timeout, ): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir) + ->assertIsFulfilled($activeDirPath, $stagingDirPath) ->shouldBeCalledOnce(); $this->composerRunner ->run($expectedCommand, $callback, $timeout) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->stage($givenCommand, $this->activeDir, $this->stagingDir, $callback, $timeout); + $sut->stage($givenCommand, $activeDirPath, $stagingDirPath, $callback, $timeout); } public function providerStageWithOptionalParams(): array @@ -94,7 +97,7 @@ public function providerStageWithOptionalParams(): array [ 'givenCommand' => ['update'], 'expectedCommand' => [ - '--working-dir=' . PathHelper::stagingDirRelative(), + '--working-dir=' . PathHelper::stagingDirAbsolute(), 'update', ], 'callback' => null, @@ -103,7 +106,7 @@ public function providerStageWithOptionalParams(): array [ 'givenCommand' => [self::INERT_COMMAND], 'expectedCommand' => [ - '--working-dir=' . PathHelper::stagingDirRelative(), + '--working-dir=' . PathHelper::stagingDirAbsolute(), self::INERT_COMMAND, ], 'callback' => new TestOutputCallback(), @@ -119,8 +122,8 @@ public function testCommandIsEmpty(): void $expectedExceptionMessage = new TestTranslatableExceptionMessage($message); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->stage([], $this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->stage([], PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, InvalidArgumentException::class, $expectedExceptionMessage); } @@ -134,11 +137,11 @@ public function testCommandContainsComposer(): void null, self::DOMAIN_EXCEPTIONS, ); - self::assertTranslatableException(function () use ($sut): void { + self::assertTranslatableException(static function () use ($sut): void { $sut->stage([ 'composer', self::INERT_COMMAND, - ], $this->activeDir, $this->stagingDir); + ], PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, InvalidArgumentException::class, $expectedExceptionMessage); } @@ -156,8 +159,8 @@ public function testCommandContainsWorkingDirOption(array $command): void null, self::DOMAIN_EXCEPTIONS, ); - self::assertTranslatableException(function () use ($sut, $command): void { - $sut->stage($command, $this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut, $command): void { + $sut->stage($command, PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, InvalidArgumentException::class, $expectedExceptionMessage); } @@ -175,13 +178,13 @@ public function testStagePreconditionsUnfulfilled(): void $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->preconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, Argument::cetera()) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), Argument::cetera()) ->shouldBeCalled() ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->stage([self::INERT_COMMAND], $this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->stage([self::INERT_COMMAND], PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class, $previous->getTranslatableMessage()); } @@ -193,8 +196,8 @@ public function testExceptions(ExceptionInterface $exception, string $message): ->willThrow($exception); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->stage([self::INERT_COMMAND], $this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->stage([self::INERT_COMMAND], PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, RuntimeException::class, $message, $exception::class); } diff --git a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php index 7e90b72e4..6dc9c531d 100644 --- a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -8,13 +8,12 @@ use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; -use Symfony\Component\Filesystem\Path as SymfonyPath; abstract class FileSyncerFunctionalTestCase extends TestCase { private static function sourceDirAbsolute(): string { - return SymfonyPath::makeAbsolute('source', PathHelper::testEnvAbsolute()); + return PathHelper::makeAbsolute('source', PathHelper::testEnvAbsolute()); } private static function sourcePath(): PathInterface @@ -24,7 +23,7 @@ private static function sourcePath(): PathInterface public static function destinationDirAbsolute(): string { - return SymfonyPath::makeAbsolute('destination', PathHelper::testEnvAbsolute()); + return PathHelper::makeAbsolute('destination', PathHelper::testEnvAbsolute()); } private static function destinationPath(): PathInterface @@ -89,10 +88,10 @@ public function providerSyncTimeout(): array /** @covers ::sync */ public function testSyncWithDirectorySymlinks(): void { - $link = SymfonyPath::makeAbsolute('link', self::sourceDirAbsolute()); - $target = SymfonyPath::makeAbsolute('directory', self::sourceDirAbsolute()); + $link = PathHelper::makeAbsolute('link', self::sourceDirAbsolute()); + $target = PathHelper::makeAbsolute('directory', self::sourceDirAbsolute()); FilesystemHelper::createDirectories($target); - $file = SymfonyPath::makeAbsolute('directory/file.txt', self::sourceDirAbsolute()); + $file = PathHelper::makeAbsolute('directory/file.txt', self::sourceDirAbsolute()); touch($file); symlink($target, $link); $sut = $this->createSut(); diff --git a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php index 19a9d80bc..2c804a8c9 100644 --- a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php +++ b/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php @@ -76,12 +76,12 @@ public function testSyncSourceNotFound(): void public function testSyncDirectoriesTheSame(): void { - $same = new TestPath('same'); + $samePath = PathHelper::activeDirPath(); $sut = $this->createSut(); - $message = sprintf('The source and destination directories cannot be the same at %s', $same->absolute()); - self::assertTranslatableException(static function () use ($sut, $same): void { - $sut->sync($same, $same); + $message = sprintf('The source and destination directories cannot be the same at %s', $samePath->absolute()); + self::assertTranslatableException(static function () use ($sut, $samePath): void { + $sut->sync($samePath, $samePath); }, LogicException::class, $message); } @@ -234,9 +234,7 @@ public function providerGetRelativePath(): array public function testTransMissingTranslatableFactory(): void { self::assertTranslatableException(function (): void { - $same = new TestPath('same'); - $source = $same; - $destination = $same; + $samePath = PathHelper::activeDirPath(); $sut = $this->createSut(); $reflection = new ReflectionClass($sut); @@ -244,7 +242,7 @@ public function testTransMissingTranslatableFactory(): void $translatableFactory = $reflection->getProperty('translatableFactory'); $translatableFactory->setValue($sut, null); - $sut->sync($source, $destination); + $sut->sync($samePath, $samePath); }, AssertionError::class, 'The "p()" method requires a translatable factory. ' . 'Provide one by calling "setTranslatableFactory()" in the constructor.'); } diff --git a/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php b/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php index 2eefa47b5..1f1f987eb 100644 --- a/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php +++ b/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php @@ -30,8 +30,6 @@ final class FilesystemUnitTest extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->pathFactory = $this->prophesize(PathFactoryInterface::class); $this->symfonyFilesystem = $this->prophesize(SymfonyFilesystem::class); } @@ -80,7 +78,12 @@ public function providerCopy(): array public function testCopyFailure(): void { $previousMessage = 'Something went wrong'; - $message = sprintf('Failed to copy active-dir to staging-dir: %s', $previousMessage); + $message = sprintf( + 'Failed to copy %s to %s: %s', + PathHelper::activeDirAbsolute(), + PathHelper::stagingDirAbsolute(), + $previousMessage, + ); $previous = new SymfonyIOException($previousMessage); $this->symfonyFilesystem ->copy(Argument::cetera()) @@ -88,8 +91,8 @@ public function testCopyFailure(): void ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->copy($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->copy(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, IOException::class, $message, $previous::class); } @@ -103,22 +106,21 @@ public function testCopySourceDirectoryNotFound(): void ->willThrow($previous); $sut = $this->createSut(); - $message = sprintf('The source file does not exist or is not a file at %s', $this->activeDir->absolute()); - self::assertTranslatableException(function () use ($sut): void { - $sut->copy($this->activeDir, $this->stagingDir); + $message = sprintf('The source file does not exist or is not a file at %s', PathHelper::activeDirAbsolute()); + self::assertTranslatableException(static function () use ($sut): void { + $sut->copy(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, LogicException::class, $message, $previous); } /** @covers ::copy */ public function testCopyDirectoriesTheSame(): void { - $source = new TestPath('same'); - $destination = $source; + $samePath = PathHelper::activeDirPath(); $sut = $this->createSut(); - $message = sprintf('The source and destination files cannot be the same at %s', $source->absolute()); - self::assertTranslatableException(static function () use ($sut, $source, $destination): void { - $sut->copy($source, $destination); + $message = sprintf('The source and destination files cannot be the same at %s', $samePath->absolute()); + self::assertTranslatableException(static function () use ($sut, $samePath): void { + $sut->copy($samePath, $samePath); }, LogicException::class, $message); } @@ -149,15 +151,15 @@ public function providerMkdir(): array /** @covers ::mkdir */ public function testMkdirFailure(): void { - $message = 'Failed to create directory at staging-dir'; + $message = sprintf('Failed to create directory at %s', PathHelper::stagingDirAbsolute()); $previous = new SymfonyIOException($message); $this->symfonyFilesystem ->mkdir(Argument::any()) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->mkdir($this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->mkdir(PathHelper::stagingDirPath()); }, IOException::class, $message, $previous::class); } @@ -211,8 +213,8 @@ public function testRemoveException(): void ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->remove($this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->remove(PathHelper::stagingDirPath()); }, IOException::class, $message, $previous::class); } } diff --git a/tests/PHPUnit/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php b/tests/PHPUnit/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php index 985b06185..c0ec47c0f 100644 --- a/tests/PHPUnit/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; use Prophecy\Argument; @@ -100,6 +101,9 @@ protected function exitEarly( */ public function testExitEarly(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->filesystem ->exists(Argument::cetera()) ->shouldNotBeCalled(); @@ -110,10 +114,10 @@ public function testExitEarly(): void /** @noinspection PhpPossiblePolymorphicInvocationInspection */ $sut->exitEarly = true; - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); } } diff --git a/tests/PHPUnit/Precondition/Service/AbstractPreconditionUnitTest.php b/tests/PHPUnit/Precondition/Service/AbstractPreconditionUnitTest.php index 7c447a255..413241757 100644 --- a/tests/PHPUnit/Precondition/Service/AbstractPreconditionUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/AbstractPreconditionUnitTest.php @@ -11,6 +11,7 @@ use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait; use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\TestUtils\TestSpyInterface; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; @@ -102,9 +103,12 @@ public function testBasicFunctionality( string $unfulfilledStatusMessage, string $expectedStatusMessage, ): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + // Double expectations: once for ::isFulfilled() and once for ::assertIsFulfilled(). $this->spy - ->report([$this->activeDir, $this->stagingDir, $exclusions]) + ->report([$activeDirPath, $stagingDirPath, $exclusions]) ->shouldBeCalledTimes(2) ->willReturn($isFulfilled); @@ -116,8 +120,8 @@ public function testBasicFunctionality( self::assertEquals($sut->getName(), $name); self::assertEquals($sut->getDescription(), $description); - self::assertEquals($sut->isFulfilled($this->activeDir, $this->stagingDir, $exclusions), $isFulfilled); - self::assertEquals($sut->getStatusMessage($this->activeDir, $this->stagingDir, $exclusions), $expectedStatusMessage); + self::assertEquals($sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions), $isFulfilled); + self::assertEquals($sut->getStatusMessage($activeDirPath, $stagingDirPath, $exclusions), $expectedStatusMessage); self::assertEquals($sut->getLeaves(), [$sut]); } @@ -151,21 +155,24 @@ public function providerBasicFunctionality(): array */ public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->spy ->report(Argument::cetera()) ->willReturn(true); $this->spy - ->report([$this->activeDir, $this->stagingDir]) + ->report([$activeDirPath, $stagingDirPath]) ->shouldBeCalledOnce() ->willReturn(true); $this->spy - ->report([$this->activeDir, $this->stagingDir, new TestPathList()]) + ->report([$activeDirPath, $stagingDirPath, new TestPathList()]) ->shouldBeCalledOnce() ->willReturn(true); $sut = $this->createSut(); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, new TestPathList()); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, new TestPathList()); } /** @@ -174,16 +181,19 @@ public function testFulfilled(): void */ public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $this->spy - ->report([$this->activeDir, $this->stagingDir, new TestPathList()]) + ->report([$activeDirPath, $stagingDirPath, new TestPathList()]) ->willReturn(false); $sut = $this->createSut(); /** @noinspection PhpPossiblePolymorphicInvocationInspection */ $sut->theUnfulfilledStatusMessage = $message; - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, new TestPathList()); + self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, new TestPathList()); }, PreconditionException::class, $message); } } diff --git a/tests/PHPUnit/Precondition/Service/AbstractPreconditionsTreeUnitTest.php b/tests/PHPUnit/Precondition/Service/AbstractPreconditionsTreeUnitTest.php index 82ab9a01a..26b1a5181 100644 --- a/tests/PHPUnit/Precondition/Service/AbstractPreconditionsTreeUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/AbstractPreconditionsTreeUnitTest.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPrecondition; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPreconditionsTree; use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\TestUtils\TestSpyInterface; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; @@ -76,6 +77,9 @@ public function testBasicFunctionality( string $expectedStatusMessage, ?TestPathList $exclusions, ): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + // Pass a mock child into the SUT so the behavior of ::assertIsFulfilled // can be controlled indirectly, without overriding the method on the SUT // itself and preventing it from actually being exercised. @@ -85,11 +89,11 @@ public function testBasicFunctionality( ->willReturn([$child]); // Double expectations: once for ::isFulfilled() and once for ::assertIsFulfilled(). - $child->assertIsFulfilled($this->activeDir, $this->stagingDir, $exclusions) + $child->assertIsFulfilled($activeDirPath, $stagingDirPath, $exclusions) ->shouldBeCalledOnce(); if (!$isFulfilled) { - $child->assertIsFulfilled($this->activeDir, $this->stagingDir, $exclusions) + $child->assertIsFulfilled($activeDirPath, $stagingDirPath, $exclusions) ->willThrow(PreconditionException::class); } @@ -105,7 +109,7 @@ public function testBasicFunctionality( self::assertEquals($name, $sut->getName()); self::assertEquals($description, $sut->getDescription()); - self::assertEquals($isFulfilled, $sut->isFulfilled($this->activeDir, $this->stagingDir, $exclusions)); + self::assertEquals($isFulfilled, $sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions)); } public function providerBasicFunctionality(): array @@ -234,11 +238,14 @@ public function assertIsFulfilled( ); // @phpcs:enable - self::assertFalse($sut->isFulfilled($this->activeDir, $this->stagingDir), 'Unfulfilled leaf status bubbled up properly.'); + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + + self::assertFalse($sut->isFulfilled($activeDirPath, $stagingDirPath), 'Unfulfilled leaf status bubbled up properly.'); self::assertSame($leaves, $sut->getLeaves()); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); }, PreconditionException::class, $message); } } diff --git a/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php b/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php index f5b24c0f9..0a293549e 100644 --- a/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php @@ -3,7 +3,7 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveAndStagingDirsAreDifferent; -use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; @@ -27,19 +27,21 @@ protected function createSut(): ActiveAndStagingDirsAreDifferent public function testFulfilled(): void { - $this->activeDir = new TestPath('/one/different'); - $this->stagingDir = new TestPath('/two/different'); - - $this->doTestFulfilled('The active and staging directories are different.'); + $this->doTestFulfilled( + 'The active and staging directories are different.', + PathHelper::activeDirPath(), + PathHelper::stagingDirPath(), + ); } /** @covers ::assertIsFulfilled */ public function testUnfulfilled(): void { - $message = new TestTranslatableExceptionMessage('The active and staging directories are the same.'); - $this->activeDir = new TestPath('/same'); - $this->stagingDir = new TestPath('/same'); - - $this->doTestUnfulfilled($message); + $this->doTestUnfulfilled( + new TestTranslatableExceptionMessage('The active and staging directories are the same.'), + null, + PathHelper::activeDirPath(), + PathHelper::activeDirPath(), + ); } } diff --git a/tests/PHPUnit/Precondition/Service/ActiveDirExistsUnitTest.php b/tests/PHPUnit/Precondition/Service/ActiveDirExistsUnitTest.php index 328f9380e..ab0aa7961 100644 --- a/tests/PHPUnit/Precondition/Service/ActiveDirExistsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/ActiveDirExistsUnitTest.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirExists; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -39,7 +40,7 @@ protected function createSut(): ActiveDirExists public function testFulfilled(): void { $this->filesystem - ->exists($this->activeDir) + ->exists(PathHelper::activeDirPath()) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE) ->willReturn(true); @@ -51,7 +52,7 @@ public function testUnfulfilled(): void { $message = 'The active directory does not exist.'; $this->filesystem - ->exists($this->activeDir) + ->exists(PathHelper::activeDirPath()) ->willReturn(false); $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); diff --git a/tests/PHPUnit/Precondition/Service/ActiveDirIsReadyUnitTest.php b/tests/PHPUnit/Precondition/Service/ActiveDirIsReadyUnitTest.php index 7e81067b8..ef37a2819 100644 --- a/tests/PHPUnit/Precondition/Service/ActiveDirIsReadyUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/ActiveDirIsReadyUnitTest.php @@ -5,6 +5,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirExistsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirIsWritableInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsReady; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -47,11 +48,14 @@ protected function createSut(): ActiveDirIsReady public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->activeDirExists - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->activeDirIsWritable - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('The active directory is ready to use.'); @@ -59,10 +63,13 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->activeDirExists - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); diff --git a/tests/PHPUnit/Precondition/Service/ActiveDirIsWritableUnitTest.php b/tests/PHPUnit/Precondition/Service/ActiveDirIsWritableUnitTest.php index 3892ce730..79db7325c 100644 --- a/tests/PHPUnit/Precondition/Service/ActiveDirIsWritableUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/ActiveDirIsWritableUnitTest.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsWritable; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -39,7 +40,7 @@ protected function createSut(): ActiveDirIsWritable public function testFulfilled(): void { $this->filesystem - ->isWritable($this->activeDir) + ->isWritable(PathHelper::activeDirPath()) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE) ->willReturn(true); @@ -51,7 +52,7 @@ public function testUnfulfilled(): void { $message = new TestTranslatableExceptionMessage('The active directory is not writable.'); $this->filesystem - ->isWritable($this->activeDir) + ->isWritable(PathHelper::activeDirPath()) ->willReturn(false); $this->doTestUnfulfilled($message); diff --git a/tests/PHPUnit/Precondition/Service/BeginnerPreconditionsUnitTest.php b/tests/PHPUnit/Precondition/Service/BeginnerPreconditionsUnitTest.php index f28488541..60fcc3d33 100644 --- a/tests/PHPUnit/Precondition/Service/BeginnerPreconditionsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/BeginnerPreconditionsUnitTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\NoUnsupportedLinksExistInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirDoesNotExistInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\BeginnerPreconditions; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -55,14 +56,17 @@ protected function createSut(): BeginnerPreconditions public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noUnsupportedLinksExist - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirDoesNotExist - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('The preconditions for beginning the staging process are fulfilled.'); @@ -70,10 +74,13 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); diff --git a/tests/PHPUnit/Precondition/Service/CleanerPreconditionsUnitTest.php b/tests/PHPUnit/Precondition/Service/CleanerPreconditionsUnitTest.php index 9124eba96..3f9bd83eb 100644 --- a/tests/PHPUnit/Precondition/Service/CleanerPreconditionsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/CleanerPreconditionsUnitTest.php @@ -5,6 +5,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsReadyInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\CleanerPreconditions; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -48,11 +49,14 @@ protected function createSut(): CleanerPreconditions public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsReady - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('The preconditions for removing the staging directory are fulfilled.'); @@ -60,10 +64,13 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); diff --git a/tests/PHPUnit/Precondition/Service/CommitterPreconditionsUnitTest.php b/tests/PHPUnit/Precondition/Service/CommitterPreconditionsUnitTest.php index eedb8144b..b6bc37365 100644 --- a/tests/PHPUnit/Precondition/Service/CommitterPreconditionsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/CommitterPreconditionsUnitTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\NoUnsupportedLinksExistInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsReadyInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\CommitterPreconditions; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -55,14 +56,17 @@ protected function createSut(): CommitterPreconditions public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noUnsupportedLinksExist - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsReady - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('The preconditions for making staged changes live are fulfilled.'); @@ -70,10 +74,13 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); diff --git a/tests/PHPUnit/Precondition/Service/CommonPreconditionsUnitTest.php b/tests/PHPUnit/Precondition/Service/CommonPreconditionsUnitTest.php index 408f14751..f6f6e2638 100644 --- a/tests/PHPUnit/Precondition/Service/CommonPreconditionsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/CommonPreconditionsUnitTest.php @@ -7,6 +7,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\ComposerIsAvailableInterface; use PhpTuf\ComposerStager\API\Precondition\Service\HostSupportsRunningProcessesInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\CommonPreconditions; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -68,17 +69,20 @@ protected function createSut(): CommonPreconditions public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->composerIsAvailable - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->activeDirIsReady - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->activeAndStagingDirsAreDifferent - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->hostSupportsRunningProcesses - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('The common preconditions are fulfilled.'); @@ -86,10 +90,13 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->activeAndStagingDirsAreDifferent - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); diff --git a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php index 6be3cb1f3..b8f98a5e0 100644 --- a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php @@ -7,7 +7,6 @@ use PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface; use PhpTuf\ComposerStager\Internal\Finder\Service\ExecutableFinder; use PhpTuf\ComposerStager\Internal\Precondition\Service\ComposerIsAvailable; -use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -24,8 +23,6 @@ protected function setUp(): void self::createTestEnvironment(); FilesystemHelper::createDirectories(PathHelper::stagingDirRelative()); - $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->executableFinderClass = ExecutableFinder::class; } @@ -61,8 +58,8 @@ public function testComposerNotFound(): void $sut = $this->createSut(); $message = ComposerNotFoundExecutableFinder::EXCEPTION_MESSAGE; - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class, $message, LogicException::class); } @@ -72,8 +69,8 @@ public function testInvalidComposerFound(): void $sut = $this->createSut(); $message = InvalidComposerFoundExecutableFinder::getExceptionMessage(); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class, $message); } } diff --git a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableUnitTest.php b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableUnitTest.php index a78be3179..ce5df91f3 100644 --- a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/ComposerIsAvailableUnitTest.php @@ -8,6 +8,7 @@ use PhpTuf\ComposerStager\API\Process\Factory\ProcessFactoryInterface; use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\ComposerIsAvailable; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; @@ -101,6 +102,9 @@ public function testFulfilled(): void /** @covers ::assertExecutableExists */ public function testExecutableNotFound(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $previous = LogicException::class; $this->executableFinder ->find('composer') @@ -110,10 +114,10 @@ public function testExecutableNotFound(): void $message = 'Cannot find Composer.'; self::assertTranslatableMessage( $message, - $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions), + $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions), ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class, $message, $previous); } @@ -140,6 +144,9 @@ public function testFailedToCreateProcess(): void /** @covers ::getProcess */ public function testFailedToRunProcess(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->process ->mustRun() ->willThrow(LogicException::class); @@ -148,16 +155,19 @@ public function testFailedToRunProcess(): void $message = $this->invalidComposerErrorMessage(); self::assertTranslatableMessage( $message, - $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions), + $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions), ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class, $message); } /** @covers ::isValidExecutable */ public function testFailedToGetOutput(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $previous = LogicException::class; $this->process ->getOutput() @@ -167,16 +177,19 @@ public function testFailedToGetOutput(): void $message = $this->invalidComposerErrorMessage(); self::assertTranslatableMessage( $message, - $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions), + $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions), ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class, $message); } /** @dataProvider providerInvalidOutput */ public function testInvalidOutput(string $output): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->process ->getOutput() ->willReturn($output); @@ -185,10 +198,10 @@ public function testInvalidOutput(string $output): void $message = $this->invalidComposerErrorMessage(); self::assertTranslatableMessage( $message, - $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions), + $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions), ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class, $message); } diff --git a/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php b/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php index 9e105b310..0f364ab3c 100644 --- a/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php +++ b/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php @@ -13,6 +13,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; use Prophecy\Argument; @@ -45,6 +46,9 @@ protected function setUp(): void /** @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::exitEarly */ public function testExitEarly(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->filesystem ->exists(Argument::cetera()) ->shouldNotBeCalled(); @@ -93,23 +97,26 @@ protected function exitEarly( } }; - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); } /** @covers ::assertIsFulfilled */ public function testActiveDirectoryDoesNotExistCountsAsFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->filesystem - ->exists($this->activeDir) + ->exists($activeDirPath) ->willReturn(false); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); - $statusMessage = $sut->getStatusMessage($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); + $statusMessage = $sut->getStatusMessage($activeDirPath, $stagingDirPath); $this->assertFulfilled($isFulfilled, $statusMessage, 'Treated non-existent directories as fulfilled.'); } @@ -117,13 +124,16 @@ public function testActiveDirectoryDoesNotExistCountsAsFulfilled(): void /** @covers ::assertIsFulfilled */ public function testStagingDirectoryDoesNotExistCountsAsFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->filesystem - ->exists($this->stagingDir) + ->exists($stagingDirPath) ->willReturn(false); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); - $statusMessage = $sut->getStatusMessage($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); + $statusMessage = $sut->getStatusMessage($activeDirPath, $stagingDirPath); $this->assertFulfilled($isFulfilled, $statusMessage, 'Treated non-existent directories as fulfilled.'); } @@ -131,13 +141,16 @@ public function testStagingDirectoryDoesNotExistCountsAsFulfilled(): void /** @covers ::assertIsFulfilled */ public function testNoFilesFound(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->fileFinder ->find(Argument::type(PathInterface::class), Argument::type(PathListInterface::class)) ->willReturn([]); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); - $statusMessage = $sut->getStatusMessage($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); + $statusMessage = $sut->getStatusMessage($activeDirPath, $stagingDirPath); $this->assertFulfilled($isFulfilled, $statusMessage, 'Treated empty codebase as fulfilled.'); } @@ -149,17 +162,20 @@ public function testNoFilesFound(): void */ public function testFileFinderExceptions(ExceptionInterface $previous): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->fileFinder ->find(Argument::type(PathInterface::class), Argument::type(PathListInterface::class)) ->willThrow($previous); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertFalse($isFulfilled); try { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); } catch (Throwable $e) { self::assertInstanceOf(PreconditionException::class, $e); self::assertSame($e->getMessage(), $previous->getMessage()); diff --git a/tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php b/tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php index e1499312c..bf6b52eff 100644 --- a/tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\HostSupportsRunningProcesses; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\HostSupportsRunningProcesses @@ -12,12 +13,6 @@ */ final class HostSupportsRunningProcessesFunctionalTest extends TestCase { - protected function setUp(): void - { - $this->activeDir = self::activeDirPath(); - $this->stagingDir = self::stagingDirPath(); - } - private function createSut(): HostSupportsRunningProcesses { $container = $this->container(); @@ -53,7 +48,7 @@ public function testUnfulfilled(): void $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertFalse($isFulfilled, 'Detected lack of support for running processes.'); } } diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php index bc5f4ec53..79a7f7f76 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php @@ -2,12 +2,12 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; +use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; -use Symfony\Component\Filesystem\Path as SymfonyPath; abstract class LinkPreconditionsFunctionalTestCase extends TestCase { @@ -15,9 +15,6 @@ protected function setUp(): void { self::createTestEnvironment(); FilesystemHelper::createDirectories(PathHelper::stagingDirRelative()); - - $this->activeDir = self::activeDirPath(); - $this->stagingDir = self::stagingDirPath(); } protected function tearDown(): void @@ -28,15 +25,15 @@ protected function tearDown(): void abstract protected function createSut(): PreconditionInterface; /** @dataProvider providerFulfilledDirectoryDoesNotExist */ - public function testFulfilledDirectoryDoesNotExist(string $activeDir, string $stagingDir): void + public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void { $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); } - final protected function doTestFulfilledDirectoryDoesNotExist(string $activeDir, string $stagingDir): void - { - $activeDir = PathFactory::create($activeDir); - $stagingDir = PathFactory::create($stagingDir); + final protected function doTestFulfilledDirectoryDoesNotExist( + PathInterface $activeDir, + PathInterface $stagingDir, + ): void { $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled($activeDir, $stagingDir); @@ -46,18 +43,15 @@ final protected function doTestFulfilledDirectoryDoesNotExist(string $activeDir, final public function providerFulfilledDirectoryDoesNotExist(): array { - $nonexistentDir = SymfonyPath::makeAbsolute( - '65eb69a274470dd84e9b5371f7e1e8c8', - PathHelper::testWorkingDirAbsolute(), - ); + $nonexistentDir = PathFactory::create('65eb69a274470dd84e9b5371f7e1e8c8'); return [ 'Active directory' => [ 'activeDir' => $nonexistentDir, - 'stagingDir' => PathHelper::stagingDirRelative(), + 'stagingDir' => PathHelper::stagingDirPath(), ], 'Staging directory' => [ - 'activeDir' => PathHelper::activeDirRelative(), + 'activeDir' => PathHelper::activeDirPath(), 'stagingDir' => $nonexistentDir, ], ]; diff --git a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index 546d82440..2f1a19428 100644 --- a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -166,7 +166,7 @@ public function providerLinksExist(): array * * @dataProvider providerFulfilledDirectoryDoesNotExist */ - public function testFulfilledDirectoryDoesNotExist(string $activeDir, string $stagingDir): void + public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void { $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); } diff --git a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php index 4a4695583..d3362fcc7 100644 --- a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -3,10 +3,12 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; +use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; +use Symfony\Component\Filesystem\Path; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist @@ -34,7 +36,7 @@ public function testFulfilledWithNoLinks(): void { $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Passed with no links in the codebase.'); } @@ -45,13 +47,13 @@ public function testFulfilledWithNoLinks(): void */ public function testFulfilledWithSymlink(): void { - $target = PathFactory::create('target.txt', $this->activeDir)->absolute(); - $link = PathFactory::create('link.txt', $this->activeDir)->absolute(); + $target = Path::makeAbsolute('target.txt', PathHelper::activeDirAbsolute()); + $link = Path::makeAbsolute('link.txt', PathHelper::activeDirAbsolute()); touch($target); symlink($target, $link); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Allowed symlink.'); } @@ -76,8 +78,8 @@ public function testUnfulfilled(string $directory, string $dirName): void PathFactory::create($directory)->absolute(), $link, ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class, $message); } @@ -100,7 +102,7 @@ public function providerUnfulfilled(): array * * @dataProvider providerFulfilledDirectoryDoesNotExist */ - public function testFulfilledDirectoryDoesNotExist(string $activeDir, string $stagingDir): void + public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void { $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); } @@ -121,12 +123,12 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s $links = array_fill_keys($links, $targetFile); $exclusions = new PathList(...$exclusions); - $dirPath = $this->activeDir->absolute(); + $dirPath = PathHelper::activeDirAbsolute(); self::createFile($dirPath, $targetFile); self::createHardlinks($dirPath, $links); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir, $exclusions); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); self::assertEquals($shouldBeFulfilled, $isFulfilled, 'Respected exclusions.'); } diff --git a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php index 447416e8d..5f81ce9f4 100644 --- a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php @@ -3,9 +3,10 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; +use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows @@ -34,7 +35,7 @@ public function testFulfilledWithNoLinks(): void { $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Passed with no links in the codebase.'); } @@ -51,24 +52,28 @@ public function testFulfilledWithNoLinks(): void */ public function testUnfulfilled(array $symlinks, array $hardLinks): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $basePath = self::activeDirPath(); - $link = PathFactory::create('link.txt', $basePath)->absolute(); - $target = PathFactory::create('target.txt', $basePath)->absolute(); + $basePathAbsolute = $basePath->absolute(); + $link = PathHelper::makeAbsolute('link.txt', $basePathAbsolute); + $target = PathHelper::makeAbsolute('target.txt', $basePathAbsolute); touch($target); - self::createSymlinks($basePath->absolute(), $symlinks); - self::createHardlinks($basePath->absolute(), $hardLinks); + self::createSymlinks($basePathAbsolute, $symlinks); + self::createHardlinks($basePathAbsolute, $hardLinks); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertFalse($isFulfilled, 'Rejected link on Windows.'); $message = sprintf( 'The active directory at %s contains links, which is not supported on Windows. The first one is %s.', - $basePath->absolute(), + $basePathAbsolute, $link, ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); }, PreconditionException::class, $message); } @@ -93,7 +98,7 @@ public function providerUnfulfilled(): array * * @dataProvider providerFulfilledDirectoryDoesNotExist */ - public function testFulfilledDirectoryDoesNotExist(string $activeDir, string $stagingDir): void + public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void { $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); } @@ -111,12 +116,12 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s $targetFile = 'target.txt'; $links = array_fill_keys($links, $targetFile); $exclusions = new PathList(...$exclusions); - $dirPath = $this->activeDir->absolute(); - self::createFile($dirPath, $targetFile); - self::createSymlinks($dirPath, $links); + $basePath = PathHelper::activeDirAbsolute(); + self::createFile($basePath, $targetFile); + self::createSymlinks($basePath, $links); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir, $exclusions); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); self::assertEquals($shouldBeFulfilled, $isFulfilled, 'Respected exclusions.'); } diff --git a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsUnitTest.php b/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsUnitTest.php index 9d85c161f..1759adffe 100644 --- a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsUnitTest.php @@ -5,6 +5,7 @@ use PhpTuf\ComposerStager\Internal\Host\Service\HostInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows; use PhpTuf\ComposerStager\Tests\Host\Service\TestHost; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use Prophecy\Argument; @@ -73,6 +74,9 @@ public function testFulfilled(): void public function testExitEarlyOnNonWindows(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->host = $this->createNonWindowsHost(); $this->filesystem ->exists(Argument::cetera()) @@ -83,10 +87,10 @@ public function testExitEarlyOnNonWindows(): void $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); } } diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index b66bcc0cd..76c2900aa 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -3,6 +3,7 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; +use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase; @@ -37,15 +38,18 @@ protected function createSut(): NoSymlinksPointOutsideTheCodebase */ public function testFulfilledWithValidLink(string $link, string $target): void { - $link = PathFactory::create($link, $this->activeDir)->absolute(); + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + + $link = PathFactory::create($link, $activeDirPath)->absolute(); self::ensureParentDirectory($link); - $target = PathFactory::create($target, $this->activeDir)->absolute(); + $target = PathFactory::create($target, $activeDirPath)->absolute(); self::ensureParentDirectory($target); touch($target); symlink($target, $link); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled, 'Allowed link pointing within the codebase.'); } @@ -90,8 +94,11 @@ public function providerFulfilledWithValidLink(): array */ public function testUnfulfilled(string $targetDir, string $linkDir, string $linkDirName): void { - $target = PathFactory::create($targetDir . '/target.txt')->absolute(); - $link = PathFactory::create($linkDir . '/link.txt')->absolute(); + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + + $target = PathHelper::makeAbsolute('target.txt', $targetDir); + $link = PathHelper::makeAbsolute('link.txt', $linkDir); touch($target); symlink($target, $link); $sut = $this->createSut(); @@ -99,11 +106,11 @@ public function testUnfulfilled(string $targetDir, string $linkDir, string $link $message = sprintf( 'The %s directory at %s contains links that point outside the codebase, which is not supported. The first one is %s.', $linkDirName, - PathFactory::create($linkDir)->absolute(), + PathHelper::makeAbsolute($linkDir, getcwd()), $link, ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); }, PreconditionException::class, $message); } @@ -112,12 +119,12 @@ public function providerUnfulfilled(): array return [ 'In active directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => PathHelper::activeDirRelative(), + 'linkDir' => PathHelper::activeDirAbsolute(), 'linkDirName' => 'active', ], 'In staging directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => PathHelper::stagingDirRelative(), + 'linkDir' => PathHelper::stagingDirAbsolute(), 'linkDirName' => 'staging', ], ]; @@ -128,7 +135,7 @@ public function providerUnfulfilled(): array * * @dataProvider providerFulfilledDirectoryDoesNotExist */ - public function testFulfilledDirectoryDoesNotExist(string $activeDir, string $stagingDir): void + public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void { $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); } @@ -139,16 +146,19 @@ public function testFulfilledDirectoryDoesNotExist(string $activeDir, string $st */ public function testWithHardLink(): void { - $dirPath = self::activeDirPath(); - $link = PathFactory::create('link.txt', $dirPath)->absolute(); - $target = PathFactory::create('target.txt', $dirPath)->absolute(); + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + + $basePathAbsolute = PathHelper::activeDirAbsolute(); + $link = PathHelper::makeAbsolute('link.txt', $basePathAbsolute); + $target = PathHelper::makeAbsolute('target.txt', $basePathAbsolute); $parentDir = dirname($link); @mkdir($parentDir, 0777, true); touch($target); link($target, $link); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled, 'Ignored hard link link.'); } @@ -161,6 +171,9 @@ public function testWithHardLink(): void */ public function testWithAbsoluteLink(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $dirPath = self::activeDirPath(); $link = PathFactory::create('link.txt', $dirPath)->absolute(); $target = PathFactory::create('target.txt', $dirPath)->absolute(); @@ -170,8 +183,8 @@ public function testWithAbsoluteLink(): void symlink($target, $link); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled, 'Ignored hard link link.'); } @@ -186,14 +199,17 @@ public function testWithAbsoluteLink(): void */ public function testFulfilledExclusions(array $links, array $exclusions, bool $shouldBeFulfilled): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $targetFile = '../'; $links = array_fill_keys($links, $targetFile); $exclusions = new PathList(...$exclusions); - $dirPath = $this->activeDir->absolute(); + $dirPath = PathHelper::activeDirAbsolute(); self::createSymlinks($dirPath, $links); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir, $exclusions); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions); self::assertEquals($shouldBeFulfilled, $isFulfilled, 'Respected exclusions.'); } diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index 6c0d0f09a..5c8f9c6b3 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -44,15 +44,16 @@ protected function createSut(): NoSymlinksPointToADirectory */ public function testFulfilledWithValidLink(): void { - $link = PathFactory::create('link.txt', $this->activeDir)->absolute(); + $parentDir = PathHelper::activeDirAbsolute(); + $link = PathHelper::makeAbsolute('link.txt', $parentDir); + $target = PathHelper::makeAbsolute('target.txt', $parentDir); self::ensureParentDirectory($link); - $target = PathFactory::create('target.txt', $this->activeDir)->absolute(); self::ensureParentDirectory($target); touch($target); symlink($target, $link); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Allowed link pointing within the codebase.'); } @@ -77,8 +78,8 @@ public function testUnfulfilled(string $targetDir, string $linkDir, string $link PathFactory::create($linkDir)->absolute(), $link, ); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + self::assertTranslatableException(static function () use ($sut): void { + $sut->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class, $message); } @@ -106,15 +107,15 @@ public function providerUnfulfilled(): array */ public function testFulfilledExclusions(array $links, array $exclusions, bool $shouldBeFulfilled): void { - $targetDir = './target_directory'; - FilesystemHelper::createDirectories(PathFactory::create($targetDir, $this->activeDir)->absolute()); - $links = array_fill_keys($links, $targetDir); + $targetDirRelative = 'target_directory'; + $targetDirAbsolute = PathHelper::makeAbsolute($targetDirRelative, PathHelper::activeDirAbsolute()); + FilesystemHelper::createDirectories($targetDirAbsolute); + $links = array_fill_keys($links, $targetDirRelative); $exclusions = new PathList(...$exclusions); - $dirPath = $this->activeDir->absolute(); - self::createSymlinks($dirPath, $links); + self::createSymlinks(PathHelper::activeDirAbsolute(), $links); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir, $exclusions); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); self::assertEquals($shouldBeFulfilled, $isFulfilled, 'Respected exclusions.'); } diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php index cc98b89e9..2ecd5c1a7 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php @@ -11,6 +11,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -63,6 +64,9 @@ protected function createSut(): NoSymlinksPointToADirectory public function testExitEarlyWithRsyncFileSyncer(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->fileSyncer = $this->prophesize(RsyncFileSyncerInterface::class); $this->filesystem ->exists(Argument::cetera()) @@ -73,10 +77,10 @@ public function testExitEarlyWithRsyncFileSyncer(): void $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); } } diff --git a/tests/PHPUnit/Precondition/Service/NoUnsupportedLinksExistUnitTest.php b/tests/PHPUnit/Precondition/Service/NoUnsupportedLinksExistUnitTest.php index be497af79..00bcb09ae 100644 --- a/tests/PHPUnit/Precondition/Service/NoUnsupportedLinksExistUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/NoUnsupportedLinksExistUnitTest.php @@ -9,6 +9,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\NoSymlinksPointOutsideTheCodebaseInterface; use PhpTuf\ComposerStager\API\Precondition\Service\NoSymlinksPointToADirectoryInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoUnsupportedLinksExist; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use Prophecy\Prophecy\ObjectProphecy; @@ -76,20 +77,23 @@ protected function createSut(): NoUnsupportedLinksExist public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->noAbsoluteSymlinksExist - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noHardLinksExist - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noLinksExistOnWindows - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noSymlinksPointOutsideTheCodebase - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noSymlinksPointToADirectory - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('There are no unsupported links in the codebase.'); @@ -97,16 +101,19 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->noAbsoluteSymlinksExist - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableMessage($message, $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions)); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class); } } diff --git a/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php b/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php index 31ded5c89..025d9bd8c 100644 --- a/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php +++ b/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php @@ -3,9 +3,9 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; +use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; -use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -18,8 +18,6 @@ abstract class PreconditionTestCase extends TestCase protected function setUp(): void { - $this->activeDir = new TestPath(PathHelper::activeDirRelative()); - $this->stagingDir = new TestPath(PathHelper::stagingDirRelative()); $this->exclusions = new TestPathList(); } @@ -40,13 +38,18 @@ public function testGetters(): void self::assertIsArray($sut->getLeaves()); } - protected function doTestFulfilled(string $expectedStatusMessage): void - { + protected function doTestFulfilled( + string $expectedStatusMessage, + ?PathInterface $activeDirPath = null, + ?PathInterface $stagingDirPath = null, + ): void { + $activeDirPath ??= PathHelper::activeDirPath(); + $stagingDirPath ??= PathHelper::stagingDirPath(); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); - $actualStatusMessage = $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions); - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); + $actualStatusMessage = $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); self::assertTrue($isFulfilled); self::assertTranslatableMessage($expectedStatusMessage, $actualStatusMessage, 'Got correct status message.'); @@ -55,11 +58,15 @@ protected function doTestFulfilled(string $expectedStatusMessage): void protected function doTestUnfulfilled( TranslatableInterface $expectedStatusMessage, ?string $previousException = null, + ?PathInterface $activeDirPath = null, + ?PathInterface $stagingDirPath = null, ): void { + $activeDirPath ??= PathHelper::activeDirPath(); + $stagingDirPath ??= PathHelper::stagingDirPath(); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class, $expectedStatusMessage, $previousException); } } diff --git a/tests/PHPUnit/Precondition/Service/StagerPreconditionsUnitTest.php b/tests/PHPUnit/Precondition/Service/StagerPreconditionsUnitTest.php index 018007fb0..84228ec67 100644 --- a/tests/PHPUnit/Precondition/Service/StagerPreconditionsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/StagerPreconditionsUnitTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsReadyInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\StagerPreconditions; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use Prophecy\Prophecy\ObjectProphecy; @@ -48,11 +49,14 @@ protected function createSut(): StagerPreconditions public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsReady - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('The preconditions for staging Composer commands are fulfilled.'); @@ -60,16 +64,19 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableMessage($message, $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions)); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class); } } diff --git a/tests/PHPUnit/Precondition/Service/StagingDirDoesNotExistUnitTest.php b/tests/PHPUnit/Precondition/Service/StagingDirDoesNotExistUnitTest.php index 309440890..c8fc41fad 100644 --- a/tests/PHPUnit/Precondition/Service/StagingDirDoesNotExistUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/StagingDirDoesNotExistUnitTest.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirDoesNotExist; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -39,7 +40,7 @@ protected function createSut(): StagingDirDoesNotExist public function testFulfilled(): void { $this->filesystem - ->exists($this->stagingDir) + ->exists(PathHelper::stagingDirPath()) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE) ->willReturn(false); @@ -51,7 +52,7 @@ public function testUnfulfilled(): void { $message = new TestTranslatableExceptionMessage('The staging directory already exists.'); $this->filesystem - ->exists($this->stagingDir) + ->exists(PathHelper::stagingDirPath()) ->willReturn(true); $this->doTestUnfulfilled($message); diff --git a/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php b/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php index 621221ecd..02a30ff99 100644 --- a/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirExists; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -38,8 +39,10 @@ protected function createSut(): StagingDirExists public function testFulfilled(): void { + $stagingDirPath = PathHelper::stagingDirPath(); + $this->filesystem - ->exists($this->stagingDir) + ->exists($stagingDirPath) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE) ->willReturn(true); @@ -51,7 +54,7 @@ public function testUnfulfilled(): void { $message = new TestTranslatableExceptionMessage('The staging directory does not exist.'); $this->filesystem - ->exists($this->stagingDir) + ->exists(PathHelper::stagingDirPath()) ->willReturn(false); $this->doTestUnfulfilled($message); diff --git a/tests/PHPUnit/Precondition/Service/StagingDirIsReadyUnitTest.php b/tests/PHPUnit/Precondition/Service/StagingDirIsReadyUnitTest.php index a2289a186..ef65093d9 100644 --- a/tests/PHPUnit/Precondition/Service/StagingDirIsReadyUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/StagingDirIsReadyUnitTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirExistsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsWritableInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirIsReady; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use Prophecy\Prophecy\ObjectProphecy; @@ -48,11 +49,14 @@ protected function createSut(): StagingDirIsReady public function testFulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $this->stagingDirExists - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsWritable - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->doTestFulfilled('The staging directory is ready to use.'); @@ -60,16 +64,19 @@ public function testFulfilled(): void public function testUnfulfilled(): void { + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $message = 'The staging directory is not ready to use.'; $previous = self::createTestPreconditionException($message); $this->stagingDirExists - ->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableMessage($message, $sut->getStatusMessage($this->activeDir, $this->stagingDir, $this->exclusions)); - self::assertTranslatableException(function () use ($sut): void { - $sut->assertIsFulfilled($this->activeDir, $this->stagingDir, $this->exclusions); + self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); }, PreconditionException::class, $message); } } diff --git a/tests/PHPUnit/Precondition/Service/StagingDirIsWritableUnitTest.php b/tests/PHPUnit/Precondition/Service/StagingDirIsWritableUnitTest.php index ed1e760ee..71cbc1911 100644 --- a/tests/PHPUnit/Precondition/Service/StagingDirIsWritableUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/StagingDirIsWritableUnitTest.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirIsWritable; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; @@ -40,7 +41,7 @@ protected function createSut(): StagingDirIsWritable public function testFulfilled(): void { $this->filesystem - ->isWritable($this->stagingDir) + ->isWritable(PathHelper::stagingDirPath()) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE) ->willReturn(true); @@ -52,7 +53,7 @@ public function testUnfulfilled(): void { $message = new TestTranslatableExceptionMessage('The staging directory is not writable.'); $this->filesystem - ->isWritable($this->stagingDir) + ->isWritable(PathHelper::stagingDirPath()) ->willReturn(false); $this->doTestUnfulfilled($message); diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index 20a9f614c..c880cb628 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -19,7 +19,6 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Filesystem\Path as SymfonyPath; abstract class TestCase extends PHPUnitTestCase { @@ -32,8 +31,6 @@ abstract class TestCase extends PHPUnitTestCase final public const DOMAIN_EXCEPTIONS = 'exceptions'; protected PathListInterface $exclusions; - protected PathInterface $activeDir; - protected PathInterface $stagingDir; protected static function testWorkingDirPath(): PathInterface { @@ -54,7 +51,7 @@ public function container(): ContainerBuilder { $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator()); - $config = SymfonyPath::makeAbsolute('config/services.yml', PathHelper::repositoryRootAbsolute()); + $config = PathHelper::makeAbsolute('config/services.yml', PathHelper::repositoryRootAbsolute()); $loader->load($config); return $container; @@ -69,7 +66,7 @@ protected static function createTestEnvironment(?string $activeDir = null): void // Create the active directory only. The staging directory is created // when the "begin" command is exercised. $workingDirAbsolute = PathHelper::testWorkingDirAbsolute(); - $activeDirAbsolute = SymfonyPath::makeAbsolute($activeDir, $workingDirAbsolute); + $activeDirAbsolute = PathHelper::makeAbsolute($activeDir, $workingDirAbsolute); FilesystemHelper::createDirectories([$workingDirAbsolute, $activeDirAbsolute]); chdir($workingDirAbsolute); } diff --git a/tests/PHPUnit/TestUtils/FilesystemHelper.php b/tests/PHPUnit/TestUtils/FilesystemHelper.php index e99fea7fb..aa01a3266 100644 --- a/tests/PHPUnit/TestUtils/FilesystemHelper.php +++ b/tests/PHPUnit/TestUtils/FilesystemHelper.php @@ -3,7 +3,6 @@ namespace PhpTuf\ComposerStager\Tests\TestUtils; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; -use Symfony\Component\Filesystem\Path as SymfonyPath; final class FilesystemHelper { @@ -16,8 +15,8 @@ public static function createDirectories(array|string $directories, ?string $bas // If a base path is provided, use it to make all directories absolute. if (is_string($basePath)) { - assert(SymfonyPath::isAbsolute($basePath), 'base path must be absolute.'); - $directories = array_map(static fn ($dirname): string => SymfonyPath::makeAbsolute($dirname, $basePath), $directories); + assert(PathHelper::isAbsolute($basePath), 'base path must be absolute.'); + $directories = array_map(static fn ($dirname): string => PathHelper::makeAbsolute($dirname, $basePath), $directories); } (new SymfonyFilesystem())->mkdir($directories); @@ -31,6 +30,6 @@ public function delete(array $paths, ?string $basePath = null): void private static function makeAbsolute(array $paths, ?string $basePath = null): array { - return array_map(static fn ($dirname): string => SymfonyPath::makeAbsolute($dirname, $basePath), $paths); + return array_map(static fn ($dirname): string => PathHelper::makeAbsolute($dirname, $basePath), $paths); } } diff --git a/tests/PHPUnit/TestUtils/PathHelper.php b/tests/PHPUnit/TestUtils/PathHelper.php index ae2be405b..80ab727e3 100644 --- a/tests/PHPUnit/TestUtils/PathHelper.php +++ b/tests/PHPUnit/TestUtils/PathHelper.php @@ -20,12 +20,12 @@ public static function repositoryRootAbsolute(): string public static function testEnvAbsolute(): string { - return SymfonyPath::makeAbsolute(self::TEST_ENV, self::repositoryRootAbsolute()); + return self::makeAbsolute(self::TEST_ENV, self::repositoryRootAbsolute()); } public static function testWorkingDirAbsolute(): string { - return SymfonyPath::makeAbsolute(self::WORKING_DIR, self::testEnvAbsolute()); + return self::makeAbsolute(self::WORKING_DIR, self::testEnvAbsolute()); } public static function activeDirRelative(): string @@ -35,7 +35,7 @@ public static function activeDirRelative(): string public static function activeDirAbsolute(): string { - return SymfonyPath::makeAbsolute(self::activeDirRelative(), self::testWorkingDirAbsolute()); + return self::makeAbsolute(self::activeDirRelative(), self::testWorkingDirAbsolute()); } public static function activeDirPath(): PathInterface @@ -50,11 +50,30 @@ public static function stagingDirRelative(): string public static function stagingDirAbsolute(): string { - return SymfonyPath::makeAbsolute(self::stagingDirRelative(), self::testWorkingDirAbsolute()); + return self::makeAbsolute(self::stagingDirRelative(), self::testWorkingDirAbsolute()); } public static function stagingDirPath(): PathInterface { return new TestPath(self::stagingDirAbsolute()); } + + public static function canonicalize(string $path): string + { + $path = SymfonyPath::canonicalize($path); + + return (string) preg_replace('#/+#', DIRECTORY_SEPARATOR, $path); + } + + public static function isAbsolute(string $path): bool + { + return SymfonyPath::isAbsolute($path); + } + + public static function makeAbsolute(string $path, string $basePath): string + { + $absolute = SymfonyPath::makeAbsolute($path, $basePath); + + return self::canonicalize($absolute); + } } From 44bbfb3270927bd02705655df33dc94aaa13f750 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 23:11:45 -0400 Subject: [PATCH 09/75] Remove unused argument to Tests\Precondition\Service\LinkPreconditionsIsolationFunctionalTest::assertPreconditionIsIsolated(). --- .../Service/LinkPreconditionsIsolationFunctionalTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php index b57a23122..a019666e3 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php @@ -155,10 +155,9 @@ public function testNoHardLinksExistExist(): void } /** @group no_windows */ - private function assertPreconditionIsIsolated(string $sut, array $conflictingPreconditions = []): void + private function assertPreconditionIsIsolated(string $sut): void { - $excludePreconditions = array_merge($conflictingPreconditions, [$sut]); - $sut = $this->createTestPreconditionsTree($excludePreconditions); + $sut = $this->createTestPreconditionsTree([$sut]); $sut->assertIsFulfilled(self::activeDirPath(), self::stagingDirPath()); From 75ec7612379ef0985efaff43867c9387197ef996 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 23:15:34 -0400 Subject: [PATCH 10/75] Eliminate Tests\TestCase::activeDirPath() and ::stagingDirPath(). --- .../Service/FileFinderFunctionalTest.php | 5 +- .../LinkPreconditionsFunctionalTestCase.php | 2 +- ...nkPreconditionsIsolationFunctionalTest.php | 29 ++++---- .../NoAbsoluteSymlinksExistFunctionalTest.php | 68 +++++++++---------- .../NoLinksExistOnWindowsFunctionalTest.php | 3 +- ...sPointOutsideTheCodebaseFunctionalTest.php | 2 +- tests/PHPUnit/TestCase.php | 15 ---- 7 files changed, 53 insertions(+), 71 deletions(-) diff --git a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php index 898c4ebcf..300917dc1 100644 --- a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php +++ b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php @@ -44,11 +44,10 @@ private function createSut(): FileFinder */ public function testFind(array $files, ?PathListInterface $exclusions, array $expected): void { - $directory = self::activeDirPath(); - self::createFiles($directory->absolute(), $files); + self::createFiles(PathHelper::activeDirAbsolute(), $files); $sut = $this->createSut(); - $actual = $sut->find($directory, $exclusions); + $actual = $sut->find(PathHelper::activeDirPath(), $exclusions); self::assertSame($expected, $actual); } diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php index 79a7f7f76..7a3d4ad1d 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php @@ -65,7 +65,7 @@ public function testFulfilledWithNoLinks(): void { $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath()); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Passed with no links in the codebase.'); } diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php index a019666e3..6e4d42787 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php @@ -3,8 +3,6 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; @@ -13,6 +11,7 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use Throwable; /** @@ -30,9 +29,9 @@ final class LinkPreconditionsIsolationFunctionalTest extends TestCase NoSymlinksPointToADirectory::class, ]; - private static function path(string $path): PathInterface + private static function path(string $path): string { - return PathFactory::create($path, self::activeDirPath()); + return PathHelper::makeAbsolute($path, PathHelper::activeDirAbsolute()); } protected function setUp(): void @@ -87,7 +86,7 @@ public function testAllPassWithoutLinks(): void $sut = $this->createTestPreconditionsTree(); self::assertTrue( - $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath()), + $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()), 'All preconditions passed together without any links present.', ); } @@ -95,8 +94,8 @@ public function testAllPassWithoutLinks(): void /** @group no_windows */ public function testNoAbsoluteSymlinksExist(): void { - $source = self::path('source.txt')->absolute(); - $target = self::path('target.txt')->absolute(); + $source = self::path('source.txt'); + $target = self::path('target.txt'); touch($target); symlink($target, $source); @@ -106,8 +105,8 @@ public function testNoAbsoluteSymlinksExist(): void /** @group windows_only */ public function testNoLinksExistOnWindows(): void { - $source = self::path('source.txt')->absolute(); - $target = self::path('target.txt')->absolute(); + $source = self::path('source.txt'); + $target = self::path('target.txt'); touch($target); symlink($target, $source); @@ -117,14 +116,14 @@ public function testNoLinksExistOnWindows(): void $sut = $container->get(NoLinksExistOnWindows::class); self::assertTranslatableException(static function () use ($sut): void { - $sut->assertIsFulfilled(self::activeDirPath(), self::stagingDirPath()); + $sut->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); }, PreconditionException::class); } /** @group no_windows */ public function testNoSymlinksPointOutsideTheCodebase(): void { - $source = self::path('source.txt')->absolute(); + $source = self::path('source.txt'); $target = '../target.txt'; touch($target); symlink($target, $source); @@ -135,7 +134,7 @@ public function testNoSymlinksPointOutsideTheCodebase(): void /** @group no_windows */ public function testNoSymlinksPointToADirectory(): void { - $source = self::path('link')->absolute(); + $source = self::path('link'); $target = 'directory'; FilesystemHelper::createDirectories($target); symlink($target, $source); @@ -146,8 +145,8 @@ public function testNoSymlinksPointToADirectory(): void /** @group no_windows */ public function testNoHardLinksExistExist(): void { - $source = self::path('source.txt')->absolute(); - $target = self::path('target.txt')->absolute(); + $source = self::path('source.txt'); + $target = self::path('target.txt'); touch($target); link($target, $source); @@ -159,7 +158,7 @@ private function assertPreconditionIsIsolated(string $sut): void { $sut = $this->createTestPreconditionsTree([$sut]); - $sut->assertIsFulfilled(self::activeDirPath(), self::stagingDirPath()); + $sut->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); $this->expectNotToPerformAssertions(); } diff --git a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index 2f1a19428..230e165b8 100644 --- a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -3,7 +3,6 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -41,7 +40,7 @@ public function testDoesNotContainLinks(array $files): void self::createFiles(PathHelper::activeDirRelative(), $files); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath()); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Found no links.'); } @@ -75,26 +74,27 @@ public function providerDoesNotContainLinks(): array * * @dataProvider providerLinksExist */ - public function testAbsoluteLinksExist(string $dirName, PathInterface $dirPath, string $link): void + public function testAbsoluteLinksExist(string $dirName, string $basePath, string $link): void { - $link = PathFactory::create($link, $dirPath); - $target = PathFactory::create('target.txt', $dirPath); - $parentDir = dirname($link->absolute()); + $linkAbsolute = PathHelper::makeAbsolute($link, $basePath); + $targetRelative = 'target.txt'; + $targetAbsolute = PathHelper::makeAbsolute($targetRelative, $basePath); + $parentDir = dirname($linkAbsolute); @mkdir($parentDir, 0777, true); - touch($target->absolute()); - // Point at the resolved target, i.e., its absolute path. - symlink($target->absolute(), $link->absolute()); + touch($targetAbsolute); + // Point at the absolute target path. + symlink($targetAbsolute, $linkAbsolute); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath()); - $statusMessage = $sut->getStatusMessage(self::activeDirPath(), self::stagingDirPath()); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); + $statusMessage = $sut->getStatusMessage(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertFalse($isFulfilled, 'Found absolute links.'); $pattern = sprintf( 'The %s directory at %s contains absolute links, which is not supported. The first one is %s.', $dirName, - $dirPath->absolute(), - $link->absolute(), + $basePath, + $linkAbsolute, ); self::assertTranslatableMessage($pattern, $statusMessage, 'Returned correct status message.'); } @@ -106,20 +106,20 @@ public function testAbsoluteLinksExist(string $dirName, PathInterface $dirPath, * * @dataProvider providerLinksExist */ - public function testOnlyRelativeLinksExist(string $dirName, PathInterface $dirPath, string $link): void + public function testOnlyRelativeLinksExist(string $dirName, string $basePath, string $link): void { - $link = PathFactory::create($link, $dirPath); - $targetFile = 'target.txt'; - $targetPath = PathFactory::create($targetFile, $dirPath); - $parentDir = dirname($link->absolute()); - @mkdir($parentDir, 0777, true); - touch($targetPath->absolute()); - chdir($parentDir); + $linkAbsolute = PathHelper::makeAbsolute($link, $basePath); + $targetRelative = 'target.txt'; + $targetAbsolute = PathHelper::makeAbsolute($targetRelative, $basePath); + $parentDirAbsolute = dirname($linkAbsolute); + @mkdir($parentDirAbsolute, 0777, true); + touch($targetAbsolute); + chdir($parentDirAbsolute); // Point at the relative target path. - symlink($targetFile, $link->absolute()); + symlink($targetRelative, $linkAbsolute); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath()); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Ignored relative links.'); } @@ -129,32 +129,32 @@ public function providerLinksExist(): array return [ 'Active directory: root' => [ 'dirName' => 'active', - 'dirPath' => self::activeDirPath(), + 'basePath' => PathHelper::activeDirAbsolute(), 'link' => 'symlink.txt', ], 'Active directory: subdir' => [ 'dirName' => 'active', - 'dirPath' => self::activeDirPath(), + 'basePath' => PathHelper::activeDirAbsolute(), 'link' => 'one/symlink.txt', ], 'Active directory: subdir with depth' => [ 'dirName' => 'active', - 'dirPath' => self::activeDirPath(), + 'basePath' => PathHelper::activeDirAbsolute(), 'link' => 'one/two/three/four/five/symlink.txt', ], 'Staging directory: root' => [ 'dirName' => 'staging', - 'dirPath' => self::stagingDirPath(), + 'basePath' => PathHelper::stagingDirAbsolute(), 'link' => 'symlink.txt', ], 'Staging directory: subdir' => [ 'dirName' => 'staging', - 'dirPath' => self::stagingDirPath(), + 'basePath' => PathHelper::stagingDirAbsolute(), 'link' => 'one/symlink.txt', ], 'Staging directory: subdir with depth' => [ 'dirName' => 'staging', - 'dirPath' => self::stagingDirPath(), + 'basePath' => PathHelper::stagingDirAbsolute(), 'link' => 'one/two/three/four/five/symlink.txt', ], ]; @@ -177,15 +177,15 @@ public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, Pat */ public function testWithHardLink(): void { - $link = PathFactory::create('link.txt', self::activeDirPath())->absolute(); - $target = PathFactory::create('target.txt', self::activeDirPath())->absolute(); + $link = PathHelper::makeAbsolute('link.txt', PathHelper::activeDirAbsolute()); + $target = PathHelper::makeAbsolute('target.txt', PathHelper::activeDirAbsolute()); $parentDir = dirname($link); @mkdir($parentDir, 0777, true); touch($target); link($target, $link); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath()); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); self::assertTrue($isFulfilled, 'Ignored hard link link.'); } @@ -201,12 +201,12 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s $targetFile = 'target.txt'; $links = array_fill_keys($links, $targetFile); $exclusions = new PathList(...$exclusions); - $dirPath = self::activeDirPath()->absolute(); + $dirPath = PathHelper::activeDirAbsolute(); self::createFile($dirPath, $targetFile); self::createSymlinks($dirPath, $links); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled(self::activeDirPath(), self::stagingDirPath(), $exclusions); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); self::assertEquals($shouldBeFulfilled, $isFulfilled, 'Respected exclusions.'); } diff --git a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php index 5f81ce9f4..55407750a 100644 --- a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php @@ -55,8 +55,7 @@ public function testUnfulfilled(array $symlinks, array $hardLinks): void $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); - $basePath = self::activeDirPath(); - $basePathAbsolute = $basePath->absolute(); + $basePathAbsolute = PathHelper::activeDirAbsolute(); $link = PathHelper::makeAbsolute('link.txt', $basePathAbsolute); $target = PathHelper::makeAbsolute('target.txt', $basePathAbsolute); touch($target); diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index 76c2900aa..e491de74f 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -174,7 +174,7 @@ public function testWithAbsoluteLink(): void $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); - $dirPath = self::activeDirPath(); + $dirPath = PathHelper::activeDirPath(); $link = PathFactory::create('link.txt', $dirPath)->absolute(); $target = PathFactory::create('target.txt', $dirPath)->absolute(); $parentDir = dirname($link); diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index c880cb628..4c71b1870 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -32,21 +32,6 @@ abstract class TestCase extends PHPUnitTestCase protected PathListInterface $exclusions; - protected static function testWorkingDirPath(): PathInterface - { - return PathFactory::create(PathHelper::testWorkingDirAbsolute()); - } - - protected static function activeDirPath(): PathInterface - { - return PathFactory::create(PathHelper::activeDirRelative(), self::testWorkingDirPath()); - } - - protected static function stagingDirPath(): PathInterface - { - return PathFactory::create(PathHelper::stagingDirRelative(), self::testWorkingDirPath()); - } - public function container(): ContainerBuilder { $container = new ContainerBuilder(); From 78cfdb0d4da2b446af07580656ea631aa3e44634 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 10 Aug 2023 23:57:47 -0400 Subject: [PATCH 11/75] Remove unused methods on Tests\TestUtils\FilesystemHelper(). --- tests/PHPUnit/TestUtils/FilesystemHelper.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/PHPUnit/TestUtils/FilesystemHelper.php b/tests/PHPUnit/TestUtils/FilesystemHelper.php index aa01a3266..0aa5e93a6 100644 --- a/tests/PHPUnit/TestUtils/FilesystemHelper.php +++ b/tests/PHPUnit/TestUtils/FilesystemHelper.php @@ -21,15 +21,4 @@ public static function createDirectories(array|string $directories, ?string $bas (new SymfonyFilesystem())->mkdir($directories); } - - public function delete(array $paths, ?string $basePath = null): void - { - $paths = self::makeAbsolute($paths, $basePath); - (new SymfonyFilesystem())->remove($paths); - } - - private static function makeAbsolute(array $paths, ?string $basePath = null): array - { - return array_map(static fn ($dirname): string => PathHelper::makeAbsolute($dirname, $basePath), $paths); - } } From e9758774a49a4101667965a849a712c92f2db2d7 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 11 Aug 2023 00:03:18 -0400 Subject: [PATCH 12/75] Extract Tests\TestCase::DOMAIN_* to \PHPUnit\TestUtils\Domain. --- tests/PHPUnit/Core/StagerUnitTest.php | 5 +++-- tests/PHPUnit/TestCase.php | 5 ++--- tests/PHPUnit/TestUtils/Domain.php | 14 ++++++++++++++ .../Translation/Service/DomainOptionsUnitTest.php | 5 +++-- .../Translation/Service/TestDomainOptions.php | 6 +++--- .../Value/TestTranslatableExceptionMessage.php | 4 ++-- 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 tests/PHPUnit/TestUtils/Domain.php diff --git a/tests/PHPUnit/Core/StagerUnitTest.php b/tests/PHPUnit/Core/StagerUnitTest.php index 477cb27b8..a0b60ef83 100644 --- a/tests/PHPUnit/Core/StagerUnitTest.php +++ b/tests/PHPUnit/Core/StagerUnitTest.php @@ -15,6 +15,7 @@ use PhpTuf\ComposerStager\Internal\Core\Stager; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\Domain; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; @@ -135,7 +136,7 @@ public function testCommandContainsComposer(): void $expectedExceptionMessage = new TestTranslatableMessage( 'The Composer command cannot begin with "composer"--it is implied', null, - self::DOMAIN_EXCEPTIONS, + Domain::EXCEPTIONS, ); self::assertTranslatableException(static function () use ($sut): void { $sut->stage([ @@ -157,7 +158,7 @@ public function testCommandContainsWorkingDirOption(array $command): void $expectedExceptionMessage = new TestTranslatableMessage( 'Cannot stage a Composer command containing the "--working-dir" (or "-d") option', null, - self::DOMAIN_EXCEPTIONS, + Domain::EXCEPTIONS, ); self::assertTranslatableException(static function () use ($sut, $command): void { $sut->stage($command, PathHelper::activeDirPath(), PathHelper::stagingDirPath()); diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index 4c71b1870..0b478e7e9 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -9,6 +9,7 @@ use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\Precondition\Service\TestPrecondition; use PhpTuf\ComposerStager\Tests\TestUtils\AssertTrait; +use PhpTuf\ComposerStager\Tests\TestUtils\Domain; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; @@ -27,8 +28,6 @@ abstract class TestCase extends PHPUnitTestCase protected const ORIGINAL_CONTENT = ''; protected const CHANGED_CONTENT = 'changed'; - final public const DOMAIN_DEFAULT = 'messages'; - final public const DOMAIN_EXCEPTIONS = 'exceptions'; protected PathListInterface $exclusions; @@ -100,7 +99,7 @@ protected static function createFile(string $basePath, string $filename): void public static function createTestPreconditionException( string $message = '', ?TranslationParametersInterface $parameters = null, - $domain = self::DOMAIN_EXCEPTIONS, + $domain = Domain::EXCEPTIONS, ): PreconditionException { return new PreconditionException( new TestPrecondition(), diff --git a/tests/PHPUnit/TestUtils/Domain.php b/tests/PHPUnit/TestUtils/Domain.php new file mode 100644 index 000000000..aaed68954 --- /dev/null +++ b/tests/PHPUnit/TestUtils/Domain.php @@ -0,0 +1,14 @@ +default(), 'Returned correct default domain.'); - self::assertSame(self::DOMAIN_EXCEPTIONS, $sut->exceptions(), 'Returned correct typecast exceptions domain.'); + self::assertSame(Domain::DEFAULT, $sut->default(), 'Returned correct default domain.'); + self::assertSame(Domain::EXCEPTIONS, $sut->exceptions(), 'Returned correct typecast exceptions domain.'); } } diff --git a/tests/PHPUnit/Translation/Service/TestDomainOptions.php b/tests/PHPUnit/Translation/Service/TestDomainOptions.php index 8f85832c5..e449a8aaf 100644 --- a/tests/PHPUnit/Translation/Service/TestDomainOptions.php +++ b/tests/PHPUnit/Translation/Service/TestDomainOptions.php @@ -3,13 +3,13 @@ namespace PhpTuf\ComposerStager\Tests\Translation\Service; use PhpTuf\ComposerStager\API\Translation\Service\DomainOptionsInterface; -use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\Domain; final class TestDomainOptions implements DomainOptionsInterface { public function __construct( - private readonly string $default = TestCase::DOMAIN_DEFAULT, - private readonly string $exceptions = TestCase::DOMAIN_EXCEPTIONS, + private readonly string $default = Domain::DEFAULT, + private readonly string $exceptions = Domain::EXCEPTIONS, ) { } diff --git a/tests/PHPUnit/Translation/Value/TestTranslatableExceptionMessage.php b/tests/PHPUnit/Translation/Value/TestTranslatableExceptionMessage.php index f5a2d00e8..f867d8f04 100644 --- a/tests/PHPUnit/Translation/Value/TestTranslatableExceptionMessage.php +++ b/tests/PHPUnit/Translation/Value/TestTranslatableExceptionMessage.php @@ -4,7 +4,7 @@ use PhpTuf\ComposerStager\API\Translation\Service\TranslatorInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface; -use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\Domain; use PhpTuf\ComposerStager\Tests\Translation\Service\TestTranslator; final class TestTranslatableExceptionMessage extends TestTranslatableMessage @@ -13,7 +13,7 @@ final class TestTranslatableExceptionMessage extends TestTranslatableMessage public function __construct( private readonly string $message = '', private readonly ?TranslationParametersInterface $parameters = null, - private readonly ?string $domain = TestCase::DOMAIN_EXCEPTIONS, + private readonly ?string $domain = Domain::EXCEPTIONS, ) { } From 63b97b0cffcf47b45461e3db82f91cfaac0e3c93 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 11 Aug 2023 01:54:09 -0400 Subject: [PATCH 13/75] Fix some missed refactorings and a few niggles. --- ...tiveAndStagingDirsAreDifferentUnitTest.php | 6 +++-- .../FileIteratingPreconditionUnitTestCase.php | 6 ++--- ...sPointOutsideTheCodebaseFunctionalTest.php | 23 ++++++++----------- .../Service/StagingDirExistsUnitTest.php | 4 +--- tests/PHPUnit/TestUtils/FilesystemHelper.php | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php b/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php index 0a293549e..c2d2060bb 100644 --- a/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php @@ -37,11 +37,13 @@ public function testFulfilled(): void /** @covers ::assertIsFulfilled */ public function testUnfulfilled(): void { + $samePath = PathHelper::activeDirPath(); + $this->doTestUnfulfilled( new TestTranslatableExceptionMessage('The active and staging directories are the same.'), null, - PathHelper::activeDirPath(), - PathHelper::activeDirPath(), + $samePath, + $samePath, ); } } diff --git a/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php b/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php index 0f364ab3c..c0665846f 100644 --- a/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php +++ b/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php @@ -46,9 +46,6 @@ protected function setUp(): void /** @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::exitEarly */ public function testExitEarly(): void { - $activeDirPath = PathHelper::activeDirPath(); - $stagingDirPath = PathHelper::stagingDirPath(); - $this->filesystem ->exists(Argument::cetera()) ->shouldNotBeCalled(); @@ -97,6 +94,9 @@ protected function exitEarly( } }; + $activeDirPath = PathHelper::activeDirPath(); + $stagingDirPath = PathHelper::stagingDirPath(); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); self::assertTrue($isFulfilled); diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index e491de74f..dbcb0b8a0 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -4,7 +4,6 @@ use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -39,11 +38,12 @@ protected function createSut(): NoSymlinksPointOutsideTheCodebase public function testFulfilledWithValidLink(string $link, string $target): void { $activeDirPath = PathHelper::activeDirPath(); + $activeDirAbsolute = PathHelper::activeDirAbsolute(); $stagingDirPath = PathHelper::stagingDirPath(); - $link = PathFactory::create($link, $activeDirPath)->absolute(); + $link = PathHelper::makeAbsolute($link, $activeDirAbsolute); self::ensureParentDirectory($link); - $target = PathFactory::create($target, $activeDirPath)->absolute(); + $target = PathHelper::makeAbsolute($target, $activeDirAbsolute); self::ensureParentDirectory($target); touch($target); symlink($target, $link); @@ -174,13 +174,13 @@ public function testWithAbsoluteLink(): void $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); - $dirPath = PathHelper::activeDirPath(); - $link = PathFactory::create('link.txt', $dirPath)->absolute(); - $target = PathFactory::create('target.txt', $dirPath)->absolute(); - $parentDir = dirname($link); + $dirPathAbsolute = PathHelper::activeDirAbsolute(); + $linkAbsolute = PathHelper::makeAbsolute('link.txt', $dirPathAbsolute); + $targetAbsolute = PathHelper::makeAbsolute('target.txt', $dirPathAbsolute); + $parentDir = dirname($linkAbsolute); @mkdir($parentDir, 0777, true); - touch($target); - symlink($target, $link); + touch($targetAbsolute); + symlink($targetAbsolute, $linkAbsolute); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); @@ -199,9 +199,6 @@ public function testWithAbsoluteLink(): void */ public function testFulfilledExclusions(array $links, array $exclusions, bool $shouldBeFulfilled): void { - $activeDirPath = PathHelper::activeDirPath(); - $stagingDirPath = PathHelper::stagingDirPath(); - $targetFile = '../'; $links = array_fill_keys($links, $targetFile); $exclusions = new PathList(...$exclusions); @@ -209,7 +206,7 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s self::createSymlinks($dirPath, $links); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions); + $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); self::assertEquals($shouldBeFulfilled, $isFulfilled, 'Respected exclusions.'); } diff --git a/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php b/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php index 02a30ff99..792a3ef37 100644 --- a/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php +++ b/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php @@ -39,10 +39,8 @@ protected function createSut(): StagingDirExists public function testFulfilled(): void { - $stagingDirPath = PathHelper::stagingDirPath(); - $this->filesystem - ->exists($stagingDirPath) + ->exists(PathHelper::stagingDirPath()) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE) ->willReturn(true); diff --git a/tests/PHPUnit/TestUtils/FilesystemHelper.php b/tests/PHPUnit/TestUtils/FilesystemHelper.php index 0aa5e93a6..0cd6011bd 100644 --- a/tests/PHPUnit/TestUtils/FilesystemHelper.php +++ b/tests/PHPUnit/TestUtils/FilesystemHelper.php @@ -15,7 +15,7 @@ public static function createDirectories(array|string $directories, ?string $bas // If a base path is provided, use it to make all directories absolute. if (is_string($basePath)) { - assert(PathHelper::isAbsolute($basePath), 'base path must be absolute.'); + assert(PathHelper::isAbsolute($basePath), 'Base path must be absolute.'); $directories = array_map(static fn ($dirname): string => PathHelper::makeAbsolute($dirname, $basePath), $directories); } From f44a4ad5ad89d88db97ee317b8bf783c00f223d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:15:19 +0000 Subject: [PATCH 14/75] Bump rector/rector from 0.17.10 to 0.17.12 Bumps [rector/rector](https://github.com/rectorphp/rector) from 0.17.10 to 0.17.12. - [Release notes](https://github.com/rectorphp/rector/releases) - [Commits](https://github.com/rectorphp/rector/compare/0.17.10...0.17.12) --- updated-dependencies: - dependency-name: rector/rector dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 5583ac975..ad945bbf0 100644 --- a/composer.lock +++ b/composer.lock @@ -3277,16 +3277,16 @@ }, { "name": "rector/rector", - "version": "0.17.10", + "version": "0.17.12", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "f4c0627d5e157272cf4783099730ef7241fddb14" + "reference": "af3a14a8a9fffa3100b730571c356f6c658d5e09" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/f4c0627d5e157272cf4783099730ef7241fddb14", - "reference": "f4c0627d5e157272cf4783099730ef7241fddb14", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/af3a14a8a9fffa3100b730571c356f6c658d5e09", + "reference": "af3a14a8a9fffa3100b730571c356f6c658d5e09", "shasum": "" }, "require": { @@ -3303,11 +3303,6 @@ "bin/rector" ], "type": "library", - "extra": { - "branch-alias": { - "dev-main": "0.15-dev" - } - }, "autoload": { "files": [ "bootstrap.php" @@ -3326,7 +3321,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.17.10" + "source": "https://github.com/rectorphp/rector/tree/0.17.12" }, "funding": [ { @@ -3334,7 +3329,7 @@ "type": "github" } ], - "time": "2023-08-03T14:19:51+00:00" + "time": "2023-08-10T15:22:02+00:00" }, { "name": "sebastian/cli-parser", From b0811d012abc5ad34cb85914c2c2be1d11c69c8d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:15:26 +0000 Subject: [PATCH 15/75] Bump ergebnis/composer-normalize from 2.34.0 to 2.35.0 Bumps [ergebnis/composer-normalize](https://github.com/ergebnis/composer-normalize) from 2.34.0 to 2.35.0. - [Release notes](https://github.com/ergebnis/composer-normalize/releases) - [Changelog](https://github.com/ergebnis/composer-normalize/blob/main/CHANGELOG.md) - [Commits](https://github.com/ergebnis/composer-normalize/compare/2.34.0...2.35.0) --- updated-dependencies: - dependency-name: ergebnis/composer-normalize dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 5583ac975..5c0dfdc97 100644 --- a/composer.lock +++ b/composer.lock @@ -862,16 +862,16 @@ }, { "name": "ergebnis/composer-normalize", - "version": "2.34.0", + "version": "2.35.0", "source": { "type": "git", "url": "https://github.com/ergebnis/composer-normalize.git", - "reference": "39beb6b5f1e2d923c27fe30c48c3b88582081228" + "reference": "fe5fab007825cdb2640e27726c17dbcf513af0d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ergebnis/composer-normalize/zipball/39beb6b5f1e2d923c27fe30c48c3b88582081228", - "reference": "39beb6b5f1e2d923c27fe30c48c3b88582081228", + "url": "https://api.github.com/repos/ergebnis/composer-normalize/zipball/fe5fab007825cdb2640e27726c17dbcf513af0d6", + "reference": "fe5fab007825cdb2640e27726c17dbcf513af0d6", "shasum": "" }, "require": { @@ -891,11 +891,11 @@ "ergebnis/phpunit-slow-test-detector": "^2.3.0", "fakerphp/faker": "^1.23.0", "infection/infection": "~0.27.0", - "phpunit/phpunit": "^10.2.6", + "phpunit/phpunit": "^10.3.1", "psalm/plugin-phpunit": "~0.18.4", - "rector/rector": "~0.17.7", + "rector/rector": "~0.17.12", "symfony/filesystem": "^6.0.13", - "vimeo/psalm": "^5.13.1" + "vimeo/psalm": "^5.14.1" }, "type": "composer-plugin", "extra": { @@ -934,7 +934,7 @@ "security": "https://github.com/ergebnis/composer-normalize/blob/main/.github/SECURITY.md", "source": "https://github.com/ergebnis/composer-normalize" }, - "time": "2023-07-28T06:34:54+00:00" + "time": "2023-08-11T09:11:22+00:00" }, { "name": "ergebnis/json", From baadf33fd3d79df5bbc7e240a955ab3d0b8f4408 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 9 Aug 2023 12:44:47 -0400 Subject: [PATCH 16/75] Introduce Internal\Helper\PathHelper. --- phpstan.neon.dist | 15 ++- src/Internal/Helper/PathHelper.php | 34 ++++++ src/Internal/Path/Value/Path.php | 16 +-- tests/PHPUnit/Helper/PathHelperUnitTest.php | 109 ++++++++++++++++++ tests/PHPUnit/Path/Value/PathUnitTestCase.php | 1 - .../Path/Value/UnixLikePathUnitTest.php | 1 - .../Path/Value/WindowsPathUnitTest.php | 1 - 7 files changed, 158 insertions(+), 19 deletions(-) create mode 100644 src/Internal/Helper/PathHelper.php create mode 100644 tests/PHPUnit/Helper/PathHelperUnitTest.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e75866093..53cfc7b01 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -41,6 +41,9 @@ parameters: - message: '#Cannot access offset .(application|name). on mixed.#' path: src/Internal/Precondition/Service/ComposerIsAvailable.php + - + message: '#Concrete class must implement an interface#' + path: src/Internal/Helper/PathHelper.php - message: '#In method ".*", caught "Throwable" must be rethrown.*#' paths: @@ -53,10 +56,14 @@ parameters: message: '#.*PreconditionException::__construct\(\) does not call parent constructor from Exception.#' path: src/API/Exception/PreconditionException.php - - message: '#Method (run|create)\(\) should not be public because it doesn''t implement a method on an interface.#' - paths: - - src/Internal/Process/Service/AbstractProcessRunner.php - - src/Internal/Translation/Service/Translator.php + message: '#Method .*\(\) should not be public because it doesn''t implement a method on an interface.#' + path: src/Internal/Helper/PathHelper.php + - + message: '#Method run\(\) should not be public because it doesn''t implement a method on an interface.#' + path: src/Internal/Process/Service/AbstractProcessRunner.php + - + message: '#Method create\(\) should not be public because it doesn''t implement a method on an interface.#' + path: src/Internal/Translation/Service/Translator.php # Test code. - diff --git a/src/Internal/Helper/PathHelper.php b/src/Internal/Helper/PathHelper.php new file mode 100644 index 000000000..f5453ffec --- /dev/null +++ b/src/Internal/Helper/PathHelper.php @@ -0,0 +1,34 @@ +path); + return PathHelper::isAbsolute($this->path); } public function relative(PathInterface $basePath): string @@ -86,18 +87,9 @@ private function doAbsolute(string $basePath): string assert(false, sprintf('Base paths must be absolute. Got %s.', $basePath)); /** @noinspection PhpUnreachableStatementInspection */ - return $this->normalize($this->path); + return PathHelper::canonicalize($this->path); } - return $this->normalize($absolute); - } - - private function normalize(string $absolutePath): string - { - return str_replace( - ['//', '/'], // Some Windows paths end up with double slashes after the drive name. - ['/', DIRECTORY_SEPARATOR], // SymfonyPath always uses forward slashes. Use the OS-specific separator. - SymfonyPath::canonicalize($absolutePath), - ); + return PathHelper::canonicalize($absolute); } } diff --git a/tests/PHPUnit/Helper/PathHelperUnitTest.php b/tests/PHPUnit/Helper/PathHelperUnitTest.php new file mode 100644 index 000000000..7f8f428f4 --- /dev/null +++ b/tests/PHPUnit/Helper/PathHelperUnitTest.php @@ -0,0 +1,109 @@ + [ + 'unixLike' => '', + 'windows' => '', + 'expected' => '', + ], + 'Single dot' => [ + 'unixLike' => '.', + 'windows' => '.', + 'expected' => '', + ], + 'Dot slash' => [ + 'unixLike' => './', + 'windows' => '.\\', + 'expected' => '', + ], + 'Simple path' => [ + 'unixLike' => 'one', + 'windows' => 'one', + 'expected' => 'one', + ], + 'Simple path with depth' => [ + 'unixLike' => 'one/two/three/four/five', + 'windows' => 'one\\two\\three\\four\\five', + 'expected' => implode(DIRECTORY_SEPARATOR, ['one', 'two', 'three', 'four', 'five']), + ], + 'Crazy relative path' => [ + 'unixLike' => 'one/.////./two/three/four/five/./././..//.//../////../././.././six/////', + 'windows' => 'one\\.\\\\\\\\.\\two\\three\\four\\five\\.\\.\\.\\..\\\\.\\\\..\\\\\\\\\\..\\.\\.\\..\\.\\six\\\\\\\\\\', + 'expected' => 'one' . DIRECTORY_SEPARATOR . 'six', + ], + 'Unix-like absolute path' => [ + 'unixLike' => '/', + 'windows' => '\\', // This is actually a legitimate UNC path on Windows: @see https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#unc-paths + 'expected' => DIRECTORY_SEPARATOR, + ], + 'Windows drive name' => [ + 'unixLike' => 'C:/', // This would be an absurd Unix-like path, of course, but it's still testable. Same below. + 'windows' => 'C:\\', + 'expected' => 'C:' . DIRECTORY_SEPARATOR, + ], + 'Windows drive name no slash' => [ + 'unixLike' => 'C:', + 'windows' => 'C:', + 'expected' => 'C:' . DIRECTORY_SEPARATOR, + ], + 'Windows drive name with extra slashes' => [ + 'unixLike' => 'C:///', + 'windows' => 'C:\\\\\\', + 'expected' => 'C:' . DIRECTORY_SEPARATOR, + ], + 'Absolute Windows path with extra slashes' => [ + 'unixLike' => 'C:////one', + 'windows' => 'C:\\\\\\\\one', + 'expected' => 'C:' . DIRECTORY_SEPARATOR . 'one', + ], + ]; + } + + /** + * @covers ::isAbsolute + * + * @dataProvider providerIsAbsolute + */ + public function testIsAbsolute(bool $expected, string $path): void + { + self::assertSame($expected, PathHelper::isAbsolute($path)); + } + + public function providerIsAbsolute(): array + { + return [ + // Yes. + [true, '/one/two'], + [true, 'C:\\One\\Two'], + [true, '\\One\\Two'], + // No. + [false, 'one/two'], + [false, '../one/two'], + [false, '..\\One\\Two'], + ]; + } +} diff --git a/tests/PHPUnit/Path/Value/PathUnitTestCase.php b/tests/PHPUnit/Path/Value/PathUnitTestCase.php index bd34a8dee..6b1e98e56 100644 --- a/tests/PHPUnit/Path/Value/PathUnitTestCase.php +++ b/tests/PHPUnit/Path/Value/PathUnitTestCase.php @@ -15,7 +15,6 @@ * @covers ::absolute * @covers ::doAbsolute * @covers ::isAbsolute - * @covers ::normalize * @covers ::relative * @covers \PhpTuf\ComposerStager\Internal\Path\Value\Path::getcwd */ diff --git a/tests/PHPUnit/Path/Value/UnixLikePathUnitTest.php b/tests/PHPUnit/Path/Value/UnixLikePathUnitTest.php index 36759ab70..3965fabaf 100644 --- a/tests/PHPUnit/Path/Value/UnixLikePathUnitTest.php +++ b/tests/PHPUnit/Path/Value/UnixLikePathUnitTest.php @@ -9,7 +9,6 @@ * @covers ::absolute * @covers ::doAbsolute * @covers ::isAbsolute - * @covers ::normalize * @covers ::relative * @covers \PhpTuf\ComposerStager\Internal\Path\Value\Path::getcwd * diff --git a/tests/PHPUnit/Path/Value/WindowsPathUnitTest.php b/tests/PHPUnit/Path/Value/WindowsPathUnitTest.php index 1170234ba..e580913a7 100644 --- a/tests/PHPUnit/Path/Value/WindowsPathUnitTest.php +++ b/tests/PHPUnit/Path/Value/WindowsPathUnitTest.php @@ -12,7 +12,6 @@ * @covers ::absolute * @covers ::doAbsolute * @covers ::isAbsolute - * @covers ::normalize * @covers ::relative * @covers \PhpTuf\ComposerStager\Internal\Path\Value\Path::getcwd */ From bf684354ca1ea7a20003c341256c91f2dfcb2a31 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 11 Aug 2023 13:55:32 -0400 Subject: [PATCH 17/75] Make API\Path\Factory\PathFactoryInterface::create() non-static. --- .idea/runConfigurations/End_to_End_Test.xml | 4 +- docs/README.md | 4 +- phpstan.neon.dist | 2 +- src/API/Path/Factory/PathFactoryInterface.php | 2 +- .../FileSyncer/Service/PhpFileSyncer.php | 8 +- .../Filesystem/Service/Filesystem.php | 4 +- src/Internal/Finder/Service/FileFinder.php | 2 +- src/Internal/Path/Factory/PathFactory.php | 2 +- .../AbstractFileIteratingPrecondition.php | 2 +- tests/PHPBench/Benchmark/BenchCase.php | 4 + tests/PHPBench/Benchmark/FileSyncerBench.php | 3 +- tests/PHPBench/TestUtils/FixtureHelper.php | 10 +- .../EndToEnd/EndToEndFunctionalTestCase.php | 47 +++++---- .../Service/FileSyncerFunctionalTestCase.php | 38 ++----- .../Service/FilesystemFunctionalTest.php | 98 ++++++++----------- .../Service/FileFinderFunctionalTest.php | 3 +- .../Path/Factory/PathFactoryUnitTest.php | 8 +- .../LinkPreconditionsFunctionalTestCase.php | 3 +- .../NoAbsoluteSymlinksExistFunctionalTest.php | 2 +- .../NoHardLinksExistFunctionalTest.php | 11 +-- ...ymlinksPointToADirectoryFunctionalTest.php | 11 +-- tests/PHPUnit/TestCase.php | 11 +-- tests/PHPUnit/TestUtils/PathHelper.php | 46 ++++++++- 23 files changed, 167 insertions(+), 158 deletions(-) diff --git a/.idea/runConfigurations/End_to_End_Test.xml b/.idea/runConfigurations/End_to_End_Test.xml index 2054196df..c8bc0dcac 100644 --- a/.idea/runConfigurations/End_to_End_Test.xml +++ b/.idea/runConfigurations/End_to_End_Test.xml @@ -1,8 +1,8 @@ - + - + diff --git a/docs/README.md b/docs/README.md index 01d5872a8..affb12638 100644 --- a/docs/README.md +++ b/docs/README.md @@ -43,8 +43,8 @@ class Updater public function update(): void { - $activeDir = $this->pathFactory::create('/var/www/public'); - $stagingDir = $this->pathFactory::create('/var/www/staging'); + $activeDir = $this->pathFactory->create('/var/www/public'); + $stagingDir = $this->pathFactory->create('/var/www/staging'); $exclusions = $this->pathListFactory->create( 'cache', 'uploads', diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 53cfc7b01..1ccef4a87 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,7 +17,7 @@ parameters: - tests/PHPUnit treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false - preconditionSystemHash: 28b3482e0ec91cbdd68d150e5c486918 + preconditionSystemHash: edc0e29f2fd55b848b7a587e7a16e557 translationSystemHash: ef73496b0fe8d024eba0831e405db0af gitattributesExportInclude: - composer.json diff --git a/src/API/Path/Factory/PathFactoryInterface.php b/src/API/Path/Factory/PathFactoryInterface.php index 9e3e90562..d8c3b3671 100644 --- a/src/API/Path/Factory/PathFactoryInterface.php +++ b/src/API/Path/Factory/PathFactoryInterface.php @@ -26,5 +26,5 @@ interface PathFactoryInterface * assumed to represent a directory, as opposed to a file--even if * it has an extension, which is no guarantee of type. */ - public static function create(string $path, ?PathInterface $basePath = null): PathInterface; + public function create(string $path, ?PathInterface $basePath = null): PathInterface; } diff --git a/src/Internal/FileSyncer/Service/PhpFileSyncer.php b/src/Internal/FileSyncer/Service/PhpFileSyncer.php index c51856534..914f714a1 100644 --- a/src/Internal/FileSyncer/Service/PhpFileSyncer.php +++ b/src/Internal/FileSyncer/Service/PhpFileSyncer.php @@ -104,13 +104,13 @@ private function deleteExtraneousFilesFromDestination( $relativePathname = self::getRelativePath($destinationAbsolute, $destinationFilePathname); $sourceFilePathname = $sourceAbsolute . DIRECTORY_SEPARATOR . $relativePathname; - $sourceFilePath = $this->pathFactory::create($sourceFilePathname); + $sourceFilePath = $this->pathFactory->create($sourceFilePathname); if ($this->filesystem->exists($sourceFilePath)) { continue; } - $destinationFilePath = $this->pathFactory::create($destinationFilePathname); + $destinationFilePath = $this->pathFactory->create($destinationFilePathname); // If it doesn't exist in the source, delete it from the destination. $this->filesystem->remove($destinationFilePath); @@ -138,8 +138,8 @@ private function copySourceFilesToDestination( $relativePathname = self::getRelativePath($sourceAbsolute, $sourceFilePathname); $destinationFilePathname = $destinationAbsolute . DIRECTORY_SEPARATOR . $relativePathname; - $sourceFilePathname = $this->pathFactory::create($sourceFilePathname); - $destinationFilePathname = $this->pathFactory::create($destinationFilePathname); + $sourceFilePathname = $this->pathFactory->create($sourceFilePathname); + $destinationFilePathname = $this->pathFactory->create($destinationFilePathname); // Copy the file--even if it already exists and is identical in the // destination. Obviously, this has performance implications, but diff --git a/src/Internal/Filesystem/Service/Filesystem.php b/src/Internal/Filesystem/Service/Filesystem.php index 9f7efbb3c..8713b772c 100644 --- a/src/Internal/Filesystem/Service/Filesystem.php +++ b/src/Internal/Filesystem/Service/Filesystem.php @@ -166,9 +166,9 @@ public function readLink(PathInterface $path): PathInterface assert(is_string($target)); // Resolve the target relative to the link's parent directory, not the CWD of the PHP process at runtime. - $basePath = $this->pathFactory::create('..', $path); + $basePath = $this->pathFactory->create('..', $path); - return $this->pathFactory::create($target, $basePath); + return $this->pathFactory->create($target, $basePath); } public function remove( diff --git a/src/Internal/Finder/Service/FileFinder.php b/src/Internal/Finder/Service/FileFinder.php index fc40ed220..260a45b01 100644 --- a/src/Internal/Finder/Service/FileFinder.php +++ b/src/Internal/Finder/Service/FileFinder.php @@ -39,7 +39,7 @@ public function find(PathInterface $directory, ?PathListInterface $exclusions = $directoryIterator = $this->getRecursiveDirectoryIterator($directory->absolute()); // Resolve the exclusions relative to the search directory. - $exclusions = array_map(fn ($path): string => $this->pathFactory::create($path) + $exclusions = array_map(fn ($path): string => $this->pathFactory->create($path) ->relative($directory), $exclusions->getAll()); // Apply exclusions. On the surface, it may look like individual descendants diff --git a/src/Internal/Path/Factory/PathFactory.php b/src/Internal/Path/Factory/PathFactory.php index b9113d1bb..bef8c1e8c 100644 --- a/src/Internal/Path/Factory/PathFactory.php +++ b/src/Internal/Path/Factory/PathFactory.php @@ -15,7 +15,7 @@ */ final class PathFactory implements PathFactoryInterface { - public static function create(string $path, ?PathInterface $basePath = null): PathInterface + public function create(string $path, ?PathInterface $basePath = null): PathInterface { return new Path($path, $basePath); } diff --git a/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php b/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php index e95ee04cb..76fd141f3 100644 --- a/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php +++ b/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php @@ -67,7 +67,7 @@ public function assertIsFulfilled( $files = $this->findFiles($directoryRootDir, $exclusions); foreach ($files as $file) { - $file = $this->pathFactory::create($file); + $file = $this->pathFactory->create($file); $this->assertIsSupportedFile($directoryName, $directoryRootDir, $file); } } diff --git a/tests/PHPBench/Benchmark/BenchCase.php b/tests/PHPBench/Benchmark/BenchCase.php index de808a3d0..cf898b90c 100644 --- a/tests/PHPBench/Benchmark/BenchCase.php +++ b/tests/PHPBench/Benchmark/BenchCase.php @@ -2,6 +2,8 @@ namespace PhpTuf\ComposerStager\PHPBench\Benchmark; +use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; +use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\PHPBench\TestUtils\FixtureHelper; use Symfony\Component\Config\FileLocator as SymfonyFileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder; @@ -11,10 +13,12 @@ abstract class BenchCase { protected SymfonyContainerBuilder $container; + protected PathFactoryInterface $pathFactory; public function __construct() { $this->container = $this->getContainer(); + $this->pathFactory = $this->container->get(PathFactory::class); } public static function setUpBeforeClass(): void diff --git a/tests/PHPBench/Benchmark/FileSyncerBench.php b/tests/PHPBench/Benchmark/FileSyncerBench.php index 1ffe7ae51..a3f1cdcc6 100644 --- a/tests/PHPBench/Benchmark/FileSyncerBench.php +++ b/tests/PHPBench/Benchmark/FileSyncerBench.php @@ -10,7 +10,6 @@ use PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface; use PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer; use PhpTuf\ComposerStager\Internal\FileSyncer\Service\RsyncFileSyncer; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\PHPBench\TestUtils\FixtureHelper; use PhpTuf\ComposerStager\PHPBench\TestUtils\ProcessHelper; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; @@ -40,7 +39,7 @@ public function benchSync(array $params): void assert($sut instanceof FileSyncerInterface); $destinationAbsolute = self::getDestinationAbsolute($syncerClassName); - $destinationPath = PathFactory::create($destinationAbsolute); + $destinationPath = $this->pathFactory->create($destinationAbsolute); $sut->sync($sourcePath, $destinationPath, null, null, ProcessHelper::PROCESS_TIMEOUT); } diff --git a/tests/PHPBench/TestUtils/FixtureHelper.php b/tests/PHPBench/TestUtils/FixtureHelper.php index 262cb87cf..970ea30a0 100644 --- a/tests/PHPBench/TestUtils/FixtureHelper.php +++ b/tests/PHPBench/TestUtils/FixtureHelper.php @@ -3,7 +3,7 @@ namespace PhpTuf\ComposerStager\PHPBench\TestUtils; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; use Symfony\Component\Filesystem\Path as SymfonyPath; use Symfony\Component\Process\Process as SymfonyProcess; @@ -39,22 +39,22 @@ public static function workingDirAbsolute(): string public static function drupalOriginalCodebasePath(): PathInterface { - return PathFactory::create(self::drupalOriginalCodebaseAbsolute()); + return PathHelper::createPath(self::drupalOriginalCodebaseAbsolute()); } public static function drupalMajorUpdateCodebasePath(): PathInterface { - return PathFactory::create(self::drupalMajorUpdateCodebaseAbsolute()); + return PathHelper::createPath(self::drupalMajorUpdateCodebaseAbsolute()); } public static function drupalMinorUpdateCodebasePath(): PathInterface { - return PathFactory::create(self::drupalMinorUpdateCodebaseAbsolute()); + return PathHelper::createPath(self::drupalMinorUpdateCodebaseAbsolute()); } public static function drupalPointUpdateCodebasePath(): PathInterface { - return PathFactory::create(self::drupalPointUpdateCodebaseAbsolute()); + return PathHelper::createPath(self::drupalPointUpdateCodebaseAbsolute()); } public static function removeWorkingDir(): void diff --git a/tests/PHPUnit/EndToEnd/EndToEndFunctionalTestCase.php b/tests/PHPUnit/EndToEnd/EndToEndFunctionalTestCase.php index b4553a4eb..3b7e0e92e 100644 --- a/tests/PHPUnit/EndToEnd/EndToEndFunctionalTestCase.php +++ b/tests/PHPUnit/EndToEnd/EndToEndFunctionalTestCase.php @@ -12,10 +12,10 @@ use PhpTuf\ComposerStager\Internal\Core\Cleaner; use PhpTuf\ComposerStager\Internal\Core\Committer; use PhpTuf\ComposerStager\Internal\Core\Stager; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** * Provides a base for end-to-end functional tests, including the API and @@ -72,11 +72,13 @@ abstract protected function fileSyncerClass(): string; */ public function testSync(string $activeDir, string $stagingDir): void { - $activeDirPath = PathFactory::create($activeDir); - $stagingDirPath = PathFactory::create($stagingDir); + $activeDirPath = PathHelper::createPath($activeDir, PathHelper::testWorkingDirAbsolute()); + $activeDirAbsolute = $activeDirPath->absolute(); + $stagingDirPath = PathHelper::createPath($stagingDir, PathHelper::testWorkingDirAbsolute()); + $stagingDirAbsolute = $stagingDirPath->absolute(); // Create fixture (active directory). - self::createFiles($activeDir, [ + self::createFiles(PathHelper::makeAbsolute($activeDir, PathHelper::testWorkingDirAbsolute()), [ // Unchanging files. 'file_in_active_dir_root_NEVER_CHANGED_anywhere.txt', 'arbitrary_subdir/file_NEVER_CHANGED_anywhere.txt', @@ -108,7 +110,7 @@ public function testSync(string $activeDir, string $stagingDir): void ]); $arbitrarySymlinkTarget = 'file_in_active_dir_root_NEVER_CHANGED_anywhere.txt'; - self::createSymlinks($activeDirPath->absolute(), [ + self::createSymlinks($activeDirAbsolute, [ 'EXCLUDED_symlink_in_active_dir_root.txt' => $arbitrarySymlinkTarget, 'EXCLUDED_dir/symlink_NEVER_CHANGED_anywhere.txt' => $arbitrarySymlinkTarget, ]); @@ -139,7 +141,7 @@ public function testSync(string $activeDir, string $stagingDir): void // Non-existent (ignore). 'file_that_NEVER_EXISTS_anywhere.txt', // Absolute path (ignore). - PathFactory::create('absolute/path')->absolute(), + PathHelper::makeAbsolute('absolute/path', PathHelper::testWorkingDirAbsolute()), ]; $exclusions = new PathList(...$exclusions); @@ -154,7 +156,8 @@ public function testSync(string $activeDir, string $stagingDir): void $preconditionMet = false; self::assertEquals(NoAbsoluteSymlinksExist::class, $failedPrecondition::class, 'Correct "codebase contains symlinks" unmet.'); } finally { - assert(filetype($activeDirPath->absolute() . '/EXCLUDED_dir/symlink_NEVER_CHANGED_anywhere.txt') === 'link', 'An actual symlink is present in the codebase.'); + $file = PathHelper::makeAbsolute('EXCLUDED_dir/symlink_NEVER_CHANGED_anywhere.txt', $activeDirAbsolute); + assert(filetype($file) === 'link', 'An actual symlink is present in the codebase.'); self::assertFalse($preconditionMet, 'Beginner fails with symlinks present in the codebase.'); } @@ -184,29 +187,29 @@ public function testSync(string $activeDir, string $stagingDir): void $newComposerName, ], $activeDirPath, $stagingDirPath); - self::assertComposerJsonName($stagingDir, $newComposerName, 'Correctly executed Composer command.'); + self::assertComposerJsonName($stagingDirAbsolute, $newComposerName, 'Correctly executed Composer command.'); // Change files. - self::changeFile($activeDir, 'EXCLUDED_dir/CHANGE_file_in_active_dir_after_syncing_to_staging_dir.txt'); - self::changeFile($stagingDir, 'very/deeply/nested/file/that/is/CHANGED/in/the/staging/directory/before/syncing/back/to/the/active/directory.txt'); - self::changeFile($stagingDir, 'CHANGE_in_staging_dir_before_syncing_back_to_active_dir.txt'); + self::changeFile($activeDirAbsolute, 'EXCLUDED_dir/CHANGE_file_in_active_dir_after_syncing_to_staging_dir.txt'); + self::changeFile($stagingDirAbsolute, 'very/deeply/nested/file/that/is/CHANGED/in/the/staging/directory/before/syncing/back/to/the/active/directory.txt'); + self::changeFile($stagingDirAbsolute, 'CHANGE_in_staging_dir_before_syncing_back_to_active_dir.txt'); // Delete files. - self::deleteFile($stagingDir, 'DELETE_from_staging_dir_before_syncing_back_to_active_dir.txt'); - self::deleteFile($activeDir, 'another_EXCLUDED_dir/DELETE_file_from_active_dir_after_syncing_to_staging_dir.txt'); + self::deleteFile($stagingDirAbsolute, 'DELETE_from_staging_dir_before_syncing_back_to_active_dir.txt'); + self::deleteFile($activeDirAbsolute, 'another_EXCLUDED_dir/DELETE_file_from_active_dir_after_syncing_to_staging_dir.txt'); // Create files. - self::createFile($stagingDir, 'EXCLUDED_dir/but_create_file_in_it_in_the_staging_dir.txt'); - self::createFile($stagingDir, 'CREATE_in_staging_dir.txt'); - self::createFile($stagingDir, 'another_subdir/CREATE_in_staging_dir.txt'); + self::createFile($stagingDirAbsolute, 'EXCLUDED_dir/but_create_file_in_it_in_the_staging_dir.txt'); + self::createFile($stagingDirAbsolute, 'CREATE_in_staging_dir.txt'); + self::createFile($stagingDirAbsolute, 'another_subdir/CREATE_in_staging_dir.txt'); // Create symlink. - self::createSymlink($stagingDirPath->absolute(), 'EXCLUDED_dir/symlink_CREATED_in_staging_dir.txt', $arbitrarySymlinkTarget); + self::createSymlink($stagingDirAbsolute, 'EXCLUDED_dir/symlink_CREATED_in_staging_dir.txt', $arbitrarySymlinkTarget); // Sanity check to ensure that the expected changes were made. $deletion = array_search('DELETE_from_staging_dir_before_syncing_back_to_active_dir.txt', $expectedStagingDirListing, true); unset($expectedStagingDirListing[$deletion]); - self::assertDirectoryListing($stagingDirPath->absolute(), [ + self::assertDirectoryListing($stagingDirAbsolute, [ ...$expectedStagingDirListing, // Additions. 'CREATE_in_staging_dir.txt', @@ -298,7 +301,13 @@ public function testSync(string $activeDir, string $stagingDir): void self::assertEquals( $previousStagingDirContents, $currentStagingDirContents, - sprintf('Staging directory was not changed when syncing back to active directory:%s%s ->%s%s', PHP_EOL, $stagingDir, PHP_EOL, $activeDir), + sprintf( + 'Staging directory was not changed when syncing back to active directory:%s%s ->%s%s', + PHP_EOL, + $stagingDirAbsolute, + PHP_EOL, + $activeDirAbsolute, + ), ); // Clean: Remove the staging directory. diff --git a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php index 6dc9c531d..2850b4e94 100644 --- a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -3,39 +3,17 @@ namespace PhpTuf\ComposerStager\Tests\FileSyncer\Service; use PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; abstract class FileSyncerFunctionalTestCase extends TestCase { - private static function sourceDirAbsolute(): string - { - return PathHelper::makeAbsolute('source', PathHelper::testEnvAbsolute()); - } - - private static function sourcePath(): PathInterface - { - return PathFactory::create(self::sourceDirAbsolute()); - } - - public static function destinationDirAbsolute(): string - { - return PathHelper::makeAbsolute('destination', PathHelper::testEnvAbsolute()); - } - - private static function destinationPath(): PathInterface - { - return PathFactory::create(self::destinationDirAbsolute()); - } - protected function setUp(): void { FilesystemHelper::createDirectories([ - self::sourceDirAbsolute(), - self::destinationDirAbsolute(), + PathHelper::sourceDirAbsolute(), + PathHelper::destinationDirAbsolute(), ]); } @@ -66,7 +44,7 @@ public function testSyncTimeout(?int $givenTimeout, int $expectedTimeout): void { $sut = $this->createSut(); - $sut->sync(self::sourcePath(), self::destinationPath(), null, null, $givenTimeout); + $sut->sync(PathHelper::sourceDirPath(), PathHelper::destinationDirPath(), null, null, $givenTimeout); self::assertSame((string) $expectedTimeout, ini_get('max_execution_time'), 'Correctly set process timeout.'); } @@ -88,17 +66,17 @@ public function providerSyncTimeout(): array /** @covers ::sync */ public function testSyncWithDirectorySymlinks(): void { - $link = PathHelper::makeAbsolute('link', self::sourceDirAbsolute()); - $target = PathHelper::makeAbsolute('directory', self::sourceDirAbsolute()); + $link = PathHelper::makeAbsolute('link', PathHelper::sourceDirAbsolute()); + $target = PathHelper::makeAbsolute('directory', PathHelper::sourceDirAbsolute()); FilesystemHelper::createDirectories($target); - $file = PathHelper::makeAbsolute('directory/file.txt', self::sourceDirAbsolute()); + $file = PathHelper::makeAbsolute('directory/file.txt', PathHelper::sourceDirAbsolute()); touch($file); symlink($target, $link); $sut = $this->createSut(); - $sut->sync(self::sourcePath(), self::destinationPath()); + $sut->sync(PathHelper::sourceDirPath(), PathHelper::destinationDirPath()); - self::assertDirectoryListing(self::destinationDirAbsolute(), [ + self::assertDirectoryListing(PathHelper::destinationDirAbsolute(), [ 'link', 'directory/file.txt', ], '', 'Correctly synced files, including a symlink to a directory.'); diff --git a/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php b/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php index f34d8f398..d3424bc71 100644 --- a/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php +++ b/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php @@ -3,9 +3,7 @@ namespace PhpTuf\ComposerStager\Tests\Filesystem\Service; use PhpTuf\ComposerStager\API\Exception\IOException; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Filesystem\Service\Filesystem; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -15,21 +13,11 @@ /** @coversDefaultClass \PhpTuf\ComposerStager\Internal\Filesystem\Service\Filesystem */ final class FilesystemFunctionalTest extends TestCase { - private static function sourceDir(): PathInterface - { - return PathFactory::create(PathHelper::testEnvAbsolute() . '/source'); - } - - private static function destinationDir(): PathInterface - { - return PathFactory::create(PathHelper::testEnvAbsolute() . '/destination'); - } - protected function setUp(): void { FilesystemHelper::createDirectories([ - self::sourceDir()->absolute(), - self::destinationDir()->absolute(), + PathHelper::sourceDirAbsolute(), + PathHelper::destinationDirAbsolute(), ]); } @@ -52,59 +40,57 @@ private function createSut(): Filesystem /** @covers ::copy */ public function testCopy(): void { - $filename = 'file.txt'; - $source = PathFactory::create($filename, self::sourceDir()); - $destination = PathFactory::create($filename, self::destinationDir()); - touch($source->absolute()); - - $filesystem = $this->createSut(); + $filenameRelative = 'file.txt'; + $sourceFilePath = PathHelper::createPath($filenameRelative, PathHelper::sourceDirAbsolute()); + $destinationFilePath = PathHelper::createPath($filenameRelative, PathHelper::destinationDirAbsolute()); + touch($sourceFilePath->absolute()); // Copy an individual file. - $filesystem->copy($source, $destination); + $filesystem = $this->createSut(); + $filesystem->copy($sourceFilePath, $destinationFilePath); - self::assertDirectoryListing(self::destinationDir()->absolute(), [$filename]); + self::assertDirectoryListing(PathHelper::destinationDirAbsolute(), [$filenameRelative]); } /** @covers ::isDirEmpty */ public function testIsDirEmptyTrue(): void { - $directory = PathFactory::create(PathHelper::testEnvAbsolute() . '/empty'); - FilesystemHelper::createDirectories($directory->absolute()); + $directoryPath = PathHelper::createPath('empty', PathHelper::testEnvAbsolute()); + FilesystemHelper::createDirectories($directoryPath->absolute()); $sut = $this->createSut(); - self::assertTrue($sut->isDirEmpty($directory), 'Correctly detected empty directory.'); + self::assertTrue($sut->isDirEmpty($directoryPath), 'Correctly detected empty directory.'); } /** @covers ::isDirEmpty */ public function testIsDirEmptyFalse(): void { - $directory = PathFactory::create(__DIR__); + $directoryPath = PathHelper::createPath(__DIR__); $sut = $this->createSut(); - self::assertFalse($sut->isDirEmpty($directory), 'Correctly detected non-empty directory.'); + self::assertFalse($sut->isDirEmpty($directoryPath), 'Correctly detected non-empty directory.'); } /** @covers ::isDirEmpty */ public function testIsDirEmptyErrorIsNotADirectory(): void { - $path = PathFactory::create(PathHelper::testEnvAbsolute()); - $file = PathFactory::create('file.txt', $path); - touch($file->absolute()); + $filePath = PathHelper::createPath('file.txt', PathHelper::testEnvAbsolute()); + touch($filePath->absolute()); $message = sprintf( 'The path does not exist or is not a directory at %s', - $file->absolute(), + $filePath->absolute(), ); $sut = $this->createSut(); - self::assertTranslatableException(static function () use ($sut, $file): void { - $sut->isDirEmpty($file); + self::assertTranslatableException(static function () use ($sut, $filePath): void { + $sut->isDirEmpty($filePath); }, IOException::class, $message); } /** @covers ::isDirEmpty */ public function testIsDirEmptyError(): void { - $path = PathFactory::create('non-existent'); + $path = PathHelper::createPath('non-existent'); $message = sprintf( 'The path does not exist or is not a directory at %s', $path->absolute(), @@ -140,11 +126,11 @@ public function testTypeCheckMethods( bool $isHardLink, bool $isSymlink, ): void { - self::createFiles(self::sourceDir()->absolute(), $files); - FilesystemHelper::createDirectories($directories, self::sourceDir()->absolute()); - self::createSymlinks(self::sourceDir()->absolute(), $symlinks); - self::createHardlinks(self::sourceDir()->absolute(), $hardLinks); - $subject = PathFactory::create($subject, self::sourceDir()); + self::createFiles(PathHelper::sourceDirAbsolute(), $files); + FilesystemHelper::createDirectories($directories, PathHelper::sourceDirAbsolute()); + self::createSymlinks(PathHelper::sourceDirAbsolute(), $symlinks); + self::createHardlinks(PathHelper::sourceDirAbsolute(), $hardLinks); + $subject = PathHelper::createPath($subject, PathHelper::sourceDirAbsolute()); $sut = $this->createSut(); $actualExists = $sut->exists($subject); @@ -255,11 +241,11 @@ public function providerTypeCheckMethods(): array */ public function testReadlink(string $given, string $expectedAbsolute): void { - $basePath = self::sourceDir(); - $symlinkPath = PathFactory::create('symlink.txt', $basePath); - $hardLinkPath = PathFactory::create('hard_link.txt', $basePath); - $targetPath = PathFactory::create($given, $basePath); - chdir($basePath->absolute()); + $basePath = PathHelper::sourceDirAbsolute(); + $symlinkPath = PathHelper::createPath('symlink.txt', $basePath); + $hardLinkPath = PathHelper::createPath('hard_link.txt', $basePath); + $targetPath = PathHelper::createPath($given, $basePath); + chdir($basePath); touch($targetPath->absolute()); symlink($given, $symlinkPath->absolute()); link($given, $hardLinkPath->absolute()); @@ -280,15 +266,9 @@ public function testReadlink(string $given, string $expectedAbsolute): void public function providerReadlink(): array { - $absolute = static function ($path): string { - $basePath = self::sourceDir(); - - return PathFactory::create($path, $basePath)->absolute(); - }; + $basePath = PathHelper::sourceDirAbsolute(); + $absolute = static fn ($path): string => PathHelper::makeAbsolute($path, $basePath); - // Note: relative links cannot be distinguished from absolute links on Windows, - // where readlink() canonicalizes the target path, making them appear identical. - // Hence the below expected values conditioned on host. return [ 'Absolute link' => [ 'given' => $absolute('target.txt'), @@ -304,7 +284,7 @@ public function providerReadlink(): array /** @covers ::readLink */ public function testReadlinkOnNonLink(): void { - $file = PathFactory::create('file.txt', self::sourceDir()); + $file = PathHelper::createPath('file.txt', PathHelper::sourceDirAbsolute()); touch($file->absolute()); assert(file_exists($file->absolute())); $sut = $this->createSut(); @@ -318,7 +298,7 @@ public function testReadlinkOnNonLink(): void /** @covers ::readLink */ public function testReadlinkOnNonExistentFile(): void { - $path = PathFactory::create('non-existent_file.txt', self::sourceDir()); + $path = PathHelper::createPath('non-existent_file.txt', PathHelper::sourceDirAbsolute()); $sut = $this->createSut(); $message = sprintf('The path does not exist or is not a symlink at %s', $path->absolute()); @@ -341,12 +321,12 @@ public function testSymfonyCopyDirectory(): void $this->expectException(SymfonyIOException::class); $this->expectExceptionMessageMatches(sprintf( '#"%s"#', - preg_quote(self::sourceDir()->absolute(), '/'), + preg_quote(PathHelper::sourceDirAbsolute(), '/'), )); $filename = 'arbitrary_file.txt'; - $sourceFile = PathFactory::create($filename, self::sourceDir()); - $destinationFile = PathFactory::create($filename, self::destinationDir()); + $sourceFile = PathHelper::createPath($filename, PathHelper::sourceDirAbsolute()); + $destinationFile = PathHelper::createPath($filename, PathHelper::destinationDirAbsolute()); touch($sourceFile->absolute()); assert(file_exists($sourceFile->absolute())); @@ -360,8 +340,8 @@ public function testSymfonyCopyDirectory(): void // Directory copy: this should fail. $sut->copy( - self::sourceDir()->absolute(), - self::destinationDir()->absolute(), + PathHelper::sourceDirAbsolute(), + PathHelper::destinationDirPath()->absolute(), ); } } diff --git a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php index 300917dc1..7eb120873 100644 --- a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php +++ b/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php @@ -4,7 +4,6 @@ use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\Internal\Finder\Service\FileFinder; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -163,7 +162,7 @@ private function normalizePaths(array $paths): array ], ); - return PathFactory::create($path)->absolute(); + return PathHelper::makeAbsolute($path, getcwd()); }, $paths); sort($paths); diff --git a/tests/PHPUnit/Path/Factory/PathFactoryUnitTest.php b/tests/PHPUnit/Path/Factory/PathFactoryUnitTest.php index e6eedac26..41658e441 100644 --- a/tests/PHPUnit/Path/Factory/PathFactoryUnitTest.php +++ b/tests/PHPUnit/Path/Factory/PathFactoryUnitTest.php @@ -22,8 +22,10 @@ public function testBasicFunctionality( PathInterface $expected, PathInterface $expectedWithBaseDir, ): void { - $actual = PathFactory::create($string); - $actualWithBaseDir = PathFactory::create($string, $basePath); + $sut = new PathFactory(); + + $actual = $sut->create($string); + $actualWithBaseDir = $sut->create($string, $basePath); self::assertEquals($expected, $actual, 'Returned correct path object.'); self::assertEquals($expectedWithBaseDir, $actualWithBaseDir, 'Returned correct path object given a $basePath argument.'); @@ -34,7 +36,7 @@ public function providerBasicFunctionality(): array return [ [ 'string' => 'test.txt', - 'baseDir' => new TestPath(), + 'basePath' => new TestPath(), 'expected' => new Path('test.txt'), 'expectedWithBaseDir' => new Path('test.txt', new TestPath()), ], diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php index 7a3d4ad1d..cd8be9de4 100644 --- a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php +++ b/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php @@ -4,7 +4,6 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -43,7 +42,7 @@ final protected function doTestFulfilledDirectoryDoesNotExist( final public function providerFulfilledDirectoryDoesNotExist(): array { - $nonexistentDir = PathFactory::create('65eb69a274470dd84e9b5371f7e1e8c8'); + $nonexistentDir = PathHelper::createPath('65eb69a274470dd84e9b5371f7e1e8c8'); return [ 'Active directory' => [ diff --git a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index 230e165b8..3a6728772 100644 --- a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -37,7 +37,7 @@ protected function createSut(): NoAbsoluteSymlinksExist */ public function testDoesNotContainLinks(array $files): void { - self::createFiles(PathHelper::activeDirRelative(), $files); + self::createFiles(PathHelper::activeDirAbsolute(), $files); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); diff --git a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php index d3362fcc7..7807fbd3f 100644 --- a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -4,7 +4,6 @@ use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -66,8 +65,8 @@ public function testFulfilledWithSymlink(): void */ public function testUnfulfilled(string $directory, string $dirName): void { - $target = PathFactory::create($directory . '/target.txt')->absolute(); - $link = PathFactory::create($directory . '/link.txt')->absolute(); + $target = PathHelper::makeAbsolute('target.txt', $directory); + $link = PathHelper::makeAbsolute('link.txt', $directory); touch($target); link($target, $link); $sut = $this->createSut(); @@ -75,7 +74,7 @@ public function testUnfulfilled(string $directory, string $dirName): void $message = sprintf( 'The %s directory at %s contains hard links, which is not supported. The first one is %s.', $dirName, - PathFactory::create($directory)->absolute(), + $directory, $link, ); self::assertTranslatableException(static function () use ($sut): void { @@ -87,11 +86,11 @@ public function providerUnfulfilled(): array { return [ 'In active directory' => [ - 'directory' => PathHelper::activeDirRelative(), + 'directory' => PathHelper::activeDirAbsolute(), 'dirName' => 'active', ], 'In staging directory' => [ - 'directory' => PathHelper::stagingDirRelative(), + 'directory' => PathHelper::stagingDirAbsolute(), 'dirName' => 'staging', ], ]; diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index 5c8f9c6b3..96eff02e7 100644 --- a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -5,7 +5,6 @@ use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface; use PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; @@ -66,8 +65,8 @@ public function testFulfilledWithValidLink(): void */ public function testUnfulfilled(string $targetDir, string $linkDir, string $linkDirName): void { - $target = PathFactory::create($targetDir . '/target_directory')->absolute(); - $link = PathFactory::create($linkDir . '/directory_link')->absolute(); + $target = PathHelper::makeAbsolute('target_directory', $targetDir); + $link = PathHelper::makeAbsolute('directory_link', $linkDir); FilesystemHelper::createDirectories($target); symlink($target, $link); $sut = $this->createSut(); @@ -75,7 +74,7 @@ public function testUnfulfilled(string $targetDir, string $linkDir, string $link $message = sprintf( 'The %s directory at %s contains symlinks that point to a directory, which is not supported. The first one is %s.', $linkDirName, - PathFactory::create($linkDir)->absolute(), + $linkDir, $link, ); self::assertTranslatableException(static function () use ($sut): void { @@ -88,12 +87,12 @@ public function providerUnfulfilled(): array return [ 'In active directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => PathHelper::activeDirRelative(), + 'linkDir' => PathHelper::activeDirAbsolute(), 'linkDirName' => 'active', ], 'In staging directory' => [ 'targetDir' => PathHelper::testWorkingDirAbsolute(), - 'linkDir' => PathHelper::stagingDirRelative(), + 'linkDir' => PathHelper::stagingDirAbsolute(), 'linkDirName' => 'staging', ], ]; diff --git a/tests/PHPUnit/TestCase.php b/tests/PHPUnit/TestCase.php index 0b478e7e9..730c4af99 100644 --- a/tests/PHPUnit/TestCase.php +++ b/tests/PHPUnit/TestCase.php @@ -6,7 +6,6 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface; -use PhpTuf\ComposerStager\Internal\Path\Factory\PathFactory; use PhpTuf\ComposerStager\Tests\Precondition\Service\TestPrecondition; use PhpTuf\ComposerStager\Tests\TestUtils\AssertTrait; use PhpTuf\ComposerStager\Tests\TestUtils\Domain; @@ -86,7 +85,7 @@ protected static function createFiles(string $basePath, array $filenames): void protected static function createFile(string $basePath, string $filename): void { - $filename = PathFactory::create("{$basePath}/{$filename}")->absolute(); + $filename = PathHelper::makeAbsolute($filename, $basePath); static::ensureParentDirectory($filename); $touchResult = touch($filename); @@ -120,8 +119,8 @@ protected static function createSymlinks(string $basePath, array $symlinks): voi protected static function createSymlink(string $basePath, string $link, string $target): void { - $link = PathFactory::create("{$basePath}/{$link}"); - $target = PathFactory::create("{$basePath}/{$target}"); + $link = PathHelper::createPath($link, $basePath); + $target = PathHelper::createPath($target, $basePath); self::prepareForLink($link, $target); @@ -137,8 +136,8 @@ protected static function createHardlinks(string $basePath, array $symlinks): vo protected static function createHardlink(string $basePath, string $link, string $target): void { - $link = PathFactory::create("{$basePath}/{$link}"); - $target = PathFactory::create("{$basePath}/{$target}"); + $link = PathHelper::createPath($link, $basePath); + $target = PathHelper::createPath($target, $basePath); self::prepareForLink($link, $target); diff --git a/tests/PHPUnit/TestUtils/PathHelper.php b/tests/PHPUnit/TestUtils/PathHelper.php index 80ab727e3..0f9e02a5e 100644 --- a/tests/PHPUnit/TestUtils/PathHelper.php +++ b/tests/PHPUnit/TestUtils/PathHelper.php @@ -12,6 +12,8 @@ final class PathHelper private const WORKING_DIR = 'working-dir'; private const ACTIVE_DIR = 'active-dir'; private const STAGING_DIR = 'staging-dir'; + private const SOURCE_DIR = 'source'; + private const DESTINATION_DIR = 'destination'; public static function repositoryRootAbsolute(): string { @@ -40,7 +42,7 @@ public static function activeDirAbsolute(): string public static function activeDirPath(): PathInterface { - return new TestPath(self::activeDirAbsolute()); + return self::createPath(self::activeDirAbsolute()); } public static function stagingDirRelative(): string @@ -55,7 +57,47 @@ public static function stagingDirAbsolute(): string public static function stagingDirPath(): PathInterface { - return new TestPath(self::stagingDirAbsolute()); + return self::createPath(self::stagingDirAbsolute()); + } + + public static function sourceDirRelative(): string + { + return self::SOURCE_DIR; + } + + public static function sourceDirAbsolute(): string + { + return self::makeAbsolute(self::sourceDirRelative(), self::testEnvAbsolute()); + } + + public static function sourceDirPath(): PathInterface + { + return self::createPath(self::sourceDirAbsolute()); + } + + public static function destinationDirRelative(): string + { + return self::DESTINATION_DIR; + } + + public static function destinationDirAbsolute(): string + { + return self::makeAbsolute(self::destinationDirRelative(), self::testEnvAbsolute()); + } + + public static function destinationDirPath(): PathInterface + { + return self::createPath(self::destinationDirAbsolute()); + } + + public static function createPath(string $path, ?string $basePath = null): PathInterface + { + if (is_string($basePath)) { + assert(self::isAbsolute($basePath)); + $path = self::makeAbsolute($path, $basePath); + } + + return new TestPath($path); } public static function canonicalize(string $path): string From 7723be46c43f3ba7117e1e08e7d032b1a67c02a4 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 4 Aug 2023 16:35:26 -0400 Subject: [PATCH 18/75] Add path canonicalization to PathList paths. --- src/API/Path/Value/PathListInterface.php | 5 ++++- src/Internal/Path/Value/PathList.php | 6 +++++- tests/PHPUnit/Path/Value/PathListUnitTest.php | 20 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/API/Path/Value/PathListInterface.php b/src/API/Path/Value/PathListInterface.php index b92e9f64c..4a1057320 100644 --- a/src/API/Path/Value/PathListInterface.php +++ b/src/API/Path/Value/PathListInterface.php @@ -12,7 +12,10 @@ interface PathListInterface { /** - * Returns all path strings as given, i.e., unresolved. + * Returns all path strings as given, canonicalized but unresolved. + * + * In other words, directory separators will be normalized and complex + * paths will be simplified, but they will not be made absolute. * * @return array */ diff --git a/src/Internal/Path/Value/PathList.php b/src/Internal/Path/Value/PathList.php index 855795f50..215c56faa 100644 --- a/src/Internal/Path/Value/PathList.php +++ b/src/Internal/Path/Value/PathList.php @@ -3,6 +3,7 @@ namespace PhpTuf\ComposerStager\Internal\Path\Value; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; +use Symfony\Component\Filesystem\Path as SymfonyPath; /** * @package Path @@ -22,7 +23,10 @@ public function __construct(string ...$paths) /** @return array */ public function getAll(): array { - return $this->paths; + return array_map( + static fn ($path): string => SymfonyPath::canonicalize($path), + $this->paths, + ); } public function add(string ...$paths): void diff --git a/tests/PHPUnit/Path/Value/PathListUnitTest.php b/tests/PHPUnit/Path/Value/PathListUnitTest.php index 92f168abd..2e1b46433 100644 --- a/tests/PHPUnit/Path/Value/PathListUnitTest.php +++ b/tests/PHPUnit/Path/Value/PathListUnitTest.php @@ -19,8 +19,6 @@ public function testBasicFunctionality(array $given, array $add, array $expected { $sut = new PathList(...$given); - self::assertEquals($given, $sut->getAll(), 'Correctly set paths via constructor and got them.'); - $sut->add(...$add); self::assertEquals($expected, $sut->getAll(), 'Correctly added paths and got them.'); @@ -72,6 +70,24 @@ public function providerBasicFunctionality(): array 'four', ], ], + 'Different directory separators' => [ + 'paths' => [ + 'one', + 'two/two', + 'three\\three\\three', + ], + 'add' => [ + 'four/four\\four/four', + 'five\\five/five\\five/five', + ], + 'expected' => [ + 'one', + 'two/two', + 'three/three/three', + 'four/four/four/four', + 'five/five/five/five/five', + ], + ], ]; } } From 3ff7f4a0144d8b888372deafd371237c381fade4 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Sat, 12 Aug 2023 01:01:52 -0400 Subject: [PATCH 19/75] Split static analysis tools back out into a separate directory. --- .gitattributes | 1 + .idea/composer-stager.iml | 3 --- composer.json | 6 +++--- phpbench.json | 2 +- phpcs.xml.dist | 8 ++++++-- {tests => tools}/PHPBench/Benchmark/BenchCase.php | 0 {tests => tools}/PHPBench/Benchmark/FileSyncerBench.php | 0 {tests => tools}/PHPBench/Benchmark/PreconditionBench.php | 0 {tests => tools}/PHPBench/Scripts/debug.php | 0 {tests => tools}/PHPBench/Scripts/regenerate-fixtures.sh | 0 {tests => tools}/PHPBench/TestUtils/FixtureHelper.php | 0 {tests => tools}/PHPBench/TestUtils/ProcessHelper.php | 0 {tests => tools}/PHPCS/Helper/DocCommentTag.php | 0 {tests => tools}/PHPCS/Helper/NamespaceHelper.php | 0 {tests => tools}/PHPCS/Helper/PHPHelper.php | 0 {tests => tools}/PHPCS/Sniffs/Commenting/APITagsSniff.php | 0 .../Sniffs/Commenting/AlphabeticallySortedTagsSniff.php | 0 .../Commenting/PropertyVarNameHasDollarSignSniff.php | 0 .../Functions/CommaBeforeClosingParenthesisSniff.php | 0 .../Functions/ProtectedFunctionOnFinalClassSniff.php | 0 .../Namespaces/APILayerDependsOnOtherLayerSniff.php | 0 .../PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php | 0 .../Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php | 0 {tests => tools}/PHPCS/phpcs.xml | 0 {tests => tools}/PHPStan/Rules/AbstractRule.php | 0 .../Calls/NoCallingTranslatableFactoryDirectlyRule.php | 0 .../Calls/NoInstantiatingTranslatableDirectlyRule.php | 0 .../PHPStan/Rules/Classes/FinalExceptionRule.php | 0 .../Rules/Classes/MissingExceptionInterfaceRule.php | 0 .../PHPStan/Rules/Classes/MissingInterfaceRule.php | 0 .../PHPStan/Rules/Classes/WrongExceptionNamespaceRule.php | 0 .../Rules/Files/GitattributesMissingExportIgnoreRule.php | 0 .../Rules/Interfaces/PreconditionDiagramsInSyncRule.php | 0 .../Rules/Interfaces/TranslationDiagramsInSyncRule.php | 0 .../PHPStan/Rules/Interfaces/UselessInterfaceRule.php | 0 .../Rules/Methods/ForbiddenConcreteTypeHintRule.php | 0 .../PHPStan/Rules/Methods/ForbiddenThrowsRule.php | 0 .../Rules/Methods/NoNonInterfacePublicMethodsRule.php | 0 .../PHPStan/Rules/PhpDoc/APIAnnotationRule.php | 0 .../PhpDoc/CoverageAnnotationHasNoParenthesesRule.php | 0 .../PHPStan/Rules/PhpDoc/PackageAnnotationRule.php | 0 .../PhpDoc/PropertyDataTypePutsObjectProphecyLastRule.php | 0 .../PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php | 0 .../Rules/PhpDoc/TranslationParametersPhpDocRule.php | 0 44 files changed, 11 insertions(+), 9 deletions(-) rename {tests => tools}/PHPBench/Benchmark/BenchCase.php (100%) rename {tests => tools}/PHPBench/Benchmark/FileSyncerBench.php (100%) rename {tests => tools}/PHPBench/Benchmark/PreconditionBench.php (100%) rename {tests => tools}/PHPBench/Scripts/debug.php (100%) rename {tests => tools}/PHPBench/Scripts/regenerate-fixtures.sh (100%) rename {tests => tools}/PHPBench/TestUtils/FixtureHelper.php (100%) rename {tests => tools}/PHPBench/TestUtils/ProcessHelper.php (100%) rename {tests => tools}/PHPCS/Helper/DocCommentTag.php (100%) rename {tests => tools}/PHPCS/Helper/NamespaceHelper.php (100%) rename {tests => tools}/PHPCS/Helper/PHPHelper.php (100%) rename {tests => tools}/PHPCS/Sniffs/Commenting/APITagsSniff.php (100%) rename {tests => tools}/PHPCS/Sniffs/Commenting/AlphabeticallySortedTagsSniff.php (100%) rename {tests => tools}/PHPCS/Sniffs/Commenting/PropertyVarNameHasDollarSignSniff.php (100%) rename {tests => tools}/PHPCS/Sniffs/Functions/CommaBeforeClosingParenthesisSniff.php (100%) rename {tests => tools}/PHPCS/Sniffs/Functions/ProtectedFunctionOnFinalClassSniff.php (100%) rename {tests => tools}/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php (100%) rename {tests => tools}/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php (100%) rename {tests => tools}/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php (100%) rename {tests => tools}/PHPCS/phpcs.xml (100%) rename {tests => tools}/PHPStan/Rules/AbstractRule.php (100%) rename {tests => tools}/PHPStan/Rules/Calls/NoCallingTranslatableFactoryDirectlyRule.php (100%) rename {tests => tools}/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php (100%) rename {tests => tools}/PHPStan/Rules/Classes/FinalExceptionRule.php (100%) rename {tests => tools}/PHPStan/Rules/Classes/MissingExceptionInterfaceRule.php (100%) rename {tests => tools}/PHPStan/Rules/Classes/MissingInterfaceRule.php (100%) rename {tests => tools}/PHPStan/Rules/Classes/WrongExceptionNamespaceRule.php (100%) rename {tests => tools}/PHPStan/Rules/Files/GitattributesMissingExportIgnoreRule.php (100%) rename {tests => tools}/PHPStan/Rules/Interfaces/PreconditionDiagramsInSyncRule.php (100%) rename {tests => tools}/PHPStan/Rules/Interfaces/TranslationDiagramsInSyncRule.php (100%) rename {tests => tools}/PHPStan/Rules/Interfaces/UselessInterfaceRule.php (100%) rename {tests => tools}/PHPStan/Rules/Methods/ForbiddenConcreteTypeHintRule.php (100%) rename {tests => tools}/PHPStan/Rules/Methods/ForbiddenThrowsRule.php (100%) rename {tests => tools}/PHPStan/Rules/Methods/NoNonInterfacePublicMethodsRule.php (100%) rename {tests => tools}/PHPStan/Rules/PhpDoc/APIAnnotationRule.php (100%) rename {tests => tools}/PHPStan/Rules/PhpDoc/CoverageAnnotationHasNoParenthesesRule.php (100%) rename {tests => tools}/PHPStan/Rules/PhpDoc/PackageAnnotationRule.php (100%) rename {tests => tools}/PHPStan/Rules/PhpDoc/PropertyDataTypePutsObjectProphecyLastRule.php (100%) rename {tests => tools}/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php (100%) rename {tests => tools}/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php (100%) diff --git a/.gitattributes b/.gitattributes index 3ef345522..413355bdc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,4 +14,5 @@ /psalm.xml.dist export-ignore /rector.php export-ignore /tests export-ignore +/tools export-ignore /var export-ignore diff --git a/.idea/composer-stager.iml b/.idea/composer-stager.iml index 39f192971..29b9e2a57 100644 --- a/.idea/composer-stager.iml +++ b/.idea/composer-stager.iml @@ -4,10 +4,7 @@ - - - diff --git a/composer.json b/composer.json index f4695db02..799c0d5ef 100644 --- a/composer.json +++ b/composer.json @@ -59,9 +59,9 @@ }, "autoload-dev": { "psr-4": { - "PhpTuf\\ComposerStager\\": "tests/PHPCS/", - "PhpTuf\\ComposerStager\\PHPBench\\": "tests/PHPBench/", - "PhpTuf\\ComposerStager\\PHPStan\\": "tests/PHPStan/", + "PhpTuf\\ComposerStager\\": "tools/PHPCS/", + "PhpTuf\\ComposerStager\\PHPBench\\": "tools/PHPBench/", + "PhpTuf\\ComposerStager\\PHPStan\\": "tools/PHPStan/", "PhpTuf\\ComposerStager\\Tests\\": "tests/PHPUnit/" } }, diff --git a/phpbench.json b/phpbench.json index d9ed10a0c..164cf83d2 100644 --- a/phpbench.json +++ b/phpbench.json @@ -2,7 +2,7 @@ "$schema": "./vendor/phpbench/phpbench/phpbench.schema.json", "runner.bootstrap": "vendor/autoload.php", - "runner.path": "tests/PHPBench", + "runner.path": "tools/PHPBench", "runner.iterations": 1, "runner.file_pattern": "*Bench.php", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 51b5582ba..9e006393a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -13,10 +13,11 @@ src tests + tools rector.php - + @@ -249,14 +250,17 @@ tests rector.php tests - tests + teststools/PHPCS rector.php tests tests tests tests tests + tools/PHPCS + tools/PHPCS tests + tools/PHPCS tests tests diff --git a/tests/PHPBench/Benchmark/BenchCase.php b/tools/PHPBench/Benchmark/BenchCase.php similarity index 100% rename from tests/PHPBench/Benchmark/BenchCase.php rename to tools/PHPBench/Benchmark/BenchCase.php diff --git a/tests/PHPBench/Benchmark/FileSyncerBench.php b/tools/PHPBench/Benchmark/FileSyncerBench.php similarity index 100% rename from tests/PHPBench/Benchmark/FileSyncerBench.php rename to tools/PHPBench/Benchmark/FileSyncerBench.php diff --git a/tests/PHPBench/Benchmark/PreconditionBench.php b/tools/PHPBench/Benchmark/PreconditionBench.php similarity index 100% rename from tests/PHPBench/Benchmark/PreconditionBench.php rename to tools/PHPBench/Benchmark/PreconditionBench.php diff --git a/tests/PHPBench/Scripts/debug.php b/tools/PHPBench/Scripts/debug.php similarity index 100% rename from tests/PHPBench/Scripts/debug.php rename to tools/PHPBench/Scripts/debug.php diff --git a/tests/PHPBench/Scripts/regenerate-fixtures.sh b/tools/PHPBench/Scripts/regenerate-fixtures.sh similarity index 100% rename from tests/PHPBench/Scripts/regenerate-fixtures.sh rename to tools/PHPBench/Scripts/regenerate-fixtures.sh diff --git a/tests/PHPBench/TestUtils/FixtureHelper.php b/tools/PHPBench/TestUtils/FixtureHelper.php similarity index 100% rename from tests/PHPBench/TestUtils/FixtureHelper.php rename to tools/PHPBench/TestUtils/FixtureHelper.php diff --git a/tests/PHPBench/TestUtils/ProcessHelper.php b/tools/PHPBench/TestUtils/ProcessHelper.php similarity index 100% rename from tests/PHPBench/TestUtils/ProcessHelper.php rename to tools/PHPBench/TestUtils/ProcessHelper.php diff --git a/tests/PHPCS/Helper/DocCommentTag.php b/tools/PHPCS/Helper/DocCommentTag.php similarity index 100% rename from tests/PHPCS/Helper/DocCommentTag.php rename to tools/PHPCS/Helper/DocCommentTag.php diff --git a/tests/PHPCS/Helper/NamespaceHelper.php b/tools/PHPCS/Helper/NamespaceHelper.php similarity index 100% rename from tests/PHPCS/Helper/NamespaceHelper.php rename to tools/PHPCS/Helper/NamespaceHelper.php diff --git a/tests/PHPCS/Helper/PHPHelper.php b/tools/PHPCS/Helper/PHPHelper.php similarity index 100% rename from tests/PHPCS/Helper/PHPHelper.php rename to tools/PHPCS/Helper/PHPHelper.php diff --git a/tests/PHPCS/Sniffs/Commenting/APITagsSniff.php b/tools/PHPCS/Sniffs/Commenting/APITagsSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Commenting/APITagsSniff.php rename to tools/PHPCS/Sniffs/Commenting/APITagsSniff.php diff --git a/tests/PHPCS/Sniffs/Commenting/AlphabeticallySortedTagsSniff.php b/tools/PHPCS/Sniffs/Commenting/AlphabeticallySortedTagsSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Commenting/AlphabeticallySortedTagsSniff.php rename to tools/PHPCS/Sniffs/Commenting/AlphabeticallySortedTagsSniff.php diff --git a/tests/PHPCS/Sniffs/Commenting/PropertyVarNameHasDollarSignSniff.php b/tools/PHPCS/Sniffs/Commenting/PropertyVarNameHasDollarSignSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Commenting/PropertyVarNameHasDollarSignSniff.php rename to tools/PHPCS/Sniffs/Commenting/PropertyVarNameHasDollarSignSniff.php diff --git a/tests/PHPCS/Sniffs/Functions/CommaBeforeClosingParenthesisSniff.php b/tools/PHPCS/Sniffs/Functions/CommaBeforeClosingParenthesisSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Functions/CommaBeforeClosingParenthesisSniff.php rename to tools/PHPCS/Sniffs/Functions/CommaBeforeClosingParenthesisSniff.php diff --git a/tests/PHPCS/Sniffs/Functions/ProtectedFunctionOnFinalClassSniff.php b/tools/PHPCS/Sniffs/Functions/ProtectedFunctionOnFinalClassSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Functions/ProtectedFunctionOnFinalClassSniff.php rename to tools/PHPCS/Sniffs/Functions/ProtectedFunctionOnFinalClassSniff.php diff --git a/tests/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php b/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php rename to tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php diff --git a/tests/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php b/tools/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php rename to tools/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php diff --git a/tests/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php b/tools/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php similarity index 100% rename from tests/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php rename to tools/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php diff --git a/tests/PHPCS/phpcs.xml b/tools/PHPCS/phpcs.xml similarity index 100% rename from tests/PHPCS/phpcs.xml rename to tools/PHPCS/phpcs.xml diff --git a/tests/PHPStan/Rules/AbstractRule.php b/tools/PHPStan/Rules/AbstractRule.php similarity index 100% rename from tests/PHPStan/Rules/AbstractRule.php rename to tools/PHPStan/Rules/AbstractRule.php diff --git a/tests/PHPStan/Rules/Calls/NoCallingTranslatableFactoryDirectlyRule.php b/tools/PHPStan/Rules/Calls/NoCallingTranslatableFactoryDirectlyRule.php similarity index 100% rename from tests/PHPStan/Rules/Calls/NoCallingTranslatableFactoryDirectlyRule.php rename to tools/PHPStan/Rules/Calls/NoCallingTranslatableFactoryDirectlyRule.php diff --git a/tests/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php b/tools/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php similarity index 100% rename from tests/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php rename to tools/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php diff --git a/tests/PHPStan/Rules/Classes/FinalExceptionRule.php b/tools/PHPStan/Rules/Classes/FinalExceptionRule.php similarity index 100% rename from tests/PHPStan/Rules/Classes/FinalExceptionRule.php rename to tools/PHPStan/Rules/Classes/FinalExceptionRule.php diff --git a/tests/PHPStan/Rules/Classes/MissingExceptionInterfaceRule.php b/tools/PHPStan/Rules/Classes/MissingExceptionInterfaceRule.php similarity index 100% rename from tests/PHPStan/Rules/Classes/MissingExceptionInterfaceRule.php rename to tools/PHPStan/Rules/Classes/MissingExceptionInterfaceRule.php diff --git a/tests/PHPStan/Rules/Classes/MissingInterfaceRule.php b/tools/PHPStan/Rules/Classes/MissingInterfaceRule.php similarity index 100% rename from tests/PHPStan/Rules/Classes/MissingInterfaceRule.php rename to tools/PHPStan/Rules/Classes/MissingInterfaceRule.php diff --git a/tests/PHPStan/Rules/Classes/WrongExceptionNamespaceRule.php b/tools/PHPStan/Rules/Classes/WrongExceptionNamespaceRule.php similarity index 100% rename from tests/PHPStan/Rules/Classes/WrongExceptionNamespaceRule.php rename to tools/PHPStan/Rules/Classes/WrongExceptionNamespaceRule.php diff --git a/tests/PHPStan/Rules/Files/GitattributesMissingExportIgnoreRule.php b/tools/PHPStan/Rules/Files/GitattributesMissingExportIgnoreRule.php similarity index 100% rename from tests/PHPStan/Rules/Files/GitattributesMissingExportIgnoreRule.php rename to tools/PHPStan/Rules/Files/GitattributesMissingExportIgnoreRule.php diff --git a/tests/PHPStan/Rules/Interfaces/PreconditionDiagramsInSyncRule.php b/tools/PHPStan/Rules/Interfaces/PreconditionDiagramsInSyncRule.php similarity index 100% rename from tests/PHPStan/Rules/Interfaces/PreconditionDiagramsInSyncRule.php rename to tools/PHPStan/Rules/Interfaces/PreconditionDiagramsInSyncRule.php diff --git a/tests/PHPStan/Rules/Interfaces/TranslationDiagramsInSyncRule.php b/tools/PHPStan/Rules/Interfaces/TranslationDiagramsInSyncRule.php similarity index 100% rename from tests/PHPStan/Rules/Interfaces/TranslationDiagramsInSyncRule.php rename to tools/PHPStan/Rules/Interfaces/TranslationDiagramsInSyncRule.php diff --git a/tests/PHPStan/Rules/Interfaces/UselessInterfaceRule.php b/tools/PHPStan/Rules/Interfaces/UselessInterfaceRule.php similarity index 100% rename from tests/PHPStan/Rules/Interfaces/UselessInterfaceRule.php rename to tools/PHPStan/Rules/Interfaces/UselessInterfaceRule.php diff --git a/tests/PHPStan/Rules/Methods/ForbiddenConcreteTypeHintRule.php b/tools/PHPStan/Rules/Methods/ForbiddenConcreteTypeHintRule.php similarity index 100% rename from tests/PHPStan/Rules/Methods/ForbiddenConcreteTypeHintRule.php rename to tools/PHPStan/Rules/Methods/ForbiddenConcreteTypeHintRule.php diff --git a/tests/PHPStan/Rules/Methods/ForbiddenThrowsRule.php b/tools/PHPStan/Rules/Methods/ForbiddenThrowsRule.php similarity index 100% rename from tests/PHPStan/Rules/Methods/ForbiddenThrowsRule.php rename to tools/PHPStan/Rules/Methods/ForbiddenThrowsRule.php diff --git a/tests/PHPStan/Rules/Methods/NoNonInterfacePublicMethodsRule.php b/tools/PHPStan/Rules/Methods/NoNonInterfacePublicMethodsRule.php similarity index 100% rename from tests/PHPStan/Rules/Methods/NoNonInterfacePublicMethodsRule.php rename to tools/PHPStan/Rules/Methods/NoNonInterfacePublicMethodsRule.php diff --git a/tests/PHPStan/Rules/PhpDoc/APIAnnotationRule.php b/tools/PHPStan/Rules/PhpDoc/APIAnnotationRule.php similarity index 100% rename from tests/PHPStan/Rules/PhpDoc/APIAnnotationRule.php rename to tools/PHPStan/Rules/PhpDoc/APIAnnotationRule.php diff --git a/tests/PHPStan/Rules/PhpDoc/CoverageAnnotationHasNoParenthesesRule.php b/tools/PHPStan/Rules/PhpDoc/CoverageAnnotationHasNoParenthesesRule.php similarity index 100% rename from tests/PHPStan/Rules/PhpDoc/CoverageAnnotationHasNoParenthesesRule.php rename to tools/PHPStan/Rules/PhpDoc/CoverageAnnotationHasNoParenthesesRule.php diff --git a/tests/PHPStan/Rules/PhpDoc/PackageAnnotationRule.php b/tools/PHPStan/Rules/PhpDoc/PackageAnnotationRule.php similarity index 100% rename from tests/PHPStan/Rules/PhpDoc/PackageAnnotationRule.php rename to tools/PHPStan/Rules/PhpDoc/PackageAnnotationRule.php diff --git a/tests/PHPStan/Rules/PhpDoc/PropertyDataTypePutsObjectProphecyLastRule.php b/tools/PHPStan/Rules/PhpDoc/PropertyDataTypePutsObjectProphecyLastRule.php similarity index 100% rename from tests/PHPStan/Rules/PhpDoc/PropertyDataTypePutsObjectProphecyLastRule.php rename to tools/PHPStan/Rules/PhpDoc/PropertyDataTypePutsObjectProphecyLastRule.php diff --git a/tests/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php b/tools/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php similarity index 100% rename from tests/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php rename to tools/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php diff --git a/tests/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php b/tools/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php similarity index 100% rename from tests/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php rename to tools/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php From 7f044d75162f424994b8ace76bc0b26de4263a7d Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Sat, 12 Aug 2023 01:29:25 -0400 Subject: [PATCH 20/75] Move tests/PHPUnit back up a level. --- .gitignore | 4 +-- .idea/composer-stager.iml | 3 +- .idea/runConfigurations/End_to_End_Test.xml | 2 +- composer.json | 2 +- phpstan.neon.dist | 32 +++++++++---------- phpunit.xml.dist | 6 ++-- rector.php | 4 +-- tests/{PHPUnit => }/Core/BeginnerUnitTest.php | 0 tests/{PHPUnit => }/Core/CleanerUnitTest.php | 0 .../{PHPUnit => }/Core/CommitterUnitTest.php | 0 tests/{PHPUnit => }/Core/StagerUnitTest.php | 0 .../EndToEnd/EndToEndFunctionalTestCase.php | 0 .../PhpFileSyncerEndToEndFunctionalTest.php | 0 .../RsyncFileSyncerEndToEndFunctionalTest.php | 0 .../Exception/ExceptionUnitTest.php | 0 .../PreconditionExceptionUnitTest.php | 0 .../TranslatableExceptionTraitUnitTest.php | 0 .../Exploratory/ExploratoryTestTemplate.php | 0 .../Factory/FileSyncerFactoryUnitTest.php | 0 .../Service/FileSyncerFunctionalTestCase.php | 0 .../Service/PhpFileSyncerFunctionalTest.php | 0 .../Service/PhpFileSyncerUnitTest.php | 0 .../Service/RsyncFileSyncerFunctionalTest.php | 0 .../Service/RsyncFileSyncerUnitTest.php | 0 .../Service/FilesystemFunctionalTest.php | 0 .../Filesystem/Service/FilesystemUnitTest.php | 0 .../Service/ExecutableFinderUnitTest.php | 0 .../Service/FileFinderFunctionalTest.php | 0 .../Helper/PathHelperUnitTest.php | 0 .../Host/Service/HostUnitTest.php | 0 tests/{PHPUnit => }/Host/Service/TestHost.php | 0 .../Path/Factory/PathFactoryUnitTest.php | 0 .../Path/Factory/PathListFactoryUnitTest.php | 0 .../Path/Value/PathListUnitTest.php | 0 .../Path/Value/PathUnitTestCase.php | 0 tests/{PHPUnit => }/Path/Value/TestPath.php | 0 .../{PHPUnit => }/Path/Value/TestPathList.php | 0 .../Path/Value/UnixLikePathUnitTest.php | 0 .../Path/Value/WindowsPathUnitTest.php | 0 ...tractFileIteratingPreconditionUnitTest.php | 0 .../Service/AbstractPreconditionUnitTest.php | 0 .../AbstractPreconditionsTreeUnitTest.php | 0 ...tiveAndStagingDirsAreDifferentUnitTest.php | 0 .../Service/ActiveDirExistsUnitTest.php | 0 .../Service/ActiveDirIsReadyUnitTest.php | 0 .../Service/ActiveDirIsWritableUnitTest.php | 0 .../Service/BeginnerPreconditionsUnitTest.php | 0 .../Service/CleanerPreconditionsUnitTest.php | 0 .../CommitterPreconditionsUnitTest.php | 0 .../Service/CommonPreconditionsUnitTest.php | 0 .../ComposerIsAvailableFunctionalTest.php | 0 .../Service/ComposerIsAvailableUnitTest.php | 0 .../FileIteratingPreconditionUnitTestCase.php | 0 ...SupportsRunningProcessesFunctionalTest.php | 0 .../HostSupportsRunningProcessesUnitTest.php | 0 .../LinkPreconditionsFunctionalTestCase.php | 0 ...nkPreconditionsIsolationFunctionalTest.php | 0 .../NoAbsoluteSymlinksExistFunctionalTest.php | 0 .../NoAbsoluteSymlinksExistUnitTest.php | 0 .../NoHardLinksExistFunctionalTest.php | 0 .../Service/NoHardLinksExistUnitTest.php | 0 .../NoLinksExistOnWindowsFunctionalTest.php | 0 .../Service/NoLinksExistOnWindowsUnitTest.php | 0 ...sPointOutsideTheCodebaseFunctionalTest.php | 0 ...ymlinksPointOutsideTheCodebaseUnitTest.php | 0 ...ymlinksPointToADirectoryFunctionalTest.php | 0 .../NoSymlinksPointToADirectoryUnitTest.php | 0 .../NoUnsupportedLinksExistUnitTest.php | 0 .../Service/PreconditionTestCase.php | 0 .../Service/StagerPreconditionsUnitTest.php | 0 .../StagingDirDoesNotExistUnitTest.php | 0 .../Service/StagingDirExistsUnitTest.php | 0 .../Service/StagingDirIsReadyUnitTest.php | 0 .../Service/StagingDirIsWritableUnitTest.php | 0 .../Precondition/Service/TestPrecondition.php | 0 .../Service/TestPreconditionsTree.php | 0 .../Factory/ProcessFactoryUnitTest.php | 0 .../Factory/SymfonyProcessFactoryUnitTest.php | 0 .../Service/AbstractProcessRunnerUnitTest.php | 0 .../Service/OutputCallbackAdapterUnitTest.php | 0 .../Process/Service/ProcessFunctionalTest.php | 0 .../Process/Service/ProcessUnitTest.php | 0 .../Process/Service/TestOutputCallback.php | 0 .../Process/Service/TestSymfonyProcess.php | 0 tests/{PHPUnit => }/TestCase.php | 0 tests/{PHPUnit => }/TestUtils/AssertTrait.php | 0 tests/{PHPUnit => }/TestUtils/Domain.php | 0 .../TestUtils/FilesystemHelper.php | 0 tests/{PHPUnit => }/TestUtils/PathHelper.php | 2 +- .../{PHPUnit => }/TestUtils/ProcessHelper.php | 0 .../TestUtils/TestSpyInterface.php | 0 .../TestUtils/TestStringable.php | 0 .../TestUtils/TranslationHelper.php | 0 .../Factory/TestTranslatableFactory.php | 0 .../Factory/TestTranslationParameters.php | 0 .../TranslatableAwareTraitUnitTest.php | 0 .../Factory/TranslatableFactoryUnitTest.php | 0 .../Service/DomainOptionsUnitTest.php | 0 .../Service/LocaleOptionsUnitTest.php | 0 .../Service/SymfonyTranslatorProxyTest.php | 0 .../Translation/Service/TestDomainOptions.php | 0 .../Translation/Service/TestLocaleOptions.php | 0 .../Translation/Service/TestTranslator.php | 0 .../Service/TranslatorUnitTest.php | 0 .../TestTranslatableExceptionMessage.php | 0 .../Value/TestTranslatableMessage.php | 0 .../Value/TestTranslationParameters.php | 0 .../Value/TranslatableMessageUnitTest.php | 0 .../Value/TranslatableReflection.php | 0 .../Value/TranslationParametersUnitTest.php | 0 110 files changed, 27 insertions(+), 28 deletions(-) rename tests/{PHPUnit => }/Core/BeginnerUnitTest.php (100%) rename tests/{PHPUnit => }/Core/CleanerUnitTest.php (100%) rename tests/{PHPUnit => }/Core/CommitterUnitTest.php (100%) rename tests/{PHPUnit => }/Core/StagerUnitTest.php (100%) rename tests/{PHPUnit => }/EndToEnd/EndToEndFunctionalTestCase.php (100%) rename tests/{PHPUnit => }/EndToEnd/PhpFileSyncerEndToEndFunctionalTest.php (100%) rename tests/{PHPUnit => }/EndToEnd/RsyncFileSyncerEndToEndFunctionalTest.php (100%) rename tests/{PHPUnit => }/Exception/ExceptionUnitTest.php (100%) rename tests/{PHPUnit => }/Exception/PreconditionExceptionUnitTest.php (100%) rename tests/{PHPUnit => }/Exception/TranslatableExceptionTraitUnitTest.php (100%) rename tests/{PHPUnit => }/Exploratory/ExploratoryTestTemplate.php (100%) rename tests/{PHPUnit => }/FileSyncer/Factory/FileSyncerFactoryUnitTest.php (100%) rename tests/{PHPUnit => }/FileSyncer/Service/FileSyncerFunctionalTestCase.php (100%) rename tests/{PHPUnit => }/FileSyncer/Service/PhpFileSyncerFunctionalTest.php (100%) rename tests/{PHPUnit => }/FileSyncer/Service/PhpFileSyncerUnitTest.php (100%) rename tests/{PHPUnit => }/FileSyncer/Service/RsyncFileSyncerFunctionalTest.php (100%) rename tests/{PHPUnit => }/FileSyncer/Service/RsyncFileSyncerUnitTest.php (100%) rename tests/{PHPUnit => }/Filesystem/Service/FilesystemFunctionalTest.php (100%) rename tests/{PHPUnit => }/Filesystem/Service/FilesystemUnitTest.php (100%) rename tests/{PHPUnit => }/Finder/Service/ExecutableFinderUnitTest.php (100%) rename tests/{PHPUnit => }/Finder/Service/FileFinderFunctionalTest.php (100%) rename tests/{PHPUnit => }/Helper/PathHelperUnitTest.php (100%) rename tests/{PHPUnit => }/Host/Service/HostUnitTest.php (100%) rename tests/{PHPUnit => }/Host/Service/TestHost.php (100%) rename tests/{PHPUnit => }/Path/Factory/PathFactoryUnitTest.php (100%) rename tests/{PHPUnit => }/Path/Factory/PathListFactoryUnitTest.php (100%) rename tests/{PHPUnit => }/Path/Value/PathListUnitTest.php (100%) rename tests/{PHPUnit => }/Path/Value/PathUnitTestCase.php (100%) rename tests/{PHPUnit => }/Path/Value/TestPath.php (100%) rename tests/{PHPUnit => }/Path/Value/TestPathList.php (100%) rename tests/{PHPUnit => }/Path/Value/UnixLikePathUnitTest.php (100%) rename tests/{PHPUnit => }/Path/Value/WindowsPathUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/AbstractPreconditionUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/AbstractPreconditionsTreeUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/ActiveDirExistsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/ActiveDirIsReadyUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/ActiveDirIsWritableUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/BeginnerPreconditionsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/CleanerPreconditionsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/CommitterPreconditionsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/CommonPreconditionsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/ComposerIsAvailableFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/ComposerIsAvailableUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/FileIteratingPreconditionUnitTestCase.php (100%) rename tests/{PHPUnit => }/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/HostSupportsRunningProcessesUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/LinkPreconditionsFunctionalTestCase.php (100%) rename tests/{PHPUnit => }/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoHardLinksExistFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoHardLinksExistUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoLinksExistOnWindowsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/NoUnsupportedLinksExistUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/PreconditionTestCase.php (100%) rename tests/{PHPUnit => }/Precondition/Service/StagerPreconditionsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/StagingDirDoesNotExistUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/StagingDirExistsUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/StagingDirIsReadyUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/StagingDirIsWritableUnitTest.php (100%) rename tests/{PHPUnit => }/Precondition/Service/TestPrecondition.php (100%) rename tests/{PHPUnit => }/Precondition/Service/TestPreconditionsTree.php (100%) rename tests/{PHPUnit => }/Process/Factory/ProcessFactoryUnitTest.php (100%) rename tests/{PHPUnit => }/Process/Factory/SymfonyProcessFactoryUnitTest.php (100%) rename tests/{PHPUnit => }/Process/Service/AbstractProcessRunnerUnitTest.php (100%) rename tests/{PHPUnit => }/Process/Service/OutputCallbackAdapterUnitTest.php (100%) rename tests/{PHPUnit => }/Process/Service/ProcessFunctionalTest.php (100%) rename tests/{PHPUnit => }/Process/Service/ProcessUnitTest.php (100%) rename tests/{PHPUnit => }/Process/Service/TestOutputCallback.php (100%) rename tests/{PHPUnit => }/Process/Service/TestSymfonyProcess.php (100%) rename tests/{PHPUnit => }/TestCase.php (100%) rename tests/{PHPUnit => }/TestUtils/AssertTrait.php (100%) rename tests/{PHPUnit => }/TestUtils/Domain.php (100%) rename tests/{PHPUnit => }/TestUtils/FilesystemHelper.php (100%) rename tests/{PHPUnit => }/TestUtils/PathHelper.php (98%) rename tests/{PHPUnit => }/TestUtils/ProcessHelper.php (100%) rename tests/{PHPUnit => }/TestUtils/TestSpyInterface.php (100%) rename tests/{PHPUnit => }/TestUtils/TestStringable.php (100%) rename tests/{PHPUnit => }/TestUtils/TranslationHelper.php (100%) rename tests/{PHPUnit => }/Translation/Factory/TestTranslatableFactory.php (100%) rename tests/{PHPUnit => }/Translation/Factory/TestTranslationParameters.php (100%) rename tests/{PHPUnit => }/Translation/Factory/TranslatableAwareTraitUnitTest.php (100%) rename tests/{PHPUnit => }/Translation/Factory/TranslatableFactoryUnitTest.php (100%) rename tests/{PHPUnit => }/Translation/Service/DomainOptionsUnitTest.php (100%) rename tests/{PHPUnit => }/Translation/Service/LocaleOptionsUnitTest.php (100%) rename tests/{PHPUnit => }/Translation/Service/SymfonyTranslatorProxyTest.php (100%) rename tests/{PHPUnit => }/Translation/Service/TestDomainOptions.php (100%) rename tests/{PHPUnit => }/Translation/Service/TestLocaleOptions.php (100%) rename tests/{PHPUnit => }/Translation/Service/TestTranslator.php (100%) rename tests/{PHPUnit => }/Translation/Service/TranslatorUnitTest.php (100%) rename tests/{PHPUnit => }/Translation/Value/TestTranslatableExceptionMessage.php (100%) rename tests/{PHPUnit => }/Translation/Value/TestTranslatableMessage.php (100%) rename tests/{PHPUnit => }/Translation/Value/TestTranslationParameters.php (100%) rename tests/{PHPUnit => }/Translation/Value/TranslatableMessageUnitTest.php (100%) rename tests/{PHPUnit => }/Translation/Value/TranslatableReflection.php (100%) rename tests/{PHPUnit => }/Translation/Value/TranslationParametersUnitTest.php (100%) diff --git a/.gitignore b/.gitignore index 0c8ace946..4a51c0f55 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,8 @@ /phpcs.xml /phpunit.xml /psalm.xml -/tests/PHPUnit/Exploratory/* -!/tests/PHPUnit/Exploratory/ExploratoryTestTemplate.php +/tests/Exploratory/* +!/tests/Exploratory/ExploratoryTestTemplate.php /var/*/* /vendor/ !/**/.gitkeep diff --git a/.idea/composer-stager.iml b/.idea/composer-stager.iml index 29b9e2a57..f467574f9 100644 --- a/.idea/composer-stager.iml +++ b/.idea/composer-stager.iml @@ -3,8 +3,7 @@ - - + diff --git a/.idea/runConfigurations/End_to_End_Test.xml b/.idea/runConfigurations/End_to_End_Test.xml index c8bc0dcac..3a80a0788 100644 --- a/.idea/runConfigurations/End_to_End_Test.xml +++ b/.idea/runConfigurations/End_to_End_Test.xml @@ -1,6 +1,6 @@ - + diff --git a/composer.json b/composer.json index 799c0d5ef..7da3a058f 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ "PhpTuf\\ComposerStager\\": "tools/PHPCS/", "PhpTuf\\ComposerStager\\PHPBench\\": "tools/PHPBench/", "PhpTuf\\ComposerStager\\PHPStan\\": "tools/PHPStan/", - "PhpTuf\\ComposerStager\\Tests\\": "tests/PHPUnit/" + "PhpTuf\\ComposerStager\\Tests\\": "tests/" } }, "config": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1ccef4a87..2f8b90177 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -14,7 +14,7 @@ parameters: paths: - .gitattributes - src - - tests/PHPUnit + - tests treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false preconditionSystemHash: edc0e29f2fd55b848b7a587e7a16e557 @@ -68,49 +68,49 @@ parameters: # Test code. - message: '#.*::__construct\(\) does not call parent constructor from .*.#' - path: tests/PHPUnit/Translation/Value/TestTranslatableExceptionMessage.php + path: tests/Translation/Value/TestTranslatableExceptionMessage.php - message: '#Access to an undefined property.*#' - path: tests/PHPUnit + path: tests - message: '#Built-in or third party exception ".*" cannot be thrown from public methods.*#' - path: tests/PHPUnit + path: tests - message: '#Call to an undefined method .*Prophecy.*::.*\(\).#' - path: tests/PHPUnit + path: tests - message: '#Cannot call .*TranslatableFactory::create.*\(\) directly.*#' - path: tests/PHPUnit + path: tests - message: '#Cannot call method .*\(\) on .*MethodProphecy.#' - path: tests/PHPUnit + path: tests - message: '#Cannot instantiate .*\\.*tableMessage directly.*#' - path: tests/PHPUnit + path: tests - message: '#Concrete class must implement an interface#' - path: tests/PHPUnit + path: tests - message: '#.*caught .* must be rethrown.*#' - path: tests/PHPUnit + path: tests - message: '#Docblock must contain "@package.*#' - path: tests/PHPUnit + path: tests - message: '#Method .* no (value )?type specified.*#' - path: tests/PHPUnit + path: tests - message: '#Method .* should not be public because it doesn''t implement a method on an interface.#' - path: tests/PHPUnit + path: tests - message: '#Method .* throws checked exception .* but it''s missing from the PHPDoc @throws tag.#' - path: tests/PHPUnit + path: tests - message: '#Parameter .* of (static )?(class|method) .* expects .* given.#' - path: tests/PHPUnit + path: tests - message: '#Property .* does not accept .*.#' - path: tests/PHPUnit + path: tests # https://phpstan.org/developing-extensions/extension-types rules: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0bee4e493..21d9630a6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,13 +16,13 @@ > - tests/PHPUnit + tests - tests/PHPUnit + tests - tests/PHPUnit + tests diff --git a/rector.php b/rector.php index dd0d5c5cf..03c34d609 100644 --- a/rector.php +++ b/rector.php @@ -21,7 +21,7 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/src', - __DIR__ . '/tests/PHPUnit', + __DIR__ . '/tests', ]); $rectorConfig->cacheClass(MemoryCacheStorage::class); @@ -46,7 +46,7 @@ MixedTypeRector::class => [__DIR__], NewlineAfterStatementRector::class => [__DIR__], NewlineBeforeNewAssignSetRector::class => [__DIR__], - NullToStrictStringFuncCallArgRector::class => [__DIR__ . '/tests/PHPUnit/TestUtils/AssertTrait.php'], + NullToStrictStringFuncCallArgRector::class => [__DIR__ . '/tests/TestUtils/AssertTrait.php'], RemoveUselessParamTagRector::class => [__DIR__], // This one has a bug: https://github.com/rectorphp/rector-src/pull/4480 RemoveUselessReturnTagRector::class => [__DIR__], // This one has a bug: https://github.com/rectorphp/rector-src/pull/4482 UnSpreadOperatorRector::class => [__DIR__], diff --git a/tests/PHPUnit/Core/BeginnerUnitTest.php b/tests/Core/BeginnerUnitTest.php similarity index 100% rename from tests/PHPUnit/Core/BeginnerUnitTest.php rename to tests/Core/BeginnerUnitTest.php diff --git a/tests/PHPUnit/Core/CleanerUnitTest.php b/tests/Core/CleanerUnitTest.php similarity index 100% rename from tests/PHPUnit/Core/CleanerUnitTest.php rename to tests/Core/CleanerUnitTest.php diff --git a/tests/PHPUnit/Core/CommitterUnitTest.php b/tests/Core/CommitterUnitTest.php similarity index 100% rename from tests/PHPUnit/Core/CommitterUnitTest.php rename to tests/Core/CommitterUnitTest.php diff --git a/tests/PHPUnit/Core/StagerUnitTest.php b/tests/Core/StagerUnitTest.php similarity index 100% rename from tests/PHPUnit/Core/StagerUnitTest.php rename to tests/Core/StagerUnitTest.php diff --git a/tests/PHPUnit/EndToEnd/EndToEndFunctionalTestCase.php b/tests/EndToEnd/EndToEndFunctionalTestCase.php similarity index 100% rename from tests/PHPUnit/EndToEnd/EndToEndFunctionalTestCase.php rename to tests/EndToEnd/EndToEndFunctionalTestCase.php diff --git a/tests/PHPUnit/EndToEnd/PhpFileSyncerEndToEndFunctionalTest.php b/tests/EndToEnd/PhpFileSyncerEndToEndFunctionalTest.php similarity index 100% rename from tests/PHPUnit/EndToEnd/PhpFileSyncerEndToEndFunctionalTest.php rename to tests/EndToEnd/PhpFileSyncerEndToEndFunctionalTest.php diff --git a/tests/PHPUnit/EndToEnd/RsyncFileSyncerEndToEndFunctionalTest.php b/tests/EndToEnd/RsyncFileSyncerEndToEndFunctionalTest.php similarity index 100% rename from tests/PHPUnit/EndToEnd/RsyncFileSyncerEndToEndFunctionalTest.php rename to tests/EndToEnd/RsyncFileSyncerEndToEndFunctionalTest.php diff --git a/tests/PHPUnit/Exception/ExceptionUnitTest.php b/tests/Exception/ExceptionUnitTest.php similarity index 100% rename from tests/PHPUnit/Exception/ExceptionUnitTest.php rename to tests/Exception/ExceptionUnitTest.php diff --git a/tests/PHPUnit/Exception/PreconditionExceptionUnitTest.php b/tests/Exception/PreconditionExceptionUnitTest.php similarity index 100% rename from tests/PHPUnit/Exception/PreconditionExceptionUnitTest.php rename to tests/Exception/PreconditionExceptionUnitTest.php diff --git a/tests/PHPUnit/Exception/TranslatableExceptionTraitUnitTest.php b/tests/Exception/TranslatableExceptionTraitUnitTest.php similarity index 100% rename from tests/PHPUnit/Exception/TranslatableExceptionTraitUnitTest.php rename to tests/Exception/TranslatableExceptionTraitUnitTest.php diff --git a/tests/PHPUnit/Exploratory/ExploratoryTestTemplate.php b/tests/Exploratory/ExploratoryTestTemplate.php similarity index 100% rename from tests/PHPUnit/Exploratory/ExploratoryTestTemplate.php rename to tests/Exploratory/ExploratoryTestTemplate.php diff --git a/tests/PHPUnit/FileSyncer/Factory/FileSyncerFactoryUnitTest.php b/tests/FileSyncer/Factory/FileSyncerFactoryUnitTest.php similarity index 100% rename from tests/PHPUnit/FileSyncer/Factory/FileSyncerFactoryUnitTest.php rename to tests/FileSyncer/Factory/FileSyncerFactoryUnitTest.php diff --git a/tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php similarity index 100% rename from tests/PHPUnit/FileSyncer/Service/FileSyncerFunctionalTestCase.php rename to tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php diff --git a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerFunctionalTest.php b/tests/FileSyncer/Service/PhpFileSyncerFunctionalTest.php similarity index 100% rename from tests/PHPUnit/FileSyncer/Service/PhpFileSyncerFunctionalTest.php rename to tests/FileSyncer/Service/PhpFileSyncerFunctionalTest.php diff --git a/tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php similarity index 100% rename from tests/PHPUnit/FileSyncer/Service/PhpFileSyncerUnitTest.php rename to tests/FileSyncer/Service/PhpFileSyncerUnitTest.php diff --git a/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerFunctionalTest.php b/tests/FileSyncer/Service/RsyncFileSyncerFunctionalTest.php similarity index 100% rename from tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerFunctionalTest.php rename to tests/FileSyncer/Service/RsyncFileSyncerFunctionalTest.php diff --git a/tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php b/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php similarity index 100% rename from tests/PHPUnit/FileSyncer/Service/RsyncFileSyncerUnitTest.php rename to tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php diff --git a/tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php b/tests/Filesystem/Service/FilesystemFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Filesystem/Service/FilesystemFunctionalTest.php rename to tests/Filesystem/Service/FilesystemFunctionalTest.php diff --git a/tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php b/tests/Filesystem/Service/FilesystemUnitTest.php similarity index 100% rename from tests/PHPUnit/Filesystem/Service/FilesystemUnitTest.php rename to tests/Filesystem/Service/FilesystemUnitTest.php diff --git a/tests/PHPUnit/Finder/Service/ExecutableFinderUnitTest.php b/tests/Finder/Service/ExecutableFinderUnitTest.php similarity index 100% rename from tests/PHPUnit/Finder/Service/ExecutableFinderUnitTest.php rename to tests/Finder/Service/ExecutableFinderUnitTest.php diff --git a/tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php b/tests/Finder/Service/FileFinderFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Finder/Service/FileFinderFunctionalTest.php rename to tests/Finder/Service/FileFinderFunctionalTest.php diff --git a/tests/PHPUnit/Helper/PathHelperUnitTest.php b/tests/Helper/PathHelperUnitTest.php similarity index 100% rename from tests/PHPUnit/Helper/PathHelperUnitTest.php rename to tests/Helper/PathHelperUnitTest.php diff --git a/tests/PHPUnit/Host/Service/HostUnitTest.php b/tests/Host/Service/HostUnitTest.php similarity index 100% rename from tests/PHPUnit/Host/Service/HostUnitTest.php rename to tests/Host/Service/HostUnitTest.php diff --git a/tests/PHPUnit/Host/Service/TestHost.php b/tests/Host/Service/TestHost.php similarity index 100% rename from tests/PHPUnit/Host/Service/TestHost.php rename to tests/Host/Service/TestHost.php diff --git a/tests/PHPUnit/Path/Factory/PathFactoryUnitTest.php b/tests/Path/Factory/PathFactoryUnitTest.php similarity index 100% rename from tests/PHPUnit/Path/Factory/PathFactoryUnitTest.php rename to tests/Path/Factory/PathFactoryUnitTest.php diff --git a/tests/PHPUnit/Path/Factory/PathListFactoryUnitTest.php b/tests/Path/Factory/PathListFactoryUnitTest.php similarity index 100% rename from tests/PHPUnit/Path/Factory/PathListFactoryUnitTest.php rename to tests/Path/Factory/PathListFactoryUnitTest.php diff --git a/tests/PHPUnit/Path/Value/PathListUnitTest.php b/tests/Path/Value/PathListUnitTest.php similarity index 100% rename from tests/PHPUnit/Path/Value/PathListUnitTest.php rename to tests/Path/Value/PathListUnitTest.php diff --git a/tests/PHPUnit/Path/Value/PathUnitTestCase.php b/tests/Path/Value/PathUnitTestCase.php similarity index 100% rename from tests/PHPUnit/Path/Value/PathUnitTestCase.php rename to tests/Path/Value/PathUnitTestCase.php diff --git a/tests/PHPUnit/Path/Value/TestPath.php b/tests/Path/Value/TestPath.php similarity index 100% rename from tests/PHPUnit/Path/Value/TestPath.php rename to tests/Path/Value/TestPath.php diff --git a/tests/PHPUnit/Path/Value/TestPathList.php b/tests/Path/Value/TestPathList.php similarity index 100% rename from tests/PHPUnit/Path/Value/TestPathList.php rename to tests/Path/Value/TestPathList.php diff --git a/tests/PHPUnit/Path/Value/UnixLikePathUnitTest.php b/tests/Path/Value/UnixLikePathUnitTest.php similarity index 100% rename from tests/PHPUnit/Path/Value/UnixLikePathUnitTest.php rename to tests/Path/Value/UnixLikePathUnitTest.php diff --git a/tests/PHPUnit/Path/Value/WindowsPathUnitTest.php b/tests/Path/Value/WindowsPathUnitTest.php similarity index 100% rename from tests/PHPUnit/Path/Value/WindowsPathUnitTest.php rename to tests/Path/Value/WindowsPathUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php b/tests/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php rename to tests/Precondition/Service/AbstractFileIteratingPreconditionUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/AbstractPreconditionUnitTest.php b/tests/Precondition/Service/AbstractPreconditionUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/AbstractPreconditionUnitTest.php rename to tests/Precondition/Service/AbstractPreconditionUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/AbstractPreconditionsTreeUnitTest.php b/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/AbstractPreconditionsTreeUnitTest.php rename to tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php b/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php rename to tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/ActiveDirExistsUnitTest.php b/tests/Precondition/Service/ActiveDirExistsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/ActiveDirExistsUnitTest.php rename to tests/Precondition/Service/ActiveDirExistsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/ActiveDirIsReadyUnitTest.php b/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/ActiveDirIsReadyUnitTest.php rename to tests/Precondition/Service/ActiveDirIsReadyUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/ActiveDirIsWritableUnitTest.php b/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/ActiveDirIsWritableUnitTest.php rename to tests/Precondition/Service/ActiveDirIsWritableUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/BeginnerPreconditionsUnitTest.php b/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/BeginnerPreconditionsUnitTest.php rename to tests/Precondition/Service/BeginnerPreconditionsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/CleanerPreconditionsUnitTest.php b/tests/Precondition/Service/CleanerPreconditionsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/CleanerPreconditionsUnitTest.php rename to tests/Precondition/Service/CleanerPreconditionsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/CommitterPreconditionsUnitTest.php b/tests/Precondition/Service/CommitterPreconditionsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/CommitterPreconditionsUnitTest.php rename to tests/Precondition/Service/CommitterPreconditionsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/CommonPreconditionsUnitTest.php b/tests/Precondition/Service/CommonPreconditionsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/CommonPreconditionsUnitTest.php rename to tests/Precondition/Service/CommonPreconditionsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php b/tests/Precondition/Service/ComposerIsAvailableFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/ComposerIsAvailableFunctionalTest.php rename to tests/Precondition/Service/ComposerIsAvailableFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/ComposerIsAvailableUnitTest.php b/tests/Precondition/Service/ComposerIsAvailableUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/ComposerIsAvailableUnitTest.php rename to tests/Precondition/Service/ComposerIsAvailableUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php b/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/FileIteratingPreconditionUnitTestCase.php rename to tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php diff --git a/tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php b/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php rename to tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesUnitTest.php b/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/HostSupportsRunningProcessesUnitTest.php rename to tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/Precondition/Service/LinkPreconditionsFunctionalTestCase.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/LinkPreconditionsFunctionalTestCase.php rename to tests/Precondition/Service/LinkPreconditionsFunctionalTestCase.php diff --git a/tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php b/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php rename to tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php rename to tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php b/tests/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php rename to tests/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoHardLinksExistFunctionalTest.php rename to tests/Precondition/Service/NoHardLinksExistFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoHardLinksExistUnitTest.php b/tests/Precondition/Service/NoHardLinksExistUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoHardLinksExistUnitTest.php rename to tests/Precondition/Service/NoHardLinksExistUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php rename to tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsUnitTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoLinksExistOnWindowsUnitTest.php rename to tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php rename to tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php rename to tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php rename to tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php b/tests/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php rename to tests/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/NoUnsupportedLinksExistUnitTest.php b/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/NoUnsupportedLinksExistUnitTest.php rename to tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/PreconditionTestCase.php b/tests/Precondition/Service/PreconditionTestCase.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/PreconditionTestCase.php rename to tests/Precondition/Service/PreconditionTestCase.php diff --git a/tests/PHPUnit/Precondition/Service/StagerPreconditionsUnitTest.php b/tests/Precondition/Service/StagerPreconditionsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/StagerPreconditionsUnitTest.php rename to tests/Precondition/Service/StagerPreconditionsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/StagingDirDoesNotExistUnitTest.php b/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/StagingDirDoesNotExistUnitTest.php rename to tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php b/tests/Precondition/Service/StagingDirExistsUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/StagingDirExistsUnitTest.php rename to tests/Precondition/Service/StagingDirExistsUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/StagingDirIsReadyUnitTest.php b/tests/Precondition/Service/StagingDirIsReadyUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/StagingDirIsReadyUnitTest.php rename to tests/Precondition/Service/StagingDirIsReadyUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/StagingDirIsWritableUnitTest.php b/tests/Precondition/Service/StagingDirIsWritableUnitTest.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/StagingDirIsWritableUnitTest.php rename to tests/Precondition/Service/StagingDirIsWritableUnitTest.php diff --git a/tests/PHPUnit/Precondition/Service/TestPrecondition.php b/tests/Precondition/Service/TestPrecondition.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/TestPrecondition.php rename to tests/Precondition/Service/TestPrecondition.php diff --git a/tests/PHPUnit/Precondition/Service/TestPreconditionsTree.php b/tests/Precondition/Service/TestPreconditionsTree.php similarity index 100% rename from tests/PHPUnit/Precondition/Service/TestPreconditionsTree.php rename to tests/Precondition/Service/TestPreconditionsTree.php diff --git a/tests/PHPUnit/Process/Factory/ProcessFactoryUnitTest.php b/tests/Process/Factory/ProcessFactoryUnitTest.php similarity index 100% rename from tests/PHPUnit/Process/Factory/ProcessFactoryUnitTest.php rename to tests/Process/Factory/ProcessFactoryUnitTest.php diff --git a/tests/PHPUnit/Process/Factory/SymfonyProcessFactoryUnitTest.php b/tests/Process/Factory/SymfonyProcessFactoryUnitTest.php similarity index 100% rename from tests/PHPUnit/Process/Factory/SymfonyProcessFactoryUnitTest.php rename to tests/Process/Factory/SymfonyProcessFactoryUnitTest.php diff --git a/tests/PHPUnit/Process/Service/AbstractProcessRunnerUnitTest.php b/tests/Process/Service/AbstractProcessRunnerUnitTest.php similarity index 100% rename from tests/PHPUnit/Process/Service/AbstractProcessRunnerUnitTest.php rename to tests/Process/Service/AbstractProcessRunnerUnitTest.php diff --git a/tests/PHPUnit/Process/Service/OutputCallbackAdapterUnitTest.php b/tests/Process/Service/OutputCallbackAdapterUnitTest.php similarity index 100% rename from tests/PHPUnit/Process/Service/OutputCallbackAdapterUnitTest.php rename to tests/Process/Service/OutputCallbackAdapterUnitTest.php diff --git a/tests/PHPUnit/Process/Service/ProcessFunctionalTest.php b/tests/Process/Service/ProcessFunctionalTest.php similarity index 100% rename from tests/PHPUnit/Process/Service/ProcessFunctionalTest.php rename to tests/Process/Service/ProcessFunctionalTest.php diff --git a/tests/PHPUnit/Process/Service/ProcessUnitTest.php b/tests/Process/Service/ProcessUnitTest.php similarity index 100% rename from tests/PHPUnit/Process/Service/ProcessUnitTest.php rename to tests/Process/Service/ProcessUnitTest.php diff --git a/tests/PHPUnit/Process/Service/TestOutputCallback.php b/tests/Process/Service/TestOutputCallback.php similarity index 100% rename from tests/PHPUnit/Process/Service/TestOutputCallback.php rename to tests/Process/Service/TestOutputCallback.php diff --git a/tests/PHPUnit/Process/Service/TestSymfonyProcess.php b/tests/Process/Service/TestSymfonyProcess.php similarity index 100% rename from tests/PHPUnit/Process/Service/TestSymfonyProcess.php rename to tests/Process/Service/TestSymfonyProcess.php diff --git a/tests/PHPUnit/TestCase.php b/tests/TestCase.php similarity index 100% rename from tests/PHPUnit/TestCase.php rename to tests/TestCase.php diff --git a/tests/PHPUnit/TestUtils/AssertTrait.php b/tests/TestUtils/AssertTrait.php similarity index 100% rename from tests/PHPUnit/TestUtils/AssertTrait.php rename to tests/TestUtils/AssertTrait.php diff --git a/tests/PHPUnit/TestUtils/Domain.php b/tests/TestUtils/Domain.php similarity index 100% rename from tests/PHPUnit/TestUtils/Domain.php rename to tests/TestUtils/Domain.php diff --git a/tests/PHPUnit/TestUtils/FilesystemHelper.php b/tests/TestUtils/FilesystemHelper.php similarity index 100% rename from tests/PHPUnit/TestUtils/FilesystemHelper.php rename to tests/TestUtils/FilesystemHelper.php diff --git a/tests/PHPUnit/TestUtils/PathHelper.php b/tests/TestUtils/PathHelper.php similarity index 98% rename from tests/PHPUnit/TestUtils/PathHelper.php rename to tests/TestUtils/PathHelper.php index 0f9e02a5e..da5de319a 100644 --- a/tests/PHPUnit/TestUtils/PathHelper.php +++ b/tests/TestUtils/PathHelper.php @@ -17,7 +17,7 @@ final class PathHelper public static function repositoryRootAbsolute(): string { - return dirname(__DIR__, 3); + return dirname(__DIR__, 2); } public static function testEnvAbsolute(): string diff --git a/tests/PHPUnit/TestUtils/ProcessHelper.php b/tests/TestUtils/ProcessHelper.php similarity index 100% rename from tests/PHPUnit/TestUtils/ProcessHelper.php rename to tests/TestUtils/ProcessHelper.php diff --git a/tests/PHPUnit/TestUtils/TestSpyInterface.php b/tests/TestUtils/TestSpyInterface.php similarity index 100% rename from tests/PHPUnit/TestUtils/TestSpyInterface.php rename to tests/TestUtils/TestSpyInterface.php diff --git a/tests/PHPUnit/TestUtils/TestStringable.php b/tests/TestUtils/TestStringable.php similarity index 100% rename from tests/PHPUnit/TestUtils/TestStringable.php rename to tests/TestUtils/TestStringable.php diff --git a/tests/PHPUnit/TestUtils/TranslationHelper.php b/tests/TestUtils/TranslationHelper.php similarity index 100% rename from tests/PHPUnit/TestUtils/TranslationHelper.php rename to tests/TestUtils/TranslationHelper.php diff --git a/tests/PHPUnit/Translation/Factory/TestTranslatableFactory.php b/tests/Translation/Factory/TestTranslatableFactory.php similarity index 100% rename from tests/PHPUnit/Translation/Factory/TestTranslatableFactory.php rename to tests/Translation/Factory/TestTranslatableFactory.php diff --git a/tests/PHPUnit/Translation/Factory/TestTranslationParameters.php b/tests/Translation/Factory/TestTranslationParameters.php similarity index 100% rename from tests/PHPUnit/Translation/Factory/TestTranslationParameters.php rename to tests/Translation/Factory/TestTranslationParameters.php diff --git a/tests/PHPUnit/Translation/Factory/TranslatableAwareTraitUnitTest.php b/tests/Translation/Factory/TranslatableAwareTraitUnitTest.php similarity index 100% rename from tests/PHPUnit/Translation/Factory/TranslatableAwareTraitUnitTest.php rename to tests/Translation/Factory/TranslatableAwareTraitUnitTest.php diff --git a/tests/PHPUnit/Translation/Factory/TranslatableFactoryUnitTest.php b/tests/Translation/Factory/TranslatableFactoryUnitTest.php similarity index 100% rename from tests/PHPUnit/Translation/Factory/TranslatableFactoryUnitTest.php rename to tests/Translation/Factory/TranslatableFactoryUnitTest.php diff --git a/tests/PHPUnit/Translation/Service/DomainOptionsUnitTest.php b/tests/Translation/Service/DomainOptionsUnitTest.php similarity index 100% rename from tests/PHPUnit/Translation/Service/DomainOptionsUnitTest.php rename to tests/Translation/Service/DomainOptionsUnitTest.php diff --git a/tests/PHPUnit/Translation/Service/LocaleOptionsUnitTest.php b/tests/Translation/Service/LocaleOptionsUnitTest.php similarity index 100% rename from tests/PHPUnit/Translation/Service/LocaleOptionsUnitTest.php rename to tests/Translation/Service/LocaleOptionsUnitTest.php diff --git a/tests/PHPUnit/Translation/Service/SymfonyTranslatorProxyTest.php b/tests/Translation/Service/SymfonyTranslatorProxyTest.php similarity index 100% rename from tests/PHPUnit/Translation/Service/SymfonyTranslatorProxyTest.php rename to tests/Translation/Service/SymfonyTranslatorProxyTest.php diff --git a/tests/PHPUnit/Translation/Service/TestDomainOptions.php b/tests/Translation/Service/TestDomainOptions.php similarity index 100% rename from tests/PHPUnit/Translation/Service/TestDomainOptions.php rename to tests/Translation/Service/TestDomainOptions.php diff --git a/tests/PHPUnit/Translation/Service/TestLocaleOptions.php b/tests/Translation/Service/TestLocaleOptions.php similarity index 100% rename from tests/PHPUnit/Translation/Service/TestLocaleOptions.php rename to tests/Translation/Service/TestLocaleOptions.php diff --git a/tests/PHPUnit/Translation/Service/TestTranslator.php b/tests/Translation/Service/TestTranslator.php similarity index 100% rename from tests/PHPUnit/Translation/Service/TestTranslator.php rename to tests/Translation/Service/TestTranslator.php diff --git a/tests/PHPUnit/Translation/Service/TranslatorUnitTest.php b/tests/Translation/Service/TranslatorUnitTest.php similarity index 100% rename from tests/PHPUnit/Translation/Service/TranslatorUnitTest.php rename to tests/Translation/Service/TranslatorUnitTest.php diff --git a/tests/PHPUnit/Translation/Value/TestTranslatableExceptionMessage.php b/tests/Translation/Value/TestTranslatableExceptionMessage.php similarity index 100% rename from tests/PHPUnit/Translation/Value/TestTranslatableExceptionMessage.php rename to tests/Translation/Value/TestTranslatableExceptionMessage.php diff --git a/tests/PHPUnit/Translation/Value/TestTranslatableMessage.php b/tests/Translation/Value/TestTranslatableMessage.php similarity index 100% rename from tests/PHPUnit/Translation/Value/TestTranslatableMessage.php rename to tests/Translation/Value/TestTranslatableMessage.php diff --git a/tests/PHPUnit/Translation/Value/TestTranslationParameters.php b/tests/Translation/Value/TestTranslationParameters.php similarity index 100% rename from tests/PHPUnit/Translation/Value/TestTranslationParameters.php rename to tests/Translation/Value/TestTranslationParameters.php diff --git a/tests/PHPUnit/Translation/Value/TranslatableMessageUnitTest.php b/tests/Translation/Value/TranslatableMessageUnitTest.php similarity index 100% rename from tests/PHPUnit/Translation/Value/TranslatableMessageUnitTest.php rename to tests/Translation/Value/TranslatableMessageUnitTest.php diff --git a/tests/PHPUnit/Translation/Value/TranslatableReflection.php b/tests/Translation/Value/TranslatableReflection.php similarity index 100% rename from tests/PHPUnit/Translation/Value/TranslatableReflection.php rename to tests/Translation/Value/TranslatableReflection.php diff --git a/tests/PHPUnit/Translation/Value/TranslationParametersUnitTest.php b/tests/Translation/Value/TranslationParametersUnitTest.php similarity index 100% rename from tests/PHPUnit/Translation/Value/TranslationParametersUnitTest.php rename to tests/Translation/Value/TranslationParametersUnitTest.php From 06a1475b93a443fe83c1fe9b275fe800610a16df Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Sat, 12 Aug 2023 02:19:22 -0400 Subject: [PATCH 21/75] Add support for Windows directory separators to Internal\FileSyncer\Service\RsyncFileSyncer. --- .../FileSyncer/Service/RsyncFileSyncer.php | 4 ++ .../Service/RsyncFileSyncerUnitTest.php | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php index 90e62565d..446171bd1 100644 --- a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php +++ b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php @@ -13,6 +13,7 @@ use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Process\Service\RsyncProcessRunnerInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; +use PhpTuf\ComposerStager\Internal\Helper\PathHelper; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait; @@ -92,6 +93,9 @@ private function runCommand( PathInterface $destination, ?OutputCallbackInterface $callback, ): void { + $sourceAbsolute = PathHelper::canonicalize($sourceAbsolute); + $destinationAbsolute = PathHelper::canonicalize($destinationAbsolute); + $this->ensureDestinationDirectoryExists($destination); $command = $this->buildCommand($exclusions, $sourceAbsolute, $destinationAbsolute); diff --git a/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php b/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php index 86f6de948..243cc04e3 100644 --- a/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php +++ b/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php @@ -143,6 +143,27 @@ public function providerSync(): array ], 'callback' => null, ], + 'Siblings: Windows directory separators' => [ + 'source' => 'source/one\\two', + 'destination' => 'destination\\one/two', + 'exclusions' => new PathList(...[ + 'three\\four', + 'five/six/seven/eight', + 'five/six/seven/eight', + 'five\\six/seven\\eight', + 'five/six\\seven/eight', + ]), + 'command' => [ + '--archive', + '--delete-after', + '--verbose', + '--exclude=/three/four', + '--exclude=/five/six/seven/eight', + 'source/one/two/', + 'destination/one/two', + ], + 'callback' => null, + ], 'Nested: destination inside source (neither is excluded)' => [ 'source' => 'source', 'destination' => 'source/destination', @@ -164,7 +185,22 @@ public function providerSync(): array '--archive', '--delete-after', '--verbose', - // This is the only case where the source directory needs to be excluded. + // "Source inside destination" is the only case where the source directory needs to be excluded. + '--exclude=/source', + 'destination/source/', + 'destination', + ], + 'callback' => null, + ], + 'Nested: with Windows directory separators' => [ + 'source' => 'destination\\source', + 'destination' => 'destination', + 'exclusions' => null, + 'command' => [ + '--archive', + '--delete-after', + '--verbose', + // "Source inside destination" is the only case where the source directory needs to be excluded. '--exclude=/source', 'destination/source/', 'destination', From 7c242b098f2c3f680243e2134ee9d157abd2d1cb Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Sat, 12 Aug 2023 02:46:54 -0400 Subject: [PATCH 22/75] Fix Sniffs\Namespaces\APILayerDependsOnOtherLayerSniff. --- .../APILayerDependsOnOtherLayerSniff.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php b/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php index 2e0d8d479..f38248503 100644 --- a/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php +++ b/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php @@ -52,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr): void $phpcsFile->addError( sprintf( 'API-layer class %s must not depend on non-API-layer class %s.', - $namespace, + $this->getClass($phpcsFile), $namespace, ), $stackPtr, @@ -86,7 +86,7 @@ private function isScopeLevelNamespace(File $phpcsFile, int $stackPtr): bool private function isAPILayerNamespace(string $namespace): bool { - return str_starts_with($namespace, 'PhpTuf\\ComposerStager'); + return str_starts_with($namespace, 'PhpTuf\\ComposerStager\\API'); } private function isExcluded(string $namespace): bool @@ -102,4 +102,26 @@ private function namespaceIsInAPILayer(File $phpcsFile, int $stackPtr): bool return $asKeywordPtr !== false; } + + private function getClass(File $phpcsFile): string + { + return $this->getClassNamespace($phpcsFile) . '\\' . $this->getClassName($phpcsFile); + } + + private function getClassNamespace(File $phpcsFile): string + { + $namespaceTokenPtr = $phpcsFile->findNext(T_NAMESPACE, 0); + $namespacePtr = $phpcsFile->findNext(T_STRING, $namespaceTokenPtr); + + return $this->getNamespace($phpcsFile, $namespacePtr); + } + + private function getClassName(File $phpcsFile): mixed + { + $tokens = $phpcsFile->getTokens(); + $scopeTokenPtr = $phpcsFile->findNext(Tokens::$ooScopeTokens, 0); + $classNamePtr = $phpcsFile->findNext(T_STRING, $scopeTokenPtr); + + return $tokens[$classNamePtr]['content']; + } } From ae209863fb6fd761d4369eda53bab5e2601d6e5c Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Sat, 12 Aug 2023 03:26:15 -0400 Subject: [PATCH 23/75] Add Sniffs\Namespaces\InternalLayerDependsOnNonProductionCodeSniff. --- ...alLayerDependsOnNonProductionCodeSniff.php | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php diff --git a/tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php b/tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php new file mode 100644 index 000000000..bfa30c366 --- /dev/null +++ b/tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php @@ -0,0 +1,111 @@ +isInternalFile($phpcsFile)) { + return; + } + + $namespace = $this->getNamespace($phpcsFile, $stackPtr); + + // Not a scope-level namespace, e.g., a class or interface. + // (It's probably an anonymous function declaration.) + if (!$this->isScopeLevelNamespace($phpcsFile, $stackPtr)) { + return; + } + + // The namespace is non-production code. + if (!$this->isNonProductionCode($namespace)) { + return; + } + + $phpcsFile->addError( + sprintf( + 'Internal-layer class %s must not depend on non-production class %s.', + $this->getClass($phpcsFile), + $namespace, + ), + $stackPtr, + self::CODE_DEPENDS_ON_NON_API_LAYER, + ); + } + + private function isInternalFile(File $phpcsFile): bool + { + $srcDir = dirname(__DIR__, 4) . '/src/Internal'; + + return str_starts_with((string) $phpcsFile->getFilename(), $srcDir); + } + + private function getNamespace(File $phpcsFile, int $scopePtr): string + { + $endOfNamespaceDeclaration = NamespaceHelper::getEndOfNamespaceDeclaration($phpcsFile, $scopePtr); + + return NamespaceHelper::getDeclarationNameWithNamespace( + $phpcsFile->getTokens(), + $endOfNamespaceDeclaration - 1, + ); + } + + private function isScopeLevelNamespace(File $phpcsFile, int $stackPtr): bool + { + $scopePtr = $phpcsFile->findNext(Tokens::$ooScopeTokens, $stackPtr); + + return $scopePtr !== false; + } + + private function isNonProductionCode(string $namespace): bool + { + // Namespace is in Composer Stager itself. + if (!str_starts_with($namespace, 'PhpTuf\\ComposerStager')) { + return false; + } + + // Namespace is not in either production layer. + return + !str_starts_with($namespace, 'PhpTuf\\ComposerStager\\API') + && !str_starts_with($namespace, 'PhpTuf\\ComposerStager\\Internal') + ; + } + + private function getClass(File $phpcsFile): string + { + return $this->getClassNamespace($phpcsFile) . '\\' . $this->getClassName($phpcsFile); + } + + private function getClassNamespace(File $phpcsFile): string + { + $namespaceTokenPtr = $phpcsFile->findNext(T_NAMESPACE, 0); + $namespacePtr = $phpcsFile->findNext(T_STRING, $namespaceTokenPtr); + + return $this->getNamespace($phpcsFile, $namespacePtr); + } + + private function getClassName(File $phpcsFile): mixed + { + $tokens = $phpcsFile->getTokens(); + $scopeTokenPtr = $phpcsFile->findNext(Tokens::$ooScopeTokens, 0); + $classNamePtr = $phpcsFile->findNext(T_STRING, $scopeTokenPtr); + + return $tokens[$classNamePtr]['content']; + } +} From 9c231442c0070ade5f6001b515908140b1f1259c Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 14 Aug 2023 05:43:46 -0400 Subject: [PATCH 24/75] Create Tests\TestUtils\FilesystemHelper::touch(). --- .../Service/FileSyncerFunctionalTestCase.php | 2 +- .../Service/FilesystemFunctionalTest.php | 11 +++++----- ...nkPreconditionsIsolationFunctionalTest.php | 4 ++-- .../NoAbsoluteSymlinksExistFunctionalTest.php | 7 ++++--- .../NoHardLinksExistFunctionalTest.php | 5 +++-- .../NoLinksExistOnWindowsFunctionalTest.php | 3 ++- ...sPointOutsideTheCodebaseFunctionalTest.php | 12 +++++------ ...ymlinksPointToADirectoryFunctionalTest.php | 5 ++--- tests/TestCase.php | 13 ++---------- tests/TestUtils/FilesystemHelper.php | 21 +++++++++++++++++++ 10 files changed, 48 insertions(+), 35 deletions(-) diff --git a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php index 2850b4e94..0d67c3b44 100644 --- a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -70,7 +70,7 @@ public function testSyncWithDirectorySymlinks(): void $target = PathHelper::makeAbsolute('directory', PathHelper::sourceDirAbsolute()); FilesystemHelper::createDirectories($target); $file = PathHelper::makeAbsolute('directory/file.txt', PathHelper::sourceDirAbsolute()); - touch($file); + FilesystemHelper::touch($file); symlink($target, $link); $sut = $this->createSut(); diff --git a/tests/Filesystem/Service/FilesystemFunctionalTest.php b/tests/Filesystem/Service/FilesystemFunctionalTest.php index d3424bc71..3ff90c0aa 100644 --- a/tests/Filesystem/Service/FilesystemFunctionalTest.php +++ b/tests/Filesystem/Service/FilesystemFunctionalTest.php @@ -43,7 +43,7 @@ public function testCopy(): void $filenameRelative = 'file.txt'; $sourceFilePath = PathHelper::createPath($filenameRelative, PathHelper::sourceDirAbsolute()); $destinationFilePath = PathHelper::createPath($filenameRelative, PathHelper::destinationDirAbsolute()); - touch($sourceFilePath->absolute()); + FilesystemHelper::touch($sourceFilePath->absolute()); // Copy an individual file. $filesystem = $this->createSut(); @@ -75,7 +75,7 @@ public function testIsDirEmptyFalse(): void public function testIsDirEmptyErrorIsNotADirectory(): void { $filePath = PathHelper::createPath('file.txt', PathHelper::testEnvAbsolute()); - touch($filePath->absolute()); + FilesystemHelper::touch($filePath->absolute()); $message = sprintf( 'The path does not exist or is not a directory at %s', $filePath->absolute(), @@ -246,7 +246,7 @@ public function testReadlink(string $given, string $expectedAbsolute): void $hardLinkPath = PathHelper::createPath('hard_link.txt', $basePath); $targetPath = PathHelper::createPath($given, $basePath); chdir($basePath); - touch($targetPath->absolute()); + FilesystemHelper::touch($targetPath->absolute()); symlink($given, $symlinkPath->absolute()); link($given, $hardLinkPath->absolute()); $sut = $this->createSut(); @@ -285,7 +285,7 @@ public function providerReadlink(): array public function testReadlinkOnNonLink(): void { $file = PathHelper::createPath('file.txt', PathHelper::sourceDirAbsolute()); - touch($file->absolute()); + FilesystemHelper::touch($file->absolute()); assert(file_exists($file->absolute())); $sut = $this->createSut(); @@ -327,8 +327,7 @@ public function testSymfonyCopyDirectory(): void $filename = 'arbitrary_file.txt'; $sourceFile = PathHelper::createPath($filename, PathHelper::sourceDirAbsolute()); $destinationFile = PathHelper::createPath($filename, PathHelper::destinationDirAbsolute()); - touch($sourceFile->absolute()); - assert(file_exists($sourceFile->absolute())); + FilesystemHelper::touch($sourceFile->absolute()); $sut = new SymfonyFilesystem(); diff --git a/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php b/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php index 6e4d42787..64d7d8910 100644 --- a/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php +++ b/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php @@ -96,7 +96,7 @@ public function testNoAbsoluteSymlinksExist(): void { $source = self::path('source.txt'); $target = self::path('target.txt'); - touch($target); + FilesystemHelper::touch($target); symlink($target, $source); $this->assertPreconditionIsIsolated(NoAbsoluteSymlinksExist::class); @@ -107,7 +107,7 @@ public function testNoLinksExistOnWindows(): void { $source = self::path('source.txt'); $target = self::path('target.txt'); - touch($target); + FilesystemHelper::touch($target); symlink($target, $source); $container = $this->container(); diff --git a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index 3a6728772..080fa57ce 100644 --- a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -5,6 +5,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; +use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** @@ -81,7 +82,7 @@ public function testAbsoluteLinksExist(string $dirName, string $basePath, string $targetAbsolute = PathHelper::makeAbsolute($targetRelative, $basePath); $parentDir = dirname($linkAbsolute); @mkdir($parentDir, 0777, true); - touch($targetAbsolute); + FilesystemHelper::touch($targetAbsolute); // Point at the absolute target path. symlink($targetAbsolute, $linkAbsolute); $sut = $this->createSut(); @@ -113,7 +114,7 @@ public function testOnlyRelativeLinksExist(string $dirName, string $basePath, st $targetAbsolute = PathHelper::makeAbsolute($targetRelative, $basePath); $parentDirAbsolute = dirname($linkAbsolute); @mkdir($parentDirAbsolute, 0777, true); - touch($targetAbsolute); + FilesystemHelper::touch($targetAbsolute); chdir($parentDirAbsolute); // Point at the relative target path. symlink($targetRelative, $linkAbsolute); @@ -181,7 +182,7 @@ public function testWithHardLink(): void $target = PathHelper::makeAbsolute('target.txt', PathHelper::activeDirAbsolute()); $parentDir = dirname($link); @mkdir($parentDir, 0777, true); - touch($target); + FilesystemHelper::touch($target); link($target, $link); $sut = $this->createSut(); diff --git a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php index 7807fbd3f..1b5cc26c8 100644 --- a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; +use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use Symfony\Component\Filesystem\Path; @@ -48,7 +49,7 @@ public function testFulfilledWithSymlink(): void { $target = Path::makeAbsolute('target.txt', PathHelper::activeDirAbsolute()); $link = Path::makeAbsolute('link.txt', PathHelper::activeDirAbsolute()); - touch($target); + FilesystemHelper::touch($target); symlink($target, $link); $sut = $this->createSut(); @@ -67,7 +68,7 @@ public function testUnfulfilled(string $directory, string $dirName): void { $target = PathHelper::makeAbsolute('target.txt', $directory); $link = PathHelper::makeAbsolute('link.txt', $directory); - touch($target); + FilesystemHelper::touch($target); link($target, $link); $sut = $this->createSut(); diff --git a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php index 55407750a..29315d680 100644 --- a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php +++ b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows; +use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** @@ -58,7 +59,7 @@ public function testUnfulfilled(array $symlinks, array $hardLinks): void $basePathAbsolute = PathHelper::activeDirAbsolute(); $link = PathHelper::makeAbsolute('link.txt', $basePathAbsolute); $target = PathHelper::makeAbsolute('target.txt', $basePathAbsolute); - touch($target); + FilesystemHelper::touch($target); self::createSymlinks($basePathAbsolute, $symlinks); self::createHardlinks($basePathAbsolute, $hardLinks); $sut = $this->createSut(); diff --git a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index dbcb0b8a0..f48252913 100644 --- a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase; +use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** @@ -42,10 +43,9 @@ public function testFulfilledWithValidLink(string $link, string $target): void $stagingDirPath = PathHelper::stagingDirPath(); $link = PathHelper::makeAbsolute($link, $activeDirAbsolute); - self::ensureParentDirectory($link); + FilesystemHelper::ensureParentDirectory($link); $target = PathHelper::makeAbsolute($target, $activeDirAbsolute); - self::ensureParentDirectory($target); - touch($target); + FilesystemHelper::touch($target); symlink($target, $link); $sut = $this->createSut(); @@ -99,7 +99,7 @@ public function testUnfulfilled(string $targetDir, string $linkDir, string $link $target = PathHelper::makeAbsolute('target.txt', $targetDir); $link = PathHelper::makeAbsolute('link.txt', $linkDir); - touch($target); + FilesystemHelper::touch($target); symlink($target, $link); $sut = $this->createSut(); @@ -154,7 +154,7 @@ public function testWithHardLink(): void $target = PathHelper::makeAbsolute('target.txt', $basePathAbsolute); $parentDir = dirname($link); @mkdir($parentDir, 0777, true); - touch($target); + FilesystemHelper::touch($target); link($target, $link); $sut = $this->createSut(); @@ -179,7 +179,7 @@ public function testWithAbsoluteLink(): void $targetAbsolute = PathHelper::makeAbsolute('target.txt', $dirPathAbsolute); $parentDir = dirname($linkAbsolute); @mkdir($parentDir, 0777, true); - touch($targetAbsolute); + FilesystemHelper::touch($targetAbsolute); symlink($targetAbsolute, $linkAbsolute); $sut = $this->createSut(); diff --git a/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index 96eff02e7..a51e8d3f4 100644 --- a/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -46,9 +46,8 @@ public function testFulfilledWithValidLink(): void $parentDir = PathHelper::activeDirAbsolute(); $link = PathHelper::makeAbsolute('link.txt', $parentDir); $target = PathHelper::makeAbsolute('target.txt', $parentDir); - self::ensureParentDirectory($link); - self::ensureParentDirectory($target); - touch($target); + FilesystemHelper::ensureParentDirectory($link); + FilesystemHelper::touch($target); symlink($target, $link); $sut = $this->createSut(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 730c4af99..a587a03ef 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -86,12 +86,9 @@ protected static function createFiles(string $basePath, array $filenames): void protected static function createFile(string $basePath, string $filename): void { $filename = PathHelper::makeAbsolute($filename, $basePath); - static::ensureParentDirectory($filename); - - $touchResult = touch($filename); + FilesystemHelper::touch($filename); $realpathResult = realpath($filename); - assert($touchResult, "Created file {$filename}."); assert($realpathResult !== false, "Got absolute path of {$filename}."); } @@ -146,7 +143,7 @@ protected static function createHardlink(string $basePath, string $link, string private static function prepareForLink(PathInterface $link, PathInterface $target): void { - static::ensureParentDirectory($link->absolute()); + FilesystemHelper::ensureParentDirectory($link->absolute()); // If the symlink target doesn't exist, the tests will pass on Unix-like // systems but fail on Windows. Avoid hard-to-debug problems by making @@ -154,12 +151,6 @@ private static function prepareForLink(PathInterface $link, PathInterface $targe assert(file_exists($target->absolute()), 'Symlink target exists.'); } - protected static function ensureParentDirectory(string $filename): void - { - $dirname = dirname($filename); - FilesystemHelper::createDirectories($dirname); - } - protected static function changeFile(string $dir, string $filename): void { $pathname = self::ensureTrailingSlash($dir) . $filename; diff --git a/tests/TestUtils/FilesystemHelper.php b/tests/TestUtils/FilesystemHelper.php index 0cd6011bd..9d6144756 100644 --- a/tests/TestUtils/FilesystemHelper.php +++ b/tests/TestUtils/FilesystemHelper.php @@ -21,4 +21,25 @@ public static function createDirectories(array|string $directories, ?string $bas (new SymfonyFilesystem())->mkdir($directories); } + + public static function touch(string $path): void + { + assert(PathHelper::isAbsolute($path)); + + self::ensureParentDirectory($path); + self::symfonyFilesystem()->touch($path); + + assert(self::symfonyFilesystem()->exists($path)); + } + + public static function ensureParentDirectory(string $filename): void + { + $dirname = dirname($filename); + self::createDirectories($dirname); + } + + private static function symfonyFilesystem(): SymfonyFilesystem + { + return new SymfonyFilesystem(); + } } From 35cc2b170d64f8fe0fe1714a1003d9931049de86 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 14 Aug 2023 21:24:53 -0400 Subject: [PATCH 25/75] Extract some filesystem test helper functions. --- tests/EndToEnd/EndToEndFunctionalTestCase.php | 9 +++- .../Service/FilesystemFunctionalTest.php | 4 +- .../NoAbsoluteSymlinksExistFunctionalTest.php | 2 +- .../NoHardLinksExistFunctionalTest.php | 2 +- .../NoLinksExistOnWindowsFunctionalTest.php | 6 +-- ...sPointOutsideTheCodebaseFunctionalTest.php | 2 +- ...ymlinksPointToADirectoryFunctionalTest.php | 2 +- tests/TestCase.php | 45 ------------------- tests/TestUtils/FilesystemHelper.php | 45 +++++++++++++++++++ 9 files changed, 61 insertions(+), 56 deletions(-) diff --git a/tests/EndToEnd/EndToEndFunctionalTestCase.php b/tests/EndToEnd/EndToEndFunctionalTestCase.php index 3b7e0e92e..73a81558c 100644 --- a/tests/EndToEnd/EndToEndFunctionalTestCase.php +++ b/tests/EndToEnd/EndToEndFunctionalTestCase.php @@ -15,6 +15,7 @@ use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** @@ -110,7 +111,7 @@ public function testSync(string $activeDir, string $stagingDir): void ]); $arbitrarySymlinkTarget = 'file_in_active_dir_root_NEVER_CHANGED_anywhere.txt'; - self::createSymlinks($activeDirAbsolute, [ + FilesystemHelper::createSymlinks($activeDirAbsolute, [ 'EXCLUDED_symlink_in_active_dir_root.txt' => $arbitrarySymlinkTarget, 'EXCLUDED_dir/symlink_NEVER_CHANGED_anywhere.txt' => $arbitrarySymlinkTarget, ]); @@ -204,7 +205,11 @@ public function testSync(string $activeDir, string $stagingDir): void self::createFile($stagingDirAbsolute, 'another_subdir/CREATE_in_staging_dir.txt'); // Create symlink. - self::createSymlink($stagingDirAbsolute, 'EXCLUDED_dir/symlink_CREATED_in_staging_dir.txt', $arbitrarySymlinkTarget); + FilesystemHelper::createSymlink( + $stagingDirAbsolute, + 'EXCLUDED_dir/symlink_CREATED_in_staging_dir.txt', + $arbitrarySymlinkTarget, + ); // Sanity check to ensure that the expected changes were made. $deletion = array_search('DELETE_from_staging_dir_before_syncing_back_to_active_dir.txt', $expectedStagingDirListing, true); diff --git a/tests/Filesystem/Service/FilesystemFunctionalTest.php b/tests/Filesystem/Service/FilesystemFunctionalTest.php index 3ff90c0aa..0f45db5fd 100644 --- a/tests/Filesystem/Service/FilesystemFunctionalTest.php +++ b/tests/Filesystem/Service/FilesystemFunctionalTest.php @@ -128,8 +128,8 @@ public function testTypeCheckMethods( ): void { self::createFiles(PathHelper::sourceDirAbsolute(), $files); FilesystemHelper::createDirectories($directories, PathHelper::sourceDirAbsolute()); - self::createSymlinks(PathHelper::sourceDirAbsolute(), $symlinks); - self::createHardlinks(PathHelper::sourceDirAbsolute(), $hardLinks); + FilesystemHelper::createSymlinks(PathHelper::sourceDirAbsolute(), $symlinks); + FilesystemHelper::createHardlinks(PathHelper::sourceDirAbsolute(), $hardLinks); $subject = PathHelper::createPath($subject, PathHelper::sourceDirAbsolute()); $sut = $this->createSut(); diff --git a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index 080fa57ce..3468cdb31 100644 --- a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -204,7 +204,7 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s $exclusions = new PathList(...$exclusions); $dirPath = PathHelper::activeDirAbsolute(); self::createFile($dirPath, $targetFile); - self::createSymlinks($dirPath, $links); + FilesystemHelper::createSymlinks($dirPath, $links); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); diff --git a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php index 1b5cc26c8..a0bec6f2a 100644 --- a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -125,7 +125,7 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s $exclusions = new PathList(...$exclusions); $dirPath = PathHelper::activeDirAbsolute(); self::createFile($dirPath, $targetFile); - self::createHardlinks($dirPath, $links); + FilesystemHelper::createHardlinks($dirPath, $links); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); diff --git a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php index 29315d680..8cddee274 100644 --- a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php +++ b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php @@ -60,8 +60,8 @@ public function testUnfulfilled(array $symlinks, array $hardLinks): void $link = PathHelper::makeAbsolute('link.txt', $basePathAbsolute); $target = PathHelper::makeAbsolute('target.txt', $basePathAbsolute); FilesystemHelper::touch($target); - self::createSymlinks($basePathAbsolute, $symlinks); - self::createHardlinks($basePathAbsolute, $hardLinks); + FilesystemHelper::createSymlinks($basePathAbsolute, $symlinks); + FilesystemHelper::createHardlinks($basePathAbsolute, $hardLinks); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath); @@ -118,7 +118,7 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s $exclusions = new PathList(...$exclusions); $basePath = PathHelper::activeDirAbsolute(); self::createFile($basePath, $targetFile); - self::createSymlinks($basePath, $links); + FilesystemHelper::createSymlinks($basePath, $links); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); diff --git a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index f48252913..ac0f23d5c 100644 --- a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -203,7 +203,7 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s $links = array_fill_keys($links, $targetFile); $exclusions = new PathList(...$exclusions); $dirPath = PathHelper::activeDirAbsolute(); - self::createSymlinks($dirPath, $links); + FilesystemHelper::createSymlinks($dirPath, $links); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); diff --git a/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index a51e8d3f4..c925a480d 100644 --- a/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -110,7 +110,7 @@ public function testFulfilledExclusions(array $links, array $exclusions, bool $s FilesystemHelper::createDirectories($targetDirAbsolute); $links = array_fill_keys($links, $targetDirRelative); $exclusions = new PathList(...$exclusions); - self::createSymlinks(PathHelper::activeDirAbsolute(), $links); + FilesystemHelper::createSymlinks(PathHelper::activeDirAbsolute(), $links); $sut = $this->createSut(); $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), $exclusions); diff --git a/tests/TestCase.php b/tests/TestCase.php index a587a03ef..1292af02e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,6 @@ namespace PhpTuf\ComposerStager\Tests; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface; use PhpTuf\ComposerStager\Tests\Precondition\Service\TestPrecondition; @@ -107,50 +106,6 @@ public static function createTestPreconditionException( ); } - protected static function createSymlinks(string $basePath, array $symlinks): void - { - foreach ($symlinks as $link => $target) { - self::createSymlink($basePath, $link, $target); - } - } - - protected static function createSymlink(string $basePath, string $link, string $target): void - { - $link = PathHelper::createPath($link, $basePath); - $target = PathHelper::createPath($target, $basePath); - - self::prepareForLink($link, $target); - - symlink($target->absolute(), $link->absolute()); - } - - protected static function createHardlinks(string $basePath, array $symlinks): void - { - foreach ($symlinks as $link => $target) { - self::createHardlink($basePath, $link, $target); - } - } - - protected static function createHardlink(string $basePath, string $link, string $target): void - { - $link = PathHelper::createPath($link, $basePath); - $target = PathHelper::createPath($target, $basePath); - - self::prepareForLink($link, $target); - - link($target->absolute(), $link->absolute()); - } - - private static function prepareForLink(PathInterface $link, PathInterface $target): void - { - FilesystemHelper::ensureParentDirectory($link->absolute()); - - // If the symlink target doesn't exist, the tests will pass on Unix-like - // systems but fail on Windows. Avoid hard-to-debug problems by making - // sure it fails everywhere in that case. - assert(file_exists($target->absolute()), 'Symlink target exists.'); - } - protected static function changeFile(string $dir, string $filename): void { $pathname = self::ensureTrailingSlash($dir) . $filename; diff --git a/tests/TestUtils/FilesystemHelper.php b/tests/TestUtils/FilesystemHelper.php index 9d6144756..c0cf71c13 100644 --- a/tests/TestUtils/FilesystemHelper.php +++ b/tests/TestUtils/FilesystemHelper.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Tests\TestUtils; +use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; final class FilesystemHelper @@ -42,4 +43,48 @@ private static function symfonyFilesystem(): SymfonyFilesystem { return new SymfonyFilesystem(); } + + public static function createSymlinks(string $basePath, array $symlinks): void + { + foreach ($symlinks as $link => $target) { + self::createSymlink($basePath, $link, $target); + } + } + + public static function createSymlink(string $basePath, string $link, string $target): void + { + $link = PathHelper::createPath($link, $basePath); + $target = PathHelper::createPath($target, $basePath); + + self::prepareForLink($link, $target); + + symlink($target->absolute(), $link->absolute()); + } + + public static function createHardlinks(string $basePath, array $symlinks): void + { + foreach ($symlinks as $link => $target) { + self::createHardlink($basePath, $link, $target); + } + } + + public static function createHardlink(string $basePath, string $link, string $target): void + { + $link = PathHelper::createPath($link, $basePath); + $target = PathHelper::createPath($target, $basePath); + + self::prepareForLink($link, $target); + + link($target->absolute(), $link->absolute()); + } + + private static function prepareForLink(PathInterface $link, PathInterface $target): void + { + self::ensureParentDirectory($link->absolute()); + + // If the symlink target doesn't exist, the tests will pass on Unix-like + // systems but fail on Windows. Avoid hard-to-debug problems by making + // sure it fails everywhere in that case. + assert(file_exists($target->absolute()), 'Symlink target exists.'); + } } From df7c9657141f51c1f34e006cb75832e86cfd8e90 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:17:03 +0000 Subject: [PATCH 26/75] Bump rector/rector from 0.17.12 to 0.17.13 Bumps [rector/rector](https://github.com/rectorphp/rector) from 0.17.12 to 0.17.13. - [Release notes](https://github.com/rectorphp/rector/releases) - [Commits](https://github.com/rectorphp/rector/compare/0.17.12...0.17.13) --- updated-dependencies: - dependency-name: rector/rector dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 6b42078b3..33785a65e 100644 --- a/composer.lock +++ b/composer.lock @@ -2510,16 +2510,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.28", + "version": "1.10.29", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e4545b55904ebef470423d3ddddb74fa7325497a" + "reference": "ee5d8f2d3977fb09e55603eee6fb53bdd76ee9c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e4545b55904ebef470423d3ddddb74fa7325497a", - "reference": "e4545b55904ebef470423d3ddddb74fa7325497a", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ee5d8f2d3977fb09e55603eee6fb53bdd76ee9c1", + "reference": "ee5d8f2d3977fb09e55603eee6fb53bdd76ee9c1", "shasum": "" }, "require": { @@ -2568,7 +2568,7 @@ "type": "tidelift" } ], - "time": "2023-08-08T12:33:42+00:00" + "time": "2023-08-14T13:24:11+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -3277,16 +3277,16 @@ }, { "name": "rector/rector", - "version": "0.17.12", + "version": "0.17.13", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "af3a14a8a9fffa3100b730571c356f6c658d5e09" + "reference": "e2003ba7c5bda06d7bb419cf4be8dae5f8672132" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/af3a14a8a9fffa3100b730571c356f6c658d5e09", - "reference": "af3a14a8a9fffa3100b730571c356f6c658d5e09", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/e2003ba7c5bda06d7bb419cf4be8dae5f8672132", + "reference": "e2003ba7c5bda06d7bb419cf4be8dae5f8672132", "shasum": "" }, "require": { @@ -3321,7 +3321,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.17.12" + "source": "https://github.com/rectorphp/rector/tree/0.17.13" }, "funding": [ { @@ -3329,7 +3329,7 @@ "type": "github" } ], - "time": "2023-08-10T15:22:02+00:00" + "time": "2023-08-14T16:33:29+00:00" }, { "name": "sebastian/cli-parser", From 7a1ab6938a2beacf733f486f42876950746186c6 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Tue, 15 Aug 2023 09:40:43 -0400 Subject: [PATCH 27/75] Add GrumPHP task to check for PSR-4 mapping errors. --- grumphp.yml.dist | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/grumphp.yml.dist b/grumphp.yml.dist index b9c2c6e8b..e0dc2de1c 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -39,6 +39,11 @@ grumphp: - windows_only psalm: ~ rector: ~ + shell: + scripts: + # Check for PSR-4 mapping errors. + - - '-c' + - composer dump-autoload --strict-psr xmllint: ignore_patterns: - .idea @@ -65,6 +70,7 @@ grumphp: - psalm - phpstan - rector + - shell - xmllint - yamllint test: From cda43eccf387a5644681e23473da71ccea7910bb Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 16 Aug 2023 15:06:30 -0400 Subject: [PATCH 28/75] Enable PEAR.Commenting.FunctionComment.Missing PHPCS sniff for exceptions and interfaces. --- phpcs.xml.dist | 11 +++++++++-- src/API/Exception/PreconditionException.php | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 9e006393a..43676111d 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -37,8 +37,15 @@ - *Exception.php$ - *Interface.php$ + src/*Exception.php$ + src/*Interface.php$ + + + + + + src/*Exception.php$ + src/*Interface.php$ diff --git a/src/API/Exception/PreconditionException.php b/src/API/Exception/PreconditionException.php index 28d5dfddf..d6999c077 100644 --- a/src/API/Exception/PreconditionException.php +++ b/src/API/Exception/PreconditionException.php @@ -33,6 +33,7 @@ public function __construct( $this->__traitConstruct($translatableMessage, $code, $previous); } + /** Gets the unfulfilled precondition. */ public function getPrecondition(): PreconditionInterface { return $this->precondition; From a79ffc3bc790df4443589b781dc64cdd7da5431a Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 16 Aug 2023 15:16:57 -0400 Subject: [PATCH 29/75] Enable Generic.Files.LineLength PHPCS sniff for production files. --- phpcs.xml.dist | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 43676111d..79f065048 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -20,12 +20,12 @@ - + @@ -252,6 +252,7 @@ + src tests tests tests From 2416cddbb69aba5dc29dbfc5fd95a42d22d77f2a Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 16 Aug 2023 15:31:58 -0400 Subject: [PATCH 30/75] Make sure that all public API functions have a one line comment summary. --- phpstan.neon.dist | 2 +- src/API/Core/StagerInterface.php | 2 ++ src/API/Exception/TranslatableExceptionTrait.php | 6 +++++- src/API/Path/Factory/PathListFactoryInterface.php | 4 +++- src/API/Translation/Service/DomainOptionsInterface.php | 4 ++-- src/API/Translation/Service/LocaleOptionsInterface.php | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2f8b90177..9d76a62dd 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -18,7 +18,7 @@ parameters: treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false preconditionSystemHash: edc0e29f2fd55b848b7a587e7a16e557 - translationSystemHash: ef73496b0fe8d024eba0831e405db0af + translationSystemHash: e573838804f62414d8488e329ec32123 gitattributesExportInclude: - composer.json - docs diff --git a/src/API/Core/StagerInterface.php b/src/API/Core/StagerInterface.php index d88664fa1..ce18db2de 100644 --- a/src/API/Core/StagerInterface.php +++ b/src/API/Core/StagerInterface.php @@ -16,6 +16,8 @@ interface StagerInterface { /** + * Executes a Composer command. + * * @param array $composerCommand * The Composer command parts exactly as they would be typed in the terminal. * There's no need to escape them in any way, only to separate them. Example: diff --git a/src/API/Exception/TranslatableExceptionTrait.php b/src/API/Exception/TranslatableExceptionTrait.php index f479bcb03..de0d7fd3c 100644 --- a/src/API/Exception/TranslatableExceptionTrait.php +++ b/src/API/Exception/TranslatableExceptionTrait.php @@ -24,7 +24,11 @@ public function __construct( parent::__construct((string) $translatableMessage, $code, $previous); } - /** @see \PhpTuf\ComposerStager\API\Exception\ExceptionInterface::getTranslatableMessage */ + /** + * Gets the translatable form of the message with original metadata intact. + * + * @see \PhpTuf\ComposerStager\API\Exception\ExceptionInterface::getTranslatableMessage + */ public function getTranslatableMessage(): TranslatableInterface { return $this->translatableMessage; diff --git a/src/API/Path/Factory/PathListFactoryInterface.php b/src/API/Path/Factory/PathListFactoryInterface.php index 041772ca7..f2270449a 100644 --- a/src/API/Path/Factory/PathListFactoryInterface.php +++ b/src/API/Path/Factory/PathListFactoryInterface.php @@ -14,7 +14,9 @@ interface PathListFactoryInterface { /** - * Creates a path list value object from a list of relative path strings. Example: + * Creates a path list value object from a list of relative path strings. + * + * Example: * ```php * $pathListFactory->create( * 'cache', diff --git a/src/API/Translation/Service/DomainOptionsInterface.php b/src/API/Translation/Service/DomainOptionsInterface.php index dc9c195a4..b3db74b2c 100644 --- a/src/API/Translation/Service/DomainOptionsInterface.php +++ b/src/API/Translation/Service/DomainOptionsInterface.php @@ -11,9 +11,9 @@ */ interface DomainOptionsInterface { - /** The default domain. */ + /** Gets the default domain. */ public function default(): string; - /** The domain for exceptions. */ + /** Gets the domain for exceptions. */ public function exceptions(): string; } diff --git a/src/API/Translation/Service/LocaleOptionsInterface.php b/src/API/Translation/Service/LocaleOptionsInterface.php index 135a1aed5..20f10947f 100644 --- a/src/API/Translation/Service/LocaleOptionsInterface.php +++ b/src/API/Translation/Service/LocaleOptionsInterface.php @@ -11,6 +11,6 @@ */ interface LocaleOptionsInterface { - /** The default locale. */ + /** Gets the default locale. */ public function default(): string; } From ac1ba0692ad1c6b2e3b26449c687094d37a2532d Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 16 Aug 2023 17:22:39 -0400 Subject: [PATCH 31/75] Fix API\Process\Service\ProcessInterface::setTimeout() taking a float instead of an int. --- src/API/Process/Service/ProcessInterface.php | 4 ++-- src/Internal/Process/Service/Process.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/API/Process/Service/ProcessInterface.php b/src/API/Process/Service/ProcessInterface.php index 19c2b7f30..1ac3200d8 100644 --- a/src/API/Process/Service/ProcessInterface.php +++ b/src/API/Process/Service/ProcessInterface.php @@ -82,12 +82,12 @@ public function setEnv(array $env): self; /** * Sets the process timeout (max. runtime) in seconds. * - * @param float|null $timeout + * @param int|null $timeout * An optional process timeout (maximum runtime) in seconds. Set to null * to disable. * * @throws \PhpTuf\ComposerStager\API\Exception\InvalidArgumentException * If the given timeout is negative. */ - public function setTimeout(?float $timeout = self::DEFAULT_TIMEOUT): self; + public function setTimeout(?int $timeout = self::DEFAULT_TIMEOUT): self; } diff --git a/src/Internal/Process/Service/Process.php b/src/Internal/Process/Service/Process.php index d2923a1ea..f8d8268a4 100644 --- a/src/Internal/Process/Service/Process.php +++ b/src/Internal/Process/Service/Process.php @@ -106,7 +106,7 @@ public function setEnv(array $env): ProcessInterface return $this; } - public function setTimeout(?float $timeout = self::DEFAULT_TIMEOUT): self + public function setTimeout(?int $timeout = self::DEFAULT_TIMEOUT): self { try { $this->symfonyProcess->setTimeout($timeout); From 3a2ffdba73cdb98dd018b6cf68df9fe1f5c72ef3 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 16 Aug 2023 20:41:26 -0400 Subject: [PATCH 32/75] Make timeout arguments non-nullable. --- src/API/Core/BeginnerInterface.php | 8 ++++---- src/API/Core/CleanerInterface.php | 8 ++++---- src/API/Core/CommitterInterface.php | 8 ++++---- src/API/Core/StagerInterface.php | 8 ++++---- src/API/FileSyncer/Service/FileSyncerInterface.php | 8 ++++---- src/API/Filesystem/Service/FilesystemInterface.php | 8 ++++---- .../Process/Service/ComposerProcessRunnerInterface.php | 8 ++++---- src/API/Process/Service/ProcessInterface.php | 8 ++++---- src/API/Process/Service/RsyncProcessRunnerInterface.php | 8 ++++---- src/Internal/Core/Beginner.php | 2 +- src/Internal/Core/Cleaner.php | 2 +- src/Internal/Core/Committer.php | 2 +- src/Internal/Core/Stager.php | 4 ++-- src/Internal/FileSyncer/Service/PhpFileSyncer.php | 4 ++-- src/Internal/FileSyncer/Service/RsyncFileSyncer.php | 4 ++-- src/Internal/Filesystem/Service/Filesystem.php | 4 ++-- src/Internal/Process/Service/AbstractProcessRunner.php | 2 +- src/Internal/Process/Service/Process.php | 2 +- tests/Core/BeginnerUnitTest.php | 4 ++-- tests/Core/CleanerUnitTest.php | 4 ++-- tests/Core/CommitterUnitTest.php | 4 ++-- tests/Core/StagerUnitTest.php | 4 ++-- tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php | 4 ++-- tests/Filesystem/Service/FilesystemUnitTest.php | 2 +- tests/Process/Service/AbstractProcessRunnerUnitTest.php | 4 ++-- 25 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/API/Core/BeginnerInterface.php b/src/API/Core/BeginnerInterface.php index bc405b964..67cf30388 100644 --- a/src/API/Core/BeginnerInterface.php +++ b/src/API/Core/BeginnerInterface.php @@ -39,9 +39,9 @@ interface BeginnerInterface * as when committing. * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException * If the preconditions are unfulfilled. @@ -55,6 +55,6 @@ public function begin( PathInterface $stagingDir, ?PathListInterface $exclusions = null, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/API/Core/CleanerInterface.php b/src/API/Core/CleanerInterface.php index 79d4dedce..4177d79af 100644 --- a/src/API/Core/CleanerInterface.php +++ b/src/API/Core/CleanerInterface.php @@ -24,9 +24,9 @@ interface CleanerInterface * The staging directory. * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException * If the preconditions are unfulfilled. @@ -37,6 +37,6 @@ public function clean( PathInterface $activeDir, PathInterface $stagingDir, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/API/Core/CommitterInterface.php b/src/API/Core/CommitterInterface.php index 64bcad47a..b8e667e79 100644 --- a/src/API/Core/CommitterInterface.php +++ b/src/API/Core/CommitterInterface.php @@ -28,9 +28,9 @@ interface CommitterInterface * you should use the same exclusions when committing as when beginning. * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException * If the preconditions are unfulfilled. @@ -44,6 +44,6 @@ public function commit( PathInterface $activeDir, ?PathListInterface $exclusions = null, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/API/Core/StagerInterface.php b/src/API/Core/StagerInterface.php index ce18db2de..0729e4eca 100644 --- a/src/API/Core/StagerInterface.php +++ b/src/API/Core/StagerInterface.php @@ -35,9 +35,9 @@ interface StagerInterface * The staging directory. * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\InvalidArgumentException * If the given Composer command is invalid. @@ -51,6 +51,6 @@ public function stage( PathInterface $activeDir, PathInterface $stagingDir, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/API/FileSyncer/Service/FileSyncerInterface.php b/src/API/FileSyncer/Service/FileSyncerInterface.php index c5f67f836..01e3c5e0e 100644 --- a/src/API/FileSyncer/Service/FileSyncerInterface.php +++ b/src/API/FileSyncer/Service/FileSyncerInterface.php @@ -35,9 +35,9 @@ interface FileSyncerInterface * "underneath" or "inside" it. * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\IOException * If the destination directory cannot be created. @@ -49,6 +49,6 @@ public function sync( PathInterface $destination, ?PathListInterface $exclusions = null, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/API/Filesystem/Service/FilesystemInterface.php b/src/API/Filesystem/Service/FilesystemInterface.php index 2968ceb97..6f0aad696 100644 --- a/src/API/Filesystem/Service/FilesystemInterface.php +++ b/src/API/Filesystem/Service/FilesystemInterface.php @@ -170,9 +170,9 @@ public function readLink(PathInterface $path): PathInterface; * A path to remove. * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\IOException * If the file cannot be removed. @@ -180,6 +180,6 @@ public function readLink(PathInterface $path): PathInterface; public function remove( PathInterface $path, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/API/Process/Service/ComposerProcessRunnerInterface.php b/src/API/Process/Service/ComposerProcessRunnerInterface.php index 7c36cf586..ec4fbec33 100644 --- a/src/API/Process/Service/ComposerProcessRunnerInterface.php +++ b/src/API/Process/Service/ComposerProcessRunnerInterface.php @@ -26,9 +26,9 @@ interface ComposerProcessRunnerInterface * ``` * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\LogicException * If the command process cannot be created due to host configuration. @@ -40,6 +40,6 @@ interface ComposerProcessRunnerInterface public function run( array $command, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/API/Process/Service/ProcessInterface.php b/src/API/Process/Service/ProcessInterface.php index 1ac3200d8..2ba0c7a3e 100644 --- a/src/API/Process/Service/ProcessInterface.php +++ b/src/API/Process/Service/ProcessInterface.php @@ -82,12 +82,12 @@ public function setEnv(array $env): self; /** * Sets the process timeout (max. runtime) in seconds. * - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\InvalidArgumentException * If the given timeout is negative. */ - public function setTimeout(?int $timeout = self::DEFAULT_TIMEOUT): self; + public function setTimeout(int $timeout = self::DEFAULT_TIMEOUT): self; } diff --git a/src/API/Process/Service/RsyncProcessRunnerInterface.php b/src/API/Process/Service/RsyncProcessRunnerInterface.php index 97e86113b..632689122 100644 --- a/src/API/Process/Service/RsyncProcessRunnerInterface.php +++ b/src/API/Process/Service/RsyncProcessRunnerInterface.php @@ -26,9 +26,9 @@ interface RsyncProcessRunnerInterface * ``` * @param \PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface|null $callback * An optional PHP callback to run whenever there is process output. - * @param int|null $timeout - * An optional process timeout (maximum runtime) in seconds. Set to null - * to disable. + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. * * @throws \PhpTuf\ComposerStager\API\Exception\LogicException * If the command process cannot be created due to host configuration. @@ -40,6 +40,6 @@ interface RsyncProcessRunnerInterface public function run( array $command, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; } diff --git a/src/Internal/Core/Beginner.php b/src/Internal/Core/Beginner.php index 03a5ab53d..23b422c11 100644 --- a/src/Internal/Core/Beginner.php +++ b/src/Internal/Core/Beginner.php @@ -30,7 +30,7 @@ public function begin( PathInterface $stagingDir, ?PathListInterface $exclusions = null, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions); diff --git a/src/Internal/Core/Cleaner.php b/src/Internal/Core/Cleaner.php index ebce84444..57695a087 100644 --- a/src/Internal/Core/Cleaner.php +++ b/src/Internal/Core/Cleaner.php @@ -28,7 +28,7 @@ public function clean( PathInterface $activeDir, PathInterface $stagingDir, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $this->preconditions->assertIsFulfilled($activeDir, $stagingDir); diff --git a/src/Internal/Core/Committer.php b/src/Internal/Core/Committer.php index 6cdff37a2..e4cbcf542 100644 --- a/src/Internal/Core/Committer.php +++ b/src/Internal/Core/Committer.php @@ -30,7 +30,7 @@ public function commit( PathInterface $activeDir, ?PathListInterface $exclusions = null, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions); diff --git a/src/Internal/Core/Stager.php b/src/Internal/Core/Stager.php index 1b6ec7635..54d927474 100644 --- a/src/Internal/Core/Stager.php +++ b/src/Internal/Core/Stager.php @@ -36,7 +36,7 @@ public function stage( PathInterface $activeDir, PathInterface $stagingDir, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $this->preconditions->assertIsFulfilled($activeDir, $stagingDir); @@ -86,7 +86,7 @@ private function runCommand( PathInterface $stagingDir, array $composerCommand, ?OutputCallbackInterface $callback, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $command = array_merge( ['--working-dir=' . $stagingDir->absolute()], diff --git a/src/Internal/FileSyncer/Service/PhpFileSyncer.php b/src/Internal/FileSyncer/Service/PhpFileSyncer.php index 914f714a1..ce5e93499 100644 --- a/src/Internal/FileSyncer/Service/PhpFileSyncer.php +++ b/src/Internal/FileSyncer/Service/PhpFileSyncer.php @@ -38,9 +38,9 @@ public function sync( PathInterface $destination, ?PathListInterface $exclusions = null, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { - set_time_limit((int) $timeout); + set_time_limit($timeout); $exclusions ??= new PathList(); diff --git a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php index 446171bd1..fcbef576f 100644 --- a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php +++ b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php @@ -47,14 +47,14 @@ public function sync( PathInterface $destination, ?PathListInterface $exclusions = null, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $sourceAbsolute = $source->absolute(); $destinationAbsolute = $destination->absolute(); $this->assertDirectoriesAreNotTheSame($source, $destination); $this->assertSourceExists($source); - set_time_limit((int) $timeout); + set_time_limit($timeout); $this->runCommand($exclusions, $sourceAbsolute, $destinationAbsolute, $destination, $callback); } diff --git a/src/Internal/Filesystem/Service/Filesystem.php b/src/Internal/Filesystem/Service/Filesystem.php index 8713b772c..f027abb72 100644 --- a/src/Internal/Filesystem/Service/Filesystem.php +++ b/src/Internal/Filesystem/Service/Filesystem.php @@ -174,12 +174,12 @@ public function readLink(PathInterface $path): PathInterface public function remove( PathInterface $path, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { try { // Symfony Filesystem doesn't have a builtin mechanism for setting a // timeout, so we have to enforce it ourselves. - set_time_limit((int) $timeout); + set_time_limit($timeout); $this->symfonyFilesystem->remove($path->absolute()); } catch (SymfonyExceptionInterface $e) { diff --git a/src/Internal/Process/Service/AbstractProcessRunner.php b/src/Internal/Process/Service/AbstractProcessRunner.php index d915371ec..31ea3cfbd 100644 --- a/src/Internal/Process/Service/AbstractProcessRunner.php +++ b/src/Internal/Process/Service/AbstractProcessRunner.php @@ -52,7 +52,7 @@ public function __construct( public function run( array $command, ?OutputCallbackInterface $callback = null, - ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { array_unshift($command, $this->findExecutable()); $process = $this->processFactory->create($command); diff --git a/src/Internal/Process/Service/Process.php b/src/Internal/Process/Service/Process.php index f8d8268a4..3bc4a5311 100644 --- a/src/Internal/Process/Service/Process.php +++ b/src/Internal/Process/Service/Process.php @@ -106,7 +106,7 @@ public function setEnv(array $env): ProcessInterface return $this; } - public function setTimeout(?int $timeout = self::DEFAULT_TIMEOUT): self + public function setTimeout(int $timeout = self::DEFAULT_TIMEOUT): self { try { $this->symfonyProcess->setTimeout($timeout); diff --git a/tests/Core/BeginnerUnitTest.php b/tests/Core/BeginnerUnitTest.php index 222f25103..e406b1253 100644 --- a/tests/Core/BeginnerUnitTest.php +++ b/tests/Core/BeginnerUnitTest.php @@ -70,7 +70,7 @@ public function testBeginWithOptionalParams( string $stagingDir, ?PathListInterface $exclusions, ?OutputCallbackInterface $callback, - ?int $timeout, + int $timeout, ): void { $activeDir = new TestPath($activeDir); $stagingDir = new TestPath($stagingDir); @@ -93,7 +93,7 @@ public function providerBeginWithOptionalParams(): array 'stagingDir' => 'three/four', 'givenExclusions' => null, 'callback' => null, - 'timeout' => null, + 'timeout' => 0, ], [ 'activeDir' => 'five/six', diff --git a/tests/Core/CleanerUnitTest.php b/tests/Core/CleanerUnitTest.php index bf69a9b15..9346baeef 100644 --- a/tests/Core/CleanerUnitTest.php +++ b/tests/Core/CleanerUnitTest.php @@ -61,7 +61,7 @@ public function testCleanWithMinimumParams(): void * * @dataProvider providerCleanWithOptionalParams */ - public function testCleanWithOptionalParams(string $path, ?OutputCallbackInterface $callback, ?int $timeout): void + public function testCleanWithOptionalParams(string $path, ?OutputCallbackInterface $callback, int $timeout): void { $path = new TestPath($path); $this->preconditions @@ -81,7 +81,7 @@ public function providerCleanWithOptionalParams(): array [ 'path' => '/one/two', 'callback' => null, - 'timeout' => null, + 'timeout' => 0, ], [ 'path' => 'three/four', diff --git a/tests/Core/CommitterUnitTest.php b/tests/Core/CommitterUnitTest.php index da99eb0ce..fdb56beb8 100644 --- a/tests/Core/CommitterUnitTest.php +++ b/tests/Core/CommitterUnitTest.php @@ -70,7 +70,7 @@ public function testCommitWithOptionalParams( string $activeDir, ?PathListInterface $exclusions, ?OutputCallbackInterface $callback, - ?int $timeout, + int $timeout, ): void { $activeDir = new TestPath($activeDir); $stagingDir = new TestPath($stagingDir); @@ -93,7 +93,7 @@ public function providerCommitWithOptionalParams(): array 'activeDir' => '/three/four', 'exclusions' => null, 'callback' => null, - 'timeout' => null, + 'timeout' => 0, ], [ 'stagingDir' => 'five/six', diff --git a/tests/Core/StagerUnitTest.php b/tests/Core/StagerUnitTest.php index a0b60ef83..b5f1fb3b9 100644 --- a/tests/Core/StagerUnitTest.php +++ b/tests/Core/StagerUnitTest.php @@ -76,7 +76,7 @@ public function testStageWithOptionalParams( array $givenCommand, array $expectedCommand, ?OutputCallbackInterface $callback, - ?int $timeout, + int $timeout, ): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); @@ -102,7 +102,7 @@ public function providerStageWithOptionalParams(): array 'update', ], 'callback' => null, - 'timeout' => null, + 'timeout' => 0, ], [ 'givenCommand' => [self::INERT_COMMAND], diff --git a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php index 0d67c3b44..3504cb8e5 100644 --- a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -40,7 +40,7 @@ abstract protected function fileSyncerClass(): string; * * @dataProvider providerSyncTimeout */ - public function testSyncTimeout(?int $givenTimeout, int $expectedTimeout): void + public function testSyncTimeout(int $givenTimeout, int $expectedTimeout): void { $sut = $this->createSut(); @@ -53,7 +53,7 @@ public function providerSyncTimeout(): array { return [ [ - 'givenTimeout' => null, + 'givenTimeout' => 0, 'expectedTimeout' => 0, ], [ diff --git a/tests/Filesystem/Service/FilesystemUnitTest.php b/tests/Filesystem/Service/FilesystemUnitTest.php index 1f1f987eb..09abf4711 100644 --- a/tests/Filesystem/Service/FilesystemUnitTest.php +++ b/tests/Filesystem/Service/FilesystemUnitTest.php @@ -191,7 +191,7 @@ public function providerRemove(): array [ 'path' => '/one/two', 'callback' => null, - 'givenTimeout' => null, + 'givenTimeout' => 0, 'expectedTimeout' => 0, ], [ diff --git a/tests/Process/Service/AbstractProcessRunnerUnitTest.php b/tests/Process/Service/AbstractProcessRunnerUnitTest.php index 82c4ba2da..cd8b26daf 100644 --- a/tests/Process/Service/AbstractProcessRunnerUnitTest.php +++ b/tests/Process/Service/AbstractProcessRunnerUnitTest.php @@ -84,7 +84,7 @@ public function testRun( array $givenCommand, array $expectedCommand, ?OutputCallbackInterface $callback, - ?int $timeout, + int $timeout, ): void { $this->executableFinder ->find($executableName) @@ -116,7 +116,7 @@ public function providerRun(): array 'givenCommand' => [], 'expectedCommand' => ['one'], 'callback' => null, - 'timeout' => null, + 'timeout' => 0, ], [ 'executableName' => 'two', From 75dbfb54c1f6a3fff4f8d5b5183fdab4673c4148 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:51:24 +0000 Subject: [PATCH 33/75] Bump rector/rector from 0.17.13 to 0.17.14 Bumps [rector/rector](https://github.com/rectorphp/rector) from 0.17.13 to 0.17.14. - [Release notes](https://github.com/rectorphp/rector/releases) - [Commits](https://github.com/rectorphp/rector/compare/0.17.13...0.17.14) --- updated-dependencies: - dependency-name: rector/rector dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 33785a65e..1d0ec7c9c 100644 --- a/composer.lock +++ b/composer.lock @@ -3277,16 +3277,16 @@ }, { "name": "rector/rector", - "version": "0.17.13", + "version": "0.17.14", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "e2003ba7c5bda06d7bb419cf4be8dae5f8672132" + "reference": "64b92c8654ec12e0c7d5e2b9569d31d06646d3a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/e2003ba7c5bda06d7bb419cf4be8dae5f8672132", - "reference": "e2003ba7c5bda06d7bb419cf4be8dae5f8672132", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/64b92c8654ec12e0c7d5e2b9569d31d06646d3a7", + "reference": "64b92c8654ec12e0c7d5e2b9569d31d06646d3a7", "shasum": "" }, "require": { @@ -3321,7 +3321,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.17.13" + "source": "https://github.com/rectorphp/rector/tree/0.17.14" }, "funding": [ { @@ -3329,7 +3329,7 @@ "type": "github" } ], - "time": "2023-08-14T16:33:29+00:00" + "time": "2023-08-17T09:45:26+00:00" }, { "name": "sebastian/cli-parser", From 23cd2b1a00d744e7a66b744f6e1b45916f8eb9f6 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 16 Aug 2023 22:56:44 -0400 Subject: [PATCH 34/75] Create Internal\Environment\Service\EnvironmentInterface. --- .../Environment/Service/Environment.php | 21 +++++++++ .../Service/EnvironmentInterface.php | 33 ++++++++++++++ .../Service/EnvironmentFunctionalTest.php | 43 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/Internal/Environment/Service/Environment.php create mode 100644 src/Internal/Environment/Service/EnvironmentInterface.php create mode 100644 tests/Environment/Service/EnvironmentFunctionalTest.php diff --git a/src/Internal/Environment/Service/Environment.php b/src/Internal/Environment/Service/Environment.php new file mode 100644 index 000000000..45b60574c --- /dev/null +++ b/src/Internal/Environment/Service/Environment.php @@ -0,0 +1,21 @@ +createSut(); + + $result = $sut->setTimeLimit($timeout); + + self::assertSame((string) $timeout, ini_get('max_execution_time'), 'Correctly set timeout.'); + // At the time of this writing, `set_time_limit()` ALWAYS return false with XDebug + // enabled. At least test that the SUT returns the same thing as a direct call. + self::assertSame($result, set_time_limit($timeout), 'Returned same result as set_time_limit() called directly.'); + } + + public function providerSetTimeLimit(): array + { + return [ + [-30], + [-5], + [0], + [5], + [30], + ]; + } +} From e5331f9ee37f28dda7c3a639df8a10c2ca927a6e Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 17 Aug 2023 14:40:22 -0400 Subject: [PATCH 35/75] Replace direct call to "set_time_limit()" in Internal\FileSyncer\Service\PhpFileSyncer::sync() with Internal\Environment\Service\EnvironmentInterface::setTimeLimit(). --- .../FileSyncer/Service/PhpFileSyncer.php | 4 +- .../Service/PhpFileSyncerUnitTest.php | 42 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Internal/FileSyncer/Service/PhpFileSyncer.php b/src/Internal/FileSyncer/Service/PhpFileSyncer.php index ce5e93499..c885524b3 100644 --- a/src/Internal/FileSyncer/Service/PhpFileSyncer.php +++ b/src/Internal/FileSyncer/Service/PhpFileSyncer.php @@ -12,6 +12,7 @@ use PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface; use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; +use PhpTuf\ComposerStager\Internal\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait; @@ -25,6 +26,7 @@ final class PhpFileSyncer implements PhpFileSyncerInterface use TranslatableAwareTrait; public function __construct( + private readonly EnvironmentInterface $environment, private readonly FileFinderInterface $fileFinder, private readonly FilesystemInterface $filesystem, private readonly PathFactoryInterface $pathFactory, @@ -40,7 +42,7 @@ public function sync( ?OutputCallbackInterface $callback = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { - set_time_limit($timeout); + $this->environment->setTimeLimit($timeout); $exclusions ??= new PathList(); diff --git a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php index 2c804a8c9..21d27abec 100644 --- a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php +++ b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\API\Finder\Service\FileFinderInterface; use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; +use PhpTuf\ComposerStager\Internal\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer; use PhpTuf\ComposerStager\Internal\Host\Service\Host; use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; @@ -20,6 +21,7 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use ReflectionClass; +use Throwable; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer @@ -28,6 +30,7 @@ */ final class PhpFileSyncerUnitTest extends TestCase { + private EnvironmentInterface|ObjectProphecy $environment; private FileFinderInterface|ObjectProphecy $fileFinder; private FilesystemInterface|ObjectProphecy $filesystem; private PathFactoryInterface|ObjectProphecy $pathFactory; @@ -38,6 +41,9 @@ protected function setUp(): void { $this->source = new TestPath(PathHelper::activeDirRelative()); $this->destination = new TestPath(PathHelper::stagingDirRelative()); + $this->environment = $this->prophesize(EnvironmentInterface::class); + $this->environment->setTimeLimit(Argument::type('integer')) + ->willReturn(true); $this->fileFinder = $this->prophesize(FileFinderInterface::class); $this->filesystem = $this->prophesize(FilesystemInterface::class); $this->filesystem @@ -53,12 +59,13 @@ protected function setUp(): void private function createSut(): PhpFileSyncer { + $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new PhpFileSyncer($fileFinder, $filesystem, $pathFactory, $translatableFactory); + return new PhpFileSyncer($environment, $fileFinder, $filesystem, $pathFactory, $translatableFactory); } public function testSyncSourceNotFound(): void @@ -239,6 +246,8 @@ public function testTransMissingTranslatableFactory(): void $reflection = new ReflectionClass($sut); $sut = $reflection->newInstanceWithoutConstructor(); + $environment = $reflection->getProperty('environment'); + $environment->setValue($sut, $this->environment->reveal()); $translatableFactory = $reflection->getProperty('translatableFactory'); $translatableFactory->setValue($sut, null); @@ -246,4 +255,35 @@ public function testTransMissingTranslatableFactory(): void }, AssertionError::class, 'The "p()" method requires a translatable factory. ' . 'Provide one by calling "setTranslatableFactory()" in the constructor.'); } + + /** + * @covers ::sync + * + * @dataProvider providerTimeout + */ + public function testTimeout(int $timeout): void + { + $this->environment->setTimeLimit($timeout) + ->shouldBeCalledOnce(); + $sut = $this->createSut(); + + // Use the same path for the source and destination in + // order to fail validation and avoid side effects. + try { + $sut->sync(PathHelper::sourceDirPath(), PathHelper::sourceDirPath(), null, null, $timeout); + } catch (Throwable) { + // @ignoreException + } + } + + public function providerTimeout(): array + { + return [ + [-30], + [-5], + [0], + [5], + [30], + ]; + } } From 0c620268814a476c88602511afcdc41597f80dbe Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 17 Aug 2023 14:56:13 -0400 Subject: [PATCH 36/75] Replace direct call to "set_time_limit()" in Internal\FileSyncer\Service\PhpFileSyncer::sync() with Internal\Environment\Service\EnvironmentInterface::setTimeLimit(). --- .../FileSyncer/Service/RsyncFileSyncer.php | 5 +- .../FileSyncer/Service/FileSyncerTestCase.php | 56 +++++++++++++++++++ .../Service/PhpFileSyncerUnitTest.php | 12 ++-- .../Service/RsyncFileSyncerUnitTest.php | 10 ++-- 4 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 tests/FileSyncer/Service/FileSyncerTestCase.php diff --git a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php index fcbef576f..dcb0958eb 100644 --- a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php +++ b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php @@ -13,6 +13,7 @@ use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Process\Service\RsyncProcessRunnerInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; +use PhpTuf\ComposerStager\Internal\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\Internal\Helper\PathHelper; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait; @@ -27,6 +28,7 @@ final class RsyncFileSyncer implements RsyncFileSyncerInterface use TranslatableAwareTrait; public function __construct( + private readonly EnvironmentInterface $environment, private readonly FilesystemInterface $filesystem, private readonly RsyncProcessRunnerInterface $rsync, TranslatableFactoryInterface $translatableFactory, @@ -49,12 +51,13 @@ public function sync( ?OutputCallbackInterface $callback = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { + $this->environment->setTimeLimit($timeout); + $sourceAbsolute = $source->absolute(); $destinationAbsolute = $destination->absolute(); $this->assertDirectoriesAreNotTheSame($source, $destination); $this->assertSourceExists($source); - set_time_limit($timeout); $this->runCommand($exclusions, $sourceAbsolute, $destinationAbsolute, $destination, $callback); } diff --git a/tests/FileSyncer/Service/FileSyncerTestCase.php b/tests/FileSyncer/Service/FileSyncerTestCase.php new file mode 100644 index 000000000..c0247366e --- /dev/null +++ b/tests/FileSyncer/Service/FileSyncerTestCase.php @@ -0,0 +1,56 @@ +environment = $this->prophesize(EnvironmentInterface::class); + $this->environment->setTimeLimit(Argument::type('integer')) + ->willReturn(true); + } + + abstract protected function createSut(): FileSyncerInterface; + + /** + * @covers ::sync + * + * @dataProvider providerTimeout + */ + public function testTimeout(int $timeout): void + { + $this->environment->setTimeLimit($timeout) + ->shouldBeCalledOnce(); + $sut = $this->createSut(); + + // Use the same path for the source and destination in + // order to fail validation and avoid side effects. + try { + $sut->sync(PathHelper::sourceDirPath(), PathHelper::sourceDirPath(), null, null, $timeout); + } catch (Throwable) { + // @ignoreException + } + } + + public function providerTimeout(): array + { + return [ + [-30], + [-5], + [0], + [5], + [30], + ]; + } +} diff --git a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php index 21d27abec..e35a26d43 100644 --- a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php +++ b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php @@ -10,11 +10,9 @@ use PhpTuf\ComposerStager\API\Finder\Service\FileFinderInterface; use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; -use PhpTuf\ComposerStager\Internal\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer; use PhpTuf\ComposerStager\Internal\Host\Service\Host; use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; -use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; @@ -28,9 +26,8 @@ * * @covers \PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer */ -final class PhpFileSyncerUnitTest extends TestCase +final class PhpFileSyncerUnitTest extends FileSyncerTestCase { - private EnvironmentInterface|ObjectProphecy $environment; private FileFinderInterface|ObjectProphecy $fileFinder; private FilesystemInterface|ObjectProphecy $filesystem; private PathFactoryInterface|ObjectProphecy $pathFactory; @@ -41,9 +38,6 @@ protected function setUp(): void { $this->source = new TestPath(PathHelper::activeDirRelative()); $this->destination = new TestPath(PathHelper::stagingDirRelative()); - $this->environment = $this->prophesize(EnvironmentInterface::class); - $this->environment->setTimeLimit(Argument::type('integer')) - ->willReturn(true); $this->fileFinder = $this->prophesize(FileFinderInterface::class); $this->filesystem = $this->prophesize(FilesystemInterface::class); $this->filesystem @@ -55,9 +49,11 @@ protected function setUp(): void $this->filesystem ->mkdir(Argument::any()); $this->pathFactory = $this->prophesize(PathFactoryInterface::class); + + parent::setUp(); } - private function createSut(): PhpFileSyncer + protected function createSut(): PhpFileSyncer { $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); diff --git a/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php b/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php index 243cc04e3..1dccbe264 100644 --- a/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php +++ b/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php @@ -15,7 +15,6 @@ use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; -use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; @@ -37,7 +36,7 @@ * * @group no_windows */ -final class RsyncFileSyncerUnitTest extends TestCase +final class RsyncFileSyncerUnitTest extends FileSyncerTestCase { private FilesystemInterface|ObjectProphecy $filesystem; private PathInterface $destination; @@ -55,15 +54,18 @@ protected function setUp(): void $this->filesystem ->mkdir(Argument::any()); $this->rsync = $this->prophesize(RsyncProcessRunnerInterface::class); + + parent::setUp(); } - private function createSut(): RsyncFileSyncer + protected function createSut(): RsyncFileSyncer { + $environment = $this->environment->reveal(); $filesystem = $this->filesystem->reveal(); $rsync = $this->rsync->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new RsyncFileSyncer($filesystem, $rsync, $translatableFactory); + return new RsyncFileSyncer($environment, $filesystem, $rsync, $translatableFactory); } /** From f8f14f2a3947a7e3c4f63b35f5ecb82b154b86d5 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 17 Aug 2023 15:12:59 -0400 Subject: [PATCH 37/75] Replace direct call to "set_time_limit()" in Internal\Filesystem\Service\Filesystem::remove() with Internal\Environment\Service\EnvironmentInterface::setTimeLimit(). --- .../Filesystem/Service/Filesystem.php | 6 ++-- .../Filesystem/Service/FilesystemUnitTest.php | 28 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Internal/Filesystem/Service/Filesystem.php b/src/Internal/Filesystem/Service/Filesystem.php index f027abb72..366414331 100644 --- a/src/Internal/Filesystem/Service/Filesystem.php +++ b/src/Internal/Filesystem/Service/Filesystem.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface; use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; +use PhpTuf\ComposerStager\Internal\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait; use Symfony\Component\Filesystem\Exception\ExceptionInterface as SymfonyExceptionInterface; use Symfony\Component\Filesystem\Exception\FileNotFoundException as SymfonyFileNotFoundException; @@ -38,6 +39,7 @@ final class Filesystem implements FilesystemInterface private const PATH_IS_SYMLINK = 'PATH_IS_SYMLINK'; public function __construct( + private readonly EnvironmentInterface $environment, private readonly PathFactoryInterface $pathFactory, private readonly SymfonyFilesystem $symfonyFilesystem, TranslatableFactoryInterface $translatableFactory, @@ -177,9 +179,7 @@ public function remove( int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { try { - // Symfony Filesystem doesn't have a builtin mechanism for setting a - // timeout, so we have to enforce it ourselves. - set_time_limit($timeout); + $this->environment->setTimeLimit($timeout); $this->symfonyFilesystem->remove($path->absolute()); } catch (SymfonyExceptionInterface $e) { diff --git a/tests/Filesystem/Service/FilesystemUnitTest.php b/tests/Filesystem/Service/FilesystemUnitTest.php index 09abf4711..9d98454e1 100644 --- a/tests/Filesystem/Service/FilesystemUnitTest.php +++ b/tests/Filesystem/Service/FilesystemUnitTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Exception\LogicException; use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface; +use PhpTuf\ComposerStager\Internal\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\Internal\Filesystem\Service\Filesystem; use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; @@ -25,22 +26,27 @@ */ final class FilesystemUnitTest extends TestCase { + private EnvironmentInterface|ObjectProphecy $environment; private PathFactoryInterface|ObjectProphecy $pathFactory; private SymfonyFilesystem|ObjectProphecy $symfonyFilesystem; protected function setUp(): void { + $this->environment = $this->prophesize(EnvironmentInterface::class); + $this->environment->setTimeLimit(Argument::type('integer')) + ->willReturn(true); $this->pathFactory = $this->prophesize(PathFactoryInterface::class); $this->symfonyFilesystem = $this->prophesize(SymfonyFilesystem::class); } private function createSut(): Filesystem { + $environment = $this->environment->reveal(); $pathFactory = $this->pathFactory->reveal(); $symfonyFilesystem = $this->symfonyFilesystem->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new Filesystem($pathFactory, $symfonyFilesystem, $translatableFactory); + return new Filesystem($environment, $pathFactory, $symfonyFilesystem, $translatableFactory); } /** @@ -168,21 +174,17 @@ public function testMkdirFailure(): void * * @dataProvider providerRemove */ - public function testRemove( - string $path, - ?OutputCallbackInterface $callback, - ?int $givenTimeout, - int $expectedTimeout, - ): void { + public function testRemove(string $path, ?OutputCallbackInterface $callback, int $timeout): void + { + $this->environment->setTimeLimit($timeout) + ->shouldBeCalledOnce(); $stagingDir = new TestPath($path); $this->symfonyFilesystem ->remove($path) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->remove($stagingDir, $callback, $givenTimeout); - - self::assertSame((string) $expectedTimeout, ini_get('max_execution_time'), 'Correctly set process timeout.'); + $sut->remove($stagingDir, $callback, $timeout); } public function providerRemove(): array @@ -191,14 +193,12 @@ public function providerRemove(): array [ 'path' => '/one/two', 'callback' => null, - 'givenTimeout' => 0, - 'expectedTimeout' => 0, + 'timeout' => 0, ], [ 'path' => 'three/four', 'callback' => new TestOutputCallback(), - 'givenTimeout' => 10, - 'expectedTimeout' => 10, + 'timeout' => 10, ], ]; } From a9cf843bc8bbb0a037a175a0de0a4c49cda2a803 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 17 Aug 2023 23:54:38 -0400 Subject: [PATCH 38/75] Niggle. --- src/Internal/Filesystem/Service/Filesystem.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Internal/Filesystem/Service/Filesystem.php b/src/Internal/Filesystem/Service/Filesystem.php index 366414331..fffd6a596 100644 --- a/src/Internal/Filesystem/Service/Filesystem.php +++ b/src/Internal/Filesystem/Service/Filesystem.php @@ -178,9 +178,8 @@ public function remove( ?OutputCallbackInterface $callback = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { + $this->environment->setTimeLimit($timeout); try { - $this->environment->setTimeLimit($timeout); - $this->symfonyFilesystem->remove($path->absolute()); } catch (SymfonyExceptionInterface $e) { throw new IOException($this->t( From 93b9a3bd387c272624d80662afa29939900d068b Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 17 Aug 2023 23:55:10 -0400 Subject: [PATCH 39/75] Fix PHPCS mistake. --- src/Internal/Filesystem/Service/Filesystem.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Internal/Filesystem/Service/Filesystem.php b/src/Internal/Filesystem/Service/Filesystem.php index fffd6a596..f80a6e506 100644 --- a/src/Internal/Filesystem/Service/Filesystem.php +++ b/src/Internal/Filesystem/Service/Filesystem.php @@ -179,6 +179,7 @@ public function remove( int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $this->environment->setTimeLimit($timeout); + try { $this->symfonyFilesystem->remove($path->absolute()); } catch (SymfonyExceptionInterface $e) { From 1eecc2aa3a450f0ef0fc0f2fcab8d56fec383b30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:42:49 +0000 Subject: [PATCH 40/75] Bump rector/rector from 0.17.14 to 0.18.0 Bumps [rector/rector](https://github.com/rectorphp/rector) from 0.17.14 to 0.18.0. - [Release notes](https://github.com/rectorphp/rector/releases) - [Commits](https://github.com/rectorphp/rector/commits/0.18.0) --- updated-dependencies: - dependency-name: rector/rector dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 7da3a058f..427d4880b 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "phpstan/phpstan-strict-rules": "^1.5", "phpunit/phpunit": "^9.6", "psalm/phar": "^5.13", - "rector/rector": "^0.17.5", + "rector/rector": "^0.17.5 || ^0.18.0", "slevomat/coding-standard": "^8.13", "squizlabs/php_codesniffer": "^3.7", "symfony/config": "^6.3", diff --git a/composer.lock b/composer.lock index 1d0ec7c9c..e4dc104a6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3e3acc50162d075b257ae0f61e7dba2f", + "content-hash": "67134c47bab480af5b2caa00768d7784", "packages": [ { "name": "symfony/filesystem", @@ -3277,16 +3277,16 @@ }, { "name": "rector/rector", - "version": "0.17.14", + "version": "0.18.0", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "64b92c8654ec12e0c7d5e2b9569d31d06646d3a7" + "reference": "758ada29b5c80d933f906735d3026520390a2a1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/64b92c8654ec12e0c7d5e2b9569d31d06646d3a7", - "reference": "64b92c8654ec12e0c7d5e2b9569d31d06646d3a7", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/758ada29b5c80d933f906735d3026520390a2a1d", + "reference": "758ada29b5c80d933f906735d3026520390a2a1d", "shasum": "" }, "require": { @@ -3321,7 +3321,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.17.14" + "source": "https://github.com/rectorphp/rector/tree/0.18.0" }, "funding": [ { @@ -3329,7 +3329,7 @@ "type": "github" } ], - "time": "2023-08-17T09:45:26+00:00" + "time": "2023-08-17T12:53:22+00:00" }, { "name": "sebastian/cli-parser", From e093ef5c15404bf6b98bf890a4fc449b6847e4e1 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 18 Aug 2023 08:27:56 -0400 Subject: [PATCH 41/75] Make Tests\Precondition\Service\PreconditionTestCase::doTestUnfulfilled() easier to use for simple strings. --- .../Service/ActiveAndStagingDirsAreDifferentUnitTest.php | 8 +------- tests/Precondition/Service/ActiveDirExistsUnitTest.php | 3 +-- tests/Precondition/Service/ActiveDirIsReadyUnitTest.php | 3 +-- .../Service/BeginnerPreconditionsUnitTest.php | 3 +-- .../Precondition/Service/CleanerPreconditionsUnitTest.php | 3 +-- .../Service/CommitterPreconditionsUnitTest.php | 3 +-- .../Precondition/Service/CommonPreconditionsUnitTest.php | 3 +-- tests/Precondition/Service/PreconditionTestCase.php | 7 ++++++- .../Service/StagingDirDoesNotExistUnitTest.php | 3 +-- tests/Precondition/Service/StagingDirExistsUnitTest.php | 3 +-- .../Precondition/Service/StagingDirIsWritableUnitTest.php | 3 +-- 11 files changed, 16 insertions(+), 26 deletions(-) diff --git a/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php b/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php index c2d2060bb..744b43ca9 100644 --- a/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php +++ b/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php @@ -5,7 +5,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveAndStagingDirsAreDifferent; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveAndStagingDirsAreDifferent @@ -39,11 +38,6 @@ public function testUnfulfilled(): void { $samePath = PathHelper::activeDirPath(); - $this->doTestUnfulfilled( - new TestTranslatableExceptionMessage('The active and staging directories are the same.'), - null, - $samePath, - $samePath, - ); + $this->doTestUnfulfilled('The active and staging directories are the same.', null, $samePath, $samePath); } } diff --git a/tests/Precondition/Service/ActiveDirExistsUnitTest.php b/tests/Precondition/Service/ActiveDirExistsUnitTest.php index ab0aa7961..4e32bde24 100644 --- a/tests/Precondition/Service/ActiveDirExistsUnitTest.php +++ b/tests/Precondition/Service/ActiveDirExistsUnitTest.php @@ -6,7 +6,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirExists; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -55,6 +54,6 @@ public function testUnfulfilled(): void ->exists(PathHelper::activeDirPath()) ->willReturn(false); - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); + $this->doTestUnfulfilled($message); } } diff --git a/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php b/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php index ef37a2819..65f0e4d3e 100644 --- a/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php +++ b/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php @@ -7,7 +7,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsReady; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -72,6 +71,6 @@ public function testUnfulfilled(): void ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); + $this->doTestUnfulfilled($message); } } diff --git a/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php b/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php index 60fcc3d33..aa3bfa552 100644 --- a/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php +++ b/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php @@ -8,7 +8,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\BeginnerPreconditions; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -83,6 +82,6 @@ public function testUnfulfilled(): void ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); + $this->doTestUnfulfilled($message); } } diff --git a/tests/Precondition/Service/CleanerPreconditionsUnitTest.php b/tests/Precondition/Service/CleanerPreconditionsUnitTest.php index 3f9bd83eb..53b15a7b1 100644 --- a/tests/Precondition/Service/CleanerPreconditionsUnitTest.php +++ b/tests/Precondition/Service/CleanerPreconditionsUnitTest.php @@ -7,7 +7,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\CleanerPreconditions; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -73,6 +72,6 @@ public function testUnfulfilled(): void ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); + $this->doTestUnfulfilled($message); } } diff --git a/tests/Precondition/Service/CommitterPreconditionsUnitTest.php b/tests/Precondition/Service/CommitterPreconditionsUnitTest.php index b6bc37365..9fd58f16f 100644 --- a/tests/Precondition/Service/CommitterPreconditionsUnitTest.php +++ b/tests/Precondition/Service/CommitterPreconditionsUnitTest.php @@ -8,7 +8,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\CommitterPreconditions; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -83,6 +82,6 @@ public function testUnfulfilled(): void ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); + $this->doTestUnfulfilled($message); } } diff --git a/tests/Precondition/Service/CommonPreconditionsUnitTest.php b/tests/Precondition/Service/CommonPreconditionsUnitTest.php index f6f6e2638..bb019ab9f 100644 --- a/tests/Precondition/Service/CommonPreconditionsUnitTest.php +++ b/tests/Precondition/Service/CommonPreconditionsUnitTest.php @@ -9,7 +9,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\CommonPreconditions; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -99,6 +98,6 @@ public function testUnfulfilled(): void ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) ->willThrow($previous); - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message)); + $this->doTestUnfulfilled($message); } } diff --git a/tests/Precondition/Service/PreconditionTestCase.php b/tests/Precondition/Service/PreconditionTestCase.php index 025d9bd8c..0e8a0f94a 100644 --- a/tests/Precondition/Service/PreconditionTestCase.php +++ b/tests/Precondition/Service/PreconditionTestCase.php @@ -9,6 +9,7 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; +use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; abstract class PreconditionTestCase extends TestCase { @@ -56,11 +57,15 @@ protected function doTestFulfilled( } protected function doTestUnfulfilled( - TranslatableInterface $expectedStatusMessage, + TranslatableInterface|string $expectedStatusMessage, ?string $previousException = null, ?PathInterface $activeDirPath = null, ?PathInterface $stagingDirPath = null, ): void { + if (is_string($expectedStatusMessage)) { + $expectedStatusMessage = new TestTranslatableExceptionMessage($expectedStatusMessage); + } + $activeDirPath ??= PathHelper::activeDirPath(); $stagingDirPath ??= PathHelper::stagingDirPath(); $sut = $this->createSut(); diff --git a/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php b/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php index c8fc41fad..27a90ac5e 100644 --- a/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php +++ b/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php @@ -6,7 +6,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirDoesNotExist; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -50,7 +49,7 @@ public function testFulfilled(): void /** @covers ::assertIsFulfilled */ public function testUnfulfilled(): void { - $message = new TestTranslatableExceptionMessage('The staging directory already exists.'); + $message = 'The staging directory already exists.'; $this->filesystem ->exists(PathHelper::stagingDirPath()) ->willReturn(true); diff --git a/tests/Precondition/Service/StagingDirExistsUnitTest.php b/tests/Precondition/Service/StagingDirExistsUnitTest.php index 792a3ef37..01e362782 100644 --- a/tests/Precondition/Service/StagingDirExistsUnitTest.php +++ b/tests/Precondition/Service/StagingDirExistsUnitTest.php @@ -6,7 +6,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirExists; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -50,7 +49,7 @@ public function testFulfilled(): void /** @covers ::assertIsFulfilled */ public function testUnfulfilled(): void { - $message = new TestTranslatableExceptionMessage('The staging directory does not exist.'); + $message = 'The staging directory does not exist.'; $this->filesystem ->exists(PathHelper::stagingDirPath()) ->willReturn(false); diff --git a/tests/Precondition/Service/StagingDirIsWritableUnitTest.php b/tests/Precondition/Service/StagingDirIsWritableUnitTest.php index 71cbc1911..0483b8e66 100644 --- a/tests/Precondition/Service/StagingDirIsWritableUnitTest.php +++ b/tests/Precondition/Service/StagingDirIsWritableUnitTest.php @@ -6,7 +6,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirIsWritable; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -51,7 +50,7 @@ public function testFulfilled(): void /** @covers ::assertIsFulfilled */ public function testUnfulfilled(): void { - $message = new TestTranslatableExceptionMessage('The staging directory is not writable.'); + $message = 'The staging directory is not writable.'; $this->filesystem ->isWritable(PathHelper::stagingDirPath()) ->willReturn(false); From f437add02d76a9e67aee13316a52d50af85f5a77 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 18 Aug 2023 10:48:36 -0400 Subject: [PATCH 42/75] Add TestDox custom Composer script and improved tests for that use and in general. --- .github/workflows/main.yml | 24 ++++++- .idea/dictionaries/project.xml | 1 + composer.json | 2 + tests/Core/BeginnerUnitTest.php | 8 +-- tests/Core/CleanerUnitTest.php | 4 +- tests/Core/CommitterUnitTest.php | 8 +-- tests/Core/StagerUnitTest.php | 12 ++-- .../Service/EnvironmentFunctionalTest.php | 8 +-- .../Factory/FileSyncerFactoryUnitTest.php | 4 +- .../Service/FileSyncerFunctionalTestCase.php | 22 ++---- .../FileSyncer/Service/FileSyncerTestCase.php | 15 +--- .../Service/PhpFileSyncerUnitTest.php | 32 --------- .../Service/RsyncFileSyncerUnitTest.php | 4 +- .../Filesystem/Service/FilesystemUnitTest.php | 56 ++++----------- .../Service/ExecutableFinderUnitTest.php | 69 ++++--------------- tests/Helper/PathHelperUnitTest.php | 12 ++-- tests/Path/Factory/PathFactoryUnitTest.php | 2 +- .../Service/AbstractPreconditionUnitTest.php | 4 +- .../AbstractPreconditionsTreeUnitTest.php | 4 +- .../FileIteratingPreconditionUnitTestCase.php | 4 +- .../Factory/ProcessFactoryUnitTest.php | 6 +- .../Factory/SymfonyProcessFactoryUnitTest.php | 12 ++-- .../Service/AbstractProcessRunnerUnitTest.php | 21 ++---- tests/Process/Service/ProcessUnitTest.php | 12 ++-- tests/TestCase.php | 2 + tests/TestUtils/ProviderTrait.php | 17 +++++ .../TranslatableAwareTraitUnitTest.php | 22 +++--- .../Factory/TranslatableFactoryUnitTest.php | 5 +- .../Service/TranslatorUnitTest.php | 8 +-- 29 files changed, 147 insertions(+), 253 deletions(-) create mode 100644 tests/TestUtils/ProviderTrait.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c87669291..2a7273a5d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ on: jobs: static_analysis: - name: "Static Analysis: ubuntu-latest" + name: "Static Analysis" runs-on: ubuntu-latest steps: - name: "Set up PHP" @@ -37,6 +37,26 @@ jobs: - name: "Run all static analysis tools" run: "composer static" + testdox: + name: "TestDox" + runs-on: ubuntu-latest + steps: + - name: "Set up PHP" + uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action + with: + php-version: "8.1" + ini-values: assert.active=1, assert.exception=1, zend.assertions=1 + coverage: none + + - name: "Checkout code" + uses: actions/checkout@v3 # https://github.com/marketplace/actions/checkout + + - name: "Install dependencies" + uses: ramsey/composer-install@v2 # https://github.com/marketplace/actions/install-composer-dependencies + + - name: "Run tests with TestDox" + run: "composer dox" + tests: name: "Test: ${{ matrix.os }} / deps-${{ matrix.dependencies }}" runs-on: "${{ matrix.os }}" @@ -91,7 +111,7 @@ jobs: if: ${{ runner.os == 'Windows' }} performance: - name: "Performance: ubuntu-latest" + name: "Performance" runs-on: ubuntu-latest steps: - name: "Set up PHP" diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml index d4ee430a2..a7258d424 100644 --- a/.idea/dictionaries/project.xml +++ b/.idea/dictionaries/project.xml @@ -58,6 +58,7 @@ strlen subdir sysexits + testdox testsuites thecodingmachine translatables diff --git a/composer.json b/composer.json index 427d4880b..00ffff0b2 100644 --- a/composer.json +++ b/composer.json @@ -98,6 +98,7 @@ "cbf": "phpcbf", "coverage": "open $(pwd)/var/phpunit/html-coverage/index.html || echo 'Run the \"test\" command to generate the coverage report.'", "cs": "@phpcs", + "dox": "phpunit --testdox --exclude-group=windows_only", "fast": "phpunit --exclude-group=slow,windows_only", "fix": "@phpcbf", "functional": "phpunit --testsuite=functional --exclude-group=windows_only", @@ -128,6 +129,7 @@ "cbf": "[phpcbf] Automatically fixes standards violations where possible", "coverage": "Opens the code coverage report generated by the \"test\" script (on macOS)", "cs": "[phpcs] Checks code for standards compliance", + "dox": "Runs tests with TestDox output", "fast": "Runs only fast automated tests", "fix": "[phpcbf] Automatically fixes standards violations where possible", "functional": "Runs functional tests", diff --git a/tests/Core/BeginnerUnitTest.php b/tests/Core/BeginnerUnitTest.php index e406b1253..3d38a666b 100644 --- a/tests/Core/BeginnerUnitTest.php +++ b/tests/Core/BeginnerUnitTest.php @@ -88,14 +88,14 @@ public function testBeginWithOptionalParams( public function providerBeginWithOptionalParams(): array { return [ - [ + 'Minimum values' => [ 'activeDir' => 'one/two', 'stagingDir' => 'three/four', 'givenExclusions' => null, 'callback' => null, 'timeout' => 0, ], - [ + 'Simple values' => [ 'activeDir' => 'five/six', 'stagingDir' => 'seven/eight', 'givenExclusions' => new TestPathList(), @@ -140,12 +140,12 @@ public function testExceptions(ExceptionInterface $exception): void public function providerExceptions(): array { return [ - [ + 'InvalidArgumentException' => [ 'exception' => new InvalidArgumentException( new TestTranslatableExceptionMessage('one'), ), ], - [ + 'IOException' => [ 'exception' => new IOException( new TestTranslatableExceptionMessage('two'), ), diff --git a/tests/Core/CleanerUnitTest.php b/tests/Core/CleanerUnitTest.php index 9346baeef..c4902bcf7 100644 --- a/tests/Core/CleanerUnitTest.php +++ b/tests/Core/CleanerUnitTest.php @@ -78,12 +78,12 @@ public function testCleanWithOptionalParams(string $path, ?OutputCallbackInterfa public function providerCleanWithOptionalParams(): array { return [ - [ + 'Minimum values' => [ 'path' => '/one/two', 'callback' => null, 'timeout' => 0, ], - [ + 'Simple values' => [ 'path' => 'three/four', 'callback' => new TestOutputCallback(), 'timeout' => 10, diff --git a/tests/Core/CommitterUnitTest.php b/tests/Core/CommitterUnitTest.php index fdb56beb8..e4628b27b 100644 --- a/tests/Core/CommitterUnitTest.php +++ b/tests/Core/CommitterUnitTest.php @@ -88,14 +88,14 @@ public function testCommitWithOptionalParams( public function providerCommitWithOptionalParams(): array { return [ - [ + 'Minimum values' => [ 'stagingDir' => '/one/two', 'activeDir' => '/three/four', 'exclusions' => null, 'callback' => null, 'timeout' => 0, ], - [ + 'Simple values' => [ 'stagingDir' => 'five/six', 'activeDir' => 'seven/eight', 'exclusions' => new TestPathList(), @@ -147,11 +147,11 @@ public function testExceptions(ExceptionInterface $exception, string $message): public function providerExceptions(): array { return [ - [ + 'InvalidArgumentException' => [ 'exception' => new InvalidArgumentException(new TestTranslatableExceptionMessage('one')), 'message' => 'one', ], - [ + 'IOException' => [ 'exception' => new IOException(new TestTranslatableExceptionMessage('two')), 'message' => 'two', ], diff --git a/tests/Core/StagerUnitTest.php b/tests/Core/StagerUnitTest.php index b5f1fb3b9..d3497e0a7 100644 --- a/tests/Core/StagerUnitTest.php +++ b/tests/Core/StagerUnitTest.php @@ -95,7 +95,7 @@ public function testStageWithOptionalParams( public function providerStageWithOptionalParams(): array { return [ - [ + 'Minimum values ' => [ 'givenCommand' => ['update'], 'expectedCommand' => [ '--working-dir=' . PathHelper::stagingDirAbsolute(), @@ -104,7 +104,7 @@ public function providerStageWithOptionalParams(): array 'callback' => null, 'timeout' => 0, ], - [ + 'Simple values ' => [ 'givenCommand' => [self::INERT_COMMAND], 'expectedCommand' => [ '--working-dir=' . PathHelper::stagingDirAbsolute(), @@ -168,8 +168,8 @@ public function testCommandContainsWorkingDirOption(array $command): void public function providerCommandContainsWorkingDirOption(): array { return [ - [['--working-dir' => 'example/package']], - [['-d' => 'example/package']], + 'Full name' => [['--working-dir' => 'example/package']], + 'Short name' => [['-d' => 'example/package']], ]; } @@ -205,11 +205,11 @@ public function testExceptions(ExceptionInterface $exception, string $message): public function providerExceptions(): array { return [ - [ + 'IOException' => [ 'exception' => new IOException(new TestTranslatableExceptionMessage('one')), 'message' => 'one', ], - [ + 'LogicException' => [ 'exception' => new LogicException(new TestTranslatableExceptionMessage('two')), 'message' => 'two', ], diff --git a/tests/Environment/Service/EnvironmentFunctionalTest.php b/tests/Environment/Service/EnvironmentFunctionalTest.php index e1935c898..d527f0a80 100644 --- a/tests/Environment/Service/EnvironmentFunctionalTest.php +++ b/tests/Environment/Service/EnvironmentFunctionalTest.php @@ -33,11 +33,9 @@ public function testSetTimeLimit(int $timeout): void public function providerSetTimeLimit(): array { return [ - [-30], - [-5], - [0], - [5], - [30], + 'Positive number' => [30], + 'Zero' => [0], + 'Negative number' => [-30], ]; } } diff --git a/tests/FileSyncer/Factory/FileSyncerFactoryUnitTest.php b/tests/FileSyncer/Factory/FileSyncerFactoryUnitTest.php index e4d28ca79..8e7c8019e 100644 --- a/tests/FileSyncer/Factory/FileSyncerFactoryUnitTest.php +++ b/tests/FileSyncer/Factory/FileSyncerFactoryUnitTest.php @@ -62,13 +62,13 @@ public function testCreate(string $executable, int $calledTimes, ?string $path, public function providerCreate(): array { return [ - [ + 'rsync found' => [ 'executable' => 'rsync', 'calledTimes' => 1, 'path' => '/usr/bin/rsync', 'instanceOf' => RsyncFileSyncerInterface::class, ], - [ + 'rsync not found' => [ 'executable' => 'n/a', 'calledTimes' => 0, 'path' => null, diff --git a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php index 3504cb8e5..99649a943 100644 --- a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -38,29 +38,15 @@ abstract protected function fileSyncerClass(): string; /** * @covers ::sync * - * @dataProvider providerSyncTimeout + * @dataProvider providerTimeouts */ - public function testSyncTimeout(int $givenTimeout, int $expectedTimeout): void + public function testSyncTimeout(int $timeout): void { $sut = $this->createSut(); - $sut->sync(PathHelper::sourceDirPath(), PathHelper::destinationDirPath(), null, null, $givenTimeout); + $sut->sync(PathHelper::sourceDirPath(), PathHelper::destinationDirPath(), null, null, $timeout); - self::assertSame((string) $expectedTimeout, ini_get('max_execution_time'), 'Correctly set process timeout.'); - } - - public function providerSyncTimeout(): array - { - return [ - [ - 'givenTimeout' => 0, - 'expectedTimeout' => 0, - ], - [ - 'givenTimeout' => 10, - 'expectedTimeout' => 10, - ], - ]; + self::assertSame((string) $timeout, ini_get('max_execution_time'), 'Correctly set process timeout.'); } /** @covers ::sync */ diff --git a/tests/FileSyncer/Service/FileSyncerTestCase.php b/tests/FileSyncer/Service/FileSyncerTestCase.php index c0247366e..0d0597639 100644 --- a/tests/FileSyncer/Service/FileSyncerTestCase.php +++ b/tests/FileSyncer/Service/FileSyncerTestCase.php @@ -26,9 +26,9 @@ abstract protected function createSut(): FileSyncerInterface; /** * @covers ::sync * - * @dataProvider providerTimeout + * @dataProvider providerTimeouts */ - public function testTimeout(int $timeout): void + public function testSyncTimeout(int $timeout): void { $this->environment->setTimeLimit($timeout) ->shouldBeCalledOnce(); @@ -42,15 +42,4 @@ public function testTimeout(int $timeout): void // @ignoreException } } - - public function providerTimeout(): array - { - return [ - [-30], - [-5], - [0], - [5], - [30], - ]; - } } diff --git a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php index e35a26d43..360503545 100644 --- a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php +++ b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php @@ -19,7 +19,6 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use ReflectionClass; -use Throwable; /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer @@ -251,35 +250,4 @@ public function testTransMissingTranslatableFactory(): void }, AssertionError::class, 'The "p()" method requires a translatable factory. ' . 'Provide one by calling "setTranslatableFactory()" in the constructor.'); } - - /** - * @covers ::sync - * - * @dataProvider providerTimeout - */ - public function testTimeout(int $timeout): void - { - $this->environment->setTimeLimit($timeout) - ->shouldBeCalledOnce(); - $sut = $this->createSut(); - - // Use the same path for the source and destination in - // order to fail validation and avoid side effects. - try { - $sut->sync(PathHelper::sourceDirPath(), PathHelper::sourceDirPath(), null, null, $timeout); - } catch (Throwable) { - // @ignoreException - } - } - - public function providerTimeout(): array - { - return [ - [-30], - [-5], - [0], - [5], - [30], - ]; - } } diff --git a/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php b/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php index 1dccbe264..312714211 100644 --- a/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php +++ b/tests/FileSyncer/Service/RsyncFileSyncerUnitTest.php @@ -234,11 +234,11 @@ public function providerSyncFailure(): array $message = new TestTranslatableExceptionMessage(__METHOD__); return [ - [ + 'LogicException' => [ 'caught' => new LogicException($message), 'thrown' => IOException::class, ], - [ + 'RuntimeException' => [ 'caught' => new RuntimeException($message), 'thrown' => IOException::class, ], diff --git a/tests/Filesystem/Service/FilesystemUnitTest.php b/tests/Filesystem/Service/FilesystemUnitTest.php index 9d98454e1..6af09e567 100644 --- a/tests/Filesystem/Service/FilesystemUnitTest.php +++ b/tests/Filesystem/Service/FilesystemUnitTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Exception\LogicException; use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Process\Service\OutputCallbackInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\Internal\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\Internal\Filesystem\Service\Filesystem; use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; @@ -49,35 +50,15 @@ private function createSut(): Filesystem return new Filesystem($environment, $pathFactory, $symfonyFilesystem, $translatableFactory); } - /** - * @covers ::copy - * - * @dataProvider providerCopy - */ - public function testCopy(string $source, string $destination): void + /** @covers ::copy */ + public function testCopy(): void { - $source = new TestPath($source); - $destination = new TestPath($destination); $this->symfonyFilesystem - ->copy($source->absolute(), $destination->absolute(), true) + ->copy(PathHelper::sourceDirAbsolute(), PathHelper::destinationDirAbsolute(), true) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->copy($source, $destination); - } - - public function providerCopy(): array - { - return [ - [ - 'source' => 'one', - 'destination' => 'two', - ], - [ - 'source' => 'three', - 'destination' => 'four', - ], - ]; + $sut->copy(PathHelper::sourceDirPath(), PathHelper::destinationDirPath()); } /** @covers ::copy */ @@ -130,28 +111,15 @@ public function testCopyDirectoriesTheSame(): void }, LogicException::class, $message); } - /** - * @covers ::mkdir - * - * @dataProvider providerMkdir - */ - public function testMkdir(string $dir): void + /** @covers ::mkdir */ + public function testMkdir(): void { - $stagingDir = new TestPath($dir); $this->symfonyFilesystem - ->mkdir($dir) + ->mkdir(PathHelper::stagingDirAbsolute()) ->shouldBeCalledOnce(); $sut = $this->createSut(); - $sut->mkdir($stagingDir); - } - - public function providerMkdir(): array - { - return [ - ['dir' => 'one'], - ['dir' => 'two'], - ]; + $sut->mkdir(PathHelper::stagingDirPath()); } /** @covers ::mkdir */ @@ -190,12 +158,12 @@ public function testRemove(string $path, ?OutputCallbackInterface $callback, int public function providerRemove(): array { return [ - [ + 'Default values' => [ 'path' => '/one/two', 'callback' => null, - 'timeout' => 0, + 'timeout' => ProcessInterface::DEFAULT_TIMEOUT, ], - [ + 'Simple values' => [ 'path' => 'three/four', 'callback' => new TestOutputCallback(), 'timeout' => 10, diff --git a/tests/Finder/Service/ExecutableFinderUnitTest.php b/tests/Finder/Service/ExecutableFinderUnitTest.php index 8a617649f..aabd7435c 100644 --- a/tests/Finder/Service/ExecutableFinderUnitTest.php +++ b/tests/Finder/Service/ExecutableFinderUnitTest.php @@ -37,85 +37,40 @@ private function createSut(): ExecutableFinderInterface return new ExecutableFinder($executableFinder, $translatorFactory); } - /** @dataProvider providerFind */ - public function testFind(string $firstCommandName, string $firstPath, string $secondCommandName): void + public function testFind(): void { + $command = 'command_name'; $this->symfonyExecutableFinder ->addSuffix('.phar') ->shouldBeCalled() ->willReturn(null); $this->symfonyExecutableFinder - ->find($firstCommandName) + ->find($command) ->shouldBeCalledOnce() - ->willReturn($firstPath); - + ->willReturn($command); $sut = $this->createSut(); - $firstExpected = $sut->find($firstCommandName); - // Find something else to test cache isolation. - $secondPath = $sut->find($secondCommandName); + $actual = $sut->find($command); - self::assertSame($firstExpected, $firstPath, 'Returned correct first path'); - self::assertSame($secondCommandName, $secondPath, 'Returned correct second path (isolated path cache)'); + self::assertSame($command, $actual, 'Returned correct path'); } - public function providerFind(): array - { - return [ - [ - 'firstCommandName' => 'two', - 'firstPath' => '/one/two/two', - 'secondCommandName' => 'three', - ], - [ - 'firstCommandName' => 'seven', - 'firstPath' => '/four/five/seven', - 'secondCommandName' => 'eight', - ], - ]; - } - - /** @dataProvider providerFindNotFound */ - public function testFindNotFound(string $name): void + public function testFindNotFound(): void { + $command = 'command_name'; $this->symfonyExecutableFinder ->addSuffix('.phar') ->shouldBeCalledOnce() ->willReturn(null); $this->symfonyExecutableFinder - ->find($name) + ->find($command) ->shouldBeCalledOnce() ->willReturn(null); $sut = $this->createSut(); - $message = sprintf('The %s executable cannot be found. Make sure it\'s installed and in the $PATH', $name); - self::assertTranslatableException(static function () use ($sut, $name): void { - $sut->find($name); - }, LogicException::class, $message); - } - - public function providerFindNotFound(): array - { - return [ - ['name' => 'one'], - ['name' => 'two'], - ]; - } - - /** Make sure ::find caches result when Composer is not found. */ - public function testFindNotFoundCaching(): void - { - $this->symfonyExecutableFinder - ->addSuffix('.phar') - ->willReturn(null); - $this->symfonyExecutableFinder - ->find('composer') - ->willReturn(null); - $sut = $this->createSut(); - - $message = 'The composer executable cannot be found. Make sure it\'s installed and in the $PATH'; - self::assertTranslatableException(static function () use ($sut): void { - $sut->find('composer'); + $message = sprintf('The %s executable cannot be found. Make sure it\'s installed and in the $PATH', $command); + self::assertTranslatableException(static function () use ($sut, $command): void { + $sut->find($command); }, LogicException::class, $message); } } diff --git a/tests/Helper/PathHelperUnitTest.php b/tests/Helper/PathHelperUnitTest.php index 7f8f428f4..f36fdec9c 100644 --- a/tests/Helper/PathHelperUnitTest.php +++ b/tests/Helper/PathHelperUnitTest.php @@ -97,13 +97,13 @@ public function providerIsAbsolute(): array { return [ // Yes. - [true, '/one/two'], - [true, 'C:\\One\\Two'], - [true, '\\One\\Two'], + 'True: Unix' => [true, '/one/two'], + 'True: Windows' => [true, 'C:\\One\\Two'], + 'True: UNC' => [true, '\\One\\Two'], // No. - [false, 'one/two'], - [false, '../one/two'], - [false, '..\\One\\Two'], + 'False: Unix' => [false, 'one/two'], + 'False: Windows' => [false, '../one/two'], + 'False: UNC' => [false, '..\\One\\Two'], ]; } } diff --git a/tests/Path/Factory/PathFactoryUnitTest.php b/tests/Path/Factory/PathFactoryUnitTest.php index 41658e441..36b599a1c 100644 --- a/tests/Path/Factory/PathFactoryUnitTest.php +++ b/tests/Path/Factory/PathFactoryUnitTest.php @@ -34,7 +34,7 @@ public function testBasicFunctionality( public function providerBasicFunctionality(): array { return [ - [ + 'Simple values' => [ 'string' => 'test.txt', 'basePath' => new TestPath(), 'expected' => new Path('test.txt'), diff --git a/tests/Precondition/Service/AbstractPreconditionUnitTest.php b/tests/Precondition/Service/AbstractPreconditionUnitTest.php index 413241757..91ea206a1 100644 --- a/tests/Precondition/Service/AbstractPreconditionUnitTest.php +++ b/tests/Precondition/Service/AbstractPreconditionUnitTest.php @@ -128,7 +128,7 @@ public function testBasicFunctionality( public function providerBasicFunctionality(): array { return [ - [ + 'Fulfilled, without exclusions' => [ 'name' => 'Name 1', 'description' => 'Description 1', 'exclusions' => null, @@ -137,7 +137,7 @@ public function providerBasicFunctionality(): array 'unfulfilledStatusMessage' => 'Unfulfilled status message 1', 'expectedStatusMessage' => 'Fulfilled status message 1', ], - [ + 'Unfulfilled, with exclusions' => [ 'name' => 'Name 2', 'description' => 'Description 2', 'exclusions' => new TestPathList(), diff --git a/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php b/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php index 26b1a5181..3369186c5 100644 --- a/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php +++ b/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php @@ -115,7 +115,7 @@ public function testBasicFunctionality( public function providerBasicFunctionality(): array { return [ - [ + 'Fulfilled, without exclusions' => [ 'name' => 'Name 1', 'description' => 'Description 1', 'isFulfilled' => true, @@ -124,7 +124,7 @@ public function providerBasicFunctionality(): array 'expectedStatusMessage' => 'Fulfilled status message 1', 'exclusions' => null, ], - [ + 'Unfulfilled, with exclusions' => [ 'name' => 'Name 2', 'description' => 'Description 2', 'isFulfilled' => false, diff --git a/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php b/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php index c0665846f..3ae68f786 100644 --- a/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php +++ b/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php @@ -186,8 +186,8 @@ public function testFileFinderExceptions(ExceptionInterface $previous): void public function providerFileFinderExceptions(): array { return [ - [new InvalidArgumentException(new TestTranslatableMessage('Exclusions include invalid paths.'))], - [new IOException(new TestTranslatableMessage('The directory cannot be found or is not actually a directory.'))], + 'InvalidArgumentException' => [new InvalidArgumentException(new TestTranslatableMessage('Exclusions include invalid paths.'))], + 'IOException' => [new IOException(new TestTranslatableMessage('The directory cannot be found or is not actually a directory.'))], ]; } diff --git a/tests/Process/Factory/ProcessFactoryUnitTest.php b/tests/Process/Factory/ProcessFactoryUnitTest.php index 9100406e2..dbe78ef3a 100644 --- a/tests/Process/Factory/ProcessFactoryUnitTest.php +++ b/tests/Process/Factory/ProcessFactoryUnitTest.php @@ -39,9 +39,9 @@ public function testFactory(array $command): void public function providerFactory(): array { return [ - [[]], - [['one']], - [['one', 'two']], + 'Empty command' => [[]], + 'Simple command' => [['one']], + 'Command with options' => [['one', 'two', 'three']], ]; } } diff --git a/tests/Process/Factory/SymfonyProcessFactoryUnitTest.php b/tests/Process/Factory/SymfonyProcessFactoryUnitTest.php index 669c7c6be..60d6f0cc4 100644 --- a/tests/Process/Factory/SymfonyProcessFactoryUnitTest.php +++ b/tests/Process/Factory/SymfonyProcessFactoryUnitTest.php @@ -14,9 +14,9 @@ final class SymfonyProcessFactoryUnitTest extends TestCase * @covers ::__construct * @covers ::create * - * @dataProvider providerFactory + * @dataProvider providerBasicFunctionality */ - public function testFactory(array $command): void + public function testBasicFunctionality(array $command): void { $translatableFactory = new TestTranslatableFactory(); $sut = new SymfonyProcessFactory($translatableFactory); @@ -27,12 +27,12 @@ public function testFactory(array $command): void self::assertEquals($expected, $actual); } - public function providerFactory(): array + public function providerBasicFunctionality(): array { return [ - [[]], - [['one']], - [['one', 'two']], + 'Empty command' => [[]], + 'Simple command' => [['one']], + 'Command with options' => [['one', 'two', 'three']], ]; } } diff --git a/tests/Process/Service/AbstractProcessRunnerUnitTest.php b/tests/Process/Service/AbstractProcessRunnerUnitTest.php index cd8b26daf..826bac889 100644 --- a/tests/Process/Service/AbstractProcessRunnerUnitTest.php +++ b/tests/Process/Service/AbstractProcessRunnerUnitTest.php @@ -77,9 +77,9 @@ protected function executableName(): string * @covers ::findExecutable * @covers ::run * - * @dataProvider providerRun + * @dataProvider providerBasicFunctionality */ - public function testRun( + public function testBasicFunctionality( string $executableName, array $givenCommand, array $expectedCommand, @@ -108,29 +108,22 @@ public function testRun( $sut->run($givenCommand, $callback, $timeout); } - public function providerRun(): array + public function providerBasicFunctionality(): array { return [ - [ + 'Minimum values' => [ 'executableName' => 'one', 'givenCommand' => [], 'expectedCommand' => ['one'], 'callback' => null, 'timeout' => 0, ], - [ + 'Simple values' => [ 'executableName' => 'two', 'givenCommand' => ['three', 'four'], 'expectedCommand' => ['two', 'three', 'four'], - 'callback' => null, - 'timeout' => 100, - ], - [ - 'executableName' => 'five', - 'givenCommand' => [], - 'expectedCommand' => ['five'], 'callback' => new TestOutputCallback(), - 'timeout' => 200, + 'timeout' => 100, ], ]; } @@ -139,7 +132,7 @@ public function providerRun(): array * @covers ::findExecutable * @covers ::run */ - public function testRunFindExecutableException(): void + public function testRunCannotFindGivenExecutable(): void { $previous = new IOException(new TestTranslatableExceptionMessage()); $this->executableFinder diff --git a/tests/Process/Service/ProcessUnitTest.php b/tests/Process/Service/ProcessUnitTest.php index 9d85af923..b594e3d02 100644 --- a/tests/Process/Service/ProcessUnitTest.php +++ b/tests/Process/Service/ProcessUnitTest.php @@ -187,9 +187,9 @@ public function testRunStatusCode(int $expected): void public function providerRunStatusCode(): array { return [ - ['success' => 0], - ['failure' => 1], - ['arbitrary' => 42], + 'success' => [0], + 'failure' => [1], + 'arbitrary' => [42], ]; } @@ -245,9 +245,9 @@ public function testRunException(Throwable $previous): void public function providerRunException(): array { return [ - [new SymfonyLogicException('SymfonyLogicException')], - [new SymfonyRuntimeException()], - [new Exception('Exception')], + 'SymfonyLogicException' => [new SymfonyLogicException('SymfonyLogicException')], + 'SymfonyRuntimeException' => [new SymfonyRuntimeException()], + 'Exception' => [new Exception('Exception')], ]; } diff --git a/tests/TestCase.php b/tests/TestCase.php index 1292af02e..63f418c4c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\Tests\TestUtils\Domain; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; +use PhpTuf\ComposerStager\Tests\TestUtils\ProviderTrait; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; use PHPUnit\Framework\TestCase as PHPUnitTestCase; use Prophecy\PhpUnit\ProphecyTrait; @@ -23,6 +24,7 @@ abstract class TestCase extends PHPUnitTestCase { use AssertTrait; use ProphecyTrait; + use ProviderTrait; protected const ORIGINAL_CONTENT = ''; protected const CHANGED_CONTENT = 'changed'; diff --git a/tests/TestUtils/ProviderTrait.php b/tests/TestUtils/ProviderTrait.php new file mode 100644 index 000000000..c7341096d --- /dev/null +++ b/tests/TestUtils/ProviderTrait.php @@ -0,0 +1,17 @@ + [30], + 'Zero' => [0], + 'Negative number' => [-30], + ]; + } +} diff --git a/tests/Translation/Factory/TranslatableAwareTraitUnitTest.php b/tests/Translation/Factory/TranslatableAwareTraitUnitTest.php index e8cfea6f0..4567c7cef 100644 --- a/tests/Translation/Factory/TranslatableAwareTraitUnitTest.php +++ b/tests/Translation/Factory/TranslatableAwareTraitUnitTest.php @@ -19,7 +19,7 @@ final class TranslatableAwareTraitUnitTest extends TestCase { /** @covers ::d */ - public function testD(): void + public function testDMethod(): void { $domainOptions = new DomainOptions(); $translator = new TestTranslator(); @@ -40,7 +40,7 @@ public function __construct(TranslatableFactoryInterface $translatableFactory) } /** @covers ::d */ - public function testDomainMissingDomainOptions(): void + public function testDMethodWithMissingTranslatableFactory(): void { $this->expectException(AssertionError::class); $this->expectExceptionMessage('The "d()" method requires a translatable factory. ' @@ -57,9 +57,9 @@ public function testDomainMissingDomainOptions(): void * @covers ::setTranslatableFactory * @covers ::t * - * @dataProvider providerT + * @dataProvider providerTMethod */ - public function testT(array $arguments): void + public function testTMethod(array $arguments): void { $arguments = array_values($arguments); $expected = new TestTranslatableMessage(...$arguments); @@ -79,10 +79,10 @@ public function __construct(TranslatableFactoryInterface $translatableFactory) self::assertEquals($expected, $actual, 'Returned correct translatable object.'); } - public function providerT(): array + public function providerTMethod(): array { return [ - 'String message' => [ + 'Minimum values' => [ ['message' => 'String message'], ], 'Default values' => [ @@ -103,7 +103,7 @@ public function providerT(): array } /** @covers ::t */ - public function testTMissingTranslatableFactory(): void + public function testTMethodWithMissingTranslatableFactory(): void { $this->expectException(AssertionError::class); $this->expectExceptionMessage('The "t()" method requires a translatable factory. ' @@ -119,9 +119,9 @@ public function testTMissingTranslatableFactory(): void /** * @covers ::p * - * @dataProvider providerP + * @dataProvider providerPMethod */ - public function testP(array $parameters): void + public function testPMethod(array $parameters): void { $translatableFactory = new TestTranslatableFactory(); @@ -141,7 +141,7 @@ public function __construct(TranslatableFactoryInterface $translatableFactory) self::assertEquals($expected, $actual); } - public function providerP(): array + public function providerPMethod(): array { return [ 'Empty parameters' => [ @@ -157,7 +157,7 @@ public function providerP(): array } /** @covers ::p */ - public function testPMissingTranslatableFactory(): void + public function testPMethodWithMissingTranslatableFactory(): void { $this->expectException(AssertionError::class); $this->expectExceptionMessage('The "p()" method requires a translatable factory. ' diff --git a/tests/Translation/Factory/TranslatableFactoryUnitTest.php b/tests/Translation/Factory/TranslatableFactoryUnitTest.php index 6f33ed91e..92380dbb4 100644 --- a/tests/Translation/Factory/TranslatableFactoryUnitTest.php +++ b/tests/Translation/Factory/TranslatableFactoryUnitTest.php @@ -33,9 +33,8 @@ public function testCreateDomainOptions(DomainOptionsInterface $expected): void public function providerCreateDomainOptions(): array { return [ - [new DomainOptions()], - [new TestDomainOptions()], - [new TestDomainOptions('one', 'two')], + 'Default' => [new DomainOptions()], + 'Overridden' => [new TestDomainOptions('one', 'two')], ]; } diff --git a/tests/Translation/Service/TranslatorUnitTest.php b/tests/Translation/Service/TranslatorUnitTest.php index 557587bf1..acbee97a9 100644 --- a/tests/Translation/Service/TranslatorUnitTest.php +++ b/tests/Translation/Service/TranslatorUnitTest.php @@ -249,12 +249,8 @@ public function testTranslatorException(Throwable $exception): void public function providerTranslatorException(): array { return [ - [ - new Error('An Error'), - ], - [ - new LogicException('A LogicException'), - ], + 'Error' => [new Error('An Error')], + 'LogicException' => [new LogicException('A LogicException')], ]; } } From 98b5f43afe553a321b52e3bff5a9b1dcda67fb25 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 18 Aug 2023 12:17:06 -0400 Subject: [PATCH 43/75] Force "dox" custom Composer script to use color output. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 00ffff0b2..8cd560a9d 100644 --- a/composer.json +++ b/composer.json @@ -98,7 +98,7 @@ "cbf": "phpcbf", "coverage": "open $(pwd)/var/phpunit/html-coverage/index.html || echo 'Run the \"test\" command to generate the coverage report.'", "cs": "@phpcs", - "dox": "phpunit --testdox --exclude-group=windows_only", + "dox": "phpunit --testdox --color=always --exclude-group=windows_only", "fast": "phpunit --exclude-group=slow,windows_only", "fix": "@phpcbf", "functional": "phpunit --testsuite=functional --exclude-group=windows_only", From 0ac00dc0e4b47423d21136de2ccff1149eaf9952 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 18 Aug 2023 12:38:05 -0400 Subject: [PATCH 44/75] Fix an inaccurate doc comment. --- src/API/Path/Value/PathListInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/API/Path/Value/PathListInterface.php b/src/API/Path/Value/PathListInterface.php index 4a1057320..f317716d9 100644 --- a/src/API/Path/Value/PathListInterface.php +++ b/src/API/Path/Value/PathListInterface.php @@ -24,8 +24,8 @@ public function getAll(): array; /** * Adds a list of raw path strings. * - * Path strings may be absolute or relative, e.g., "/var/www/example" or - * "example". Nothing needs to actually exist at them. + * Path strings must be relative, e.g., "example" or "../example" but + * not "/var/www/example". Nothing needs to actually exist at them. */ public function add(string ...$paths): void; } From cd65d00e3b8d8f382a90095d1b6c46049e12fa92 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 18 Aug 2023 12:48:59 -0400 Subject: [PATCH 45/75] Add "missing" Internal\Helper\PathHelperInterface. --- phpstan.neon.dist | 6 ------ src/Internal/Helper/PathHelper.php | 2 +- src/Internal/Helper/PathHelperInterface.php | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 src/Internal/Helper/PathHelperInterface.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9d76a62dd..7ea81580e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -41,9 +41,6 @@ parameters: - message: '#Cannot access offset .(application|name). on mixed.#' path: src/Internal/Precondition/Service/ComposerIsAvailable.php - - - message: '#Concrete class must implement an interface#' - path: src/Internal/Helper/PathHelper.php - message: '#In method ".*", caught "Throwable" must be rethrown.*#' paths: @@ -55,9 +52,6 @@ parameters: - message: '#.*PreconditionException::__construct\(\) does not call parent constructor from Exception.#' path: src/API/Exception/PreconditionException.php - - - message: '#Method .*\(\) should not be public because it doesn''t implement a method on an interface.#' - path: src/Internal/Helper/PathHelper.php - message: '#Method run\(\) should not be public because it doesn''t implement a method on an interface.#' path: src/Internal/Process/Service/AbstractProcessRunner.php diff --git a/src/Internal/Helper/PathHelper.php b/src/Internal/Helper/PathHelper.php index f5453ffec..6badaae2d 100644 --- a/src/Internal/Helper/PathHelper.php +++ b/src/Internal/Helper/PathHelper.php @@ -9,7 +9,7 @@ * * @internal Don't depend directly on this class. It may be changed or removed at any time without notice. */ -final class PathHelper +final class PathHelper implements PathHelperInterface { /** @codeCoverageIgnore */ private function __construct() diff --git a/src/Internal/Helper/PathHelperInterface.php b/src/Internal/Helper/PathHelperInterface.php new file mode 100644 index 000000000..697b4ec0e --- /dev/null +++ b/src/Internal/Helper/PathHelperInterface.php @@ -0,0 +1,17 @@ + Date: Fri, 18 Aug 2023 13:04:58 -0400 Subject: [PATCH 46/75] Merge Tests\TestUtils into Tests\Translation\Service\TestDomainOptions. --- tests/Core/StagerUnitTest.php | 6 +++--- tests/TestCase.php | 4 ++-- tests/TestUtils/Domain.php | 14 -------------- .../Translation/Service/DomainOptionsUnitTest.php | 5 ++--- tests/Translation/Service/TestDomainOptions.php | 8 +++++--- .../Value/TestTranslatableExceptionMessage.php | 4 ++-- 6 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 tests/TestUtils/Domain.php diff --git a/tests/Core/StagerUnitTest.php b/tests/Core/StagerUnitTest.php index d3497e0a7..cca13e6ca 100644 --- a/tests/Core/StagerUnitTest.php +++ b/tests/Core/StagerUnitTest.php @@ -15,9 +15,9 @@ use PhpTuf\ComposerStager\Internal\Core\Stager; use PhpTuf\ComposerStager\Tests\Process\Service\TestOutputCallback; use PhpTuf\ComposerStager\Tests\TestCase; -use PhpTuf\ComposerStager\Tests\TestUtils\Domain; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; +use PhpTuf\ComposerStager\Tests\Translation\Service\TestDomainOptions; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; use Prophecy\Argument; @@ -136,7 +136,7 @@ public function testCommandContainsComposer(): void $expectedExceptionMessage = new TestTranslatableMessage( 'The Composer command cannot begin with "composer"--it is implied', null, - Domain::EXCEPTIONS, + TestDomainOptions::EXCEPTIONS, ); self::assertTranslatableException(static function () use ($sut): void { $sut->stage([ @@ -158,7 +158,7 @@ public function testCommandContainsWorkingDirOption(array $command): void $expectedExceptionMessage = new TestTranslatableMessage( 'Cannot stage a Composer command containing the "--working-dir" (or "-d") option', null, - Domain::EXCEPTIONS, + TestDomainOptions::EXCEPTIONS, ); self::assertTranslatableException(static function () use ($sut, $command): void { $sut->stage($command, PathHelper::activeDirPath(), PathHelper::stagingDirPath()); diff --git a/tests/TestCase.php b/tests/TestCase.php index 63f418c4c..10aeaa989 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,10 +7,10 @@ use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface; use PhpTuf\ComposerStager\Tests\Precondition\Service\TestPrecondition; use PhpTuf\ComposerStager\Tests\TestUtils\AssertTrait; -use PhpTuf\ComposerStager\Tests\TestUtils\Domain; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\TestUtils\ProviderTrait; +use PhpTuf\ComposerStager\Tests\Translation\Service\TestDomainOptions; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; use PHPUnit\Framework\TestCase as PHPUnitTestCase; use Prophecy\PhpUnit\ProphecyTrait; @@ -96,7 +96,7 @@ protected static function createFile(string $basePath, string $filename): void public static function createTestPreconditionException( string $message = '', ?TranslationParametersInterface $parameters = null, - $domain = Domain::EXCEPTIONS, + $domain = TestDomainOptions::EXCEPTIONS, ): PreconditionException { return new PreconditionException( new TestPrecondition(), diff --git a/tests/TestUtils/Domain.php b/tests/TestUtils/Domain.php deleted file mode 100644 index aaed68954..000000000 --- a/tests/TestUtils/Domain.php +++ /dev/null @@ -1,14 +0,0 @@ -default(), 'Returned correct default domain.'); - self::assertSame(Domain::EXCEPTIONS, $sut->exceptions(), 'Returned correct typecast exceptions domain.'); + self::assertSame(TestDomainOptions::DEFAULT, $sut->default(), 'Returned correct default domain.'); + self::assertSame(TestDomainOptions::EXCEPTIONS, $sut->exceptions(), 'Returned correct typecast exceptions domain.'); } } diff --git a/tests/Translation/Service/TestDomainOptions.php b/tests/Translation/Service/TestDomainOptions.php index e449a8aaf..2721c676c 100644 --- a/tests/Translation/Service/TestDomainOptions.php +++ b/tests/Translation/Service/TestDomainOptions.php @@ -3,13 +3,15 @@ namespace PhpTuf\ComposerStager\Tests\Translation\Service; use PhpTuf\ComposerStager\API\Translation\Service\DomainOptionsInterface; -use PhpTuf\ComposerStager\Tests\TestUtils\Domain; final class TestDomainOptions implements DomainOptionsInterface { + public const EXCEPTIONS = 'exceptions'; + public const DEFAULT = 'messages'; + public function __construct( - private readonly string $default = Domain::DEFAULT, - private readonly string $exceptions = Domain::EXCEPTIONS, + private readonly string $default = self::DEFAULT, + private readonly string $exceptions = self::EXCEPTIONS, ) { } diff --git a/tests/Translation/Value/TestTranslatableExceptionMessage.php b/tests/Translation/Value/TestTranslatableExceptionMessage.php index f867d8f04..610e0f74c 100644 --- a/tests/Translation/Value/TestTranslatableExceptionMessage.php +++ b/tests/Translation/Value/TestTranslatableExceptionMessage.php @@ -4,7 +4,7 @@ use PhpTuf\ComposerStager\API\Translation\Service\TranslatorInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface; -use PhpTuf\ComposerStager\Tests\TestUtils\Domain; +use PhpTuf\ComposerStager\Tests\Translation\Service\TestDomainOptions; use PhpTuf\ComposerStager\Tests\Translation\Service\TestTranslator; final class TestTranslatableExceptionMessage extends TestTranslatableMessage @@ -13,7 +13,7 @@ final class TestTranslatableExceptionMessage extends TestTranslatableMessage public function __construct( private readonly string $message = '', private readonly ?TranslationParametersInterface $parameters = null, - private readonly ?string $domain = Domain::EXCEPTIONS, + private readonly ?string $domain = TestDomainOptions::EXCEPTIONS, ) { } From b0adf366edba020a6ec5cc3af35e161da4d8ad28 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Fri, 18 Aug 2023 13:08:58 -0400 Subject: [PATCH 47/75] Introduce Tests\TestUtils\ContainerHelper. --- tests/EndToEnd/EndToEndFunctionalTestCase.php | 3 ++- .../Service/FileSyncerFunctionalTestCase.php | 3 ++- .../Service/FilesystemFunctionalTest.php | 3 ++- .../Service/FileFinderFunctionalTest.php | 3 ++- .../ComposerIsAvailableFunctionalTest.php | 3 ++- ...SupportsRunningProcessesFunctionalTest.php | 3 ++- ...nkPreconditionsIsolationFunctionalTest.php | 5 +++-- .../NoAbsoluteSymlinksExistFunctionalTest.php | 3 ++- .../NoHardLinksExistFunctionalTest.php | 3 ++- .../NoLinksExistOnWindowsFunctionalTest.php | 3 ++- ...sPointOutsideTheCodebaseFunctionalTest.php | 3 ++- ...ymlinksPointToADirectoryFunctionalTest.php | 3 ++- .../Process/Service/ProcessFunctionalTest.php | 3 ++- tests/TestCase.php | 13 ------------ tests/TestUtils/ContainerHelper.php | 20 +++++++++++++++++++ 15 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 tests/TestUtils/ContainerHelper.php diff --git a/tests/EndToEnd/EndToEndFunctionalTestCase.php b/tests/EndToEnd/EndToEndFunctionalTestCase.php index 73a81558c..8a86549b3 100644 --- a/tests/EndToEnd/EndToEndFunctionalTestCase.php +++ b/tests/EndToEnd/EndToEndFunctionalTestCase.php @@ -15,6 +15,7 @@ use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -34,7 +35,7 @@ abstract class EndToEndFunctionalTestCase extends TestCase protected function setUp(): void { - $container = $this->container(); + $container = ContainerHelper::container(); // Override the FileSyncer implementation. $fileSyncer = $container->getDefinition(FileSyncerInterface::class); diff --git a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php index 99649a943..ef0558fea 100644 --- a/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php +++ b/tests/FileSyncer/Service/FileSyncerFunctionalTestCase.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -24,7 +25,7 @@ protected function tearDown(): void final protected function createSut(): FileSyncerInterface { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface $sut */ diff --git a/tests/Filesystem/Service/FilesystemFunctionalTest.php b/tests/Filesystem/Service/FilesystemFunctionalTest.php index 0f45db5fd..e823fe59f 100644 --- a/tests/Filesystem/Service/FilesystemFunctionalTest.php +++ b/tests/Filesystem/Service/FilesystemFunctionalTest.php @@ -5,6 +5,7 @@ use PhpTuf\ComposerStager\API\Exception\IOException; use PhpTuf\ComposerStager\Internal\Filesystem\Service\Filesystem; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use Symfony\Component\Filesystem\Exception\IOException as SymfonyIOException; @@ -28,7 +29,7 @@ protected function tearDown(): void private function createSut(): Filesystem { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Filesystem\Service\Filesystem $filesystem */ diff --git a/tests/Finder/Service/FileFinderFunctionalTest.php b/tests/Finder/Service/FileFinderFunctionalTest.php index 7eb120873..7f3684c69 100644 --- a/tests/Finder/Service/FileFinderFunctionalTest.php +++ b/tests/Finder/Service/FileFinderFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\Internal\Finder\Service\FileFinder; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** @@ -27,7 +28,7 @@ protected function tearDown(): void private function createSut(): FileFinder { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Finder\Service\FileFinder $fileFinder */ diff --git a/tests/Precondition/Service/ComposerIsAvailableFunctionalTest.php b/tests/Precondition/Service/ComposerIsAvailableFunctionalTest.php index b8f98a5e0..b4f560ebc 100644 --- a/tests/Precondition/Service/ComposerIsAvailableFunctionalTest.php +++ b/tests/Precondition/Service/ComposerIsAvailableFunctionalTest.php @@ -8,6 +8,7 @@ use PhpTuf\ComposerStager\Internal\Finder\Service\ExecutableFinder; use PhpTuf\ComposerStager\Internal\Precondition\Service\ComposerIsAvailable; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; @@ -33,7 +34,7 @@ protected function tearDown(): void private function createSut(): ComposerIsAvailable { - $container = $this->container(); + $container = ContainerHelper::container(); // Override the ExecutableFinder implementation. $executableFinder = new Definition($this->executableFinderClass); diff --git a/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php b/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php index bf6b52eff..a6d48725e 100644 --- a/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php +++ b/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\HostSupportsRunningProcesses; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; /** @@ -15,7 +16,7 @@ final class HostSupportsRunningProcessesFunctionalTest extends TestCase { private function createSut(): HostSupportsRunningProcesses { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Precondition\Service\HostSupportsRunningProcesses $sut */ diff --git a/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php b/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php index 64d7d8910..e08fbf718 100644 --- a/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php +++ b/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php @@ -10,6 +10,7 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use Throwable; @@ -42,7 +43,7 @@ protected function setUp(): void /** A NoUnsupportedLinksExist object can't be created directly because some preconditions need to be excluded. */ private function createTestPreconditionsTree(array $excludePreconditions = []): TestPreconditionsTree { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); $allNoUnsupportedLinkPreconditions = []; @@ -110,7 +111,7 @@ public function testNoLinksExistOnWindows(): void FilesystemHelper::touch($target); symlink($target, $source); - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows $sut */ $sut = $container->get(NoLinksExistOnWindows::class); diff --git a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index 3468cdb31..8e0169712 100644 --- a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -5,6 +5,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -20,7 +21,7 @@ final class NoAbsoluteSymlinksExistFunctionalTest extends LinkPreconditionsFunct { protected function createSut(): NoAbsoluteSymlinksExist { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist $sut */ diff --git a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php index a0bec6f2a..b082305ab 100644 --- a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use Symfony\Component\Filesystem\Path; @@ -19,7 +20,7 @@ final class NoHardLinksExistFunctionalTest extends LinkPreconditionsFunctionalTe { protected function createSut(): NoHardLinksExist { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist $sut */ diff --git a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php index 8cddee274..9544cff10 100644 --- a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php +++ b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -18,7 +19,7 @@ final class NoLinksExistOnWindowsFunctionalTest extends LinkPreconditionsFunctio { protected function createSut(): NoLinksExistOnWindows { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows $sut */ diff --git a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index ac0f23d5c..87415c9d3 100644 --- a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -19,7 +20,7 @@ final class NoSymlinksPointOutsideTheCodebaseFunctionalTest extends LinkPrecondi { protected function createSut(): NoSymlinksPointOutsideTheCodebase { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase $sut */ diff --git a/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php index c925a480d..8c0f6e0a2 100644 --- a/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php +++ b/tests/Precondition/Service/NoSymlinksPointToADirectoryFunctionalTest.php @@ -7,6 +7,7 @@ use PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; use PhpTuf\ComposerStager\Tests\TestUtils\FilesystemHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; @@ -20,7 +21,7 @@ final class NoSymlinksPointToADirectoryFunctionalTest extends LinkPreconditionsF { protected function createSut(): NoSymlinksPointToADirectory { - $container = $this->container(); + $container = ContainerHelper::container(); // Override the FileSyncer implementation. $fileSyncer = $container->getDefinition(FileSyncerInterface::class); diff --git a/tests/Process/Service/ProcessFunctionalTest.php b/tests/Process/Service/ProcessFunctionalTest.php index e05f3c2d2..9b2a98315 100644 --- a/tests/Process/Service/ProcessFunctionalTest.php +++ b/tests/Process/Service/ProcessFunctionalTest.php @@ -5,13 +5,14 @@ use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\Internal\Process\Factory\ProcessFactory; use PhpTuf\ComposerStager\Tests\TestCase; +use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; /** @coversNothing */ final class ProcessFunctionalTest extends TestCase { private function createSut(array $command): ProcessInterface { - $container = $this->container(); + $container = ContainerHelper::container(); $container->compile(); /** @var \PhpTuf\ComposerStager\Internal\Process\Factory\ProcessFactory $factory */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 10aeaa989..48d6a5e84 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,9 +14,6 @@ use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; use PHPUnit\Framework\TestCase as PHPUnitTestCase; use Prophecy\PhpUnit\ProphecyTrait; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; @@ -31,16 +28,6 @@ abstract class TestCase extends PHPUnitTestCase protected PathListInterface $exclusions; - public function container(): ContainerBuilder - { - $container = new ContainerBuilder(); - $loader = new YamlFileLoader($container, new FileLocator()); - $config = PathHelper::makeAbsolute('config/services.yml', PathHelper::repositoryRootAbsolute()); - $loader->load($config); - - return $container; - } - protected static function createTestEnvironment(?string $activeDir = null): void { $activeDir ??= PathHelper::activeDirRelative(); diff --git a/tests/TestUtils/ContainerHelper.php b/tests/TestUtils/ContainerHelper.php new file mode 100644 index 000000000..1287ae0f5 --- /dev/null +++ b/tests/TestUtils/ContainerHelper.php @@ -0,0 +1,20 @@ +load($config); + + return $container; + } +} From 21f0e4ab0e60b40c502021da4610bafa19179a77 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Aug 2023 11:21:43 +0000 Subject: [PATCH 48/75] Bump phpunit/phpunit from 9.6.10 to 9.6.11 Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.6.10 to 9.6.11. - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.6.11/ChangeLog-9.6.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.6.10...9.6.11) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/composer.lock b/composer.lock index e4dc104a6..4fee8b3ab 100644 --- a/composer.lock +++ b/composer.lock @@ -1510,16 +1510,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.16.0", + "version": "v4.17.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17" + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", "shasum": "" }, "require": { @@ -1560,9 +1560,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" }, - "time": "2023-06-25T14:52:30+00:00" + "time": "2023-08-13T19:53:39+00:00" }, { "name": "pdepend/pdepend", @@ -2669,16 +2669,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.26", + "version": "9.2.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1" + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", "shasum": "" }, "require": { @@ -2734,7 +2734,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.26" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" }, "funding": [ { @@ -2742,7 +2743,7 @@ "type": "github" } ], - "time": "2023-03-06T12:58:08+00:00" + "time": "2023-07-26T13:44:30+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2987,16 +2988,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.10", + "version": "9.6.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" + "reference": "810500e92855eba8a7a5319ae913be2da6f957b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/810500e92855eba8a7a5319ae913be2da6f957b0", + "reference": "810500e92855eba8a7a5319ae913be2da6f957b0", "shasum": "" }, "require": { @@ -3070,7 +3071,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.11" }, "funding": [ { @@ -3086,7 +3087,7 @@ "type": "tidelift" } ], - "time": "2023-07-10T04:04:23+00:00" + "time": "2023-08-19T07:10:56+00:00" }, { "name": "psalm/phar", @@ -3837,16 +3838,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -3889,7 +3890,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -3897,7 +3898,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", From 57bf27ab60b3cc6a2173724910e481db4fd3ae40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:05:44 +0000 Subject: [PATCH 49/75] Bump psalm/phar from 5.14.1 to 5.15.0 Bumps [psalm/phar](https://github.com/psalm/phar) from 5.14.1 to 5.15.0. - [Release notes](https://github.com/psalm/phar/releases) - [Commits](https://github.com/psalm/phar/compare/5.14.1...5.15.0) --- updated-dependencies: - dependency-name: psalm/phar dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 4fee8b3ab..400a7ad50 100644 --- a/composer.lock +++ b/composer.lock @@ -3091,16 +3091,16 @@ }, { "name": "psalm/phar", - "version": "5.14.1", + "version": "5.15.0", "source": { "type": "git", "url": "https://github.com/psalm/phar.git", - "reference": "7b832de0cfa7791f663f056b8e01af262027a3d8" + "reference": "19dde3eba5901ff50ca43a5e4c43540f097e0511" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/psalm/phar/zipball/7b832de0cfa7791f663f056b8e01af262027a3d8", - "reference": "7b832de0cfa7791f663f056b8e01af262027a3d8", + "url": "https://api.github.com/repos/psalm/phar/zipball/19dde3eba5901ff50ca43a5e4c43540f097e0511", + "reference": "19dde3eba5901ff50ca43a5e4c43540f097e0511", "shasum": "" }, "require": { @@ -3120,9 +3120,9 @@ "description": "Composer-based Psalm Phar", "support": { "issues": "https://github.com/psalm/phar/issues", - "source": "https://github.com/psalm/phar/tree/5.14.1" + "source": "https://github.com/psalm/phar/tree/5.15.0" }, - "time": "2023-08-01T06:05:09+00:00" + "time": "2023-08-21T03:20:52+00:00" }, { "name": "psr/cache", From 4c6fed7a82b725342b8d7439e341d1da2f92051f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:51:09 +0000 Subject: [PATCH 50/75] Bump phpstan/phpstan from 1.10.29 to 1.10.30 Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.10.29 to 1.10.30. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.29...1.10.30) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index 400a7ad50..d5cec2905 100644 --- a/composer.lock +++ b/composer.lock @@ -2510,16 +2510,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.29", + "version": "1.10.30", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "ee5d8f2d3977fb09e55603eee6fb53bdd76ee9c1" + "reference": "2910afdd3fe33e5afd71c09f3fb0d0845b48c410" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ee5d8f2d3977fb09e55603eee6fb53bdd76ee9c1", - "reference": "ee5d8f2d3977fb09e55603eee6fb53bdd76ee9c1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2910afdd3fe33e5afd71c09f3fb0d0845b48c410", + "reference": "2910afdd3fe33e5afd71c09f3fb0d0845b48c410", "shasum": "" }, "require": { @@ -2568,7 +2568,7 @@ "type": "tidelift" } ], - "time": "2023-08-14T13:24:11+00:00" + "time": "2023-08-22T13:48:25+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", From a48bef5a5cbb6bd96344b5cb984bbff8e2fd2a98 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 23 Aug 2023 12:22:37 -0400 Subject: [PATCH 51/75] Remove obsolete PHPMD warning suppression comment. --- src/Internal/Path/Factory/PathFactory.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Internal/Path/Factory/PathFactory.php b/src/Internal/Path/Factory/PathFactory.php index bef8c1e8c..4513e6741 100644 --- a/src/Internal/Path/Factory/PathFactory.php +++ b/src/Internal/Path/Factory/PathFactory.php @@ -10,8 +10,6 @@ * @package Path * * @internal Don't depend directly on this class. It may be changed or removed at any time without notice. - * - * @SuppressWarnings(PHPMD.StaticAccess) */ final class PathFactory implements PathFactoryInterface { From 64cb52086f0be96cac01517ac7c7edea4cb9ec45 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 23 Aug 2023 20:32:10 -0400 Subject: [PATCH 52/75] Remove workaround for fixed PHPStan bug. --- phpstan.neon.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7ea81580e..b468347b6 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -24,9 +24,6 @@ parameters: - docs - LICENSE - src - excludePaths: - # @see https://github.com/phpstan/phpstan/issues/9577 - - src/API/Exception/TranslatableExceptionTrait.php ignoreErrors: # Production code. - From 3f32b4837fdd9b2201b063f44a1508285137b4bd Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 23 Aug 2023 20:18:34 -0400 Subject: [PATCH 53/75] Merge Internal\Host\Service\HostInterface into Internal\Environment\Service\EnvironmentInterface. --- phpstan.neon.dist | 2 +- .../Environment/Service/Environment.php | 5 +++ .../Service/EnvironmentInterface.php | 3 ++ src/Internal/Host/Service/Host.php | 16 -------- src/Internal/Host/Service/HostInterface.php | 16 -------- .../Service/NoLinksExistOnWindows.php | 6 +-- .../Service/EnvironmentUnitTest.php | 24 ++++++++++++ .../Service/PhpFileSyncerUnitTest.php | 4 +- tests/Host/Service/HostUnitTest.php | 18 --------- tests/Host/Service/TestHost.php | 19 --------- tests/Path/Value/WindowsPathUnitTest.php | 4 +- .../FileIteratingPreconditionUnitTestCase.php | 6 +++ .../Service/NoLinksExistOnWindowsUnitTest.php | 39 +++++-------------- tests/TestUtils/EnvironmentHelper.php | 11 ++++++ 14 files changed, 66 insertions(+), 107 deletions(-) delete mode 100644 src/Internal/Host/Service/Host.php delete mode 100644 src/Internal/Host/Service/HostInterface.php create mode 100644 tests/Environment/Service/EnvironmentUnitTest.php delete mode 100644 tests/Host/Service/HostUnitTest.php delete mode 100644 tests/Host/Service/TestHost.php create mode 100644 tests/TestUtils/EnvironmentHelper.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b468347b6..a29d285b4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,7 +17,7 @@ parameters: - tests treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false - preconditionSystemHash: edc0e29f2fd55b848b7a587e7a16e557 + preconditionSystemHash: 90ee72eee15b35f7daacd473ea33484a translationSystemHash: e573838804f62414d8488e329ec32123 gitattributesExportInclude: - composer.json diff --git a/src/Internal/Environment/Service/Environment.php b/src/Internal/Environment/Service/Environment.php index 45b60574c..9c516e84a 100644 --- a/src/Internal/Environment/Service/Environment.php +++ b/src/Internal/Environment/Service/Environment.php @@ -9,6 +9,11 @@ */ final class Environment implements EnvironmentInterface { + public function isWindows(): bool + { + return PHP_OS_FAMILY === 'Windows'; + } + public function setTimeLimit(int $seconds): bool { if (!function_exists('set_time_limit')) { diff --git a/src/Internal/Environment/Service/EnvironmentInterface.php b/src/Internal/Environment/Service/EnvironmentInterface.php index f2c9f4ddb..61f9265b1 100644 --- a/src/Internal/Environment/Service/EnvironmentInterface.php +++ b/src/Internal/Environment/Service/EnvironmentInterface.php @@ -11,6 +11,9 @@ */ interface EnvironmentInterface { + /** Determines whether the operating system is Windows. */ + public function isWindows(): bool; + /** * Limits the maximum execution time of the current script in seconds. * diff --git a/src/Internal/Host/Service/Host.php b/src/Internal/Host/Service/Host.php deleted file mode 100644 index 43def3149..000000000 --- a/src/Internal/Host/Service/Host.php +++ /dev/null @@ -1,16 +0,0 @@ -host::isWindows(); + return !$this->environment->isWindows(); } protected function getFulfilledStatusMessage(): TranslatableInterface diff --git a/tests/Environment/Service/EnvironmentUnitTest.php b/tests/Environment/Service/EnvironmentUnitTest.php new file mode 100644 index 000000000..981912e7e --- /dev/null +++ b/tests/Environment/Service/EnvironmentUnitTest.php @@ -0,0 +1,24 @@ +createSut(); + + self::assertEquals($isWindowsDirectorySeparator, $sut->isWindows()); + } +} diff --git a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php index 360503545..bfc6b24f7 100644 --- a/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php +++ b/tests/FileSyncer/Service/PhpFileSyncerUnitTest.php @@ -11,8 +11,8 @@ use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\FileSyncer\Service\PhpFileSyncer; -use PhpTuf\ComposerStager\Internal\Host\Service\Host; use PhpTuf\ComposerStager\Tests\Path\Value\TestPath; +use PhpTuf\ComposerStager\Tests\TestUtils\EnvironmentHelper; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; @@ -139,7 +139,7 @@ public function testGetRelativePath(string $ancestor, string $path, string $expe public function providerGetRelativePath(): array { // UNIX-like OS paths. - if (!Host::isWindows()) { + if (!EnvironmentHelper::isWindows()) { return [ 'Match: single directory depth' => [ 'ancestor' => 'one', diff --git a/tests/Host/Service/HostUnitTest.php b/tests/Host/Service/HostUnitTest.php deleted file mode 100644 index e76763f19..000000000 --- a/tests/Host/Service/HostUnitTest.php +++ /dev/null @@ -1,18 +0,0 @@ -environment = $this->prophesize(EnvironmentInterface::class); + $this->environment + ->isWindows() + ->willReturn(false); $this->fileFinder = $this->prophesize(FileFinderInterface::class); $this->fileFinder ->find(Argument::type(PathInterface::class), Argument::type(PathListInterface::class)) diff --git a/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php index 1759adffe..ccce8d864 100644 --- a/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php +++ b/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php @@ -2,9 +2,7 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; -use PhpTuf\ComposerStager\Internal\Host\Service\HostInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows; -use PhpTuf\ComposerStager\Tests\Host\Service\TestHost; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use Prophecy\Argument; @@ -21,13 +19,13 @@ */ final class NoLinksExistOnWindowsUnitTest extends FileIteratingPreconditionUnitTestCase { - private HostInterface $host; - protected function setUp(): void { - $this->host = $this->createWindowsHost(); - parent::setUp(); + + $this->environment + ->isWindows() + ->willReturn(true); } protected function fulfilledStatusMessage(): string @@ -37,34 +35,13 @@ protected function fulfilledStatusMessage(): string protected function createSut(): NoLinksExistOnWindows { + $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new NoLinksExistOnWindows($fileFinder, $filesystem, $this->host, $pathFactory, $translatableFactory); - } - - private function createWindowsHost(): HostInterface - { - return new class() extends TestHost - { - public static function isWindows(): bool - { - return true; - } - }; - } - - private function createNonWindowsHost(): HostInterface - { - return new class() extends TestHost - { - public static function isWindows(): bool - { - return false; - } - }; + return new NoLinksExistOnWindows($environment, $fileFinder, $filesystem, $pathFactory, $translatableFactory); } public function testFulfilled(): void @@ -77,7 +54,9 @@ public function testExitEarlyOnNonWindows(): void $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); - $this->host = $this->createNonWindowsHost(); + $this->environment + ->isWindows() + ->willReturn(false); $this->filesystem ->exists(Argument::cetera()) ->shouldNotBeCalled(); diff --git a/tests/TestUtils/EnvironmentHelper.php b/tests/TestUtils/EnvironmentHelper.php new file mode 100644 index 000000000..3af486703 --- /dev/null +++ b/tests/TestUtils/EnvironmentHelper.php @@ -0,0 +1,11 @@ + Date: Wed, 23 Aug 2023 20:30:00 -0400 Subject: [PATCH 54/75] Move Internal\Environment\Service\EnvironmentInterface into the API layer. --- phpstan.neon.dist | 2 +- .../Environment/Service/EnvironmentInterface.php | 4 ++-- src/Internal/Environment/Service/Environment.php | 2 ++ src/Internal/FileSyncer/Service/PhpFileSyncer.php | 2 +- src/Internal/FileSyncer/Service/RsyncFileSyncer.php | 2 +- src/Internal/Filesystem/Service/Filesystem.php | 2 +- src/Internal/Precondition/Service/NoLinksExistOnWindows.php | 2 +- tests/FileSyncer/Service/FileSyncerTestCase.php | 2 +- tests/Filesystem/Service/FilesystemUnitTest.php | 2 +- .../Service/FileIteratingPreconditionUnitTestCase.php | 2 +- 10 files changed, 12 insertions(+), 10 deletions(-) rename src/{Internal => API}/Environment/Service/EnvironmentInterface.php (86%) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a29d285b4..2f14e2a98 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,7 +17,7 @@ parameters: - tests treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false - preconditionSystemHash: 90ee72eee15b35f7daacd473ea33484a + preconditionSystemHash: 7965d1d9a999ebea1d6fd81571afc495 translationSystemHash: e573838804f62414d8488e329ec32123 gitattributesExportInclude: - composer.json diff --git a/src/Internal/Environment/Service/EnvironmentInterface.php b/src/API/Environment/Service/EnvironmentInterface.php similarity index 86% rename from src/Internal/Environment/Service/EnvironmentInterface.php rename to src/API/Environment/Service/EnvironmentInterface.php index 61f9265b1..9ca3c2bef 100644 --- a/src/Internal/Environment/Service/EnvironmentInterface.php +++ b/src/API/Environment/Service/EnvironmentInterface.php @@ -1,13 +1,13 @@ Date: Thu, 24 Aug 2023 13:46:48 -0400 Subject: [PATCH 55/75] Alphabetize a couple of items in config/services.yml. --- config/services.yml | 4 ++-- docs/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/services.yml b/config/services.yml index 0c229030d..739e972b8 100644 --- a/config/services.yml +++ b/config/services.yml @@ -15,12 +15,12 @@ services: # It is not strictly necessary to specify these details for Composer Stager # itself, but they represent the way a client would configure its container. # Therefore it is how Composer Stager should test itself. See ../docs/README.md. + PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface: + factory: [ '@PhpTuf\ComposerStager\API\FileSyncer\Factory\FileSyncerFactoryInterface', 'create' ] PhpTuf\ComposerStager\Internal\FileSyncer\Factory\FileSyncerFactory: arguments: $phpFileSyncer: '@PhpTuf\ComposerStager\API\FileSyncer\Service\PhpFileSyncerInterface' $rsyncFileSyncer: '@PhpTuf\ComposerStager\API\FileSyncer\Service\RsyncFileSyncerInterface' - PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface: - factory: [ '@PhpTuf\ComposerStager\API\FileSyncer\Factory\FileSyncerFactoryInterface', 'create' ] Symfony\Component\Filesystem\Filesystem: ~ diff --git a/docs/README.md b/docs/README.md index affb12638..0aa61bc6f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -88,12 +88,12 @@ services: - '../vendor/php-tuf/composer-stager/src/*/*/Value' - '../vendor/php-tuf/composer-stager/src/API/Exception' + PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface: + factory: [ '@PhpTuf\ComposerStager\API\FileSyncer\Factory\FileSyncerFactoryInterface', 'create' ] PhpTuf\ComposerStager\Internal\FileSyncer\Factory\FileSyncerFactory: arguments: $phpFileSyncer: '@PhpTuf\ComposerStager\API\FileSyncer\Service\PhpFileSyncerInterface' $rsyncFileSyncer: '@PhpTuf\ComposerStager\API\FileSyncer\Service\RsyncFileSyncerInterface' - PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface: - factory: [ '@PhpTuf\ComposerStager\API\FileSyncer\Factory\FileSyncerFactoryInterface', 'create' ] Symfony\Component\Filesystem\Filesystem: ~ Symfony\Component\Process\ExecutableFinder: ~ From f3cb2ab9ca03354eb53d54a49ec3742ce8254696 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 24 Aug 2023 15:25:01 -0400 Subject: [PATCH 56/75] Add a couple of exception message assertions. --- tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php | 2 +- tests/Precondition/Service/StagerPreconditionsUnitTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php b/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php index 00bcb09ae..f4e585dde 100644 --- a/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php +++ b/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php @@ -114,6 +114,6 @@ public function testUnfulfilled(): void self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); - }, PreconditionException::class); + }, PreconditionException::class, $message); } } diff --git a/tests/Precondition/Service/StagerPreconditionsUnitTest.php b/tests/Precondition/Service/StagerPreconditionsUnitTest.php index 84228ec67..9d236b2b3 100644 --- a/tests/Precondition/Service/StagerPreconditionsUnitTest.php +++ b/tests/Precondition/Service/StagerPreconditionsUnitTest.php @@ -77,6 +77,6 @@ public function testUnfulfilled(): void self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); - }, PreconditionException::class); + }, PreconditionException::class, $message); } } From a7205146490298b32955d94c2f41c13f8112025c Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 24 Aug 2023 15:43:49 -0400 Subject: [PATCH 57/75] Simplify Tests\Precondition\Service\PreconditionTestCase::doTestUnfulfilled(). --- .../Service/ActiveAndStagingDirsAreDifferentUnitTest.php | 3 ++- .../Precondition/Service/ActiveDirIsWritableUnitTest.php | 3 +-- .../Precondition/Service/ComposerIsAvailableUnitTest.php | 8 +++----- .../Service/HostSupportsRunningProcessesUnitTest.php | 8 +++----- tests/Precondition/Service/PreconditionTestCase.php | 7 +------ 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php b/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php index 744b43ca9..1332dffa1 100644 --- a/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php +++ b/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php @@ -36,8 +36,9 @@ public function testFulfilled(): void /** @covers ::assertIsFulfilled */ public function testUnfulfilled(): void { + $message = 'The active and staging directories are the same.'; $samePath = PathHelper::activeDirPath(); - $this->doTestUnfulfilled('The active and staging directories are the same.', null, $samePath, $samePath); + $this->doTestUnfulfilled($message, null, $samePath, $samePath); } } diff --git a/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php b/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php index 79db7325c..85397d4f9 100644 --- a/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php +++ b/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php @@ -6,7 +6,6 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsWritable; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use Prophecy\Prophecy\ObjectProphecy; /** @@ -50,7 +49,7 @@ public function testFulfilled(): void /** @covers ::assertIsFulfilled */ public function testUnfulfilled(): void { - $message = new TestTranslatableExceptionMessage('The active directory is not writable.'); + $message = 'The active directory is not writable.'; $this->filesystem ->isWritable(PathHelper::activeDirPath()) ->willReturn(false); diff --git a/tests/Precondition/Service/ComposerIsAvailableUnitTest.php b/tests/Precondition/Service/ComposerIsAvailableUnitTest.php index ce5df91f3..1c7c68579 100644 --- a/tests/Precondition/Service/ComposerIsAvailableUnitTest.php +++ b/tests/Precondition/Service/ComposerIsAvailableUnitTest.php @@ -10,9 +10,7 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\ComposerIsAvailable; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslationParameters; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -135,9 +133,9 @@ public function testFailedToCreateProcess(): void ->create(Argument::type('array')) ->willThrow($previous); - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage( - 'Cannot check for Composer due to a host configuration problem: %details', - new TestTranslationParameters(['%details' => $message]), + $this->doTestUnfulfilled(sprintf( + 'Cannot check for Composer due to a host configuration problem: %s', + $message, ), $previous::class); } diff --git a/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php b/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php index ca2b41e73..5777e36c0 100644 --- a/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php +++ b/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php @@ -6,9 +6,7 @@ use PhpTuf\ComposerStager\API\Process\Factory\ProcessFactoryInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\HostSupportsRunningProcesses; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslationParameters; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Symfony\Component\Process\Process; @@ -67,9 +65,9 @@ public function testUnfulfilled(): void // longer testing the translated value of the message, just its parts--which is more // like testing assumptions than testing expectations. Add an argument to it to test // the translated string, too. - $this->doTestUnfulfilled(new TestTranslatableExceptionMessage( - 'The host does not support running independent PHP processes: %details', - new TestTranslationParameters(['%details' => $message]), + $this->doTestUnfulfilled(sprintf( + 'The host does not support running independent PHP processes: %s', + $message, ), $previous::class); } } diff --git a/tests/Precondition/Service/PreconditionTestCase.php b/tests/Precondition/Service/PreconditionTestCase.php index 0e8a0f94a..0f2a2fd24 100644 --- a/tests/Precondition/Service/PreconditionTestCase.php +++ b/tests/Precondition/Service/PreconditionTestCase.php @@ -9,7 +9,6 @@ use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; -use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableExceptionMessage; abstract class PreconditionTestCase extends TestCase { @@ -57,15 +56,11 @@ protected function doTestFulfilled( } protected function doTestUnfulfilled( - TranslatableInterface|string $expectedStatusMessage, + string $expectedStatusMessage, ?string $previousException = null, ?PathInterface $activeDirPath = null, ?PathInterface $stagingDirPath = null, ): void { - if (is_string($expectedStatusMessage)) { - $expectedStatusMessage = new TestTranslatableExceptionMessage($expectedStatusMessage); - } - $activeDirPath ??= PathHelper::activeDirPath(); $stagingDirPath ??= PathHelper::stagingDirPath(); $sut = $this->createSut(); From 2392ab7e7759590776cbc42e96345351a9f91294 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 24 Aug 2023 16:26:04 -0400 Subject: [PATCH 58/75] Rename a variable. --- src/Internal/Precondition/Service/CommonPreconditions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Internal/Precondition/Service/CommonPreconditions.php b/src/Internal/Precondition/Service/CommonPreconditions.php index 0a2f92e4b..fb43c683b 100644 --- a/src/Internal/Precondition/Service/CommonPreconditions.php +++ b/src/Internal/Precondition/Service/CommonPreconditions.php @@ -22,14 +22,14 @@ public function __construct( ActiveAndStagingDirsAreDifferentInterface $activeAndStagingDirsAreDifferent, ActiveDirIsReadyInterface $activeDirIsReady, ComposerIsAvailableInterface $composerIsAvailable, - HostSupportsRunningProcessesInterface $hostCanRunProcesses, + HostSupportsRunningProcessesInterface $hostSupportsRunningProcesses, ) { parent::__construct( $translatableFactory, $activeAndStagingDirsAreDifferent, $activeDirIsReady, $composerIsAvailable, - $hostCanRunProcesses, + $hostSupportsRunningProcesses, ); } From ef5ffc45e43880abd0a4d4bc3ebf38668e88d64e Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 24 Aug 2023 16:27:03 -0400 Subject: [PATCH 59/75] Update phpstan.neon.dist. --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2f14e2a98..678942a52 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,7 +17,7 @@ parameters: - tests treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false - preconditionSystemHash: 7965d1d9a999ebea1d6fd81571afc495 + preconditionSystemHash: 6a5ceaef4859614dbdc33c651f8fa6c7 translationSystemHash: e573838804f62414d8488e329ec32123 gitattributesExportInclude: - composer.json From 05b8bf818de3d270127261e6c555538cc4a0dc10 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 24 Aug 2023 18:37:36 -0400 Subject: [PATCH 60/75] Make unnecessarily non-final Internal\Precondition\Service\AbstractPreconditionsTree::getLeaves() final. --- phpstan.neon.dist | 2 +- .../Service/AbstractPreconditionsTree.php | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 678942a52..d7b21d00a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,7 +17,7 @@ parameters: - tests treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false - preconditionSystemHash: 6a5ceaef4859614dbdc33c651f8fa6c7 + preconditionSystemHash: c6b2b48b68975314dc3708c271559fae translationSystemHash: e573838804f62414d8488e329ec32123 gitattributesExportInclude: - composer.json diff --git a/src/Internal/Precondition/Service/AbstractPreconditionsTree.php b/src/Internal/Precondition/Service/AbstractPreconditionsTree.php index e767690e6..86a40d0af 100644 --- a/src/Internal/Precondition/Service/AbstractPreconditionsTree.php +++ b/src/Internal/Precondition/Service/AbstractPreconditionsTree.php @@ -26,6 +26,17 @@ abstract class AbstractPreconditionsTree implements PreconditionInterface /** @var array<\PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface> */ private readonly array $children; + final public function getLeaves(): array + { + $leaves = []; + + foreach ($this->children as $child) { + $leaves[] = $child->getLeaves(); + } + + return array_merge(...$leaves); + } + /** Gets a status message for when the precondition is fulfilled. */ abstract protected function getFulfilledStatusMessage(): TranslatableInterface; @@ -78,16 +89,4 @@ public function assertIsFulfilled( $leaf->assertIsFulfilled($activeDir, $stagingDir, $exclusions); } } - - /** This function is non-final in case subclasses want to implement a different strategy. */ - public function getLeaves(): array - { - $leaves = []; - - foreach ($this->children as $child) { - $leaves[] = $child->getLeaves(); - } - - return array_merge(...$leaves); - } } From aa95978d5921cb09d80136079936273131010748 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 24 Aug 2023 19:01:11 -0400 Subject: [PATCH 61/75] Remove a few obsolete "@todo" comments. [skip ci] --- src/Internal/Filesystem/Service/Filesystem.php | 3 --- .../Service/HostSupportsRunningProcessesUnitTest.php | 4 ---- 2 files changed, 7 deletions(-) diff --git a/src/Internal/Filesystem/Service/Filesystem.php b/src/Internal/Filesystem/Service/Filesystem.php index 1a709bc2b..c8699ba70 100644 --- a/src/Internal/Filesystem/Service/Filesystem.php +++ b/src/Internal/Filesystem/Service/Filesystem.php @@ -97,8 +97,6 @@ public function isDirEmpty(PathInterface $path): bool $scandir = @scandir($path->absolute()); if ($scandir === false) { - // @todo This doesn't seem to fail without the exceptions domain. - /** @noinspection PhpUnhandledExceptionInspection */ throw new IOException($this->t( 'The path does not exist or is not a directory at %path', @@ -156,7 +154,6 @@ public function mkdir(PathInterface $path): void public function readLink(PathInterface $path): PathInterface { if (!$this->isSymlink($path)) { - // @todo This doesn't seem to fail without the exceptions domain. throw new IOException($this->t( 'The path does not exist or is not a symlink at %path', $this->p(['%path' => $path->absolute()]), diff --git a/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php b/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php index 5777e36c0..103411e68 100644 --- a/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php +++ b/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php @@ -61,10 +61,6 @@ public function testUnfulfilled(): void ->shouldBeCalled() ->willThrow($previous); - // @todo Now that ::doTestUnfulfilled() is taking a whole translatable message, it's no - // longer testing the translated value of the message, just its parts--which is more - // like testing assumptions than testing expectations. Add an argument to it to test - // the translated string, too. $this->doTestUnfulfilled(sprintf( 'The host does not support running independent PHP processes: %s', $message, From 47e077d2934a0ee1b32947ffbcf3257f97b261e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 11:46:47 +0000 Subject: [PATCH 62/75] Bump phpstan/phpstan from 1.10.30 to 1.10.32 Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.10.30 to 1.10.32. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.30...1.10.32) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index d5cec2905..084842183 100644 --- a/composer.lock +++ b/composer.lock @@ -2510,16 +2510,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.30", + "version": "1.10.32", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "2910afdd3fe33e5afd71c09f3fb0d0845b48c410" + "reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2910afdd3fe33e5afd71c09f3fb0d0845b48c410", - "reference": "2910afdd3fe33e5afd71c09f3fb0d0845b48c410", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c47e47d3ab03137c0e121e77c4d2cb58672f6d44", + "reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44", "shasum": "" }, "require": { @@ -2568,7 +2568,7 @@ "type": "tidelift" } ], - "time": "2023-08-22T13:48:25+00:00" + "time": "2023-08-24T21:54:50+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", From 121abea8bb29f242e007ba81be48fb62fa7c5124 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Sun, 27 Aug 2023 14:40:21 -0400 Subject: [PATCH 63/75] Add "Source Files" PhpStorm scope. [skip ci] --- .idea/scopes/Source_Files.xml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .idea/scopes/Source_Files.xml diff --git a/.idea/scopes/Source_Files.xml b/.idea/scopes/Source_Files.xml new file mode 100644 index 000000000..799ed27da --- /dev/null +++ b/.idea/scopes/Source_Files.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file From dcd8f9da442e64a5738a19a33a35c888480b53df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:01:31 +0000 Subject: [PATCH 64/75] Bump symfony/dependency-injection from 6.3.2 to 6.3.4 Bumps [symfony/dependency-injection](https://github.com/symfony/dependency-injection) from 6.3.2 to 6.3.4. - [Release notes](https://github.com/symfony/dependency-injection/releases) - [Changelog](https://github.com/symfony/dependency-injection/blob/6.3/CHANGELOG.md) - [Commits](https://github.com/symfony/dependency-injection/compare/v6.3.2...v6.3.4) --- updated-dependencies: - dependency-name: symfony/dependency-injection dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index d5cec2905..9a5f6b88e 100644 --- a/composer.lock +++ b/composer.lock @@ -4649,16 +4649,16 @@ }, { "name": "symfony/dependency-injection", - "version": "v6.3.2", + "version": "v6.3.4", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "474cfbc46aba85a1ca11a27db684480d0db64ba7" + "reference": "68a5a9570806a087982f383f6109c5e925892a49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/474cfbc46aba85a1ca11a27db684480d0db64ba7", - "reference": "474cfbc46aba85a1ca11a27db684480d0db64ba7", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/68a5a9570806a087982f383f6109c5e925892a49", + "reference": "68a5a9570806a087982f383f6109c5e925892a49", "shasum": "" }, "require": { @@ -4710,7 +4710,7 @@ "description": "Allows you to standardize and centralize the way objects are constructed in your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/dependency-injection/tree/v6.3.2" + "source": "https://github.com/symfony/dependency-injection/tree/v6.3.4" }, "funding": [ { @@ -4726,7 +4726,7 @@ "type": "tidelift" } ], - "time": "2023-07-19T20:17:28+00:00" + "time": "2023-08-16T17:55:17+00:00" }, { "name": "symfony/deprecation-contracts", @@ -5261,16 +5261,16 @@ }, { "name": "symfony/var-exporter", - "version": "v6.3.2", + "version": "v6.3.4", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "3400949782c0cb5b3e73aa64cfd71dde000beccc" + "reference": "df1f8aac5751871b83d30bf3e2c355770f8f0691" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/3400949782c0cb5b3e73aa64cfd71dde000beccc", - "reference": "3400949782c0cb5b3e73aa64cfd71dde000beccc", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/df1f8aac5751871b83d30bf3e2c355770f8f0691", + "reference": "df1f8aac5751871b83d30bf3e2c355770f8f0691", "shasum": "" }, "require": { @@ -5315,7 +5315,7 @@ "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v6.3.2" + "source": "https://github.com/symfony/var-exporter/tree/v6.3.4" }, "funding": [ { @@ -5331,7 +5331,7 @@ "type": "tidelift" } ], - "time": "2023-07-26T17:39:03+00:00" + "time": "2023-08-16T18:14:47+00:00" }, { "name": "symfony/yaml", From 9ed1a151b5763086c7f92f2babc2d0de850931e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:01:37 +0000 Subject: [PATCH 65/75] Bump symfony/process from 6.3.2 to 6.3.4 Bumps [symfony/process](https://github.com/symfony/process) from 6.3.2 to 6.3.4. - [Release notes](https://github.com/symfony/process/releases) - [Changelog](https://github.com/symfony/process/blob/6.3/CHANGELOG.md) - [Commits](https://github.com/symfony/process/compare/v6.3.2...v6.3.4) --- updated-dependencies: - dependency-name: symfony/process dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index d5cec2905..eb6e0b742 100644 --- a/composer.lock +++ b/composer.lock @@ -236,16 +236,16 @@ }, { "name": "symfony/process", - "version": "v6.3.2", + "version": "v6.3.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "c5ce962db0d9b6e80247ca5eb9af6472bd4d7b5d" + "reference": "0b5c29118f2e980d455d2e34a5659f4579847c54" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/c5ce962db0d9b6e80247ca5eb9af6472bd4d7b5d", - "reference": "c5ce962db0d9b6e80247ca5eb9af6472bd4d7b5d", + "url": "https://api.github.com/repos/symfony/process/zipball/0b5c29118f2e980d455d2e34a5659f4579847c54", + "reference": "0b5c29118f2e980d455d2e34a5659f4579847c54", "shasum": "" }, "require": { @@ -277,7 +277,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v6.3.2" + "source": "https://github.com/symfony/process/tree/v6.3.4" }, "funding": [ { @@ -293,7 +293,7 @@ "type": "tidelift" } ], - "time": "2023-07-12T16:00:22+00:00" + "time": "2023-08-07T10:39:22+00:00" }, { "name": "symfony/translation-contracts", From 4d9801790c294d008201d21bda70ca7a9cacb053 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Thu, 24 Aug 2023 15:14:19 -0400 Subject: [PATCH 66/75] Add $timeout argument to relevant API\Precondition\Service\PreconditionInterface methods. --- phpstan.neon.dist | 2 +- .../Service/PreconditionInterface.php | 20 +++++++++- src/Internal/Core/Beginner.php | 2 +- src/Internal/Core/Cleaner.php | 2 +- src/Internal/Core/Committer.php | 2 +- .../AbstractFileIteratingPrecondition.php | 8 +++- .../Service/AbstractPrecondition.php | 35 +++++++++++++++-- .../Service/AbstractPreconditionsTree.php | 20 +++++++--- .../ActiveAndStagingDirsAreDifferent.php | 4 +- .../Precondition/Service/ActiveDirExists.php | 8 +++- .../Precondition/Service/ActiveDirIsReady.php | 4 +- .../Service/ActiveDirIsWritable.php | 8 +++- .../Service/BeginnerPreconditions.php | 3 ++ .../Service/CleanerPreconditions.php | 4 +- .../Service/CommitterPreconditions.php | 10 ++++- .../Service/CommonPreconditions.php | 3 ++ .../Service/ComposerIsAvailable.php | 7 +++- .../Service/HostSupportsRunningProcesses.php | 8 +++- .../Service/NoLinksExistOnWindows.php | 15 ------- .../Service/NoSymlinksPointToADirectory.php | 4 +- .../Service/NoUnsupportedLinksExist.php | 3 ++ .../Service/StagerPreconditions.php | 4 +- .../Service/StagingDirDoesNotExist.php | 8 +++- .../Precondition/Service/StagingDirExists.php | 8 +++- .../Service/StagingDirIsReady.php | 4 +- .../Service/StagingDirIsWritable.php | 8 +++- tests/Core/BeginnerUnitTest.php | 8 ++-- tests/Core/CleanerUnitTest.php | 8 ++-- tests/Core/CommitterUnitTest.php | 8 ++-- tests/Core/StagerUnitTest.php | 3 +- tests/Environment/Service/TestEnvironment.php | 18 +++++++++ ...tractFileIteratingPreconditionUnitTest.php | 15 ++++--- .../Service/AbstractPreconditionUnitTest.php | 39 ++++++++++++------- .../AbstractPreconditionsTreeUnitTest.php | 25 +++++++----- ...tiveAndStagingDirsAreDifferentUnitTest.php | 19 ++++----- .../Service/ActiveDirExistsUnitTest.php | 13 ++++--- .../Service/ActiveDirIsReadyUnitTest.php | 19 ++++----- .../Service/ActiveDirIsWritableUnitTest.php | 13 ++++--- .../Service/BeginnerPreconditionsUnitTest.php | 33 ++++++++++------ .../Service/CleanerPreconditionsUnitTest.php | 25 +++++++----- .../CommitterPreconditionsUnitTest.php | 27 +++++++------ .../Service/CommonPreconditionsUnitTest.php | 23 +++++------ .../Service/ComposerIsAvailableUnitTest.php | 10 ++--- .../FileIteratingPreconditionUnitTestCase.php | 19 +++++---- ...SupportsRunningProcessesFunctionalTest.php | 2 +- .../HostSupportsRunningProcessesUnitTest.php | 7 ++-- .../LinkPreconditionsFunctionalTestCase.php | 18 +++++++-- ...nkPreconditionsIsolationFunctionalTest.php | 2 +- .../NoAbsoluteSymlinksExistFunctionalTest.php | 25 +----------- .../NoAbsoluteSymlinksExistUnitTest.php | 6 +-- .../NoHardLinksExistFunctionalTest.php | 31 +-------------- .../Service/NoHardLinksExistUnitTest.php | 17 ++++---- .../NoLinksExistOnWindowsFunctionalTest.php | 29 -------------- .../Service/NoLinksExistOnWindowsUnitTest.php | 4 +- ...sPointOutsideTheCodebaseFunctionalTest.php | 11 ------ ...ymlinksPointOutsideTheCodebaseUnitTest.php | 7 ++-- .../NoSymlinksPointToADirectoryUnitTest.php | 7 ++-- .../NoUnsupportedLinksExistUnitTest.php | 37 +++++++++++------- .../Service/PreconditionTestCase.php | 31 ++++++++++++--- .../Service/StagerPreconditionsUnitTest.php | 29 ++++++++++---- .../StagingDirDoesNotExistUnitTest.php | 9 ++--- .../Service/StagingDirExistsUnitTest.php | 9 ++--- .../Service/StagingDirIsReadyUnitTest.php | 27 +++++++------ .../Service/StagingDirIsWritableUnitTest.php | 9 ++--- .../Precondition/Service/TestPrecondition.php | 4 ++ .../Service/TestPreconditionsTree.php | 4 +- tests/TestCase.php | 3 -- 67 files changed, 493 insertions(+), 364 deletions(-) create mode 100644 tests/Environment/Service/TestEnvironment.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index d7b21d00a..c4b421f39 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,7 +17,7 @@ parameters: - tests treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false - preconditionSystemHash: c6b2b48b68975314dc3708c271559fae + preconditionSystemHash: 54a37bf8c9e9be8e703d4e2219df1d49 translationSystemHash: e573838804f62414d8488e329ec32123 gitattributesExportInclude: - composer.json diff --git a/src/API/Precondition/Service/PreconditionInterface.php b/src/API/Precondition/Service/PreconditionInterface.php index c43119f35..9c33106c6 100644 --- a/src/API/Precondition/Service/PreconditionInterface.php +++ b/src/API/Precondition/Service/PreconditionInterface.php @@ -4,6 +4,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; /** @@ -38,23 +39,39 @@ public function getDescription(): TranslatableInterface; * example dependency is ready," or if unfulfilled, "The example dependency * cannot be found. Make sure it's installed." If the precondition has * unfulfilled leaves, the status message from the first one will be returned. + * + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. */ public function getStatusMessage( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): TranslatableInterface; - /** Determines whether the precondition is fulfilled. */ + /** + * Determines whether the precondition is fulfilled. + * + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. + */ public function isFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): bool; /** * Asserts that the precondition is fulfilled. * + * @param int $timeout + * An optional process timeout (maximum runtime) in seconds. If set to + * zero (0), no time limit is imposed. + * * @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException * If the precondition is unfulfilled. */ @@ -62,6 +79,7 @@ public function assertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void; /** diff --git a/src/Internal/Core/Beginner.php b/src/Internal/Core/Beginner.php index 23b422c11..f69b6ab53 100644 --- a/src/Internal/Core/Beginner.php +++ b/src/Internal/Core/Beginner.php @@ -32,7 +32,7 @@ public function begin( ?OutputCallbackInterface $callback = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { - $this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions); + $this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); try { $this->fileSyncer->sync($activeDir, $stagingDir, $exclusions, $callback, $timeout); diff --git a/src/Internal/Core/Cleaner.php b/src/Internal/Core/Cleaner.php index 57695a087..d1be5a7e0 100644 --- a/src/Internal/Core/Cleaner.php +++ b/src/Internal/Core/Cleaner.php @@ -30,7 +30,7 @@ public function clean( ?OutputCallbackInterface $callback = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { - $this->preconditions->assertIsFulfilled($activeDir, $stagingDir); + $this->preconditions->assertIsFulfilled($activeDir, $stagingDir, null, $timeout); try { $this->filesystem->remove($stagingDir, $callback, $timeout); diff --git a/src/Internal/Core/Committer.php b/src/Internal/Core/Committer.php index e4cbcf542..6d53497ed 100644 --- a/src/Internal/Core/Committer.php +++ b/src/Internal/Core/Committer.php @@ -32,7 +32,7 @@ public function commit( ?OutputCallbackInterface $callback = null, int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { - $this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions); + $this->preconditions->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); try { $this->fileSyncer->sync($stagingDir, $activeDir, $exclusions, $callback, $timeout); diff --git a/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php b/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php index 76fd141f3..4ba31c594 100644 --- a/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php +++ b/src/Internal/Precondition/Service/AbstractFileIteratingPrecondition.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\ExceptionInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; @@ -9,6 +10,7 @@ use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; @@ -37,18 +39,20 @@ abstract protected function assertIsSupportedFile( ): void; public function __construct( + EnvironmentInterface $environment, protected readonly FileFinderInterface $fileFinder, protected readonly FilesystemInterface $filesystem, protected readonly PathFactoryInterface $pathFactory, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { try { $exclusions ??= new PathList(); diff --git a/src/Internal/Precondition/Service/AbstractPrecondition.php b/src/Internal/Precondition/Service/AbstractPrecondition.php index edc2ea2d0..e8015e8ed 100644 --- a/src/Internal/Precondition/Service/AbstractPrecondition.php +++ b/src/Internal/Precondition/Service/AbstractPrecondition.php @@ -2,10 +2,12 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait; @@ -23,9 +25,10 @@ final public function getStatusMessage( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): TranslatableInterface { try { - $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions); + $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); } catch (PreconditionException $e) { return $e->getTranslatableMessage(); } @@ -42,9 +45,10 @@ final public function isFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): bool { try { - $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions); + $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); } catch (PreconditionException) { return false; } @@ -52,11 +56,34 @@ final public function isFulfilled( return true; } + /** + * @throws \PhpTuf\ComposerStager\API\Exception\PreconditionException + * If the precondition is unfulfilled. + */ + abstract protected function doAssertIsFulfilled( + PathInterface $activeDir, + PathInterface $stagingDir, + ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + ): void; + /** Gets a status message for when the precondition is fulfilled. */ abstract protected function getFulfilledStatusMessage(): TranslatableInterface; - public function __construct(TranslatableFactoryInterface $translatableFactory) - { + public function __construct( + protected readonly EnvironmentInterface $environment, + TranslatableFactoryInterface $translatableFactory, + ) { $this->setTranslatableFactory($translatableFactory); } + + public function assertIsFulfilled( + PathInterface $activeDir, + PathInterface $stagingDir, + ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, + ): void { + $this->environment->setTimeLimit($timeout); + $this->doAssertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); + } } diff --git a/src/Internal/Precondition/Service/AbstractPreconditionsTree.php b/src/Internal/Precondition/Service/AbstractPreconditionsTree.php index 86a40d0af..c1024d8c0 100644 --- a/src/Internal/Precondition/Service/AbstractPreconditionsTree.php +++ b/src/Internal/Precondition/Service/AbstractPreconditionsTree.php @@ -2,10 +2,12 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Internal\Translation\Factory\TranslatableAwareTrait; @@ -46,8 +48,11 @@ abstract protected function getFulfilledStatusMessage(): TranslatableInterface; * * @see https://github.com/php-tuf/composer-stager/issues/75 */ - public function __construct(TranslatableFactoryInterface $translatableFactory, PreconditionInterface ...$children) - { + public function __construct( + private readonly EnvironmentInterface $environment, + TranslatableFactoryInterface $translatableFactory, + PreconditionInterface ...$children, + ) { $this->setTranslatableFactory($translatableFactory); $this->children = $children; } @@ -56,9 +61,10 @@ public function getStatusMessage( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): TranslatableInterface { try { - $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions); + $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); } catch (PreconditionException $e) { return $e->getTranslatableMessage(); } @@ -70,9 +76,10 @@ public function isFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): bool { try { - $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions); + $this->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); } catch (PreconditionException) { return false; } @@ -84,9 +91,12 @@ public function assertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { + $this->environment->setTimeLimit($timeout); + foreach ($this->getLeaves() as $leaf) { - $leaf->assertIsFulfilled($activeDir, $stagingDir, $exclusions); + $leaf->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout); } } } diff --git a/src/Internal/Precondition/Service/ActiveAndStagingDirsAreDifferent.php b/src/Internal/Precondition/Service/ActiveAndStagingDirsAreDifferent.php index c311f56ba..73791d25f 100644 --- a/src/Internal/Precondition/Service/ActiveAndStagingDirsAreDifferent.php +++ b/src/Internal/Precondition/Service/ActiveAndStagingDirsAreDifferent.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; /** @@ -26,10 +27,11 @@ public function getDescription(): TranslatableInterface return $this->t('The active and staging directories cannot be the same.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if ($activeDir->absolute() === $stagingDir->absolute()) { throw new PreconditionException($this, $this->t( diff --git a/src/Internal/Precondition/Service/ActiveDirExists.php b/src/Internal/Precondition/Service/ActiveDirExists.php index c76bba3f1..2bde1f608 100644 --- a/src/Internal/Precondition/Service/ActiveDirExists.php +++ b/src/Internal/Precondition/Service/ActiveDirExists.php @@ -2,11 +2,13 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirExistsInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; @@ -18,10 +20,11 @@ final class ActiveDirExists extends AbstractPrecondition implements ActiveDirExistsInterface { public function __construct( + EnvironmentInterface $environment, private readonly FilesystemInterface $filesystem, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -34,10 +37,11 @@ public function getDescription(): TranslatableInterface return $this->t('There must be an active directory present before any operations can be performed.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if (!$this->filesystem->exists($activeDir)) { throw new PreconditionException($this, $this->t( diff --git a/src/Internal/Precondition/Service/ActiveDirIsReady.php b/src/Internal/Precondition/Service/ActiveDirIsReady.php index 079746d14..36a0261f2 100644 --- a/src/Internal/Precondition/Service/ActiveDirIsReady.php +++ b/src/Internal/Precondition/Service/ActiveDirIsReady.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirExistsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirIsReadyInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirIsWritableInterface; @@ -16,11 +17,12 @@ final class ActiveDirIsReady extends AbstractPreconditionsTree implements ActiveDirIsReadyInterface { public function __construct( + EnvironmentInterface $environment, ActiveDirExistsInterface $activeDirExists, ActiveDirIsWritableInterface $activeDirIsWritable, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory, $activeDirExists, $activeDirIsWritable); + parent::__construct($environment, $translatableFactory, $activeDirExists, $activeDirIsWritable); } public function getName(): TranslatableInterface diff --git a/src/Internal/Precondition/Service/ActiveDirIsWritable.php b/src/Internal/Precondition/Service/ActiveDirIsWritable.php index 7eeba0d52..c40b83089 100644 --- a/src/Internal/Precondition/Service/ActiveDirIsWritable.php +++ b/src/Internal/Precondition/Service/ActiveDirIsWritable.php @@ -2,11 +2,13 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirIsWritableInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; @@ -18,10 +20,11 @@ final class ActiveDirIsWritable extends AbstractPrecondition implements ActiveDirIsWritableInterface { public function __construct( + EnvironmentInterface $environment, private readonly FilesystemInterface $filesystem, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -34,10 +37,11 @@ public function getDescription(): TranslatableInterface return $this->t('The active directory must be writable before any operations can be performed.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if (!$this->filesystem->isWritable($activeDir)) { throw new PreconditionException($this, $this->t( diff --git a/src/Internal/Precondition/Service/BeginnerPreconditions.php b/src/Internal/Precondition/Service/BeginnerPreconditions.php index e2ae6c547..5d7b6ba1d 100644 --- a/src/Internal/Precondition/Service/BeginnerPreconditions.php +++ b/src/Internal/Precondition/Service/BeginnerPreconditions.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\BeginnerPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\NoUnsupportedLinksExistInterface; @@ -17,12 +18,14 @@ final class BeginnerPreconditions extends AbstractPreconditionsTree implements BeginnerPreconditionsInterface { public function __construct( + EnvironmentInterface $environment, CommonPreconditionsInterface $commonPreconditions, NoUnsupportedLinksExistInterface $noUnsupportedLinksExist, StagingDirDoesNotExistInterface $stagingDirDoesNotExist, TranslatableFactoryInterface $translatableFactory, ) { parent::__construct( + $environment, $translatableFactory, $commonPreconditions, $noUnsupportedLinksExist, diff --git a/src/Internal/Precondition/Service/CleanerPreconditions.php b/src/Internal/Precondition/Service/CleanerPreconditions.php index 7b2e4ffb9..a9ce7cfbc 100644 --- a/src/Internal/Precondition/Service/CleanerPreconditions.php +++ b/src/Internal/Precondition/Service/CleanerPreconditions.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\CleanerPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsReadyInterface; @@ -16,11 +17,12 @@ final class CleanerPreconditions extends AbstractPreconditionsTree implements CleanerPreconditionsInterface { public function __construct( + EnvironmentInterface $environment, CommonPreconditionsInterface $commonPreconditions, StagingDirIsReadyInterface $stagingDirIsReady, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory, $commonPreconditions, $stagingDirIsReady); + parent::__construct($environment, $translatableFactory, $commonPreconditions, $stagingDirIsReady); } public function getName(): TranslatableInterface diff --git a/src/Internal/Precondition/Service/CommitterPreconditions.php b/src/Internal/Precondition/Service/CommitterPreconditions.php index d57def25e..847eaac48 100644 --- a/src/Internal/Precondition/Service/CommitterPreconditions.php +++ b/src/Internal/Precondition/Service/CommitterPreconditions.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\CommitterPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\NoUnsupportedLinksExistInterface; @@ -17,12 +18,19 @@ final class CommitterPreconditions extends AbstractPreconditionsTree implements CommitterPreconditionsInterface { public function __construct( + EnvironmentInterface $environment, CommonPreconditionsInterface $commonPreconditions, NoUnsupportedLinksExistInterface $noUnsupportedLinksExist, StagingDirIsReadyInterface $stagingDirIsReady, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory, $commonPreconditions, $noUnsupportedLinksExist, $stagingDirIsReady); + parent::__construct( + $environment, + $translatableFactory, + $commonPreconditions, + $noUnsupportedLinksExist, + $stagingDirIsReady, + ); } public function getName(): TranslatableInterface diff --git a/src/Internal/Precondition/Service/CommonPreconditions.php b/src/Internal/Precondition/Service/CommonPreconditions.php index fb43c683b..e47aa5b63 100644 --- a/src/Internal/Precondition/Service/CommonPreconditions.php +++ b/src/Internal/Precondition/Service/CommonPreconditions.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveDirIsReadyInterface; use PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface; @@ -18,6 +19,7 @@ final class CommonPreconditions extends AbstractPreconditionsTree implements CommonPreconditionsInterface { public function __construct( + EnvironmentInterface $environment, TranslatableFactoryInterface $translatableFactory, ActiveAndStagingDirsAreDifferentInterface $activeAndStagingDirsAreDifferent, ActiveDirIsReadyInterface $activeDirIsReady, @@ -25,6 +27,7 @@ public function __construct( HostSupportsRunningProcessesInterface $hostSupportsRunningProcesses, ) { parent::__construct( + $environment, $translatableFactory, $activeAndStagingDirsAreDifferent, $activeDirIsReady, diff --git a/src/Internal/Precondition/Service/ComposerIsAvailable.php b/src/Internal/Precondition/Service/ComposerIsAvailable.php index 5392ba3f9..e320d06ed 100644 --- a/src/Internal/Precondition/Service/ComposerIsAvailable.php +++ b/src/Internal/Precondition/Service/ComposerIsAvailable.php @@ -3,6 +3,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; use JsonException; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\ExceptionInterface; use PhpTuf\ComposerStager\API\Exception\LogicException; use PhpTuf\ComposerStager\API\Exception\PreconditionException; @@ -25,11 +26,12 @@ final class ComposerIsAvailable extends AbstractPrecondition implements Composer private string $executablePath; public function __construct( + EnvironmentInterface $environment, private readonly ExecutableFinderInterface $executableFinder, private readonly ProcessFactoryInterface $processFactory, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -42,10 +44,11 @@ public function getDescription(): TranslatableInterface return $this->t('Composer must be available in order to stage commands.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $this->assertExecutableExists(); $this->assertIsActuallyComposer(); diff --git a/src/Internal/Precondition/Service/HostSupportsRunningProcesses.php b/src/Internal/Precondition/Service/HostSupportsRunningProcesses.php index 2e5eb113d..5726d3e9a 100644 --- a/src/Internal/Precondition/Service/HostSupportsRunningProcesses.php +++ b/src/Internal/Precondition/Service/HostSupportsRunningProcesses.php @@ -2,12 +2,14 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\ExceptionInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\HostSupportsRunningProcessesInterface; use PhpTuf\ComposerStager\API\Process\Factory\ProcessFactoryInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; @@ -19,10 +21,11 @@ final class HostSupportsRunningProcesses extends AbstractPrecondition implements HostSupportsRunningProcessesInterface { public function __construct( + EnvironmentInterface $environment, private readonly ProcessFactoryInterface $processFactory, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -36,10 +39,11 @@ public function getDescription(): TranslatableInterface . 'PHP processes in order to run Composer and other shell commands.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { try { $this->processFactory->create([]); diff --git a/src/Internal/Precondition/Service/NoLinksExistOnWindows.php b/src/Internal/Precondition/Service/NoLinksExistOnWindows.php index c1012433a..d92057618 100644 --- a/src/Internal/Precondition/Service/NoLinksExistOnWindows.php +++ b/src/Internal/Precondition/Service/NoLinksExistOnWindows.php @@ -2,15 +2,10 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; -use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; -use PhpTuf\ComposerStager\API\Finder\Service\FileFinderInterface; -use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\NoLinksExistOnWindowsInterface; -use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; /** @@ -20,16 +15,6 @@ */ final class NoLinksExistOnWindows extends AbstractFileIteratingPrecondition implements NoLinksExistOnWindowsInterface { - public function __construct( - private readonly EnvironmentInterface $environment, - FileFinderInterface $fileFinder, - FilesystemInterface $filesystem, - PathFactoryInterface $pathFactory, - TranslatableFactoryInterface $translatableFactory, - ) { - parent::__construct($fileFinder, $filesystem, $pathFactory, $translatableFactory); - } - public function getName(): TranslatableInterface { return $this->t('No links exist on Windows'); diff --git a/src/Internal/Precondition/Service/NoSymlinksPointToADirectory.php b/src/Internal/Precondition/Service/NoSymlinksPointToADirectory.php index 8045b0c54..b8e285a54 100644 --- a/src/Internal/Precondition/Service/NoSymlinksPointToADirectory.php +++ b/src/Internal/Precondition/Service/NoSymlinksPointToADirectory.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\FileSyncer\Service\FileSyncerInterface; use PhpTuf\ComposerStager\API\FileSyncer\Service\RsyncFileSyncerInterface; @@ -23,13 +24,14 @@ final class NoSymlinksPointToADirectory extends AbstractFileIteratingPreconditio NoSymlinksPointToADirectoryInterface { public function __construct( + EnvironmentInterface $environment, FileFinderInterface $fileFinder, private readonly FileSyncerInterface $fileSyncer, FilesystemInterface $filesystem, PathFactoryInterface $pathFactory, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($fileFinder, $filesystem, $pathFactory, $translatableFactory); + parent::__construct($environment, $fileFinder, $filesystem, $pathFactory, $translatableFactory); } public function getName(): TranslatableInterface diff --git a/src/Internal/Precondition/Service/NoUnsupportedLinksExist.php b/src/Internal/Precondition/Service/NoUnsupportedLinksExist.php index 8eda949fe..4d1673f87 100644 --- a/src/Internal/Precondition/Service/NoUnsupportedLinksExist.php +++ b/src/Internal/Precondition/Service/NoUnsupportedLinksExist.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\NoAbsoluteSymlinksExistInterface; use PhpTuf\ComposerStager\API\Precondition\Service\NoHardLinksExistInterface; use PhpTuf\ComposerStager\API\Precondition\Service\NoLinksExistOnWindowsInterface; @@ -19,6 +20,7 @@ final class NoUnsupportedLinksExist extends AbstractPreconditionsTree implements NoUnsupportedLinksExistInterface { public function __construct( + EnvironmentInterface $environment, TranslatableFactoryInterface $translatableFactory, NoAbsoluteSymlinksExistInterface $noAbsoluteSymlinksExist, NoHardLinksExistInterface $noHardLinksExist, @@ -27,6 +29,7 @@ public function __construct( NoSymlinksPointToADirectoryInterface $noSymlinksPointToADirectory, ) { parent::__construct( + $environment, $translatableFactory, $noAbsoluteSymlinksExist, $noHardLinksExist, diff --git a/src/Internal/Precondition/Service/StagerPreconditions.php b/src/Internal/Precondition/Service/StagerPreconditions.php index f4d72d1e0..dd03d2e87 100644 --- a/src/Internal/Precondition/Service/StagerPreconditions.php +++ b/src/Internal/Precondition/Service/StagerPreconditions.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\CommonPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagerPreconditionsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsReadyInterface; @@ -16,11 +17,12 @@ final class StagerPreconditions extends AbstractPreconditionsTree implements StagerPreconditionsInterface { public function __construct( + EnvironmentInterface $environment, TranslatableFactoryInterface $translatableFactory, CommonPreconditionsInterface $commonPreconditions, StagingDirIsReadyInterface $stagingDirIsReady, ) { - parent::__construct($translatableFactory, $commonPreconditions, $stagingDirIsReady); + parent::__construct($environment, $translatableFactory, $commonPreconditions, $stagingDirIsReady); } public function getName(): TranslatableInterface diff --git a/src/Internal/Precondition/Service/StagingDirDoesNotExist.php b/src/Internal/Precondition/Service/StagingDirDoesNotExist.php index 00ebba907..b4d9a0479 100644 --- a/src/Internal/Precondition/Service/StagingDirDoesNotExist.php +++ b/src/Internal/Precondition/Service/StagingDirDoesNotExist.php @@ -2,11 +2,13 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirDoesNotExistInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; @@ -18,10 +20,11 @@ final class StagingDirDoesNotExist extends AbstractPrecondition implements StagingDirDoesNotExistInterface { public function __construct( + EnvironmentInterface $environment, private readonly FilesystemInterface $filesystem, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -34,10 +37,11 @@ public function getDescription(): TranslatableInterface return $this->t('The staging directory must not already exist before beginning the staging process.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if ($this->filesystem->exists($stagingDir)) { throw new PreconditionException($this, $this->t( diff --git a/src/Internal/Precondition/Service/StagingDirExists.php b/src/Internal/Precondition/Service/StagingDirExists.php index 289e29455..379499d60 100644 --- a/src/Internal/Precondition/Service/StagingDirExists.php +++ b/src/Internal/Precondition/Service/StagingDirExists.php @@ -2,11 +2,13 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirExistsInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; @@ -18,10 +20,11 @@ final class StagingDirExists extends AbstractPrecondition implements StagingDirExistsInterface { public function __construct( + EnvironmentInterface $environment, private readonly FilesystemInterface $filesystem, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -34,10 +37,11 @@ public function getDescription(): TranslatableInterface return $this->t('The staging directory must exist before any operations can be performed.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if (!$this->filesystem->exists($stagingDir)) { throw new PreconditionException($this, $this->t( diff --git a/src/Internal/Precondition/Service/StagingDirIsReady.php b/src/Internal/Precondition/Service/StagingDirIsReady.php index 73949640c..597b87028 100644 --- a/src/Internal/Precondition/Service/StagingDirIsReady.php +++ b/src/Internal/Precondition/Service/StagingDirIsReady.php @@ -2,6 +2,7 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirExistsInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsReadyInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsWritableInterface; @@ -16,11 +17,12 @@ final class StagingDirIsReady extends AbstractPreconditionsTree implements StagingDirIsReadyInterface { public function __construct( + EnvironmentInterface $environment, TranslatableFactoryInterface $translatableFactory, StagingDirExistsInterface $stagingDirExists, StagingDirIsWritableInterface $stagingDirIsWritable, ) { - parent::__construct($translatableFactory, $stagingDirExists, $stagingDirIsWritable); + parent::__construct($environment, $translatableFactory, $stagingDirExists, $stagingDirIsWritable); } public function getName(): TranslatableInterface diff --git a/src/Internal/Precondition/Service/StagingDirIsWritable.php b/src/Internal/Precondition/Service/StagingDirIsWritable.php index 0a13412c3..de680fd6b 100644 --- a/src/Internal/Precondition/Service/StagingDirIsWritable.php +++ b/src/Internal/Precondition/Service/StagingDirIsWritable.php @@ -2,11 +2,13 @@ namespace PhpTuf\ComposerStager\Internal\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Filesystem\Service\FilesystemInterface; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\StagingDirIsWritableInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; @@ -18,10 +20,11 @@ final class StagingDirIsWritable extends AbstractPrecondition implements StagingDirIsWritableInterface { public function __construct( + EnvironmentInterface $environment, private readonly FilesystemInterface $filesystem, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -34,10 +37,11 @@ public function getDescription(): TranslatableInterface return $this->t('The staging directory must be writable before any operations can be performed.'); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if (!$this->filesystem->isWritable($stagingDir)) { throw new PreconditionException($this, $this->t( diff --git a/tests/Core/BeginnerUnitTest.php b/tests/Core/BeginnerUnitTest.php index 3d38a666b..2bbaf75f7 100644 --- a/tests/Core/BeginnerUnitTest.php +++ b/tests/Core/BeginnerUnitTest.php @@ -49,11 +49,13 @@ private function createSut(): Beginner /** @covers ::begin */ public function testBeginWithMinimumParams(): void { + $timeout = ProcessInterface::DEFAULT_TIMEOUT; + $this->preconditions - ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null, $timeout) ->shouldBeCalledOnce(); $this->fileSyncer - ->sync(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null, null, ProcessInterface::DEFAULT_TIMEOUT) + ->sync(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null, null, $timeout) ->shouldBeCalledOnce(); $sut = $this->createSut(); @@ -75,7 +77,7 @@ public function testBeginWithOptionalParams( $activeDir = new TestPath($activeDir); $stagingDir = new TestPath($stagingDir); $this->preconditions - ->assertIsFulfilled($activeDir, $stagingDir, $exclusions) + ->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout) ->shouldBeCalledOnce(); $this->fileSyncer ->sync($activeDir, $stagingDir, $exclusions, $callback, $timeout) diff --git a/tests/Core/CleanerUnitTest.php b/tests/Core/CleanerUnitTest.php index c4902bcf7..1a43c4ed4 100644 --- a/tests/Core/CleanerUnitTest.php +++ b/tests/Core/CleanerUnitTest.php @@ -45,11 +45,13 @@ private function createSut(): Cleaner /** @covers ::clean */ public function testCleanWithMinimumParams(): void { + $timeout = ProcessInterface::DEFAULT_TIMEOUT; + $this->preconditions - ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null, $timeout) ->shouldBeCalledOnce(); $this->filesystem - ->remove(PathHelper::stagingDirPath(), null, ProcessInterface::DEFAULT_TIMEOUT) + ->remove(PathHelper::stagingDirPath(), null, $timeout) ->shouldBeCalledOnce(); $sut = $this->createSut(); @@ -65,7 +67,7 @@ public function testCleanWithOptionalParams(string $path, ?OutputCallbackInterfa { $path = new TestPath($path); $this->preconditions - ->assertIsFulfilled(PathHelper::activeDirPath(), $path) + ->assertIsFulfilled(PathHelper::activeDirPath(), $path, null, $timeout) ->shouldBeCalledOnce(); $this->filesystem ->remove($path, $callback, $timeout) diff --git a/tests/Core/CommitterUnitTest.php b/tests/Core/CommitterUnitTest.php index e4628b27b..10e30985d 100644 --- a/tests/Core/CommitterUnitTest.php +++ b/tests/Core/CommitterUnitTest.php @@ -49,11 +49,13 @@ private function createSut(): Committer /** @covers ::commit */ public function testCommitWithMinimumParams(): void { + $timeout = ProcessInterface::DEFAULT_TIMEOUT; + $this->preconditions - ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null) + ->assertIsFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath(), null, $timeout) ->shouldBeCalledOnce(); $this->fileSyncer - ->sync(PathHelper::stagingDirPath(), PathHelper::activeDirPath(), null, null, ProcessInterface::DEFAULT_TIMEOUT) + ->sync(PathHelper::stagingDirPath(), PathHelper::activeDirPath(), null, null, $timeout) ->shouldBeCalledOnce(); $sut = $this->createSut(); @@ -75,7 +77,7 @@ public function testCommitWithOptionalParams( $activeDir = new TestPath($activeDir); $stagingDir = new TestPath($stagingDir); $this->preconditions - ->assertIsFulfilled($activeDir, $stagingDir, $exclusions) + ->assertIsFulfilled($activeDir, $stagingDir, $exclusions, $timeout) ->shouldBeCalledOnce(); $this->fileSyncer ->sync($stagingDir, $activeDir, $exclusions, $callback, $timeout) diff --git a/tests/Core/StagerUnitTest.php b/tests/Core/StagerUnitTest.php index cca13e6ca..ce37e09c7 100644 --- a/tests/Core/StagerUnitTest.php +++ b/tests/Core/StagerUnitTest.php @@ -55,6 +55,7 @@ public function testStageWithMinimumParams(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = ProcessInterface::DEFAULT_TIMEOUT; $this->preconditions ->assertIsFulfilled($activeDirPath, $stagingDirPath) @@ -64,7 +65,7 @@ public function testStageWithMinimumParams(): void self::INERT_COMMAND, ]; $this->composerRunner - ->run($expectedCommand, null, ProcessInterface::DEFAULT_TIMEOUT) + ->run($expectedCommand, null, $timeout) ->shouldBeCalledOnce(); $sut = $this->createSut(); diff --git a/tests/Environment/Service/TestEnvironment.php b/tests/Environment/Service/TestEnvironment.php new file mode 100644 index 000000000..6f5d9e054 --- /dev/null +++ b/tests/Environment/Service/TestEnvironment.php @@ -0,0 +1,18 @@ +environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); @@ -58,7 +57,13 @@ protected function createSut(): PreconditionInterface // Create a concrete implementation for testing since the SUT in // this case, being abstract, can't be instantiated directly. - return new class ($fileFinder, $filesystem, $pathFactory, $translatableFactory) extends AbstractFileIteratingPrecondition + return new class ( + $environment, + $fileFinder, + $filesystem, + $pathFactory, + $translatableFactory, + ) extends AbstractFileIteratingPrecondition { public bool $exitEarly = false; @@ -96,8 +101,8 @@ protected function exitEarly( } /** - * @covers ::assertIsFulfilled - * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::exitEarly + * @covers ::doAssertIsFulfilled + * @covers ::exitEarly */ public function testExitEarly(): void { diff --git a/tests/Precondition/Service/AbstractPreconditionUnitTest.php b/tests/Precondition/Service/AbstractPreconditionUnitTest.php index 91ea206a1..d02df0a27 100644 --- a/tests/Precondition/Service/AbstractPreconditionUnitTest.php +++ b/tests/Precondition/Service/AbstractPreconditionUnitTest.php @@ -2,9 +2,11 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Factory\TranslatableFactoryInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPrecondition; @@ -32,12 +34,13 @@ protected function setUp(): void protected function createSut(): AbstractPrecondition { + $environment = $this->environment->reveal(); $spy = $this->spy->reveal(); $translatableFactory = new TestTranslatableFactory(); // Create a concrete implementation for testing since the SUT, being // abstract, can't be instantiated directly. - return new class ($spy, $translatableFactory) extends AbstractPrecondition + return new class ($environment, $spy, $translatableFactory) extends AbstractPrecondition { use TranslatableAwareTrait; @@ -47,12 +50,11 @@ protected function createSut(): AbstractPrecondition public string $theUnfulfilledStatusMessage = 'Unfulfilled'; public function __construct( + EnvironmentInterface $environment, protected TestSpyInterface $spy, TranslatableFactoryInterface $translatableFactory, ) { - parent::__construct(new TestTranslatableFactory()); - - $this->setTranslatableFactory($translatableFactory); + parent::__construct($environment, $translatableFactory); } public function getName(): TranslatableInterface @@ -70,10 +72,11 @@ protected function getFulfilledStatusMessage(): TranslatableInterface return new TestTranslatableMessage($this->theFulfilledStatusMessage); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if (!$this->spy->report(func_get_args())) { throw TestCase::createTestPreconditionException($this->theUnfulfilledStatusMessage); @@ -102,13 +105,14 @@ public function testBasicFunctionality( string $fulfilledStatusMessage, string $unfulfilledStatusMessage, string $expectedStatusMessage, + int $timeout, ): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); // Double expectations: once for ::isFulfilled() and once for ::assertIsFulfilled(). $this->spy - ->report([$activeDirPath, $stagingDirPath, $exclusions]) + ->report([$activeDirPath, $stagingDirPath, $exclusions, $timeout]) ->shouldBeCalledTimes(2) ->willReturn($isFulfilled); @@ -120,8 +124,8 @@ public function testBasicFunctionality( self::assertEquals($sut->getName(), $name); self::assertEquals($sut->getDescription(), $description); - self::assertEquals($sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions), $isFulfilled); - self::assertEquals($sut->getStatusMessage($activeDirPath, $stagingDirPath, $exclusions), $expectedStatusMessage); + self::assertEquals($sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions, $timeout), $isFulfilled); + self::assertEquals($sut->getStatusMessage($activeDirPath, $stagingDirPath, $exclusions, $timeout), $expectedStatusMessage); self::assertEquals($sut->getLeaves(), [$sut]); } @@ -136,6 +140,7 @@ public function providerBasicFunctionality(): array 'fulfilledStatusMessage' => 'Fulfilled status message 1', 'unfulfilledStatusMessage' => 'Unfulfilled status message 1', 'expectedStatusMessage' => 'Fulfilled status message 1', + 'timeout' => 0, ], 'Unfulfilled, with exclusions' => [ 'name' => 'Name 2', @@ -145,6 +150,7 @@ public function providerBasicFunctionality(): array 'fulfilledStatusMessage' => 'Fulfilled status message 2', 'unfulfilledStatusMessage' => 'Unfulfilled status message 2', 'expectedStatusMessage' => 'Unfulfilled status message 2', + 'timeout' => 100, ], ]; } @@ -157,22 +163,23 @@ public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->spy ->report(Argument::cetera()) ->willReturn(true); $this->spy - ->report([$activeDirPath, $stagingDirPath]) + ->report([$activeDirPath, $stagingDirPath, $this->exclusions, $timeout]) ->shouldBeCalledOnce() ->willReturn(true); $this->spy - ->report([$activeDirPath, $stagingDirPath, new TestPathList()]) + ->report([$activeDirPath, $stagingDirPath, new TestPathList(), $timeout]) ->shouldBeCalledOnce() ->willReturn(true); $sut = $this->createSut(); - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, new TestPathList()); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, null, $timeout); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, new TestPathList(), $timeout); } /** @@ -183,17 +190,19 @@ public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $exclusions = $this->exclusions; + $timeout = 42; $message = __METHOD__; $this->spy - ->report([$activeDirPath, $stagingDirPath, new TestPathList()]) + ->report([$activeDirPath, $stagingDirPath, $exclusions, $timeout]) ->willReturn(false); $sut = $this->createSut(); /** @noinspection PhpPossiblePolymorphicInvocationInspection */ $sut->theUnfulfilledStatusMessage = $message; - self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath): void { - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, new TestPathList()); + self::assertTranslatableException(static function () use ($sut, $activeDirPath, $stagingDirPath, $exclusions, $timeout): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $exclusions, $timeout); }, PreconditionException::class, $message); } } diff --git a/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php b/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php index 3369186c5..b0125c2f6 100644 --- a/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php +++ b/tests/Precondition/Service/AbstractPreconditionsTreeUnitTest.php @@ -2,10 +2,12 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPrecondition; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPreconditionsTree; @@ -30,11 +32,12 @@ final class AbstractPreconditionsTreeUnitTest extends PreconditionTestCase protected function createSut(...$children): AbstractPreconditionsTree { + $environment = $this->environment->reveal(); $translatableFactory = new TestTranslatableFactory(); // Create a concrete implementation for testing since the SUT, being // abstract, can't be instantiated directly. - return new class ($translatableFactory, ...$children) extends AbstractPreconditionsTree + return new class ($environment, $translatableFactory, ...$children) extends AbstractPreconditionsTree { public string $name = 'Name'; public string $description = 'Description'; @@ -59,9 +62,7 @@ protected function getFulfilledStatusMessage(): TranslatableInterface } /** - * @covers ::getDescription * @covers ::getLeaves - * @covers ::getName * @covers ::getStatusMessage * * @dataProvider providerBasicFunctionality @@ -76,6 +77,7 @@ public function testBasicFunctionality( string $unfulfilledStatusMessage, string $expectedStatusMessage, ?TestPathList $exclusions, + int $timeout, ): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); @@ -89,11 +91,11 @@ public function testBasicFunctionality( ->willReturn([$child]); // Double expectations: once for ::isFulfilled() and once for ::assertIsFulfilled(). - $child->assertIsFulfilled($activeDirPath, $stagingDirPath, $exclusions) + $child->assertIsFulfilled($activeDirPath, $stagingDirPath, $exclusions, $timeout) ->shouldBeCalledOnce(); if (!$isFulfilled) { - $child->assertIsFulfilled($activeDirPath, $stagingDirPath, $exclusions) + $child->assertIsFulfilled($activeDirPath, $stagingDirPath, $exclusions, $timeout) ->willThrow(PreconditionException::class); } @@ -109,7 +111,7 @@ public function testBasicFunctionality( self::assertEquals($name, $sut->getName()); self::assertEquals($description, $sut->getDescription()); - self::assertEquals($isFulfilled, $sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions)); + self::assertEquals($isFulfilled, $sut->isFulfilled($activeDirPath, $stagingDirPath, $exclusions, $timeout)); } public function providerBasicFunctionality(): array @@ -123,6 +125,7 @@ public function providerBasicFunctionality(): array 'unfulfilledStatusMessage' => 'Unfulfilled status message 1', 'expectedStatusMessage' => 'Fulfilled status message 1', 'exclusions' => null, + 'timeout' => 10, ], 'Unfulfilled, with exclusions' => [ 'name' => 'Name 2', @@ -132,6 +135,7 @@ public function providerBasicFunctionality(): array 'unfulfilledStatusMessage' => 'Unfulfilled status message 2', 'expectedStatusMessage' => 'Unfulfilled status message 2', 'exclusions' => new TestPathList(), + 'timeout' => 100, ], ]; } @@ -142,6 +146,7 @@ public function testIsFulfilledBubbling(): void $message = new TestTranslatableExceptionMessage(__METHOD__); $createLeaf = function (bool $isFulfilled) use ($message): PreconditionInterface { + $environment = $this->environment->reveal(); /** @var \Prophecy\Prophecy\ObjectProphecy|\PhpTuf\ComposerStager\Tests\TestUtils\TestSpyInterface $spy */ $spy = $this->prophesize(TestSpyInterface::class); $spy->report('assertIsFulfilled') @@ -149,14 +154,15 @@ public function testIsFulfilledBubbling(): void ->shouldBeCalledTimes(2); $spy = $spy->reveal(); - return new Class($isFulfilled, $message, $spy) extends AbstractPrecondition + return new Class($environment, $isFulfilled, $message, $spy) extends AbstractPrecondition { public function __construct( + EnvironmentInterface $environment, private readonly bool $isFulfilled, private readonly TranslatableInterface $message, private readonly TestSpyInterface $spy, ) { - parent::__construct(new TestTranslatableFactory()); + parent::__construct($environment, new TestTranslatableFactory()); } protected function getFulfilledStatusMessage(): TranslatableInterface @@ -174,10 +180,11 @@ public function getDescription(): TranslatableInterface return new TestTranslatableMessage(); } - public function assertIsFulfilled( + protected function doAssertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $this->spy->report('assertIsFulfilled'); diff --git a/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php b/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php index 1332dffa1..6ed9c5ca3 100644 --- a/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php +++ b/tests/Precondition/Service/ActiveAndStagingDirsAreDifferentUnitTest.php @@ -6,24 +6,21 @@ use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -/** - * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveAndStagingDirsAreDifferent - * - * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled - */ +/** @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveAndStagingDirsAreDifferent */ final class ActiveAndStagingDirsAreDifferentUnitTest extends PreconditionTestCase { protected function createSut(): ActiveAndStagingDirsAreDifferent { + $environment = $this->environment->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new ActiveAndStagingDirsAreDifferent($translatableFactory); + return new ActiveAndStagingDirsAreDifferent($environment, $translatableFactory); } + /** + * @covers ::doAssertIsFulfilled + * @covers ::getFulfilledStatusMessage + */ public function testFulfilled(): void { $this->doTestFulfilled( @@ -33,7 +30,7 @@ public function testFulfilled(): void ); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testUnfulfilled(): void { $message = 'The active and staging directories are the same.'; diff --git a/tests/Precondition/Service/ActiveDirExistsUnitTest.php b/tests/Precondition/Service/ActiveDirExistsUnitTest.php index 4e32bde24..a3d1c3dc4 100644 --- a/tests/Precondition/Service/ActiveDirExistsUnitTest.php +++ b/tests/Precondition/Service/ActiveDirExistsUnitTest.php @@ -12,10 +12,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirExists * * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class ActiveDirExistsUnitTest extends PreconditionTestCase { @@ -30,12 +26,17 @@ protected function setUp(): void protected function createSut(): ActiveDirExists { + $environment = $this->environment->reveal(); $filesystem = $this->filesystem->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new ActiveDirExists($filesystem, $translatableFactory); + return new ActiveDirExists($environment, $filesystem, $translatableFactory); } + /** + * @covers ::doAssertIsFulfilled + * @covers ::getFulfilledStatusMessage + */ public function testFulfilled(): void { $this->filesystem @@ -46,7 +47,7 @@ public function testFulfilled(): void $this->doTestFulfilled('The active directory exists.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testUnfulfilled(): void { $message = 'The active directory does not exist.'; diff --git a/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php b/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php index 65f0e4d3e..229035f01 100644 --- a/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php +++ b/tests/Precondition/Service/ActiveDirIsReadyUnitTest.php @@ -13,9 +13,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsReady * * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::isFulfilled */ final class ActiveDirIsReadyUnitTest extends PreconditionTestCase { @@ -38,39 +35,43 @@ protected function setUp(): void protected function createSut(): ActiveDirIsReady { + $environment = $this->environment->reveal(); $stagingDirExists = $this->activeDirExists->reveal(); $stagingDirIsWritable = $this->activeDirIsWritable->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new ActiveDirIsReady($stagingDirExists, $stagingDirIsWritable, $translatableFactory); + return new ActiveDirIsReady($environment, $stagingDirExists, $stagingDirIsWritable, $translatableFactory); } + /** @covers ::getFulfilledStatusMessage */ public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->activeDirExists - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->activeDirIsWritable - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('The active directory is ready to use.'); + $this->doTestFulfilled('The active directory is ready to use.', $activeDirPath, $stagingDirPath, $timeout); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->activeDirExists - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); - $this->doTestUnfulfilled($message); + $this->doTestUnfulfilled($message, null, $activeDirPath, $stagingDirPath, $timeout); } } diff --git a/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php b/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php index 85397d4f9..9e1eff5ec 100644 --- a/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php +++ b/tests/Precondition/Service/ActiveDirIsWritableUnitTest.php @@ -12,10 +12,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\ActiveDirIsWritable * * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class ActiveDirIsWritableUnitTest extends PreconditionTestCase { @@ -30,12 +26,17 @@ protected function setUp(): void protected function createSut(): ActiveDirIsWritable { + $environment = $this->environment->reveal(); $filesystem = $this->filesystem->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new ActiveDirIsWritable($filesystem, $translatableFactory); + return new ActiveDirIsWritable($environment, $filesystem, $translatableFactory); } + /** + * @covers ::doAssertIsFulfilled + * @covers ::getFulfilledStatusMessage + */ public function testFulfilled(): void { $this->filesystem @@ -46,7 +47,7 @@ public function testFulfilled(): void $this->doTestFulfilled('The active directory is writable.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testUnfulfilled(): void { $message = 'The active directory is not writable.'; diff --git a/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php b/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php index aa3bfa552..5083839fb 100644 --- a/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php +++ b/tests/Precondition/Service/BeginnerPreconditionsUnitTest.php @@ -14,10 +14,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\BeginnerPreconditions * * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class BeginnerPreconditionsUnitTest extends PreconditionTestCase { @@ -46,42 +42,57 @@ protected function setUp(): void protected function createSut(): BeginnerPreconditions { $commonPreconditions = $this->commonPreconditions->reveal(); + $environment = $this->environment->reveal(); $noUnsupportedLinksExist = $this->noUnsupportedLinksExist->reveal(); $stagingDirDoesNotExist = $this->stagingDirDoesNotExist->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new BeginnerPreconditions($commonPreconditions, $noUnsupportedLinksExist, $stagingDirDoesNotExist, $translatableFactory); + return new BeginnerPreconditions( + $environment, + $commonPreconditions, + $noUnsupportedLinksExist, + $stagingDirDoesNotExist, + $translatableFactory, + ); } + /** @covers ::getFulfilledStatusMessage */ public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noUnsupportedLinksExist - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirDoesNotExist - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('The preconditions for beginning the staging process are fulfilled.'); + $this->doTestFulfilled( + 'The preconditions for beginning the staging process are fulfilled.', + $activeDirPath, + $stagingDirPath, + $timeout, + ); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); - $this->doTestUnfulfilled($message); + $this->doTestUnfulfilled($message, null, $activeDirPath, $stagingDirPath, $timeout); } } diff --git a/tests/Precondition/Service/CleanerPreconditionsUnitTest.php b/tests/Precondition/Service/CleanerPreconditionsUnitTest.php index 53b15a7b1..fc94d9ea1 100644 --- a/tests/Precondition/Service/CleanerPreconditionsUnitTest.php +++ b/tests/Precondition/Service/CleanerPreconditionsUnitTest.php @@ -13,10 +13,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\CleanerPreconditions * * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class CleanerPreconditionsUnitTest extends PreconditionTestCase { @@ -39,39 +35,48 @@ protected function setUp(): void protected function createSut(): CleanerPreconditions { + $environment = $this->environment->reveal(); $commonPreconditions = $this->commonPreconditions->reveal(); $stagingDirIsReady = $this->stagingDirIsReady->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new CleanerPreconditions($commonPreconditions, $stagingDirIsReady, $translatableFactory); + return new CleanerPreconditions($environment, $commonPreconditions, $stagingDirIsReady, $translatableFactory); } + /** @covers ::getFulfilledStatusMessage */ public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsReady - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('The preconditions for removing the staging directory are fulfilled.'); + $this->doTestFulfilled( + 'The preconditions for removing the staging directory are fulfilled.', + $activeDirPath, + $stagingDirPath, + $timeout, + ); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); - $this->doTestUnfulfilled($message); + $this->doTestUnfulfilled($message, null, $activeDirPath, $stagingDirPath, $timeout); } } diff --git a/tests/Precondition/Service/CommitterPreconditionsUnitTest.php b/tests/Precondition/Service/CommitterPreconditionsUnitTest.php index 9fd58f16f..5b22dd639 100644 --- a/tests/Precondition/Service/CommitterPreconditionsUnitTest.php +++ b/tests/Precondition/Service/CommitterPreconditionsUnitTest.php @@ -14,10 +14,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\CommitterPreconditions * * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class CommitterPreconditionsUnitTest extends PreconditionTestCase { @@ -45,43 +41,52 @@ protected function setUp(): void protected function createSut(): CommitterPreconditions { + $environment = $this->environment->reveal(); $commonPreconditions = $this->commonPreconditions->reveal(); $noUnsupportedLinksExist = $this->noUnsupportedLinksExist->reveal(); $stagingDirIsReady = $this->stagingDirIsReady->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new CommitterPreconditions($commonPreconditions, $noUnsupportedLinksExist, $stagingDirIsReady, $translatableFactory); + return new CommitterPreconditions($environment, $commonPreconditions, $noUnsupportedLinksExist, $stagingDirIsReady, $translatableFactory); } + /** @covers ::getFulfilledStatusMessage */ public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noUnsupportedLinksExist - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsReady - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('The preconditions for making staged changes live are fulfilled.'); + $this->doTestFulfilled( + 'The preconditions for making staged changes live are fulfilled.', + $activeDirPath, + $stagingDirPath, + $timeout, + ); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); - $this->doTestUnfulfilled($message); + $this->doTestUnfulfilled($message, null, $activeDirPath, $stagingDirPath, $timeout); } } diff --git a/tests/Precondition/Service/CommonPreconditionsUnitTest.php b/tests/Precondition/Service/CommonPreconditionsUnitTest.php index bb019ab9f..634358546 100644 --- a/tests/Precondition/Service/CommonPreconditionsUnitTest.php +++ b/tests/Precondition/Service/CommonPreconditionsUnitTest.php @@ -15,10 +15,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\CommonPreconditions * * @covers ::__construct - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class CommonPreconditionsUnitTest extends PreconditionTestCase { @@ -54,10 +50,12 @@ protected function createSut(): CommonPreconditions $activeAndStagingDirsAreDifferent = $this->activeAndStagingDirsAreDifferent->reveal(); $activeDirIsReady = $this->activeDirIsReady->reveal(); $composerIsAvailable = $this->composerIsAvailable->reveal(); + $environment = $this->environment->reveal(); $hostSupportsRunningProcesses = $this->hostSupportsRunningProcesses->reveal(); $translatableFactory = new TestTranslatableFactory(); return new CommonPreconditions( + $environment, $translatableFactory, $activeAndStagingDirsAreDifferent, $activeDirIsReady, @@ -66,38 +64,41 @@ protected function createSut(): CommonPreconditions ); } + /** @covers ::getFulfilledStatusMessage */ public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->composerIsAvailable - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->activeDirIsReady - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->activeAndStagingDirsAreDifferent - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->hostSupportsRunningProcesses - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('The common preconditions are fulfilled.'); + $this->doTestFulfilled('The common preconditions are fulfilled.', $activeDirPath, $stagingDirPath, $timeout); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->activeAndStagingDirsAreDifferent - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); - $this->doTestUnfulfilled($message); + $this->doTestUnfulfilled($message, null, $activeDirPath, $stagingDirPath, $timeout); } } diff --git a/tests/Precondition/Service/ComposerIsAvailableUnitTest.php b/tests/Precondition/Service/ComposerIsAvailableUnitTest.php index 1c7c68579..b30ec9f70 100644 --- a/tests/Precondition/Service/ComposerIsAvailableUnitTest.php +++ b/tests/Precondition/Service/ComposerIsAvailableUnitTest.php @@ -20,11 +20,7 @@ * @covers ::__construct * @covers ::assertExecutableExists * @covers ::assertIsActuallyComposer - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage * @covers ::getProcess - * @covers ::getStatusMessage - * @covers ::isFulfilled * @covers ::isValidExecutable */ final class ComposerIsAvailableUnitTest extends PreconditionTestCase @@ -60,6 +56,7 @@ protected function setUp(): void protected function createSut(): ComposerIsAvailable { + $environment = $this->environment->reveal(); $executableFinder = $this->executableFinder->reveal(); $process = $this->process->reveal(); $this->processFactory @@ -68,12 +65,13 @@ protected function createSut(): ComposerIsAvailable $processFactory = $this->processFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new ComposerIsAvailable($executableFinder, $processFactory, $translatableFactory); + return new ComposerIsAvailable($environment, $executableFinder, $processFactory, $translatableFactory); } /** * @covers ::assertExecutableExists * @covers ::assertIsActuallyComposer + * @covers ::getFulfilledStatusMessage * @covers ::getProcess * @covers ::isValidExecutable */ @@ -122,7 +120,7 @@ public function testExecutableNotFound(): void /** * @covers ::assertExecutableExists * @covers ::assertIsActuallyComposer - * @covers ::assertIsFulfilled + * @covers ::doAssertIsFulfilled * @covers ::getProcess */ public function testFailedToCreateProcess(): void diff --git a/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php b/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php index ac73c74f8..2f5ac4229 100644 --- a/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php +++ b/tests/Precondition/Service/FileIteratingPreconditionUnitTestCase.php @@ -21,6 +21,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Throwable; +/** @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition */ abstract class FileIteratingPreconditionUnitTestCase extends PreconditionTestCase { abstract protected function fulfilledStatusMessage(): string; @@ -32,10 +33,6 @@ abstract protected function fulfilledStatusMessage(): string; protected function setUp(): void { - $this->environment = $this->prophesize(EnvironmentInterface::class); - $this->environment - ->isWindows() - ->willReturn(false); $this->fileFinder = $this->prophesize(FileFinderInterface::class); $this->fileFinder ->find(Argument::type(PathInterface::class), Argument::type(PathListInterface::class)) @@ -49,7 +46,7 @@ protected function setUp(): void parent::setUp(); } - /** @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::exitEarly */ + /** @covers ::exitEarly */ public function testExitEarly(): void { $this->filesystem @@ -59,6 +56,7 @@ public function testExitEarly(): void ->find(Argument::cetera()) ->shouldNotBeCalled(); + $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); @@ -66,7 +64,7 @@ public function testExitEarly(): void // Create a concrete implementation for testing since the SUT in // this case, being abstract, can't be instantiated directly. - $sut = new class ($fileFinder, $filesystem, $pathFactory, $translatableFactory) extends AbstractFileIteratingPrecondition + $sut = new class ($environment, $fileFinder, $filesystem, $pathFactory, $translatableFactory) extends AbstractFileIteratingPrecondition { // @phpcs:ignore SlevomatCodingStandard.Functions.DisallowEmptyFunction.EmptyFunction protected function assertIsSupportedFile( @@ -110,7 +108,7 @@ protected function exitEarly( $sut->assertIsFulfilled($activeDirPath, $stagingDirPath); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testActiveDirectoryDoesNotExistCountsAsFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); @@ -127,7 +125,7 @@ public function testActiveDirectoryDoesNotExistCountsAsFulfilled(): void $this->assertFulfilled($isFulfilled, $statusMessage, 'Treated non-existent directories as fulfilled.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testStagingDirectoryDoesNotExistCountsAsFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); @@ -144,7 +142,7 @@ public function testStagingDirectoryDoesNotExistCountsAsFulfilled(): void $this->assertFulfilled($isFulfilled, $statusMessage, 'Treated non-existent directories as fulfilled.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testNoFilesFound(): void { $activeDirPath = PathHelper::activeDirPath(); @@ -162,7 +160,7 @@ public function testNoFilesFound(): void } /** - * @covers ::assertIsFulfilled + * @covers ::doAssertIsFulfilled * * @dataProvider providerFileFinderExceptions */ @@ -197,6 +195,7 @@ public function providerFileFinderExceptions(): array ]; } + /** @covers ::doAssertIsFulfilled */ public function assertFulfilled( bool $isFulfilled, TranslatableInterface $statusMessage, diff --git a/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php b/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php index a6d48725e..7104e21c2 100644 --- a/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php +++ b/tests/Precondition/Service/HostSupportsRunningProcessesFunctionalTest.php @@ -26,7 +26,7 @@ private function createSut(): HostSupportsRunningProcesses } /** - * @covers ::assertIsFulfilled + * @covers ::doAssertIsFulfilled * * This test proves that the precondition correctly detects a failure from * the Symfony Process component when the the proc_open() function is diff --git a/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php b/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php index 103411e68..24e851026 100644 --- a/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php +++ b/tests/Precondition/Service/HostSupportsRunningProcessesUnitTest.php @@ -15,7 +15,7 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\HostSupportsRunningProcesses * * @covers ::__construct - * @covers ::assertIsFulfilled + * @covers ::doAssertIsFulfilled * @covers ::getFulfilledStatusMessage * @covers ::getStatusMessage * @covers ::isFulfilled @@ -36,10 +36,11 @@ protected function setUp(): void protected function createSut(): HostSupportsRunningProcesses { + $environment = $this->environment->reveal(); $processFactory = $this->processFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new HostSupportsRunningProcesses($processFactory, $translatableFactory); + return new HostSupportsRunningProcesses($environment, $processFactory, $translatableFactory); } public function testFulfilled(): void @@ -51,7 +52,7 @@ public function testFulfilled(): void $this->doTestFulfilled('The host supports running independent PHP processes.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testUnfulfilled(): void { $message = __METHOD__; diff --git a/tests/Precondition/Service/LinkPreconditionsFunctionalTestCase.php b/tests/Precondition/Service/LinkPreconditionsFunctionalTestCase.php index cd8be9de4..e77641bb3 100644 --- a/tests/Precondition/Service/LinkPreconditionsFunctionalTestCase.php +++ b/tests/Precondition/Service/LinkPreconditionsFunctionalTestCase.php @@ -23,7 +23,16 @@ protected function tearDown(): void abstract protected function createSut(): PreconditionInterface; - /** @dataProvider providerFulfilledDirectoryDoesNotExist */ + /** + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::doAssertIsFulfilled + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::findFiles + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPrecondition::assertIsFulfilled + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPrecondition::doAssertIsFulfilled + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPrecondition::isFulfilled + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows::exitEarly + * + * @dataProvider providerFulfilledDirectoryDoesNotExist + */ public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void { $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); @@ -57,8 +66,11 @@ final public function providerFulfilledDirectoryDoesNotExist(): array } /** - * @covers ::assertIsFulfilled - * @covers ::isFulfilled + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::doAssertIsFulfilled + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition::findFiles + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPrecondition::isFulfilled + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist::assertIsSupportedFile + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows::exitEarly */ public function testFulfilledWithNoLinks(): void { diff --git a/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php b/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php index e08fbf718..f16d4be51 100644 --- a/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php +++ b/tests/Precondition/Service/LinkPreconditionsIsolationFunctionalTest.php @@ -18,7 +18,7 @@ /** * Tests the interaction of unsupported links preconditions. * - * @coversNothing + * @covers \PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractFileIteratingPrecondition */ final class LinkPreconditionsIsolationFunctionalTest extends TestCase { diff --git a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php index 8e0169712..066388dcf 100644 --- a/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoAbsoluteSymlinksExistFunctionalTest.php @@ -2,7 +2,6 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist; use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; @@ -13,7 +12,6 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist * * @covers ::__construct - * @covers ::findFiles * * @group no_windows */ @@ -31,9 +29,7 @@ protected function createSut(): NoAbsoluteSymlinksExist } /** - * @covers ::assertIsFulfilled * @covers ::assertIsSupportedFile - * @covers ::isFulfilled * * @dataProvider providerDoesNotContainLinks */ @@ -71,8 +67,6 @@ public function providerDoesNotContainLinks(): array /** * @covers ::assertIsSupportedFile - * @covers ::findFiles - * @covers ::isFulfilled * * @dataProvider providerLinksExist */ @@ -103,8 +97,6 @@ public function testAbsoluteLinksExist(string $dirName, string $basePath, string /** * @covers ::assertIsSupportedFile - * @covers ::findFiles - * @covers ::isFulfilled * * @dataProvider providerLinksExist */ @@ -162,21 +154,7 @@ public function providerLinksExist(): array ]; } - /** - * @covers ::findFiles - * @covers ::isFulfilled - * - * @dataProvider providerFulfilledDirectoryDoesNotExist - */ - public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void - { - $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); - } - - /** - * @covers ::assertIsSupportedFile - * @covers ::isFulfilled - */ + /** @covers ::assertIsSupportedFile */ public function testWithHardLink(): void { $link = PathHelper::makeAbsolute('link.txt', PathHelper::activeDirAbsolute()); @@ -194,7 +172,6 @@ public function testWithHardLink(): void /** * @covers ::assertIsSupportedFile - * @covers ::isFulfilled * * @dataProvider providerExclusions */ diff --git a/tests/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php b/tests/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php index 48fbee65f..f911f65b8 100644 --- a/tests/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php +++ b/tests/Precondition/Service/NoAbsoluteSymlinksExistUnitTest.php @@ -8,22 +8,20 @@ /** * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoAbsoluteSymlinksExist * - * @covers ::assertIsFulfilled * @covers ::exitEarly * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class NoAbsoluteSymlinksExistUnitTest extends FileIteratingPreconditionUnitTestCase { protected function createSut(): NoAbsoluteSymlinksExist { + $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new NoAbsoluteSymlinksExist($fileFinder, $filesystem, $pathFactory, $translatableFactory); + return new NoAbsoluteSymlinksExist($environment, $fileFinder, $filesystem, $pathFactory, $translatableFactory); } protected function fulfilledStatusMessage(): string diff --git a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php index b082305ab..98efa5368 100644 --- a/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php +++ b/tests/Precondition/Service/NoHardLinksExistFunctionalTest.php @@ -3,7 +3,6 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; @@ -29,23 +28,7 @@ protected function createSut(): NoHardLinksExist return $sut; } - /** - * @covers ::assertIsFulfilled - * @covers ::assertIsSupportedFile - */ - public function testFulfilledWithNoLinks(): void - { - $sut = $this->createSut(); - - $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); - - self::assertTrue($isFulfilled, 'Passed with no links in the codebase.'); - } - - /** - * @covers ::assertIsFulfilled - * @covers ::assertIsSupportedFile - */ + /** @covers ::assertIsSupportedFile */ public function testFulfilledWithSymlink(): void { $target = Path::makeAbsolute('target.txt', PathHelper::activeDirAbsolute()); @@ -60,7 +43,6 @@ public function testFulfilledWithSymlink(): void } /** - * @covers ::assertIsFulfilled * @covers ::assertIsSupportedFile * * @dataProvider providerUnfulfilled @@ -98,19 +80,8 @@ public function providerUnfulfilled(): array ]; } - /** - * @covers ::assertIsFulfilled - * - * @dataProvider providerFulfilledDirectoryDoesNotExist - */ - public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void - { - $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); - } - /** * @covers ::assertIsSupportedFile - * @covers ::isFulfilled * * @dataProvider providerExclusions */ diff --git a/tests/Precondition/Service/NoHardLinksExistUnitTest.php b/tests/Precondition/Service/NoHardLinksExistUnitTest.php index 5afceba6b..d3674e721 100644 --- a/tests/Precondition/Service/NoHardLinksExistUnitTest.php +++ b/tests/Precondition/Service/NoHardLinksExistUnitTest.php @@ -5,24 +5,18 @@ use PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; -/** - * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist - * - * @covers ::assertIsFulfilled - * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled - */ +/** @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoHardLinksExist */ final class NoHardLinksExistUnitTest extends FileIteratingPreconditionUnitTestCase { protected function createSut(): NoHardLinksExist { + $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new NoHardLinksExist($fileFinder, $filesystem, $pathFactory, $translatableFactory); + return new NoHardLinksExist($environment, $fileFinder, $filesystem, $pathFactory, $translatableFactory); } protected function fulfilledStatusMessage(): string @@ -30,11 +24,16 @@ protected function fulfilledStatusMessage(): string return 'There are no hard links in the codebase.'; } + /** + * @covers ::assertIsSupportedFile + * @covers ::getFulfilledStatusMessage + */ public function testFulfilled(): void { $this->doTestFulfilled('There are no hard links in the codebase.'); } + /** @covers ::assertIsSupportedFile */ public function testUnfulfilled(): void { // @todo Implement once the corresponding functionality is added. diff --git a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php index 9544cff10..2287befce 100644 --- a/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php +++ b/tests/Precondition/Service/NoLinksExistOnWindowsFunctionalTest.php @@ -3,7 +3,6 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows; use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; @@ -28,25 +27,9 @@ protected function createSut(): NoLinksExistOnWindows return $sut; } - /** - * @covers ::exitEarly - * @covers ::findFiles - * @covers ::isFulfilled - */ - public function testFulfilledWithNoLinks(): void - { - $sut = $this->createSut(); - - $isFulfilled = $sut->isFulfilled(PathHelper::activeDirPath(), PathHelper::stagingDirPath()); - - self::assertTrue($isFulfilled, 'Passed with no links in the codebase.'); - } - /** * @covers ::assertIsSupportedFile * @covers ::exitEarly - * @covers ::findFiles - * @covers ::isFulfilled * * @dataProvider providerUnfulfilled * @@ -92,18 +75,6 @@ public function providerUnfulfilled(): array ]; } - /** - * @covers ::exitEarly - * @covers ::findFiles - * @covers ::isFulfilled - * - * @dataProvider providerFulfilledDirectoryDoesNotExist - */ - public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void - { - $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); - } - /** * @covers ::exitEarly * @covers ::isFulfilled diff --git a/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php b/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php index ccce8d864..378e13c28 100644 --- a/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php +++ b/tests/Precondition/Service/NoLinksExistOnWindowsUnitTest.php @@ -11,11 +11,9 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoLinksExistOnWindows * * @covers ::__construct - * @covers ::assertIsFulfilled + * @covers ::assertIsSupportedFile * @covers ::exitEarly * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class NoLinksExistOnWindowsUnitTest extends FileIteratingPreconditionUnitTestCase { diff --git a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php index 87415c9d3..6d63e4dcb 100644 --- a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php +++ b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseFunctionalTest.php @@ -3,7 +3,6 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\Internal\Path\Value\PathList; use PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase; use PhpTuf\ComposerStager\Tests\TestUtils\ContainerHelper; @@ -131,16 +130,6 @@ public function providerUnfulfilled(): array ]; } - /** - * @covers ::isFulfilled - * - * @dataProvider providerFulfilledDirectoryDoesNotExist - */ - public function testFulfilledDirectoryDoesNotExist(PathInterface $activeDir, PathInterface $stagingDir): void - { - $this->doTestFulfilledDirectoryDoesNotExist($activeDir, $stagingDir); - } - /** * @covers ::assertIsSupportedFile * @covers ::isFulfilled diff --git a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php index 04db773dc..fe491cee6 100644 --- a/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php +++ b/tests/Precondition/Service/NoSymlinksPointOutsideTheCodebaseUnitTest.php @@ -15,10 +15,8 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointOutsideTheCodebase * * @covers ::__construct - * @covers ::assertIsFulfilled + * @covers ::assertIsSupportedFile * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class NoSymlinksPointOutsideTheCodebaseUnitTest extends FileIteratingPreconditionUnitTestCase { @@ -44,11 +42,12 @@ protected function fulfilledStatusMessage(): string protected function createSut(): NoSymlinksPointOutsideTheCodebase { + $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new NoSymlinksPointOutsideTheCodebase($fileFinder, $filesystem, $pathFactory, $translatableFactory); + return new NoSymlinksPointOutsideTheCodebase($environment, $fileFinder, $filesystem, $pathFactory, $translatableFactory); } } diff --git a/tests/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php b/tests/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php index 2ecd5c1a7..dbb0d81ef 100644 --- a/tests/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php +++ b/tests/Precondition/Service/NoSymlinksPointToADirectoryUnitTest.php @@ -20,11 +20,9 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoSymlinksPointToADirectory * * @covers ::__construct - * @covers ::assertIsFulfilled + * @covers ::assertIsSupportedFile * @covers ::exitEarly * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class NoSymlinksPointToADirectoryUnitTest extends FileIteratingPreconditionUnitTestCase { @@ -53,13 +51,14 @@ protected function fulfilledStatusMessage(): string protected function createSut(): NoSymlinksPointToADirectory { + $environment = $this->environment->reveal(); $fileFinder = $this->fileFinder->reveal(); $fileSyncer = $this->fileSyncer->reveal(); $filesystem = $this->filesystem->reveal(); $pathFactory = $this->pathFactory->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new NoSymlinksPointToADirectory($fileFinder, $fileSyncer, $filesystem, $pathFactory, $translatableFactory); + return new NoSymlinksPointToADirectory($environment, $fileFinder, $fileSyncer, $filesystem, $pathFactory, $translatableFactory); } public function testExitEarlyWithRsyncFileSyncer(): void diff --git a/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php b/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php index f4e585dde..1f2c5897f 100644 --- a/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php +++ b/tests/Precondition/Service/NoUnsupportedLinksExistUnitTest.php @@ -17,10 +17,7 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\NoUnsupportedLinksExist * * @covers ::__construct - * @covers ::assertIsFulfilled * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class NoUnsupportedLinksExistUnitTest extends PreconditionTestCase { @@ -58,6 +55,7 @@ protected function setUp(): void protected function createSut(): NoUnsupportedLinksExist { + $environment = $this->environment->reveal(); $noAbsoluteSymlinksExist = $this->noAbsoluteSymlinksExist->reveal(); $noHardLinksExist = $this->noHardLinksExist->reveal(); $noLinksExistOnWindows = $this->noLinksExistOnWindows->reveal(); @@ -66,6 +64,7 @@ protected function createSut(): NoUnsupportedLinksExist $translatableFactory = new TestTranslatableFactory(); return new NoUnsupportedLinksExist( + $environment, $translatableFactory, $noAbsoluteSymlinksExist, $noHardLinksExist, @@ -79,41 +78,53 @@ public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->noAbsoluteSymlinksExist - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noHardLinksExist - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noLinksExistOnWindows - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noSymlinksPointOutsideTheCodebase - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->noSymlinksPointToADirectory - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('There are no unsupported links in the codebase.'); + $this->doTestFulfilled( + 'There are no unsupported links in the codebase.', + $activeDirPath, + $stagingDirPath, + $timeout, + ); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->noAbsoluteSymlinksExist - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); - self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); + self::assertTranslatableMessage($message, $sut->getStatusMessage( + $activeDirPath, + $stagingDirPath, + $this->exclusions, + $timeout, + )); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath, $timeout): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout); }, PreconditionException::class, $message); } } diff --git a/tests/Precondition/Service/PreconditionTestCase.php b/tests/Precondition/Service/PreconditionTestCase.php index 0f2a2fd24..ec9d4c75e 100644 --- a/tests/Precondition/Service/PreconditionTestCase.php +++ b/tests/Precondition/Service/PreconditionTestCase.php @@ -2,13 +2,18 @@ namespace PhpTuf\ComposerStager\Tests\Precondition\Service; +use PhpTuf\ComposerStager\API\Environment\Service\EnvironmentInterface; use PhpTuf\ComposerStager\API\Exception\PreconditionException; use PhpTuf\ComposerStager\API\Path\Value\PathInterface; +use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Tests\Path\Value\TestPathList; use PhpTuf\ComposerStager\Tests\TestCase; use PhpTuf\ComposerStager\Tests\TestUtils\PathHelper; +use Prophecy\Argument; +use Prophecy\Prophecy\ObjectProphecy; abstract class PreconditionTestCase extends TestCase { @@ -16,8 +21,18 @@ abstract class PreconditionTestCase extends TestCase // and assertIsFulfilled() in ::doTestFulfilled() and ::doTestUnfulfilled(), respectively. protected const EXPECTED_CALLS_MULTIPLE = 3; + protected EnvironmentInterface|ObjectProphecy $environment; + protected PathListInterface $exclusions; + protected function setUp(): void { + $this->environment = $this->prophesize(EnvironmentInterface::class); + $this->environment + ->isWindows() + ->willReturn(false); + $this->environment + ->setTimeLimit(Argument::any()) + ->willReturn(true); $this->exclusions = new TestPathList(); } @@ -42,14 +57,19 @@ protected function doTestFulfilled( string $expectedStatusMessage, ?PathInterface $activeDirPath = null, ?PathInterface $stagingDirPath = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $activeDirPath ??= PathHelper::activeDirPath(); $stagingDirPath ??= PathHelper::stagingDirPath(); + + $this->environment + ->setTimeLimit($timeout) + ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $sut = $this->createSut(); - $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); - $actualStatusMessage = $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions); - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); + $isFulfilled = $sut->isFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout); + $actualStatusMessage = $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions, $timeout); + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout); self::assertTrue($isFulfilled); self::assertTranslatableMessage($expectedStatusMessage, $actualStatusMessage, 'Got correct status message.'); @@ -60,13 +80,14 @@ protected function doTestUnfulfilled( ?string $previousException = null, ?PathInterface $activeDirPath = null, ?PathInterface $stagingDirPath = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { $activeDirPath ??= PathHelper::activeDirPath(); $stagingDirPath ??= PathHelper::stagingDirPath(); $sut = $this->createSut(); - self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath, $timeout): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout); }, PreconditionException::class, $expectedStatusMessage, $previousException); } } diff --git a/tests/Precondition/Service/StagerPreconditionsUnitTest.php b/tests/Precondition/Service/StagerPreconditionsUnitTest.php index 9d236b2b3..eaee87c5b 100644 --- a/tests/Precondition/Service/StagerPreconditionsUnitTest.php +++ b/tests/Precondition/Service/StagerPreconditionsUnitTest.php @@ -40,43 +40,56 @@ protected function setUp(): void protected function createSut(): StagerPreconditions { + $environment = $this->environment->reveal(); $commonPreconditions = $this->commonPreconditions->reveal(); $stagingDirIsReady = $this->stagingDirIsReady->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new StagerPreconditions($translatableFactory, $commonPreconditions, $stagingDirIsReady); + return new StagerPreconditions($environment, $translatableFactory, $commonPreconditions, $stagingDirIsReady); } public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsReady - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('The preconditions for staging Composer commands are fulfilled.'); + $this->doTestFulfilled( + 'The preconditions for staging Composer commands are fulfilled.', + $activeDirPath, + $stagingDirPath, + $timeout, + ); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = __METHOD__; $previous = self::createTestPreconditionException($message); $this->commonPreconditions - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); - self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); + self::assertTranslatableMessage($message, $sut->getStatusMessage( + $activeDirPath, + $stagingDirPath, + $this->exclusions, + $timeout, + )); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath, $timeout): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout); }, PreconditionException::class, $message); } } diff --git a/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php b/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php index 27a90ac5e..2dac0e990 100644 --- a/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php +++ b/tests/Precondition/Service/StagingDirDoesNotExistUnitTest.php @@ -12,10 +12,8 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirDoesNotExist * * @covers ::__construct - * @covers ::assertIsFulfilled + * @covers ::doAssertIsFulfilled * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class StagingDirDoesNotExistUnitTest extends PreconditionTestCase { @@ -30,10 +28,11 @@ protected function setUp(): void protected function createSut(): StagingDirDoesNotExist { + $environment = $this->environment->reveal(); $filesystem = $this->filesystem->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new StagingDirDoesNotExist($filesystem, $translatableFactory); + return new StagingDirDoesNotExist($environment, $filesystem, $translatableFactory); } public function testFulfilled(): void @@ -46,7 +45,7 @@ public function testFulfilled(): void $this->doTestFulfilled('The staging directory does not already exist.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testUnfulfilled(): void { $message = 'The staging directory already exists.'; diff --git a/tests/Precondition/Service/StagingDirExistsUnitTest.php b/tests/Precondition/Service/StagingDirExistsUnitTest.php index 01e362782..d6075b5b8 100644 --- a/tests/Precondition/Service/StagingDirExistsUnitTest.php +++ b/tests/Precondition/Service/StagingDirExistsUnitTest.php @@ -12,10 +12,8 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirExists * * @covers ::__construct - * @covers ::assertIsFulfilled + * @covers ::doAssertIsFulfilled * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class StagingDirExistsUnitTest extends PreconditionTestCase { @@ -30,10 +28,11 @@ protected function setUp(): void protected function createSut(): StagingDirExists { + $environment = $this->environment->reveal(); $filesystem = $this->filesystem->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new StagingDirExists($filesystem, $translatableFactory); + return new StagingDirExists($environment, $filesystem, $translatableFactory); } public function testFulfilled(): void @@ -46,7 +45,7 @@ public function testFulfilled(): void $this->doTestFulfilled('The staging directory exists.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testUnfulfilled(): void { $message = 'The staging directory does not exist.'; diff --git a/tests/Precondition/Service/StagingDirIsReadyUnitTest.php b/tests/Precondition/Service/StagingDirIsReadyUnitTest.php index ef65093d9..f71eda04a 100644 --- a/tests/Precondition/Service/StagingDirIsReadyUnitTest.php +++ b/tests/Precondition/Service/StagingDirIsReadyUnitTest.php @@ -14,10 +14,7 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirIsReady * * @covers ::__construct - * @covers ::assertIsFulfilled * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class StagingDirIsReadyUnitTest extends PreconditionTestCase { @@ -40,43 +37,51 @@ protected function setUp(): void protected function createSut(): StagingDirIsReady { + $environment = $this->environment->reveal(); $stagingDirExists = $this->stagingDirExists->reveal(); $stagingDirIsWritable = $this->stagingDirIsWritable->reveal(); $translatableFactory = new TestTranslatableFactory(); - return new StagingDirIsReady($translatableFactory, $stagingDirExists, $stagingDirIsWritable); + return new StagingDirIsReady($environment, $translatableFactory, $stagingDirExists, $stagingDirIsWritable); } public function testFulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $this->stagingDirExists - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); $this->stagingDirIsWritable - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->shouldBeCalledTimes(self::EXPECTED_CALLS_MULTIPLE); - $this->doTestFulfilled('The staging directory is ready to use.'); + $this->doTestFulfilled('The staging directory is ready to use.', $activeDirPath, $stagingDirPath, $timeout); } public function testUnfulfilled(): void { $activeDirPath = PathHelper::activeDirPath(); $stagingDirPath = PathHelper::stagingDirPath(); + $timeout = 42; $message = 'The staging directory is not ready to use.'; $previous = self::createTestPreconditionException($message); $this->stagingDirExists - ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions) + ->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout) ->willThrow($previous); $sut = $this->createSut(); - self::assertTranslatableMessage($message, $sut->getStatusMessage($activeDirPath, $stagingDirPath, $this->exclusions)); - self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath): void { - $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions); + self::assertTranslatableMessage($message, $sut->getStatusMessage( + $activeDirPath, + $stagingDirPath, + $this->exclusions, + $timeout, + )); + self::assertTranslatableException(function () use ($sut, $activeDirPath, $stagingDirPath, $timeout): void { + $sut->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions, $timeout); }, PreconditionException::class, $message); } } diff --git a/tests/Precondition/Service/StagingDirIsWritableUnitTest.php b/tests/Precondition/Service/StagingDirIsWritableUnitTest.php index 0483b8e66..251a9deb7 100644 --- a/tests/Precondition/Service/StagingDirIsWritableUnitTest.php +++ b/tests/Precondition/Service/StagingDirIsWritableUnitTest.php @@ -12,10 +12,8 @@ * @coversDefaultClass \PhpTuf\ComposerStager\Internal\Precondition\Service\StagingDirIsWritable * * @covers ::__construct - * @covers ::assertIsFulfilled + * @covers ::doAssertIsFulfilled * @covers ::getFulfilledStatusMessage - * @covers ::getStatusMessage - * @covers ::isFulfilled */ final class StagingDirIsWritableUnitTest extends PreconditionTestCase { @@ -30,11 +28,12 @@ protected function setUp(): void protected function createSut(): StagingDirIsWritable { + $environment = $this->environment->reveal(); $filesystem = $this->filesystem->reveal(); assert($filesystem instanceof FilesystemInterface); $translatableFactory = new TestTranslatableFactory(); - return new StagingDirIsWritable($filesystem, $translatableFactory); + return new StagingDirIsWritable($environment, $filesystem, $translatableFactory); } public function testFulfilled(): void @@ -47,7 +46,7 @@ public function testFulfilled(): void $this->doTestFulfilled('The staging directory is writable.'); } - /** @covers ::assertIsFulfilled */ + /** @covers ::doAssertIsFulfilled */ public function testUnfulfilled(): void { $message = 'The staging directory is not writable.'; diff --git a/tests/Precondition/Service/TestPrecondition.php b/tests/Precondition/Service/TestPrecondition.php index e8deb32a8..f30a88263 100644 --- a/tests/Precondition/Service/TestPrecondition.php +++ b/tests/Precondition/Service/TestPrecondition.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface; +use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; @@ -33,6 +34,7 @@ public function getStatusMessage( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): TranslatableInterface { return new TestTranslatableMessage($this->statusMessage); } @@ -41,6 +43,7 @@ public function isFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): bool { return $this->isFulfilled; } @@ -49,6 +52,7 @@ public function assertIsFulfilled( PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = null, + int $timeout = ProcessInterface::DEFAULT_TIMEOUT, ): void { if ($this->isFulfilled) { return; diff --git a/tests/Precondition/Service/TestPreconditionsTree.php b/tests/Precondition/Service/TestPreconditionsTree.php index b0a5aebe9..57876a10c 100644 --- a/tests/Precondition/Service/TestPreconditionsTree.php +++ b/tests/Precondition/Service/TestPreconditionsTree.php @@ -6,6 +6,7 @@ use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface; use PhpTuf\ComposerStager\Internal\Precondition\Service\AbstractPreconditionsTree; +use PhpTuf\ComposerStager\Tests\Environment\Service\TestEnvironment; use PhpTuf\ComposerStager\Tests\Translation\Factory\TestTranslatableFactory; use PhpTuf\ComposerStager\Tests\Translation\Value\TestTranslatableMessage; @@ -26,9 +27,10 @@ public function getName(): TranslatableInterface public function __construct(PreconditionInterface ...$children) { + $environment = new TestEnvironment(); $translatableFactory = new TestTranslatableFactory(); - parent::__construct($translatableFactory, ...$children); + parent::__construct($environment, $translatableFactory, ...$children); } public function getDescription(): TranslatableInterface diff --git a/tests/TestCase.php b/tests/TestCase.php index 48d6a5e84..c35508b55 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,6 @@ namespace PhpTuf\ComposerStager\Tests; use PhpTuf\ComposerStager\API\Exception\PreconditionException; -use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslationParametersInterface; use PhpTuf\ComposerStager\Tests\Precondition\Service\TestPrecondition; use PhpTuf\ComposerStager\Tests\TestUtils\AssertTrait; @@ -26,8 +25,6 @@ abstract class TestCase extends PHPUnitTestCase protected const ORIGINAL_CONTENT = ''; protected const CHANGED_CONTENT = 'changed'; - protected PathListInterface $exclusions; - protected static function createTestEnvironment(?string $activeDir = null): void { $activeDir ??= PathHelper::activeDirRelative(); From 55dcef245f737d64e6f62f32ff2ed9b8d454b5bb Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 28 Aug 2023 11:58:33 -0400 Subject: [PATCH 67/75] Add a test to Tests\EndToEnd\EndToEndFunctionalTestCase for an unsupported link in an excluded directory. --- tests/EndToEnd/EndToEndFunctionalTestCase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/EndToEnd/EndToEndFunctionalTestCase.php b/tests/EndToEnd/EndToEndFunctionalTestCase.php index 8a86549b3..620439885 100644 --- a/tests/EndToEnd/EndToEndFunctionalTestCase.php +++ b/tests/EndToEnd/EndToEndFunctionalTestCase.php @@ -115,6 +115,7 @@ public function testSync(string $activeDir, string $stagingDir): void FilesystemHelper::createSymlinks($activeDirAbsolute, [ 'EXCLUDED_symlink_in_active_dir_root.txt' => $arbitrarySymlinkTarget, 'EXCLUDED_dir/symlink_NEVER_CHANGED_anywhere.txt' => $arbitrarySymlinkTarget, + 'EXCLUDED_dir/UNSUPPORTED_link_pointing_outside_the_codebase.txt' => PathHelper::testWorkingDirAbsolute(), ]); // Create initial composer.json. (Doing so manually can be up to one @@ -259,6 +260,7 @@ public function testSync(string $activeDir, string $stagingDir): void 'EXCLUDED_dir/CHANGE_file_in_active_dir_after_syncing_to_staging_dir.txt', 'EXCLUDED_dir/make_NO_CHANGES_anywhere.txt', 'EXCLUDED_dir/symlink_NEVER_CHANGED_anywhere.txt', + 'EXCLUDED_dir/UNSUPPORTED_link_pointing_outside_the_codebase.txt', 'another_EXCLUDED_dir/make_NO_CHANGES_anywhere.txt', 'arbitrary_subdir/with/nested/EXCLUDED_dir/with/a/file/in/it/that/is/NEVER/CHANGED/anywhere.txt', // Files excluded by "hidden" directory are still in the active directory. From a8f2a20d711d3585eaf53afa7e7837b3240761b9 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 28 Aug 2023 13:15:46 -0400 Subject: [PATCH 68/75] Fix some PhpStorm inspections. --- phpstan.neon.dist | 2 +- src/Internal/FileSyncer/Service/RsyncFileSyncer.php | 2 -- src/Internal/Filesystem/Service/Filesystem.php | 1 - src/Internal/Translation/Service/SymfonyTranslatorProxy.php | 5 ++--- tests/EndToEnd/EndToEndFunctionalTestCase.php | 1 - tools/PHPCS/Helper/PHPHelper.php | 1 - .../Sniffs/Commenting/PropertyVarNameHasDollarSignSniff.php | 2 +- .../Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php | 2 +- tools/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php | 2 +- .../InternalLayerDependsOnNonProductionCodeSniff.php | 2 +- .../PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php | 4 ++-- tools/PHPStan/Rules/AbstractRule.php | 2 +- .../Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php | 1 - tools/PHPStan/Rules/Interfaces/UselessInterfaceRule.php | 1 + tools/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php | 2 +- .../PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php | 2 +- 16 files changed, 13 insertions(+), 19 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c4b421f39..5e19daafa 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -18,7 +18,7 @@ parameters: treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false preconditionSystemHash: 54a37bf8c9e9be8e703d4e2219df1d49 - translationSystemHash: e573838804f62414d8488e329ec32123 + translationSystemHash: 0df1e2f49634b4bf0b655f2eada7f493 gitattributesExportInclude: - composer.json - docs diff --git a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php index 41c70cab4..78d929ca1 100644 --- a/src/Internal/FileSyncer/Service/RsyncFileSyncer.php +++ b/src/Internal/FileSyncer/Service/RsyncFileSyncer.php @@ -41,8 +41,6 @@ public function __construct( * descendant requires a unique approach, which has been documented here: * * @see https://serverfault.com/q/1094803/956603 - * - * @noinspection PhpUnhandledExceptionInspection */ public function sync( PathInterface $source, diff --git a/src/Internal/Filesystem/Service/Filesystem.php b/src/Internal/Filesystem/Service/Filesystem.php index c8699ba70..4a2b756d5 100644 --- a/src/Internal/Filesystem/Service/Filesystem.php +++ b/src/Internal/Filesystem/Service/Filesystem.php @@ -97,7 +97,6 @@ public function isDirEmpty(PathInterface $path): bool $scandir = @scandir($path->absolute()); if ($scandir === false) { - /** @noinspection PhpUnhandledExceptionInspection */ throw new IOException($this->t( 'The path does not exist or is not a directory at %path', $this->p(['%path' => $path->absolute()]), diff --git a/src/Internal/Translation/Service/SymfonyTranslatorProxy.php b/src/Internal/Translation/Service/SymfonyTranslatorProxy.php index 718711b4a..84ee9ad3f 100644 --- a/src/Internal/Translation/Service/SymfonyTranslatorProxy.php +++ b/src/Internal/Translation/Service/SymfonyTranslatorProxy.php @@ -27,14 +27,13 @@ public function __construct() }; } - /** @noinspection PhpParameterNameChangedDuringInheritanceInspection */ public function trans( - string $message, + string $id, array $parameters = [], ?string $domain = null, ?string $locale = self::LOCALE, ): string { - return $this->symfonyTranslator->trans($message, $parameters, $domain, $locale); + return $this->symfonyTranslator->trans($id, $parameters, $domain, $locale); } public function getLocale(): string diff --git a/tests/EndToEnd/EndToEndFunctionalTestCase.php b/tests/EndToEnd/EndToEndFunctionalTestCase.php index 620439885..42ecae8e8 100644 --- a/tests/EndToEnd/EndToEndFunctionalTestCase.php +++ b/tests/EndToEnd/EndToEndFunctionalTestCase.php @@ -234,7 +234,6 @@ public function testSync(string $activeDir, string $stagingDir): void $preconditionMet = true; } catch (PreconditionException $e) { $failedPrecondition = $e->getPrecondition(); - $preconditionMet = false; self::assertEquals(NoAbsoluteSymlinksExist::class, $failedPrecondition::class, 'Correct "codebase contains symlinks" unmet.'); } finally { assert(filetype($activeDirPath->absolute() . '/EXCLUDED_dir/symlink_NEVER_CHANGED_anywhere.txt') === 'link', 'An actual symlink is present in the codebase.'); diff --git a/tools/PHPCS/Helper/PHPHelper.php b/tools/PHPCS/Helper/PHPHelper.php index b3120ad74..07aba9f17 100644 --- a/tools/PHPCS/Helper/PHPHelper.php +++ b/tools/PHPCS/Helper/PHPHelper.php @@ -1,6 +1,5 @@ getContent(); $contentParts = explode(' ', $content); - $contentParts = array_values((array) $contentParts); + $contentParts = array_values($contentParts); $varName = array_pop($contentParts); // The variable name (correctly) begins with a dollar sign. diff --git a/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php b/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php index f38248503..9a4239d59 100644 --- a/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php +++ b/tools/PHPCS/Sniffs/Namespaces/APILayerDependsOnOtherLayerSniff.php @@ -64,7 +64,7 @@ private function isAPIFile(File $phpcsFile): bool { $srcDir = dirname(__DIR__, 4) . '/src/API'; - return str_starts_with((string) $phpcsFile->getFilename(), $srcDir); + return str_starts_with($phpcsFile->getFilename(), $srcDir); } private function getNamespace(File $phpcsFile, int $scopePtr): string diff --git a/tools/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php b/tools/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php index f3b062d25..14bac9ca2 100644 --- a/tools/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php +++ b/tools/PHPCS/Sniffs/Namespaces/AliasEndsWithAliasSniff.php @@ -56,7 +56,7 @@ private function isSrcFile(File $phpcsFile): bool { $srcDir = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'src'; - return str_starts_with((string) $phpcsFile->getFilename(), $srcDir); + return str_starts_with($phpcsFile->getFilename(), $srcDir); } private function getNamespace(File $phpcsFile, int $scopePtr): string diff --git a/tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php b/tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php index bfa30c366..93910eb3c 100644 --- a/tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php +++ b/tools/PHPCS/Sniffs/Namespaces/InternalLayerDependsOnNonProductionCodeSniff.php @@ -53,7 +53,7 @@ private function isInternalFile(File $phpcsFile): bool { $srcDir = dirname(__DIR__, 4) . '/src/Internal'; - return str_starts_with((string) $phpcsFile->getFilename(), $srcDir); + return str_starts_with($phpcsFile->getFilename(), $srcDir); } private function getNamespace(File $phpcsFile, int $scopePtr): string diff --git a/tools/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php b/tools/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php index 93d93c9f0..a03552a64 100644 --- a/tools/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php +++ b/tools/PHPCS/Sniffs/Namespaces/UnaliasedNonProjectUsesSniff.php @@ -26,7 +26,7 @@ public function process(File $phpcsFile, $stackPtr): void return; } - $namespace = NamespaceHelper::getNamespace($phpcsFile, $stackPtr, $this); + $namespace = NamespaceHelper::getNamespace($phpcsFile, $stackPtr); // Not a scope-level namespace, e.g., a class or interface. // (It's probably an anonymous function declaration.) @@ -63,7 +63,7 @@ private function isSrcFile(File $phpcsFile): bool { $srcDir = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'src'; - return str_starts_with((string) $phpcsFile->getFilename(), $srcDir); + return str_starts_with($phpcsFile->getFilename(), $srcDir); } private function isScopeLevelNamespace(File $phpcsFile, int $stackPtr): bool diff --git a/tools/PHPStan/Rules/AbstractRule.php b/tools/PHPStan/Rules/AbstractRule.php index 1b9699cb8..38cf0c3d2 100644 --- a/tools/PHPStan/Rules/AbstractRule.php +++ b/tools/PHPStan/Rules/AbstractRule.php @@ -57,7 +57,7 @@ protected function isProjectClass(ClassReflection $class): bool protected function isInNamespace(string $name, string $namespace): bool { - return str_starts_with("{$name}\\", $namespace); + return str_starts_with("$name\\", $namespace); } protected function getNamespace(string $name): string diff --git a/tools/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php b/tools/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php index 3654d1c31..28e4e01d7 100644 --- a/tools/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php +++ b/tools/PHPStan/Rules/Calls/NoInstantiatingTranslatableDirectlyRule.php @@ -28,7 +28,6 @@ public function getNodeType(): string return New_::class; } - /** @noinspection PhpPossiblePolymorphicInvocationInspection */ public function processNode(Node $node, Scope $scope): array { // Target instantiation via the "new" keyword. diff --git a/tools/PHPStan/Rules/Interfaces/UselessInterfaceRule.php b/tools/PHPStan/Rules/Interfaces/UselessInterfaceRule.php index a2f5921c4..c93a90ac3 100644 --- a/tools/PHPStan/Rules/Interfaces/UselessInterfaceRule.php +++ b/tools/PHPStan/Rules/Interfaces/UselessInterfaceRule.php @@ -18,6 +18,7 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { $interface = $this->getClassReflection($node); + /** @noinspection NullPointerExceptionInspection */ $reflection = $interface->getNativeReflection(); $methods = $reflection->getMethods(); $constants = $reflection->getReflectionConstants(); diff --git a/tools/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php b/tools/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php index c9b5be22a..df61efe5e 100644 --- a/tools/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php +++ b/tools/PHPStan/Rules/PhpDoc/TranslatablePhpDocRule.php @@ -14,7 +14,7 @@ use ReflectionClass; use ReflectionMethod; -/** Ensures that the docblockss for TranslatableMessage creation methods stay in sync. */ +/** Ensures that the docblocks for TranslatableMessage creation methods stay in sync. */ final class TranslatablePhpDocRule extends AbstractRule { /** The class that covered methods must be in sync with. */ diff --git a/tools/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php b/tools/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php index 8e902ad0d..429bb1f18 100644 --- a/tools/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php +++ b/tools/PHPStan/Rules/PhpDoc/TranslationParametersPhpDocRule.php @@ -14,7 +14,7 @@ use ReflectionClass; use ReflectionMethod; -/** Ensures that the docblockss for TranslationParameters creation methods stay in sync. */ +/** Ensures that the docblocks for TranslationParameters creation methods stay in sync. */ final class TranslationParametersPhpDocRule extends AbstractRule { /** The class that covered methods must be in sync with. */ From 621294437e972f0816b42ac25c5bca451a7cd1f8 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 28 Aug 2023 13:28:29 -0400 Subject: [PATCH 69/75] Add a "missing" test case to Tests\Path\Value\PathListUnitTest::testBasicFunctionality. --- tests/Path/Value/PathListUnitTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Path/Value/PathListUnitTest.php b/tests/Path/Value/PathListUnitTest.php index 2e1b46433..4bb754a1c 100644 --- a/tests/Path/Value/PathListUnitTest.php +++ b/tests/Path/Value/PathListUnitTest.php @@ -88,6 +88,20 @@ public function providerBasicFunctionality(): array 'five/five/five/five/five', ], ], + 'Complex paths' => [ + 'paths' => [ + 'one/two', + 'three\\four\\five', + 'six/seven\\../eight\\nine', + ], + 'add' => ['nine/ten/../../eleven/twelve'], + 'expected' => [ + 'one/two', + 'three/four/five', + 'six/eight/nine', + 'eleven/twelve', + ], + ], ]; } } From cbef81e71a2091c816d49467eff63a81edb7163e Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 28 Aug 2023 20:02:29 -0400 Subject: [PATCH 70/75] Reduce the number of Dependabot PRs coming in. --- .github/dependabot.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e5c760ed3..bcefdfeba 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,4 +11,8 @@ updates: - package-ecosystem: "composer" directory: "/" schedule: - interval: "daily" \ No newline at end of file + interval: "weekly" + groups: + all: + patterns: + - "*" From 1ea97091ba929d784243e7fc45af72b37e8d6ce1 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Mon, 28 Aug 2023 20:03:12 -0400 Subject: [PATCH 71/75] Reorder .github/dependabot.yml --- .github/dependabot.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bcefdfeba..aac3228e7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,11 +3,6 @@ version: 2 updates: - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" - - package-ecosystem: "composer" directory: "/" schedule: @@ -16,3 +11,8 @@ updates: all: patterns: - "*" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" From 6852c44f799fd64678f2a13595cec9052cfac8c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Aug 2023 00:05:27 +0000 Subject: [PATCH 72/75] Bump the all group with 1 update Bumps the all group with 1 update: [rector/rector](https://github.com/rectorphp/rector). - [Release notes](https://github.com/rectorphp/rector/releases) - [Commits](https://github.com/rectorphp/rector/compare/0.18.0...0.18.1) --- updated-dependencies: - dependency-name: rector/rector dependency-type: direct:development update-type: version-update:semver-patch dependency-group: all ... Signed-off-by: dependabot[bot] --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 7e8fca7fa..2c6e70416 100644 --- a/composer.lock +++ b/composer.lock @@ -3278,21 +3278,21 @@ }, { "name": "rector/rector", - "version": "0.18.0", + "version": "0.18.1", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "758ada29b5c80d933f906735d3026520390a2a1d" + "reference": "ee72ef542680a7f47ed8c6784f78b032c0d2f381" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/758ada29b5c80d933f906735d3026520390a2a1d", - "reference": "758ada29b5c80d933f906735d3026520390a2a1d", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/ee72ef542680a7f47ed8c6784f78b032c0d2f381", + "reference": "ee72ef542680a7f47ed8c6784f78b032c0d2f381", "shasum": "" }, "require": { "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.10.26" + "phpstan/phpstan": "^1.10.31" }, "conflict": { "rector/rector-doctrine": "*", @@ -3322,7 +3322,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.18.0" + "source": "https://github.com/rectorphp/rector/tree/0.18.1" }, "funding": [ { @@ -3330,7 +3330,7 @@ "type": "github" } ], - "time": "2023-08-17T12:53:22+00:00" + "time": "2023-08-28T18:01:58+00:00" }, { "name": "sebastian/cli-parser", From b6c788138a38f890acbd6741e28f873a99d3dcad Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Tue, 29 Aug 2023 20:36:05 -0400 Subject: [PATCH 73/75] Update PhpStorm source folders configuration. [skip ci] --- .idea/composer-stager.iml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.idea/composer-stager.iml b/.idea/composer-stager.iml index f467574f9..3cc65ebc7 100644 --- a/.idea/composer-stager.iml +++ b/.idea/composer-stager.iml @@ -3,7 +3,10 @@ - + + + + From fef38683a16b75be09e1a01d03b84fa725b62900 Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Tue, 29 Aug 2023 23:44:00 -0400 Subject: [PATCH 74/75] Add PHPStan rule to detect Internal layer autoloader dependencies. --- .idea/dictionaries/project.xml | 2 + phpstan.neon.dist | 7 ++++ .../Rules/Files/InternalLayerExposureRule.php | 42 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tools/PHPStan/Rules/Files/InternalLayerExposureRule.php diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml index a7258d424..be99177fa 100644 --- a/.idea/dictionaries/project.xml +++ b/.idea/dictionaries/project.xml @@ -5,6 +5,8 @@ Shmop Spoofchecker Transliterator + autoloaders + autoloading autowire autowiring canonicalized diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5e19daafa..15ed6d683 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,6 +13,7 @@ parameters: tmpDir: var/phpstan paths: - .gitattributes + - config/services.yml - src - tests treatPhpDocTypesAsCertain: false @@ -55,6 +56,11 @@ parameters: - message: '#Method create\(\) should not be public because it doesn''t implement a method on an interface.#' path: src/Internal/Translation/Service/Translator.php + - + # @todo Ignore this error until the error can be resolved: + # @see https://github.com/php-tuf/composer-stager/issues/268 + message: '#Service autoloading depends on the Internal layer.*#' + path: config/services.yml # Test code. - @@ -111,6 +117,7 @@ rules: - PhpTuf\ComposerStager\PHPStan\Rules\Classes\MissingExceptionInterfaceRule # Requires exceptions to implement ExceptionInterface. - PhpTuf\ComposerStager\PHPStan\Rules\Classes\MissingInterfaceRule # Requires concrete classes to implement an interface. - PhpTuf\ComposerStager\PHPStan\Rules\Classes\WrongExceptionNamespaceRule # Requires exceptions to be in the correct namespace. + - PhpTuf\ComposerStager\PHPStan\Rules\Files\InternalLayerExposureRule # Ensures that a client autoloaders don't depend on the Internal layer. - PhpTuf\ComposerStager\PHPStan\Rules\Interfaces\UselessInterfaceRule # Forbids empty interfaces, i.e., without methods or constants. - PhpTuf\ComposerStager\PHPStan\Rules\Methods\ForbiddenConcreteTypeHintRule # Forbids using concrete classes in type hints when an interface is available. - PhpTuf\ComposerStager\PHPStan\Rules\Methods\ForbiddenThrowsRule # Forbids throwing third party exceptions from public methods. diff --git a/tools/PHPStan/Rules/Files/InternalLayerExposureRule.php b/tools/PHPStan/Rules/Files/InternalLayerExposureRule.php new file mode 100644 index 000000000..536e8e19b --- /dev/null +++ b/tools/PHPStan/Rules/Files/InternalLayerExposureRule.php @@ -0,0 +1,42 @@ +getFile()); + + // Target services configuration. + if (!str_ends_with($filename, self::FILENAME)) { + return []; + } + + $contents = file_get_contents($filename); + + if (str_contains($contents, 'PhpTuf\\ComposerStager\\Internal\\')) { + return [ + $this->buildErrorMessage( + 'Service autoloading depends on the Internal layer, i.e., ' + . 'explicitly refers to PhpTuf\\ComposerStager\\Internal.', + ), + ]; + } + + return []; + } +} From 47747a0a1ffb719e096dbe411cca48ff20c087ca Mon Sep 17 00:00:00 2001 From: Travis Carden Date: Wed, 30 Aug 2023 09:54:33 -0400 Subject: [PATCH 75/75] Downgrade Symfony components to support Drupal 10.0.x. --- composer.json | 4 ++-- composer.lock | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 8cd560a9d..537766124 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ "require": { "php": ">=8.1.0", "ext-json": "*", - "symfony/filesystem": "^6.3", - "symfony/process": "^6.3", + "symfony/filesystem": "^6.2", + "symfony/process": "^6.2", "symfony/translation-contracts": "^3.2" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 2c6e70416..39102d647 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "67134c47bab480af5b2caa00768d7784", + "content-hash": "612aec18474d8a37f493be9dec4cdb1e", "packages": [ { "name": "symfony/filesystem", @@ -71,16 +71,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", "shasum": "" }, "require": { @@ -95,7 +95,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -133,7 +133,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" }, "funding": [ { @@ -149,20 +149,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + "reference": "42292d99c55abe617799667f454222c54c60e229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", + "reference": "42292d99c55abe617799667f454222c54c60e229", "shasum": "" }, "require": { @@ -177,7 +177,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -216,7 +216,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" }, "funding": [ { @@ -232,7 +232,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-07-28T09:04:16+00:00" }, { "name": "symfony/process",