|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheCodingMachine\FluidSchema; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
6
|
|
|
use Doctrine\DBAL\Types\Type; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class TdbmFluidColumnGraphqlOptionsTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testGraphql() |
|
12
|
|
|
{ |
|
13
|
|
|
$schema = new Schema(); |
|
14
|
|
|
$fluid = new TdbmFluidSchema($schema); |
|
15
|
|
|
|
|
16
|
|
|
$posts = $fluid->table('posts'); |
|
17
|
|
|
|
|
18
|
|
|
$column = $posts->column('foo'); |
|
19
|
|
|
$columnOptions = $column->integer(); |
|
20
|
|
|
|
|
21
|
|
|
$graphqlOptions = $columnOptions->graphqlField(); |
|
22
|
|
|
|
|
23
|
|
|
$graphqlOptions->fieldName('bar') |
|
24
|
|
|
->logged(true) |
|
25
|
|
|
->right('CAN_EDIT') |
|
26
|
|
|
->failWith(null); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertSame("\n@TheCodingMachine\GraphQLite\Annotations\Field(name = \"bar\") |
|
29
|
|
|
@TheCodingMachine\GraphQLite\Annotations\Logged |
|
30
|
|
|
@TheCodingMachine\GraphQLite\Annotations\Right(name = \"CAN_EDIT\") |
|
31
|
|
|
@TheCodingMachine\GraphQLite\Annotations\FailWith(null)", $schema->getTable('posts')->getColumn('foo')->getComment()); |
|
32
|
|
|
|
|
33
|
|
|
$graphqlOptions->logged(false) |
|
34
|
|
|
->outputType('ID'); |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$this->assertSame("\n@TheCodingMachine\GraphQLite\Annotations\Right(name = \"CAN_EDIT\") |
|
38
|
|
|
@TheCodingMachine\GraphQLite\Annotations\FailWith(null) |
|
39
|
|
|
@TheCodingMachine\GraphQLite\Annotations\Field(name = \"bar\", outputType = \"ID\")", $schema->getTable('posts')->getColumn('foo')->getComment()); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertSame($columnOptions, $graphqlOptions->endGraphql()); |
|
42
|
|
|
|
|
43
|
|
|
$column2 = $graphqlOptions->column('foo'); |
|
44
|
|
|
$this->assertSame($column2, $column); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertContains('@TheCodingMachine\GraphQLite\Annotations\Type', $schema->getTable('posts')->getOptions()['comment']); |
|
47
|
|
|
|
|
48
|
|
|
$idColumn = $posts->id()->graphqlField(); |
|
|
|
|
|
|
49
|
|
|
$this->assertContains('outputType = "ID"', $schema->getTable('posts')->getColumn('id')->getComment()); |
|
50
|
|
|
|
|
51
|
|
|
$users = $fluid->table('users'); |
|
52
|
|
|
$uuidColumn = $users->uuid()->graphqlField(); |
|
|
|
|
|
|
53
|
|
|
$this->assertContains('outputType = "ID"', $schema->getTable('users')->getColumn('uuid')->getComment()); |
|
54
|
|
|
|
|
55
|
|
|
$products = $fluid->table('products'); |
|
56
|
|
|
$graphqlField = $products->uuid() |
|
57
|
|
|
->column('user_id')->references('users')->graphqlField(); |
|
58
|
|
|
$this->assertNotContains('outputType = "ID"', $schema->getTable('products')->getColumn('user_id')->getComment()); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertSame('products', $graphqlField->then()->getDbalTable()->getName()); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.