-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
6 changed files
with
274 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Orisai\ObjectMapper\Unit\Context; | ||
|
||
use Orisai\ObjectMapper\Context\ArgsContext; | ||
use Orisai\ObjectMapper\Tester\ObjectMapperTester; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ArgsContextTest extends TestCase | ||
{ | ||
|
||
public function test(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
|
||
$context = new ArgsContext($deps->metaLoader, $deps->metaResolver); | ||
|
||
self::assertSame($deps->metaLoader, $context->getMetaLoader()); | ||
self::assertSame($deps->metaResolver, $context->getMetaResolver()); | ||
} | ||
|
||
} |
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,38 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Orisai\ObjectMapper\Unit\Context; | ||
|
||
use Orisai\ObjectMapper\Context\ArgsFieldContext; | ||
use Orisai\ObjectMapper\Meta\Shared\DefaultValueMeta; | ||
use Orisai\ObjectMapper\Tester\ObjectMapperTester; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ArgsFieldContextTest extends TestCase | ||
{ | ||
|
||
public function test(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$default = DefaultValueMeta::fromNothing(); | ||
|
||
$context = new ArgsFieldContext($deps->metaLoader, $deps->metaResolver, $default); | ||
|
||
self::assertSame($deps->metaLoader, $context->getMetaLoader()); | ||
self::assertSame($deps->metaResolver, $context->getMetaResolver()); | ||
self::assertFalse($context->hasDefaultValue()); | ||
} | ||
|
||
public function testHasDefault(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$default = DefaultValueMeta::fromValue('foo'); | ||
|
||
$context = new ArgsFieldContext($deps->metaLoader, $deps->metaResolver, $default); | ||
|
||
self::assertSame($deps->metaLoader, $context->getMetaLoader()); | ||
self::assertSame($deps->metaResolver, $context->getMetaResolver()); | ||
self::assertTrue($context->hasDefaultValue()); | ||
self::assertSame('foo', $context->getDefaultValue()); | ||
} | ||
|
||
} |
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 Tests\Orisai\ObjectMapper\Unit\Context; | ||
|
||
use Orisai\ObjectMapper\Context\FieldContext; | ||
use Orisai\ObjectMapper\Meta\Shared\DefaultValueMeta; | ||
use Orisai\ObjectMapper\Processing\Options; | ||
use Orisai\ObjectMapper\Tester\ObjectMapperTester; | ||
use Orisai\ObjectMapper\Types\SimpleValueType; | ||
use Orisai\ObjectMapper\Types\Type; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionProperty; | ||
use Tests\Orisai\ObjectMapper\Doubles\DefaultsVO; | ||
|
||
final class FieldContextTest extends TestCase | ||
{ | ||
|
||
public function test(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$options = new Options(); | ||
$typeCreator = static fn (): Type => new SimpleValueType('string'); | ||
$default = DefaultValueMeta::fromNothing(); | ||
$fieldName = 'field'; | ||
$property = new ReflectionProperty(DefaultsVO::class, 'string'); | ||
|
||
$context = new FieldContext( | ||
$deps->metaLoader, | ||
$deps->ruleManager, | ||
$deps->processor, | ||
$options, | ||
$typeCreator, | ||
$default, | ||
true, | ||
$fieldName, | ||
$property, | ||
); | ||
|
||
self::assertSame($deps->processor, $context->getProcessor()); | ||
self::assertTrue($context->shouldInitializeObjects()); | ||
|
||
self::assertFalse($context->hasDefaultValue()); | ||
self::assertSame($property->getName(), $context->getPropertyName()); | ||
self::assertSame($fieldName, $context->getFieldName()); | ||
|
||
self::assertEquals($typeCreator(), $context->getType()); | ||
self::assertNotSame($typeCreator(), $context->getType()); | ||
self::assertSame($context->getType(), $context->getType()); | ||
} | ||
|
||
} |
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,39 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Orisai\ObjectMapper\Unit\Context; | ||
|
||
use Orisai\ObjectMapper\Context\MappedObjectContext; | ||
use Orisai\ObjectMapper\Processing\Options; | ||
use Orisai\ObjectMapper\Tester\ObjectMapperTester; | ||
use Orisai\ObjectMapper\Types\MappedObjectType; | ||
use Orisai\ObjectMapper\Types\Type; | ||
use PHPUnit\Framework\TestCase; | ||
use Tests\Orisai\ObjectMapper\Doubles\DefaultsVO; | ||
|
||
final class MappedObjectContextTest extends TestCase | ||
{ | ||
|
||
public function test(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$options = new Options(); | ||
$typeCreator = static fn (): Type => new MappedObjectType(DefaultsVO::class); | ||
|
||
$context = new MappedObjectContext( | ||
$deps->metaLoader, | ||
$deps->ruleManager, | ||
$deps->processor, | ||
$options, | ||
$typeCreator, | ||
true, | ||
); | ||
|
||
self::assertSame($deps->processor, $context->getProcessor()); | ||
self::assertTrue($context->shouldInitializeObjects()); | ||
|
||
self::assertEquals($typeCreator(), $context->getType()); | ||
self::assertNotSame($typeCreator(), $context->getType()); | ||
self::assertSame($context->getType(), $context->getType()); | ||
} | ||
|
||
} |
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,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Orisai\ObjectMapper\Unit\Context; | ||
|
||
use Orisai\ObjectMapper\Context\ProcessorCallContext; | ||
use Orisai\ObjectMapper\Processing\ObjectCreator; | ||
use Orisai\ObjectMapper\Processing\ObjectHolder; | ||
use Orisai\ObjectMapper\Tester\ObjectMapperTester; | ||
use PHPUnit\Framework\TestCase; | ||
use Tests\Orisai\ObjectMapper\Doubles\DefaultsVO; | ||
|
||
final class ProcessorCallContextTest extends TestCase | ||
{ | ||
|
||
public function test(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$meta = $deps->metaLoader->load(DefaultsVO::class); | ||
$holder = new ObjectHolder( | ||
new ObjectCreator($deps->dependencyInjectorManager), | ||
DefaultsVO::class, | ||
$meta->getClass(), | ||
null, | ||
); | ||
|
||
$context = new ProcessorCallContext(DefaultsVO::class, $holder, $meta); | ||
|
||
self::assertSame(DefaultsVO::class, $context->getClass()); | ||
self::assertSame($holder, $context->getObjectHolder()); | ||
self::assertSame($meta, $context->getMeta()); | ||
} | ||
|
||
} |
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,91 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Orisai\ObjectMapper\Unit\Context; | ||
|
||
use Orisai\ObjectMapper\Context\TypeContext; | ||
use Orisai\ObjectMapper\Processing\Options; | ||
use Orisai\ObjectMapper\Rules\StringRule; | ||
use Orisai\ObjectMapper\Tester\ObjectMapperTester; | ||
use PHPUnit\Framework\TestCase; | ||
use Tests\Orisai\ObjectMapper\Doubles\DefaultsVO; | ||
use Tests\Orisai\ObjectMapper\Doubles\NoDefaultsVO; | ||
use Throwable; | ||
|
||
final class TypeContextTest extends TestCase | ||
{ | ||
|
||
public function testDependencies(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$options = new Options(); | ||
|
||
$context = new TypeContext($deps->metaLoader, $deps->ruleManager, $options); | ||
|
||
try { | ||
$context->getMeta(DefaultsVO::class); | ||
} catch (Throwable $e) { | ||
// Handled bellow | ||
} | ||
|
||
self::assertFalse(isset($e)); | ||
|
||
try { | ||
$context->getRule(StringRule::class); | ||
} catch (Throwable $e) { | ||
// Handled bellow | ||
} | ||
|
||
self::assertFalse(isset($e)); | ||
} | ||
|
||
public function testClone(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$options = new Options(); | ||
|
||
$initContext = new TypeContext($deps->metaLoader, $deps->ruleManager, $options); | ||
$context = $initContext->createClone(); | ||
|
||
self::assertEquals($initContext, $context); | ||
self::assertNotSame($initContext, $context); | ||
} | ||
|
||
public function testOptions(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$options = new Options(); | ||
|
||
$initContext = new TypeContext($deps->metaLoader, $deps->ruleManager, $options); | ||
|
||
self::assertSame($options, $initContext->getOptions()); | ||
|
||
$context = $initContext->createClone(); | ||
self::assertSame($options, $initContext->getOptions()); | ||
self::assertEquals($options, $context->getOptions()); | ||
self::assertNotSame($options, $context->getOptions()); | ||
} | ||
|
||
public function testProcessedClasses(): void | ||
{ | ||
$deps = (new ObjectMapperTester())->buildDependencies(); | ||
$options = new Options(); | ||
|
||
$initContext = new TypeContext($deps->metaLoader, $deps->ruleManager, $options); | ||
|
||
self::assertSame([], $initContext->getProcessedClasses()); | ||
|
||
$context = $initContext | ||
->withProcessedClass(DefaultsVO::class) | ||
->withProcessedClass(NoDefaultsVO::class); | ||
|
||
self::assertSame([], $initContext->getProcessedClasses()); | ||
self::assertSame( | ||
[ | ||
DefaultsVO::class, | ||
NoDefaultsVO::class, | ||
], | ||
$context->getProcessedClasses(), | ||
); | ||
} | ||
|
||
} |