Skip to content

Commit

Permalink
[TASK] Streamline PHPUnit attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Mar 30, 2023
1 parent 4d5b888 commit 4c0f9e3
Show file tree
Hide file tree
Showing 70 changed files with 377 additions and 337 deletions.
19 changes: 10 additions & 9 deletions tests/src/Builder/BuildInstructionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use CPSIT\ProjectBuilder as Src;
use CPSIT\ProjectBuilder\Tests;
use PHPUnit\Framework;

use function dirname;
use function sys_get_temp_dir;
Expand All @@ -47,31 +48,31 @@ protected function setUp(): void
);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getConfigReturnsConfig(): void
{
self::assertSame(self::$container->get('app.config'), $this->subject->getConfig());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getTemplateDirectoryReturnsTemplateDirectory(): void
{
self::assertSame(dirname(__DIR__), $this->subject->getTemplateDirectory());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getSourceDirectoryReturnsSourceDirectory(): void
{
self::assertSame(dirname(__DIR__).'/templates/src', $this->subject->getSourceDirectory());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getSharedSourceDirectoryReturnsSharedSourceDirectory(): void
{
self::assertSame(dirname(__DIR__).'/templates/shared', $this->subject->getSharedSourceDirectory());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getTemporaryDirectoryReturnsUniqueTemporaryDirectory(): void
{
$prefix = sys_get_temp_dir();
Expand All @@ -82,13 +83,13 @@ public function getTemporaryDirectoryReturnsUniqueTemporaryDirectory(): void
self::assertStringStartsWith($prefix, $actual);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getTargetDirectoryReturnsTargetDirectory(): void
{
self::assertSame('foo', $this->subject->getTargetDirectory());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getTemplateVariablesReturnsTemplateVariables(): void
{
self::assertSame([], $this->subject->getTemplateVariables());
Expand All @@ -98,7 +99,7 @@ public function getTemplateVariablesReturnsTemplateVariables(): void
self::assertSame(['foo' => 'bar'], $this->subject->getTemplateVariables());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getTemplateVariableReturnsTemplateVariableAtGivenPath(): void
{
self::assertNull($this->subject->getTemplateVariable('foo.bar.hello'));
Expand All @@ -112,7 +113,7 @@ public function getTemplateVariableReturnsTemplateVariableAtGivenPath(): void
self::assertSame('world!', $this->subject->getTemplateVariable('foo.bar.hello'));
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function addTemplateVariableSetsTemplateVariableAtGivenPath(): void
{
self::assertNull($this->subject->getTemplateVariable('foo.bar.hello'));
Expand Down
19 changes: 10 additions & 9 deletions tests/src/Builder/BuildResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Composer\Package;
use CPSIT\ProjectBuilder as Src;
use CPSIT\ProjectBuilder\Tests;
use PHPUnit\Framework;
use Symfony\Component\Finder;

use function basename;
Expand All @@ -51,20 +52,20 @@ protected function setUp(): void
$this->subject = new Src\Builder\BuildResult($this->instructions);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getInstructionsReturnsInstructions(): void
{
self::assertSame($this->instructions, $this->subject->getInstructions());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function isMirroredReturnsMirrorState(): void
{
self::assertFalse($this->subject->isMirrored());
self::assertTrue($this->subject->setMirrored(true)->isMirrored());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getBuildArtifactReturnsBuildArtifact(): void
{
self::assertNull($this->subject->getBuildArtifact());
Expand All @@ -78,7 +79,7 @@ public function getBuildArtifactReturnsBuildArtifact(): void
self::assertSame($buildArtifact, $this->subject->setBuildArtifact($buildArtifact)->getBuildArtifact());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getAppliedStepsReturnsAppliedSteps(): void
{
$step = new Tests\Fixtures\DummyStep();
Expand All @@ -90,7 +91,7 @@ public function getAppliedStepsReturnsAppliedSteps(): void
self::assertSame([$step::getType() => $step], $this->subject->getAppliedSteps());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function isStepAppliedTestsWhetherStepIsApplied(): void
{
$step = new Tests\Fixtures\DummyStep();
Expand All @@ -107,7 +108,7 @@ public function isStepAppliedTestsWhetherStepIsApplied(): void
));
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function applyStepAddsStepToAppliedSteps(): void
{
$step = new Tests\Fixtures\DummyStep();
Expand All @@ -119,7 +120,7 @@ public function applyStepAddsStepToAppliedSteps(): void
self::assertTrue($this->subject->isStepApplied($step));
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getProcessedFilesReturnsProcessedFiles(): void
{
self::assertSame([], $this->subject->getProcessedFiles());
Expand All @@ -137,13 +138,13 @@ public function getProcessedFilesReturnsProcessedFiles(): void
self::assertSame([$barFile], $this->subject->getProcessedFiles('/bar'));
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getWrittenDirectoryReturnsTemporaryDirectoryIfBuildWasNotMirrored(): void
{
self::assertSame($this->instructions->getTemporaryDirectory(), $this->subject->getWrittenDirectory());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getWrittenDirectoryReturnsTargetDirectoryIfBuildWasMirrored(): void
{
$this->subject->setMirrored(true);
Expand Down
10 changes: 5 additions & 5 deletions tests/src/Builder/Config/ConfigFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace CPSIT\ProjectBuilder\Tests\Builder\Config;

use CPSIT\ProjectBuilder as Src;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework;

use function dirname;
use function ucfirst;
Expand All @@ -35,7 +35,7 @@
* @author Elias Häußler <e.haeussler@familie-redlich.de>
* @license GPL-3.0-or-later
*/
final class ConfigFactoryTest extends TestCase
final class ConfigFactoryTest extends Framework\TestCase
{
private Src\Builder\Config\ConfigFactory $subject;

Expand All @@ -44,7 +44,7 @@ protected function setUp(): void
$this->subject = Src\Builder\Config\ConfigFactory::create();
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function buildFromFileThrowsExceptionIfFileContentsAreInvalid(): void
{
$this->expectException(Src\Exception\InvalidConfigurationException::class);
Expand All @@ -53,7 +53,7 @@ public function buildFromFileThrowsExceptionIfFileContentsAreInvalid(): void
$this->subject->buildFromFile(dirname(__DIR__, 2).'/Fixtures/Files/invalid-config.yaml', 'foo');
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function buildFromFileReturnsHydratedConfigObject(): void
{
$createConfig = fn (string $type): Src\Builder\Config\Config => new Src\Builder\Config\Config(
Expand Down Expand Up @@ -132,7 +132,7 @@ public function buildFromFileReturnsHydratedConfigObject(): void
}
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function buildFromStringThrowsExceptionIfGivenContentIsInvalid(): void
{
$this->expectException(Src\Exception\InvalidConfigurationException::class);
Expand Down
18 changes: 9 additions & 9 deletions tests/src/Builder/Config/ConfigReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace CPSIT\ProjectBuilder\Tests\Builder\Config;

use CPSIT\ProjectBuilder as Src;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework;

use function dirname;

Expand All @@ -34,7 +34,7 @@
* @author Elias Häußler <e.haeussler@familie-redlich.de>
* @license GPL-3.0-or-later
*/
final class ConfigReaderTest extends TestCase
final class ConfigReaderTest extends Framework\TestCase
{
private Src\Builder\Config\ConfigReader $subject;

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

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function createCreatesTemplateDirectoryIfItDoesNotExist(): void
{
$templateDirectory = Src\Helper\FilesystemHelper::getNewTemporaryDirectory();
Expand All @@ -57,7 +57,7 @@ public function createCreatesTemplateDirectoryIfItDoesNotExist(): void
self::assertDirectoryExists($templateDirectory);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function readConfigThrowsExceptionIfTemplateHasNoComposerJson(): void
{
$templateDirectory = dirname(__DIR__, 2).'/Fixtures';
Expand All @@ -70,7 +70,7 @@ public function readConfigThrowsExceptionIfTemplateHasNoComposerJson(): void
$subject->readConfig('foo');
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function readConfigThrowsExceptionIfTemplateWithGivenIdentifierDoesNotExist(): void
{
$this->expectException(Src\Exception\InvalidConfigurationException::class);
Expand All @@ -80,7 +80,7 @@ public function readConfigThrowsExceptionIfTemplateWithGivenIdentifierDoesNotExi
$this->subject->readConfig('foo');
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function readConfigThrowsExceptionIfTemplateContainsMultipleConfigFiles(): void
{
$subject = Src\Builder\Config\ConfigReader::create(
Expand All @@ -94,7 +94,7 @@ public function readConfigThrowsExceptionIfTemplateContainsMultipleConfigFiles()
$subject->readConfig('cpsit/project-builder-template-invalid');
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function readConfigReturnsHydratedConfigObject(): void
{
$actual = $this->subject->readConfig('cpsit/project-builder-template-yaml');
Expand All @@ -106,15 +106,15 @@ public function readConfigReturnsHydratedConfigObject(): void
);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function hasConfigChecksWhetherConfigWithGivenIdentifierExists(): void
{
self::assertTrue($this->subject->hasConfig('cpsit/project-builder-template-json'));
self::assertTrue($this->subject->hasConfig('cpsit/project-builder-template-yaml'));
self::assertFalse($this->subject->hasConfig('foo'));
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function listTemplateListsAllAvailableTemplates(): void
{
$expected = [
Expand Down
22 changes: 11 additions & 11 deletions tests/src/Builder/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use Composer\Package;
use CPSIT\ProjectBuilder as Src;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework;

use function serialize;

Expand All @@ -35,7 +35,7 @@
* @author Elias Häußler <e.haeussler@familie-redlich.de>
* @license GPL-3.0-or-later
*/
final class ConfigTest extends TestCase
final class ConfigTest extends Framework\TestCase
{
private Src\Builder\Config\Config $subject;

Expand All @@ -53,19 +53,19 @@ protected function setUp(): void
);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getIdentifierReturnsIdentifier(): void
{
self::assertSame('identifier', $this->subject->getIdentifier());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getNameReturnsName(): void
{
self::assertSame('name', $this->subject->getName());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getStepsReturnsSteps(): void
{
self::assertEquals(
Expand All @@ -76,7 +76,7 @@ public function getStepsReturnsSteps(): void
);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getPropertiesReturnsProperties(): void
{
self::assertEquals(
Expand All @@ -87,7 +87,7 @@ public function getPropertiesReturnsProperties(): void
);
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getDeclaringFileThrowsExceptionIfDeclaringFileIsNotSet(): void
{
$this->expectException(Src\Exception\InvalidConfigurationException::class);
Expand All @@ -97,13 +97,13 @@ public function getDeclaringFileThrowsExceptionIfDeclaringFileIsNotSet(): void
$this->subject->getDeclaringFile();
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function setDeclaringFileAppliesDeclaringFile(): void
{
self::assertSame('foo', $this->subject->setDeclaringFile('foo')->getDeclaringFile());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function getTemplateSourceThrowsExceptionIfTemplateSourceIsNotSet(): void
{
$this->expectException(Src\Exception\InvalidConfigurationException::class);
Expand All @@ -113,7 +113,7 @@ public function getTemplateSourceThrowsExceptionIfTemplateSourceIsNotSet(): void
$this->subject->getTemplateSource();
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function setTemplateSourceAppliesTemplateSource(): void
{
$templateSource = new Src\Template\TemplateSource(
Expand All @@ -124,7 +124,7 @@ public function setTemplateSourceAppliesTemplateSource(): void
self::assertSame($templateSource, $this->subject->setTemplateSource($templateSource)->getTemplateSource());
}

#[\PHPUnit\Framework\Attributes\Test]
#[Framework\Attributes\Test]
public function buildHashCalculatesConfigHash(): void
{
$hash = sha1(
Expand Down
Loading

0 comments on commit 4c0f9e3

Please sign in to comment.