generated from yiisoft/package-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test coverage 100% + minor refactoring (#27)
- Loading branch information
Showing
13 changed files
with
352 additions
and
18 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
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Php8; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use RuntimeException; | ||
use Yiisoft\Definitions\DefinitionStorage; | ||
use Yiisoft\Definitions\Tests\Support\ColorInterface; | ||
use Yiisoft\Definitions\Tests\Support\ColorPink; | ||
use Yiisoft\Definitions\Tests\Support\UnionCar; | ||
use Yiisoft\Definitions\Tests\Support\UnionSelfDependency; | ||
use Yiisoft\Test\Support\Container\SimpleContainer; | ||
|
||
final class DefinitionStorageTest extends TestCase | ||
{ | ||
public function testUnresolvableUnionSelfDependency(): void | ||
{ | ||
$storage = new DefinitionStorage(); | ||
|
||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage( | ||
'Service ' . UnionSelfDependency::class . ' doesn\'t exist in DefinitionStorage.' | ||
); | ||
$storage->get(UnionSelfDependency::class); | ||
} | ||
|
||
public function testResolvableUnionTypeDependency(): void | ||
{ | ||
$storage = new DefinitionStorage(); | ||
|
||
$definition = $storage->get(UnionCar::class); | ||
|
||
$this->assertSame(UnionCar::class, $definition); | ||
} | ||
|
||
public function testResolvableFromContainerUnionTypeDependency(): void | ||
{ | ||
$storage = new DefinitionStorage(); | ||
|
||
$container = new SimpleContainer([ | ||
ColorInterface::class => new ColorPink(), | ||
]); | ||
$storage->setDelegateContainer($container); | ||
|
||
$definition = $storage->get(UnionSelfDependency::class); | ||
|
||
$this->assertSame(UnionSelfDependency::class, $definition); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Support\Circular; | ||
|
||
class Chicken | ||
{ | ||
public function __construct(Egg $egg) | ||
{ | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Support\Circular; | ||
|
||
class Egg | ||
{ | ||
public function __construct(Chicken $chicken) | ||
{ | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Support; | ||
|
||
final class UnionBuiltinDependency | ||
{ | ||
private $value; | ||
|
||
public function __construct(string|int $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Support; | ||
|
||
final class UnionOptionalDependency | ||
{ | ||
private $value; | ||
|
||
public function __construct(string|ColorInterface $value = null) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
} |
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
Oops, something went wrong.