Skip to content

Commit

Permalink
Add DNF test for TypeDef. Only runs on 8.2 and later.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Oct 29, 2023
1 parent 83cfed2 commit 7c32782
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/TypeDef/TypeExamples82.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Crell\AttributeUtils\TypeDef;

use Crell\AttributeUtils\I1;
use Crell\AttributeUtils\I2;

class TypeExamples82
{
public function returnsDnf(): (I1&I2)|int
{
}
}
18 changes: 18 additions & 0 deletions tests/TypeDefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Crell\AttributeUtils\TypeDef\Suit;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

Expand All @@ -23,6 +24,23 @@ public function typedefs(string $methodName, callable $test): void
$test($def);
}

#[Test, RequiresPhp('>=8.2')]
public function analyze_dnf_attributes(): void
{
$rType = (new \ReflectionClass(TypeDef\TypeExamples82::class))
->getMethod('returnsDnf')
->getReturnType();

$def = new TypeDef($rType);

static::assertFalse($def->allowsNull);
static::assertFalse($def->isSimple());
static::assertEquals(TypeComplexity::Compound, $def->complexity);
static::assertTrue($def->accepts('int'));
static::assertTrue($def->accepts(Implementer::class));
static::assertFalse($def->accepts(SomeClass::class));
}

public static function typeDefProvider(): iterable
{
yield 'simpleInt' => [
Expand Down

0 comments on commit 7c32782

Please sign in to comment.