Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Feb 15, 2024
1 parent 200c4d7 commit 72bcb11
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<testsuite name="Yii Definitions tests">
<directory>./tests/Unit</directory>
<directory phpVersion="8.1" phpVersionOperator=">=">./tests/Php8_1</directory>
<directory phpVersion="8.2" phpVersionOperator=">=">./tests/Php8_2</directory>
</testsuite>
</testsuites>

Expand Down
17 changes: 0 additions & 17 deletions tests/Php8_1/ParameterDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use ReflectionParameter;
use Yiisoft\Definitions\Exception\NotInstantiableException;
use Yiisoft\Definitions\ParameterDefinition;
use Yiisoft\Definitions\Tests\Support\Bike;
use Yiisoft\Definitions\Tests\Support\Chair;
use Yiisoft\Test\Support\Container\SimpleContainer;

final class ParameterDefinitionTest extends TestCase
Expand All @@ -29,21 +27,6 @@ public function testNotResolveIntersectionType(): void
$definition->resolve($container);
}

public function testResolveUnionTypeWithIntersectionType(): void
{
$container = new SimpleContainer([
Chair::class => new Chair(),
]);

$definition = new ParameterDefinition(
$this->getFirstParameter(fn (Bike|(GearBox&stdClass)|Chair $class) => true)
);

$result = $definition->resolve($container);

$this->assertInstanceOf(Chair::class, $result);
}

/**
* @return ReflectionParameter[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Definitions\Tests\Php8_1;
namespace Yiisoft\Definitions\Tests\Php8_2;

use PHPUnit\Framework\TestCase;
use Yiisoft\Definitions\DefinitionStorage;
Expand Down
46 changes: 46 additions & 0 deletions tests/Php8_2/ParameterDefinitionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Definitions\Tests\Php8_2;

use Closure;
use PHPUnit\Framework\TestCase;
use ReflectionFunction;
use ReflectionParameter;
use Yiisoft\Definitions\ParameterDefinition;
use Yiisoft\Definitions\Tests\Support\Bike;
use Yiisoft\Definitions\Tests\Support\Chair;
use Yiisoft\Test\Support\Container\SimpleContainer;

final class ParameterDefinitionTest extends TestCase
{
public function testResolveUnionTypeWithIntersectionType(): void
{
$container = new SimpleContainer([
Chair::class => new Chair(),
]);

$definition = new ParameterDefinition(
$this->getFirstParameter(fn (Bike|(GearBox&stdClass)|Chair $class) => true)
);

$result = $definition->resolve($container);

$this->assertInstanceOf(Chair::class, $result);
}

/**
* @return ReflectionParameter[]
*/
private function getParameters(callable $callable): array
{
$closure = $callable instanceof Closure ? $callable : Closure::fromCallable($callable);
return (new ReflectionFunction($closure))->getParameters();
}

private function getFirstParameter(Closure $closure): ReflectionParameter
{
return $this->getParameters($closure)[0];
}
}

0 comments on commit 72bcb11

Please sign in to comment.