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.
Fix #31: Add support for objects as default parameter values
- Loading branch information
Showing
9 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ jobs: | |
php: | ||
- "7.4" | ||
- "8.0" | ||
- "8.1" | ||
|
||
steps: | ||
- name: Checkout | ||
|
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ jobs: | |
php: | ||
- "7.4" | ||
- "8.0" | ||
- "8.1" | ||
|
||
steps: | ||
- name: Checkout | ||
|
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Php8_1\Helpers; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use ReflectionFunction; | ||
use Yiisoft\Definitions\Helpers\DefinitionExtractor; | ||
use Yiisoft\Definitions\Tests\Support\Chair; | ||
use Yiisoft\Definitions\Tests\Support\RedChair; | ||
use Yiisoft\Test\Support\Container\SimpleContainer; | ||
|
||
final class DefinitionExtractorTest extends TestCase | ||
{ | ||
public function testResolvableDependencyWithDefaultObject(): void | ||
{ | ||
$container = new SimpleContainer([ | ||
Chair::class => new Chair(), | ||
]); | ||
|
||
$definitions = DefinitionExtractor::fromFunction( | ||
new ReflectionFunction(static fn (Chair $chair = new RedChair()) => true) | ||
); | ||
|
||
$this->assertInstanceOf(Chair::class, $definitions['chair']->resolve($container)); | ||
} | ||
|
||
public function testResolvableNullableDependencyWithDefaultObject(): void | ||
{ | ||
$container = new SimpleContainer([ | ||
Chair::class => new Chair(), | ||
]); | ||
|
||
$definitions = DefinitionExtractor::fromFunction( | ||
new ReflectionFunction(static fn (?Chair $chair = new RedChair()) => true) | ||
); | ||
|
||
$this->assertInstanceOf(Chair::class, $definitions['chair']->resolve($container)); | ||
} | ||
|
||
public function testUnresolvableDependencyWithDefaultObject(): void | ||
{ | ||
$container = new SimpleContainer(); | ||
|
||
$definitions = DefinitionExtractor::fromFunction( | ||
new ReflectionFunction(static fn (Chair $chair = new RedChair()) => true) | ||
); | ||
|
||
$this->assertInstanceOf(RedChair::class, $definitions['chair']->resolve($container)); | ||
} | ||
|
||
public function testUnresolvablNullableDependencyWithDefaultObject(): void | ||
{ | ||
$container = new SimpleContainer(); | ||
|
||
$definitions = DefinitionExtractor::fromFunction( | ||
new ReflectionFunction(static fn (?Chair $chair = new RedChair()) => true) | ||
); | ||
|
||
$this->assertInstanceOf(RedChair::class, $definitions['chair']->resolve($container)); | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Support; | ||
|
||
class Chair | ||
{ | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Definitions\Tests\Support; | ||
|
||
final class RedChair | ||
{ | ||
} |