generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
261 additions
and
44 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
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
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ObjectFactory; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use ReflectionClass; | ||
use Yiisoft\Hydrator\Exception\WrongConstructorArgumentsCountException; | ||
use Yiisoft\Hydrator\ObjectFactory\ReflectionObjectFactory; | ||
use Yiisoft\Hydrator\Tests\Support\StringableObject; | ||
|
||
final class ReflectionObjectFactoryTest extends TestCase | ||
{ | ||
public function testWrongConstructorArgumentsCount(): void | ||
{ | ||
$factory = new ReflectionObjectFactory(); | ||
$reflection = new ReflectionClass(StringableObject::class); | ||
|
||
$this->expectException(WrongConstructorArgumentsCountException::class); | ||
$this->expectExceptionMessage( | ||
'Class "' . StringableObject::class . '" cannot be instantiated because it has 1 required parameters in constructor, but passed only 0.' | ||
); | ||
$factory->create($reflection, []); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/Support/Attribute/ResolverWithConstructorWithoutParameters.php
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Hydrator\Tests\Support\Attribute; | ||
|
||
use LogicException; | ||
use Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface; | ||
use Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface; | ||
use Yiisoft\Hydrator\AttributeHandling\ParameterAttributeResolveContext; | ||
use Yiisoft\Hydrator\Result; | ||
|
||
final class ResolverWithConstructorWithoutParameters implements ParameterAttributeResolverInterface | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
public function getParameterValue( | ||
ParameterAttributeInterface $attribute, | ||
ParameterAttributeResolveContext $context | ||
): Result { | ||
throw new LogicException('This method should not be called.'); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Hydrator\Tests\Support\Classes; | ||
|
||
use Yiisoft\Hydrator\Attribute\Parameter\Di; | ||
|
||
final class DiNonExists | ||
{ | ||
#[Di('non-exists')] | ||
public $engine; | ||
} |
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
50 changes: 50 additions & 0 deletions
50
tests/TestEnvironments/Php81/TypeCaster/PhpNativeTypeCasterTest.php
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TestEnvironments\Php81\TypeCaster; | ||
|
||
use Closure; | ||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Hydrator\Result; | ||
use Yiisoft\Hydrator\Tests\Support\StringableObject; | ||
use Yiisoft\Hydrator\Tests\Support\TestHelper; | ||
use Yiisoft\Hydrator\TypeCaster\PhpNativeTypeCaster; | ||
|
||
final class PhpNativeTypeCasterTest extends TestCase | ||
{ | ||
public function dataBase(): array | ||
{ | ||
return [ | ||
'int to object|int|string' => [ | ||
Result::success(42), | ||
42, | ||
static fn(StringableObject|int|string $a) => null, | ||
], | ||
'string to object|int|string' => [ | ||
Result::success('42'), | ||
'42', | ||
static fn(StringableObject|int|string $a) => null, | ||
], | ||
'string to object|int' => [ | ||
Result::success(42), | ||
'42', | ||
static fn(StringableObject|int $a) => null, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dataBase | ||
*/ | ||
public function testBase(Result $expected, mixed $value, Closure $closure): void | ||
{ | ||
$typeCaster = new PhpNativeTypeCaster(); | ||
$context = TestHelper::createTypeCastContext($closure); | ||
|
||
$result = $typeCaster->cast($value, $context); | ||
|
||
$this->assertSame($expected->isResolved(), $result->isResolved()); | ||
$this->assertSame($expected->getValue(), $result->getValue()); | ||
} | ||
} |
Oops, something went wrong.