Skip to content

Commit

Permalink
Make Tests\Precondition\Service\PreconditionTestCase::doTestUnfulfill…
Browse files Browse the repository at this point in the history
…ed() easier to use for simple strings.
  • Loading branch information
TravisCarden committed Aug 18, 2023
1 parent 93b9a3b commit e093ef5
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions tests/Precondition/Service/ActiveDirExistsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -55,6 +54,6 @@ public function testUnfulfilled(): void
->exists(PathHelper::activeDirPath())
->willReturn(false);

$this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message));
$this->doTestUnfulfilled($message);
}
}
3 changes: 1 addition & 2 deletions tests/Precondition/Service/ActiveDirIsReadyUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -72,6 +71,6 @@ public function testUnfulfilled(): void
->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions)
->willThrow($previous);

$this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message));
$this->doTestUnfulfilled($message);
}
}
3 changes: 1 addition & 2 deletions tests/Precondition/Service/BeginnerPreconditionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -83,6 +82,6 @@ public function testUnfulfilled(): void
->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions)
->willThrow($previous);

$this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message));
$this->doTestUnfulfilled($message);
}
}
3 changes: 1 addition & 2 deletions tests/Precondition/Service/CleanerPreconditionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -73,6 +72,6 @@ public function testUnfulfilled(): void
->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions)
->willThrow($previous);

$this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message));
$this->doTestUnfulfilled($message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -83,6 +82,6 @@ public function testUnfulfilled(): void
->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions)
->willThrow($previous);

$this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message));
$this->doTestUnfulfilled($message);
}
}
3 changes: 1 addition & 2 deletions tests/Precondition/Service/CommonPreconditionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -99,6 +98,6 @@ public function testUnfulfilled(): void
->assertIsFulfilled($activeDirPath, $stagingDirPath, $this->exclusions)
->willThrow($previous);

$this->doTestUnfulfilled(new TestTranslatableExceptionMessage($message));
$this->doTestUnfulfilled($message);
}
}
7 changes: 6 additions & 1 deletion tests/Precondition/Service/PreconditionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions tests/Precondition/Service/StagingDirExistsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions tests/Precondition/Service/StagingDirIsWritableUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e093ef5

Please sign in to comment.