Skip to content

Commit

Permalink
Fix PrimitiveGenerators (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster authored Oct 2, 2021
1 parent 3fed12e commit 6e11429
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/PhpFileRenderer/DefaultSchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(array $generators = [])
continue;
}

$generators[$value] = new PrimitiveGenerator($key, 'SchemaInterface::' . $key);
$generators[$value] = new PrimitiveGenerator('SchemaInterface::' . $key, $value);
}
}

Expand Down
42 changes: 42 additions & 0 deletions tests/Schema/Renderer/Fixtures/console_output_plain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[user] :: default.user
Entity: Cycle\Schema\Renderer\Tests\Fixtures\User
Mapper: Cycle\ORM\Mapper\Mapper
Constrain: not defined
Repository: not defined
Primary key: id
Fields:
(property -> db.field -> typecast)
0 -> id -> int
1 -> email
2 -> balance -> float
Relations:
user->tags many to many tag ? load cascaded
n/a user.id <= tag_context.user_id | tag_context.tag_id => tag.id
user->tag belongs to tag ? load cascaded
n/a user.tag_id <==> tag.id
Custom props:
123 : sdasd
abc : [111, 11]

[tag] :: default.tag
Entity: Cycle\Schema\Renderer\Tests\Fixtures\Tag
Mapper: Cycle\ORM\Mapper\Mapper
Constrain: not defined
Repository: not defined
Primary key: id, name
Fields:
(property -> db.field -> typecast)
0 -> id -> int
1 -> name
Relations:
tag->user belongs to user ? load cascaded
n/a tag.user_id <==> user.id

[tag_context] :: default.tag_user_map
Entity: Cycle\Schema\Renderer\Tests\Fixtures\TagContext
Mapper: Cycle\ORM\Mapper\Mapper
Constrain: not defined
Repository: not defined
Primary key: not defined
Fields: not defined
Relations: not defined
93 changes: 51 additions & 42 deletions tests/Schema/Renderer/Fixtures/generated_schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

