Skip to content

Commit

Permalink
Add AbstractDtoTestCase to automatically test simple models
Browse files Browse the repository at this point in the history
  • Loading branch information
123jkarssen authored Jul 24, 2024
1 parent a1be063 commit 47a1243
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Test/AbstractDtoTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DigitalRevolution\AccessorPairConstraint\Test;

use DigitalRevolution\AccessorPairConstraint\AccessorPairAsserter;
use DigitalRevolution\AccessorPairConstraint\Constraint\ConstraintConfig;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use ReflectionAttribute;
use ReflectionClass;

abstract class AbstractDtoTestCase extends TestCase
{
use AccessorPairAsserter;

public function testModel(): void
{
$attributes = (new ReflectionClass(static::class))

Check failure on line 20 in src/Test/AbstractDtoTestCase.php

View workflow job for this annotation

GitHub Actions / Quality checks

Call to an undefined method ReflectionClass<static(DigitalRevolution\AccessorPairConstraint\Test\AbstractDtoTestCase)>::getAttributes().
->getAttributes(CoversClass::class, ReflectionAttribute::IS_INSTANCEOF);

Check failure on line 21 in src/Test/AbstractDtoTestCase.php

View workflow job for this annotation

GitHub Actions / Quality checks

Class PHPUnit\Framework\Attributes\CoversClass not found.
$testedAttributes = false;
foreach ($attributes as $attribute) {
if ($attribute->getName() === 'PHPUnit\Framework\Attributes\CoversClass') {
$testedAttributes = true;
$config = $this->getAccessorPairConfig();
static::assertAccessorPairs($attribute->getArguments()[0], $config);
}
}
static::assertTrue($testedAttributes, 'Missing CoversClass attribute');
}

protected function getAccessorPairConfig(): ConstraintConfig
{
return (new ConstraintConfig())->setAssertPropertyDefaults(true);
}
}

0 comments on commit 47a1243

Please sign in to comment.