-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
133 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,29 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Graphpommando\Tests; | ||
|
||
final class MainEntity implements \Graphpommando\Entity | ||
{ | ||
public int $fieldInt; | ||
public float $fieldFloat; | ||
public bool $fieldBool; | ||
public string $fieldString; | ||
#[\Graphpommando\Attribute\Alias('fieldString')] | ||
public string $fieldAliasedString; | ||
public SubEntity $subfield; | ||
#[\Graphpommando\Attribute\OfType('string', false)] | ||
public array $listOfStrings; | ||
#[\Graphpommando\Attribute\OfType('array', false, ['string', false])] | ||
public array $matrixOfStrings; | ||
#[\Graphpommando\Attribute\OfType(SubEntity::class, false)] | ||
public array $listOfSubfields; | ||
#[\Graphpommando\Attribute\OfType('array', false, [SubEntity::class, false])] | ||
public array $matrixOfSubfields; | ||
#[\Graphpommando\Attribute\Argument('arg1', \Graphpommando\Value\VariableValue::class, ['var1'])] | ||
public int $fieldWithArgs; | ||
#[\Graphpommando\Attribute\ConstructorPass] | ||
public \DateTime $fieldDateTime; | ||
public ?int $fieldNullable; | ||
} |
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Graphpommando\Tests; | ||
|
||
final class SubEntity implements \Graphpommando\Entity | ||
{ | ||
public int $fieldInt; | ||
} |
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Graphpommando\Tests\Unit; | ||
|
||
final class EntityHydratorTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testSimple() : void | ||
{ | ||
$hydrator = new \Graphpommando\EntityHydrator(); | ||
$result = $hydrator->hydrate(\Graphpommando\Tests\MainEntity::class, \Infinityloop\Utils\Json::fromNative((object) [ | ||
'data' => [ | ||
'fieldInt' => 1, | ||
'fieldFloat' => 2.0, | ||
'fieldBool' => true, | ||
'fieldString' => '3', | ||
'fieldAliasedString' => '4', | ||
'subfield' => ['fieldInt' => 5], | ||
'listOfStrings' => ['6', '7'], | ||
'matrixOfStrings' => [['8'], [], ['9', '10']], | ||
'listOfSubfields' => [['fieldInt' => 11], ['fieldInt' => 12]], | ||
'matrixOfSubfields' => [[['fieldInt' => 13], ['fieldInt' => 14]], [['fieldInt' => 15]]], | ||
'fieldWithArgs' => 16, | ||
'fieldDateTime' => '2021-01-01', | ||
'fieldNullable' => null, | ||
], | ||
])->toString()); | ||
|
||
self::assertInstanceOf(\Graphpommando\Tests\MainEntity::class, $result); | ||
\assert($result instanceof \Graphpommando\Tests\MainEntity); | ||
self::assertSame(1, $result->fieldInt); | ||
self::assertSame(2.0, $result->fieldFloat); | ||
self::assertTrue($result->fieldBool); | ||
self::assertSame('3', $result->fieldString); | ||
self::assertSame('4', $result->fieldAliasedString); | ||
self::assertInstanceOf(\Graphpommando\Tests\SubEntity::class, $result->subfield); | ||
self::assertSame(5, $result->subfield->fieldInt); | ||
self::assertSame(16, $result->fieldWithArgs); | ||
self::assertInstanceOf(\DateTime::class, $result->fieldDateTime); | ||
self::assertSame($result->fieldDateTime->format('Y-m-d'), '2021-01-01'); | ||
self::assertNull($result->fieldNullable); | ||
self::assertIsArray($result->listOfStrings); | ||
|
||
foreach ($result->listOfStrings as $field) { | ||
self::assertIsString($field); | ||
} | ||
|
||
self::assertIsArray($result->listOfSubfields); | ||
|
||
foreach ($result->listOfSubfields as $field) { | ||
self::assertInstanceOf(\Graphpommando\Tests\SubEntity::class, $field); | ||
} | ||
|
||
self::assertIsArray($result->matrixOfStrings); | ||
|
||
foreach ($result->matrixOfStrings as $field) { | ||
self::assertIsArray($field); | ||
|
||
foreach ($field as $subField) { | ||
self::assertIsString($subField); | ||
} | ||
} | ||
|
||
self::assertIsArray($result->matrixOfSubfields); | ||
|
||
foreach ($result->matrixOfSubfields as $field) { | ||
self::assertIsArray($field); | ||
|
||
foreach ($field as $subField) { | ||
self::assertInstanceOf(\Graphpommando\Tests\SubEntity::class, $subField); | ||
} | ||
} | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Graphpommando\Tests\Unit; | ||
|
||
final class QueryBuilderTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testSimple() : void | ||
{ | ||
$builder = new \Graphpommando\QueryBuilder(); | ||
$operation = new \Graphpommando\DefaultOperation('query', [], [], \Graphpommando\Tests\MainEntity::class); | ||
|
||
self::assertSame( | ||
'query{fieldInt fieldFloat fieldBool fieldString fieldAliasedString: fieldString subfield{fieldInt} listOfStrings matrixOfStrings listOfSubfields{fieldInt} matrixOfSubfields{fieldInt} fieldWithArgs(arg1: $var1) fieldDateTime fieldNullable}', | ||
$builder->build($operation), | ||
); | ||
} | ||
} |