return [
'user' => [
ROLE => null,
ENTITY => null,
MAPPER => null,
SOURCE => null,
REPOSITORY => null,
DATABASE => null,
TABLE => null,
PRIMARY_KEY => null,
FIND_BY_KEYS => null,
COLUMNS => null,
SchemaInterface::ROLE => null,
SchemaInterface::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixtures\\User',
SchemaInterface::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
SchemaInterface::SOURCE => null,
SchemaInterface::REPOSITORY => null,
SchemaInterface::DATABASE => 'default',
SchemaInterface::TABLE => 'user',
SchemaInterface::PRIMARY_KEY => 'id',
SchemaInterface::FIND_BY_KEYS => null,
SchemaInterface::COLUMNS => ['id', 'email', 'balance'],
SchemaInterface::RELATIONS => [
'tags' => [
Relation::TYPE => Relation::MANY_TO_MANY,
Expand All @@ -40,22 +40,25 @@
],
],
],
CHILDREN => null,
SCOPE => null,
TYPECAST => null,
SCHEMA => null,
SchemaInterface::CHILDREN => null,
SchemaInterface::SCOPE => null,
SchemaInterface::TYPECAST => [
'id' => 'int',
'balance' => 'float',
],
SchemaInterface::SCHEMA => [],
],
'tag' => [
ROLE => null,
ENTITY => null,
MAPPER => null,
SOURCE => null,
REPOSITORY => null,
DATABASE => null,
TABLE => null,
PRIMARY_KEY => null,
FIND_BY_KEYS => null,
COLUMNS => null,
SchemaInterface::ROLE => null,
SchemaInterface::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixtures\\Tag',
SchemaInterface::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
SchemaInterface::SOURCE => null,
SchemaInterface::REPOSITORY => null,
SchemaInterface::DATABASE => 'default',
SchemaInterface::TABLE => 'tag',
SchemaInterface::PRIMARY_KEY => ['id', 'name'],
SchemaInterface::FIND_BY_KEYS => null,
SchemaInterface::COLUMNS => ['id', 'name'],
SchemaInterface::RELATIONS => [
'user' => [
Relation::TYPE => Relation::BELONGS_TO,
Expand All @@ -67,26 +70,32 @@
],
],
],
CHILDREN => null,
SCOPE => null,
TYPECAST => null,
SCHEMA => null,
SchemaInterface::CHILDREN => null,
SchemaInterface::SCOPE => null,
SchemaInterface::TYPECAST => [
'id' => 'int',
],
SchemaInterface::SCHEMA => [],
],
'tag_context' => [
ROLE => null,
ENTITY => null,
MAPPER => null,
SOURCE => null,
REPOSITORY => null,
DATABASE => null,
TABLE => null,
PRIMARY_KEY => null,
FIND_BY_KEYS => null,
COLUMNS => null,
SchemaInterface::ROLE => null,
SchemaInterface::ENTITY => 'Cycle\\Schema\\Renderer\\Tests\\Fixtures\\TagContext',
SchemaInterface::MAPPER => 'Cycle\\ORM\\Mapper\\Mapper',
SchemaInterface::SOURCE => null,
SchemaInterface::REPOSITORY => null,
SchemaInterface::DATABASE => 'default',
SchemaInterface::TABLE => 'tag_user_map',
SchemaInterface::PRIMARY_KEY => null,
SchemaInterface::FIND_BY_KEYS => null,
SchemaInterface::COLUMNS => [],
SchemaInterface::RELATIONS => [],
CHILDREN => null,
SCOPE => null,
TYPECAST => null,
SCHEMA => null,
SchemaInterface::CHILDREN => null,
SchemaInterface::SCOPE => null,
SchemaInterface::TYPECAST => [
'id' => 'int',
'user_id' => 'int',
'tag_id' => 'int',
],
SchemaInterface::SCHEMA => [],
]
];
64 changes: 36 additions & 28 deletions tests/Schema/Renderer/SchemaToPhpFileRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,25 @@ public function testRenderSchemaWithCustomPropertyToPhpCode(): void
return [
'Cycle\Schema\Renderer\Tests\Fixtures\TagContext' => [
ROLE => null,
ENTITY => null,
MAPPER => null,
SOURCE => null,
REPOSITORY => null,
DATABASE => null,
TABLE => null,
PRIMARY_KEY => null,
FIND_BY_KEYS => null,
COLUMNS => null,
SchemaInterface::ROLE => 'tag_context',
SchemaInterface::ENTITY => null,
SchemaInterface::MAPPER => 'Cycle\\\\ORM\\\\Mapper\\\\Mapper',
SchemaInterface::SOURCE => null,
SchemaInterface::REPOSITORY => null,
SchemaInterface::DATABASE => 'default',
SchemaInterface::TABLE => 'tag_user_map',
SchemaInterface::PRIMARY_KEY => null,
SchemaInterface::FIND_BY_KEYS => null,
SchemaInterface::COLUMNS => [],
SchemaInterface::RELATIONS => [],
CHILDREN => null,
SCOPE => null,
TYPECAST => null,
SCHEMA => null,
SchemaInterface::CHILDREN => null,
SchemaInterface::SCOPE => null,
SchemaInterface::TYPECAST => [
'id' => 'int',
'user_id' => 'int',
'tag_id' => 'int',
],
SchemaInterface::SCHEMA => [],
100 => 'Hello world',
'hello' => 'world',
]
Expand Down Expand Up @@ -219,21 +223,25 @@ public function generate(array $schema, string $role): array
return [
'Cycle\Schema\Renderer\Tests\Fixtures\TagContext' => [
'Hello' => 'World',
ROLE => null,
ENTITY => null,
MAPPER => null,
SOURCE => null,
REPOSITORY => null,
DATABASE => null,
TABLE => null,
PRIMARY_KEY => null,
FIND_BY_KEYS => null,
COLUMNS => null,
SchemaInterface::ROLE => 'tag_context',
SchemaInterface::ENTITY => null,
SchemaInterface::MAPPER => 'Cycle\\\\ORM\\\\Mapper\\\\Mapper',
SchemaInterface::SOURCE => null,
SchemaInterface::REPOSITORY => null,
SchemaInterface::DATABASE => 'default',
SchemaInterface::TABLE => 'tag_user_map',
SchemaInterface::PRIMARY_KEY => null,
SchemaInterface::FIND_BY_KEYS => null,
SchemaInterface::COLUMNS => [],
SchemaInterface::RELATIONS => [],
CHILDREN => null,
SCOPE => null,
TYPECAST => null,
SCHEMA => null,
SchemaInterface::CHILDREN => null,
SchemaInterface::SCOPE => null,
SchemaInterface::TYPECAST => [
'id' => 'int',
'user_id' => 'int',
'tag_id' => 'int',
],
SchemaInterface::SCHEMA => [],
'hello' => 'world',
]
];
Expand Down

0 comments on commit 6e11429

Please sign in to comment.