-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
matt
committed
Feb 23, 2024
1 parent
549684d
commit db77704
Showing
6 changed files
with
111 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kynx\Laminas\FormShape\Writer\Tag; | ||
|
||
use function sprintf; | ||
use function trim; | ||
|
||
final readonly class PsalmImplements implements TagInterface | ||
{ | ||
public function __construct(private string $interface, private string $type) | ||
{ | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return sprintf('@implements %s<%s>', $this->interface, $this->type); | ||
} | ||
|
||
public function isBefore(TagInterface $tag): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function matches(TagInterface $tag): bool | ||
{ | ||
return str_starts_with(trim((string) $tag), '@implements '); | ||
Check failure on line 28 in src/Writer/Tag/PsalmImplements.php GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...
|
||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KynxTest\Laminas\FormShape\Writer\Tag; | ||
|
||
use Kynx\Laminas\FormShape\Writer\Tag\GenericTag; | ||
use Kynx\Laminas\FormShape\Writer\Tag\PsalmImplements; | ||
use Kynx\Laminas\FormShape\Writer\Tag\TagInterface; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(PsalmImplements::class)] | ||
final class PsalmImplementsTest extends TestCase | ||
{ | ||
public function testToStringReturnsTag(): void | ||
{ | ||
$expected = '@implements FormInterface<TFormArray>'; | ||
$tag = new PsalmImplements('FormInterface', 'TFormArray'); | ||
$actual = (string) $tag; | ||
self::assertSame($expected, $actual); | ||
} | ||
|
||
#[DataProvider('isBeforeProvider')] | ||
public function testIsBefore(TagInterface $match, bool $expected): void | ||
{ | ||
$tag = new PsalmImplements('FormInterface', 'TFormArray'); | ||
$actual = $tag->isBefore($match); | ||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public static function isBeforeProvider(): array | ||
Check failure on line 33 in test/Writer/Tag/PsalmImplementsTest.php GitHub Actions / ci / QA Checks (Psalm [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...PossiblyUnusedMethod
|
||
{ | ||
return [ | ||
'internal' => [new GenericTag('@internal'), false], | ||
'psalm-type' => [new GenericTag('@psalm-type TFoo = array<int>'), false], | ||
]; | ||
} | ||
|
||
#[DataProvider('matchProvider')] | ||
public function testMatches(TagInterface $match, bool $expected): void | ||
{ | ||
$tag = new PsalmImplements('FormInterface', 'TFormArray'); | ||
$actual = $tag->matches($match); | ||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public static function matchProvider(): array | ||
Check failure on line 49 in test/Writer/Tag/PsalmImplementsTest.php GitHub Actions / ci / QA Checks (Psalm [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...PossiblyUnusedMethod
|
||
{ | ||
return [ | ||
'extends' => [new GenericTag('@implements Foo<Bar>'), true], | ||
'psalm-type' => [new GenericTag('@psalm-type TFoo = array<int>'), false], | ||
]; | ||
} | ||
} |