Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize AbstractLinkIteratingPrecondition as AbstractFileIteratingPrecondition #102

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface;
use PhpTuf\ComposerStager\Infrastructure\Value\PathList\PathList;

abstract class AbstractLinkIteratingPrecondition extends AbstractPrecondition
abstract class AbstractFileIteratingPrecondition extends AbstractPrecondition
{
protected string $defaultUnfulfilledStatusMessage;

Expand All @@ -23,7 +23,7 @@ final protected function getUnfulfilledStatusMessage(): string
abstract protected function getDefaultUnfulfilledStatusMessage(): string;

/** @throws \PhpTuf\ComposerStager\Domain\Exception\IOException */
abstract protected function isSupportedLink(PathInterface $file, PathInterface $codebaseRootDir): bool;
abstract protected function isSupportedFile(PathInterface $file, PathInterface $codebaseRootDir): bool;

public function __construct(
protected readonly RecursiveFileFinderInterface $fileFinder,
Expand Down Expand Up @@ -57,11 +57,7 @@ public function isFulfilled(
foreach ($files as $file) {
$file = $this->pathFactory::create($file);

if (!$this->filesystem->isLink($file)) {
continue;
}

if (!$this->isSupportedLink($file, $directoryRoot)) {
if (!$this->isSupportedFile($file, $directoryRoot)) {
$this->defaultUnfulfilledStatusMessage = sprintf(
$this->defaultUnfulfilledStatusMessage,
$name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PhpTuf\ComposerStager\Domain\Value\Path\PathInterface;

/** phpcs:disable SlevomatCodingStandard.Files.LineLength.LineTooLong */
final class NoAbsoluteSymlinksExist extends AbstractLinkIteratingPrecondition implements NoAbsoluteSymlinksExistInterface
final class NoAbsoluteSymlinksExist extends AbstractFileIteratingPrecondition implements NoAbsoluteSymlinksExistInterface
{
public function getName(): string
{
Expand All @@ -28,7 +28,7 @@ protected function getDefaultUnfulfilledStatusMessage(): string
return 'The %s directory at "%s" contains absolute links, which is not supported. The first one is "%s".';
}

protected function isSupportedLink(PathInterface $file, PathInterface $codebaseRootDir): bool
protected function isSupportedFile(PathInterface $file, PathInterface $codebaseRootDir): bool
{
if (!$this->filesystem->isSymlink($file)) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/Service/Precondition/NoHardLinksExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PhpTuf\ComposerStager\Domain\Service\Precondition\NoHardLinksExistInterface;
use PhpTuf\ComposerStager\Domain\Value\Path\PathInterface;

final class NoHardLinksExist extends AbstractLinkIteratingPrecondition implements NoHardLinksExistInterface
final class NoHardLinksExist extends AbstractFileIteratingPrecondition implements NoHardLinksExistInterface
{
public function getName(): string
{
Expand All @@ -27,7 +27,7 @@ protected function getDefaultUnfulfilledStatusMessage(): string
return 'The %s directory at "%s" contains hard links, which is not supported. The first one is "%s".';
}

protected function isSupportedLink(PathInterface $file, PathInterface $codebaseRootDir): bool
protected function isSupportedFile(PathInterface $file, PathInterface $codebaseRootDir): bool
{
return !$this->filesystem->isHardLink($file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface;

final class NoLinksExistOnWindows extends AbstractLinkIteratingPrecondition implements NoLinksExistOnWindowsInterface
final class NoLinksExistOnWindows extends AbstractFileIteratingPrecondition implements NoLinksExistOnWindowsInterface
{
public function __construct(
RecursiveFileFinderInterface $fileFinder,
Expand Down Expand Up @@ -50,7 +50,7 @@ protected function getDefaultUnfulfilledStatusMessage(): string
return 'The %s directory at "%s" contains links, which is not supported on Windows. The first one is "%s".';
}

protected function isSupportedLink(PathInterface $file, PathInterface $codebaseRootDir): bool
protected function isSupportedFile(PathInterface $file, PathInterface $codebaseRootDir): bool
{
// This code is host-specific, so it shouldn't be counted against code coverage
// numbers. Nevertheless, it IS covered by tests on Windows-based CI jobs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PhpTuf\ComposerStager\Domain\Service\Precondition\NoSymlinksPointOutsideTheCodebaseInterface;
use PhpTuf\ComposerStager\Domain\Value\Path\PathInterface;

final class NoSymlinksPointOutsideTheCodebase extends AbstractLinkIteratingPrecondition implements
final class NoSymlinksPointOutsideTheCodebase extends AbstractFileIteratingPrecondition implements
NoSymlinksPointOutsideTheCodebaseInterface
{
public function getName(): string
Expand All @@ -30,7 +30,7 @@ protected function getDefaultUnfulfilledStatusMessage(): string
EOF;
}

protected function isSupportedLink(PathInterface $file, PathInterface $codebaseRootDir): bool
protected function isSupportedFile(PathInterface $file, PathInterface $codebaseRootDir): bool
{
if (!$this->filesystem->isSymlink($file)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion tests/EndToEnd/PhpFileSyncerEndToEndFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Finder\ExecutableFinder
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinder
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Host\Host
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveAndStagingDirsAreDifferent
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\ActiveDirExists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use PhpTuf\ComposerStager\Domain\Value\PathList\PathListInterface;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition;
use Prophecy\Argument;

/**
* @coversDefaultClass \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @coversDefaultClass \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
*
* @covers ::__construct
* @covers ::findFiles
Expand All @@ -28,7 +28,7 @@
* @property \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface|\Prophecy\Prophecy\ObjectProphecy $pathFactory
* @property \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface|\Prophecy\Prophecy\ObjectProphecy $fileFinder
*/
final class AbstractLinkIteratingPreconditionUnitTest extends LinkIteratingPreconditionUnitTestCase
final class AbstractFileIteratingPreconditionUnitTest extends FileIteratingPreconditionUnitTestCase
{
protected function fulfilledStatusMessage(): string
{
Expand Down Expand Up @@ -58,7 +58,7 @@ 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) extends AbstractLinkIteratingPrecondition
return new class ($fileFinder, $filesystem, $pathFactory) extends AbstractFileIteratingPrecondition
{
public bool $exitEarly = false;

Expand All @@ -67,7 +67,7 @@ protected function getDefaultUnfulfilledStatusMessage(): string
return '';
}

protected function isSupportedLink(PathInterface $file, PathInterface $codebaseRootDir): bool
protected function isSupportedFile(PathInterface $file, PathInterface $codebaseRootDir): bool
{
return true;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ protected function exitEarly(
};
}

/** @covers \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition::exitEarly */
/** @covers \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition::exitEarly */
public function testExitEarly(): void
{
$activeDir = $this->activeDir->reveal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use PhpTuf\ComposerStager\Domain\Value\PathList\PathListInterface;
use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface;
use PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition;
use Prophecy\Argument;

/**
Expand All @@ -21,7 +21,7 @@
* @property \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface|\Prophecy\Prophecy\ObjectProphecy $pathFactory
* @property \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface|\Prophecy\Prophecy\ObjectProphecy $fileFinder
*/
abstract class LinkIteratingPreconditionUnitTestCase extends PreconditionTestCase
abstract class FileIteratingPreconditionUnitTestCase extends PreconditionTestCase
{
abstract protected function fulfilledStatusMessage(): string;

Expand All @@ -40,7 +40,7 @@ protected function setUp(): void
parent::setUp();
}

/** @covers \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition::exitEarly */
/** @covers \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition::exitEarly */
public function testExitEarly(): void
{
$activeDir = $this->activeDir->reveal();
Expand All @@ -58,14 +58,14 @@ 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) extends AbstractLinkIteratingPrecondition
$sut = new class ($fileFinder, $filesystem, $pathFactory) extends AbstractFileIteratingPrecondition
{
protected function getDefaultUnfulfilledStatusMessage(): string
{
return '';
}

protected function isSupportedLink(PathInterface $file, PathInterface $codebaseRootDir): bool
protected function isSupportedFile(PathInterface $file, PathInterface $codebaseRootDir): bool
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace PhpTuf\ComposerStager\Tests\Infrastructure\Service\Precondition;

use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactory;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\NoAbsoluteSymlinksExist;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\NoHardLinksExist;
use PhpTuf\ComposerStager\Infrastructure\Service\Precondition\NoLinksExistOnWindows;
Expand Down Expand Up @@ -64,7 +64,7 @@ protected function createTestPreconditionsTree(array $excludePreconditions = [])
}

// Limit to link iterating preconditions.
if (!($service instanceof AbstractLinkIteratingPrecondition)) {
if (!($service instanceof AbstractFileIteratingPrecondition)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
* @covers ::__construct
* @covers ::findFiles
* @covers ::getDefaultUnfulfilledStatusMessage
* @covers ::isSupportedLink
* @covers ::isSupportedFile
*
* @uses \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactory
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Filesystem\Filesystem
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinder
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\Path\AbstractPath
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\Path\UnixLikePath
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\Path\WindowsPath
Expand Down Expand Up @@ -200,7 +200,7 @@ public function testDirectoryDoesNotExist(string $activeDir, string $stagingDir)

/**
* @covers ::isFulfilled
* @covers ::isSupportedLink
* @covers ::isSupportedFile
*/
public function testWithHardLink(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* @covers ::isFulfilled
*
* @uses \PhpTuf\ComposerStager\Domain\Exception\PreconditionException
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\PathList\PathList
*
* @property \PhpTuf\ComposerStager\Domain\Service\Filesystem\FilesystemInterface|\Prophecy\Prophecy\ObjectProphecy $filesystem
* @property \PhpTuf\ComposerStager\Domain\Value\Path\PathInterface|\Prophecy\Prophecy\ObjectProphecy $activeDir
* @property \PhpTuf\ComposerStager\Domain\Value\Path\PathInterface|\Prophecy\Prophecy\ObjectProphecy $stagingDir
*/
final class NoAbsoluteSymlinksExistUnitTest extends LinkIteratingPreconditionUnitTestCase
final class NoAbsoluteSymlinksExistUnitTest extends FileIteratingPreconditionUnitTestCase
{
protected function createSut(): NoAbsoluteSymlinksExist
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @uses \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactory
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Filesystem\Filesystem
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinder
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\Path\AbstractPath
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\Path\UnixLikePath
Expand All @@ -40,7 +40,7 @@ protected function createSut(): NoHardLinksExist
return $sut;
}

/** @covers ::isSupportedLink */
/** @covers ::isSupportedFile */
public function testFulfilledWithNoLinks(): void
{
$sut = $this->createSut();
Expand All @@ -50,7 +50,7 @@ public function testFulfilledWithNoLinks(): void
self::assertTrue($isFulfilled, 'Passed with no links in the codebase.');
}

/** @covers ::isSupportedLink */
/** @covers ::isSupportedFile */
public function testFulfilledWithSymlink(): void
{
$target = PathFactory::create('target.txt', $this->activeDir)->resolve();
Expand All @@ -66,7 +66,7 @@ public function testFulfilledWithSymlink(): void

/**
* @covers ::getUnfulfilledStatusMessage
* @covers ::isSupportedLink
* @covers ::isSupportedFile
*
* @dataProvider providerUnfulfilled
*/
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testDirectoryDoesNotExist(string $activeDir, string $stagingDir)

/**
* @covers ::isFulfilled
* @covers ::isSupportedLink
* @covers ::isSupportedFile
*
* @dataProvider providerExclusions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @covers ::isFulfilled
*
* @uses \PhpTuf\ComposerStager\Domain\Exception\PreconditionException
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\PathList\PathList
*
* @property \PhpTuf\ComposerStager\Domain\Service\Filesystem\FilesystemInterface|\Prophecy\Prophecy\ObjectProphecy $filesystem
Expand All @@ -24,7 +24,7 @@
* @property \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface|\Prophecy\Prophecy\ObjectProphecy $pathFactory
* @property \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface|\Prophecy\Prophecy\ObjectProphecy $fileFinder
*/
final class NoHardLinksExistUnitTest extends LinkIteratingPreconditionUnitTestCase
final class NoHardLinksExistUnitTest extends FileIteratingPreconditionUnitTestCase
{
protected function createSut(): NoHardLinksExist
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinder
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinder
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Host\Host
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\Path\AbstractPath
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\Path\UnixLikePath
Expand Down Expand Up @@ -62,7 +62,7 @@ public function testFulfilledWithNoLinks(): void
* @covers ::getDefaultUnfulfilledStatusMessage
* @covers ::getUnfulfilledStatusMessage
* @covers ::isFulfilled
* @covers ::isSupportedLink
* @covers ::isSupportedFile
*
* @dataProvider providerUnfulfilled
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @covers ::isFulfilled
*
* @uses \PhpTuf\ComposerStager\Domain\Exception\PreconditionException
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractLinkIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Service\Precondition\AbstractFileIteratingPrecondition
* @uses \PhpTuf\ComposerStager\Infrastructure\Value\PathList\PathList
*
* @property \PhpTuf\ComposerStager\Domain\Service\Filesystem\FilesystemInterface|\Prophecy\Prophecy\ObjectProphecy $filesystem
Expand All @@ -29,7 +29,7 @@
* @property \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface|\Prophecy\Prophecy\ObjectProphecy $pathFactory
* @property \PhpTuf\ComposerStager\Infrastructure\Service\Finder\RecursiveFileFinderInterface|\Prophecy\Prophecy\ObjectProphecy $fileFinder
*/
final class NoLinksExistOnWindowsUnitTest extends LinkIteratingPreconditionUnitTestCase
final class NoLinksExistOnWindowsUnitTest extends FileIteratingPreconditionUnitTestCase
{
protected function setUp(): void
{
Expand Down
Loading