Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
- tests/benchmark/Assets/*
paths:
- src
- tests
ignoreErrors:
-
message: "#^Parameter \\#1 \\$constExprParser of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser\\|null, PHPStan\\\\PhpDocParser\\\\ParserConfig given\\.$#"
Expand All @@ -24,3 +25,20 @@ parameters:
message: "#^Parameter \\#2 \\$quoteAwareConstExprString of class PHPStan\\\\PhpDocParser\\\\Parser\\\\TypeParser constructor expects bool, PHPStan\\\\PhpDocParser\\\\Parser\\\\ConstExprParser given\\.$#"
count: 1
path: src/TypeResolver.php

# We are intentionally adding invalid parameters here
-
message: "#^Parameter \\#2 \\$typeClassName of method phpDocumentor\\\\Reflection\\\\TypeResolver\\:\\:addKeyword\\(\\) expects class\\-string\\<phpDocumentor\\\\Reflection\\\\Type\\>\\, string given\\.$#"
count: 2
path: tests/unit/TypeResolverTest.php

# We are intentionally adding invalid parameters here
-
message: "#^Parameter \\#1 \\$types of class phpDocumentor\\\\Reflection\\\\Types\\\\Compound constructor expects array\\<phpDocumentor\\\\Reflection\\\\Type\\>\\, array\\<int\\, string\\> given\\.$#"
count: 1
path: tests/unit/Types/CompoundTest.php

-
message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\<Foo\\\\Bar\\>\\|Foo\\\\Bar\\, string given\\.$#"
count: 1
path: tests/unit/Types/ContextFactoryTest.php
6 changes: 3 additions & 3 deletions tests/benchmark/ContextFactoryBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ final class ContextFactoryBench
{
private string $source;

public function setup()
public function setup(): void
{
$this->source = file_get_contents(__DIR__ . '/Assets/mpdf.php');
$this->source = (string) file_get_contents(__DIR__ . '/Assets/mpdf.php');
}

/**
* @Warmup(1)
*/
public function benchCreateContextForNamespace()
public function benchCreateContextForNamespace(): void
{
$factory = new ContextFactory();
$factory->createForNamespace(
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark/TypeResolverBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TypeResolverBench
{
private TypeResolver $typeResolver;

public function setup()
public function setup(): void
{
$this->typeResolver = new TypeResolver();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/benchmark/TypeResolverWithContextBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ final class TypeResolverWithContextBench
*/
private $typeResolver;

public function setup()
public function setup(): void
{
$factory = new ContextFactory();
$this->context = $factory->createForNamespace('mpdf', file_get_contents(__DIR__ . '/Assets/mpdf.php'));
$this->context = $factory->createForNamespace('mpdf', (string) file_get_contents(__DIR__ . '/Assets/mpdf.php'));
$this->typeResolver = new TypeResolver();
}

Expand Down
8 changes: 6 additions & 2 deletions tests/unit/NumericResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use phpDocumentor\Reflection\PseudoTypes\Numeric_;
use phpDocumentor\Reflection\PseudoTypes\NumericString;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;
Expand All @@ -40,7 +41,10 @@ public function testResolvingIntRange(): void

$this->assertInstanceOf(Numeric_::class, $resolvedType);
$this->assertSame('numeric', (string) $resolvedType);
$this->assertSame(false, $resolvedType->underlyingType()->contains(new String_()));
$this->assertSame(true, $resolvedType->underlyingType()->contains(new NumericString()));

$underlyingType = $resolvedType->underlyingType();
$this->assertInstanceOf(Compound::class, $underlyingType);
$this->assertFalse($underlyingType->contains(new String_()));
$this->assertTrue($underlyingType->contains(new NumericString()));
}
}
8 changes: 5 additions & 3 deletions tests/unit/TypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class TypeResolverTest extends TestCase
* @uses \phpDocumentor\Reflection\Types\Array_
* @uses \phpDocumentor\Reflection\Types\Object_
*
* @param class-string $expectedClass
*
* @covers ::__construct
* @covers ::resolve
* @covers ::createType
Expand Down Expand Up @@ -291,9 +293,8 @@ public function testResolvingNestedTypedArrays(): void

$resolvedType = $fixture->resolve('string[][]', new Context(''));

$childValueType = $resolvedType->getValueType();

$this->assertInstanceOf(Array_::class, $resolvedType);
$childValueType = $resolvedType->getValueType();

$this->assertSame('string[][]', (string) $resolvedType);
$this->assertInstanceOf(Compound::class, $resolvedType->getKeyType());
Expand Down Expand Up @@ -414,11 +415,12 @@ public function testResolvingMixedCompoundTypes(): void

$resolvedType = $firstType->getValueType();

$this->assertInstanceOf(Intersection::class, $resolvedType);
$firstSubType = $resolvedType->get(0);
$secondSubType = $resolvedType->get(1);

$this->assertInstanceOf(Object_::class, $firstSubType);
$this->assertInstanceOf(Fqsen::class, $secondSubType->getFqsen());
$this->assertInstanceOf(Fqsen::class, $firstSubType->getFqsen());
$this->assertInstanceOf(Object_::class, $secondSubType);
$this->assertInstanceOf(Fqsen::class, $secondSubType->getFqsen());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/Types/ContextFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testReadsAliasesFromClassReflection() : void
public function testReadsNamespaceFromProvidedNamespaceAndContent() : void
{
$fixture = new ContextFactory();
$context = $fixture->createForNamespace(__NAMESPACE__, file_get_contents(__FILE__));
$context = $fixture->createForNamespace(__NAMESPACE__, (string) file_get_contents(__FILE__));

$this->assertSame(__NAMESPACE__, $context->getNamespace());
}
Expand All @@ -73,7 +73,7 @@ public function testReadsNamespaceFromProvidedNamespaceAndContent() : void
public function testReadsAliasesFromProvidedNamespaceAndContent() : void
{
$fixture = new ContextFactory();
$context = $fixture->createForNamespace(__NAMESPACE__, file_get_contents(__FILE__));
$context = $fixture->createForNamespace(__NAMESPACE__, (string) file_get_contents(__FILE__));

$this->assertNamespaceAliasesFrom($context);
}
Expand Down Expand Up @@ -198,7 +198,7 @@ class Bar
$this->assertSame([], $context->getNamespaceAliases());
}

public function assertNamespaceAliasesFrom(Context $context)
public function assertNamespaceAliasesFrom(Context $context): void
{
$expected = [
'm' => m::class,
Expand Down