Skip to content

Commit d95f396

Browse files
Enrich E2E test vol2
1 parent de6ed36 commit d95f396

1 file changed

Lines changed: 47 additions & 12 deletions

File tree

tests/Integration/DirectiveLayerEndToEndTest.php

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,60 +23,95 @@
2323
*/
2424
final class DirectiveLayerEndToEndTest extends TestCase
2525
{
26-
private function buildSchema(): Schema
26+
private Schema $schema;
27+
28+
public function setUp(): void
2729
{
2830
$factory = new SchemaFactory(new Psr16Cache(new ArrayAdapter()), new BasicAutoWiringContainer(new EmptyContainer()));
29-
$factory->prodMode();
3031
$factory->addNamespace('TheCodingMachine\\GraphQLite\\Fixtures\\DirectiveLayerIntegration');
3132

32-
return $factory->createSchema();
33+
$this->schema = $factory->createSchema();
3334
}
3435

3536
/** @return array<string, mixed> */
36-
private function execute(Schema $schema, string $query): array
37+
private function execute(string $query): array
3738
{
38-
return GraphQL::executeQuery($schema, $query, null, new Context())
39+
return GraphQL::executeQuery($this->schema, $query, null, new Context())
3940
->toArray(DebugFlag::INCLUDE_DEBUG_MESSAGE);
4041
}
4142

4243
public function testOneOfPrintsInSdl(): void
4344
{
44-
$sdl = SchemaPrinter::doPrint($this->buildSchema());
45+
$sdl = SchemaPrinter::doPrint($this->schema);
4546

4647
$this->assertStringContainsString('input LookupInput @oneOf', $sdl);
4748
}
4849

4950
public function testDeprecatedPrintsInSdl(): void
5051
{
51-
$sdl = SchemaPrinter::doPrint($this->buildSchema());
52+
$sdl = SchemaPrinter::doPrint($this->schema);
5253

5354
$this->assertStringContainsString('legacy: String! @deprecated(reason: "Use current instead.")', $sdl);
5455
}
5556

5657
public function testBareDeprecatedKeepsTheDocblockReason(): void
5758
{
58-
$sdl = SchemaPrinter::doPrint($this->buildSchema());
59+
$sdl = SchemaPrinter::doPrint($this->schema);
5960

6061
$this->assertStringContainsString('legacyDocblock: String! @deprecated(reason: "Use lookup instead.")', $sdl);
6162
}
6263

6364
public function testDeprecatedFieldStillResolves(): void
6465
{
65-
$result = $this->execute($this->buildSchema(), 'query { legacy }');
66+
$result = $this->execute('query { legacy }');
6667

6768
$this->assertSame(['data' => ['legacy' => 'legacy']], $result);
6869
}
6970

71+
/**
72+
* The deprecation reason is only observable at runtime through introspection (a deprecated field
73+
* still returns its normal value). Asserting the introspection response proves the directive both
74+
* applies the reason and leaves introspection working.
75+
*/
76+
public function testDeprecationIsExposedThroughIntrospection(): void
77+
{
78+
$query = '
79+
query {
80+
__type(name: "Query") {
81+
fields(includeDeprecated: true) {
82+
name
83+
isDeprecated
84+
deprecationReason
85+
}
86+
}
87+
}
88+
';
89+
90+
$result = $this->execute($query);
91+
92+
$this->assertSame([
93+
'data' => [
94+
'__type' => [
95+
'fields' => [
96+
['name' => 'legacy', 'isDeprecated' => true, 'deprecationReason' => 'Use current instead.'],
97+
['name' => 'lookup', 'isDeprecated' => false, 'deprecationReason' => null],
98+
['name' => 'legacyDocblock', 'isDeprecated' => true, 'deprecationReason' => 'Use lookup instead.'],
99+
],
100+
],
101+
],
102+
], $result);
103+
}
104+
70105
public function testOneOfAcceptsExactlyOneField(): void
71106
{
72-
$result = $this->execute($this->buildSchema(), 'query { lookup(lookup: {sku: "abc"}) }');
107+
$result = $this->execute('query { lookup(lookup: {sku: "abc"}) }');
73108

74109
$this->assertSame(['data' => ['lookup' => 'abc']], $result);
75110
}
76111

77112
public function testOneOfRejectsMoreThanOneField(): void
78113
{
79-
$result = $this->execute($this->buildSchema(), 'query { lookup(lookup: {sku: "abc", id: 1}) }');
114+
$result = $this->execute('query { lookup(lookup: {sku: "abc", id: 1}) }');
80115

81116
$this->assertArrayNotHasKey('data', $result);
82117
$this->assertStringContainsString(
@@ -87,7 +122,7 @@ public function testOneOfRejectsMoreThanOneField(): void
87122

88123
public function testOneOfRejectsZeroFields(): void
89124
{
90-
$result = $this->execute($this->buildSchema(), 'query { lookup(lookup: {}) }');
125+
$result = $this->execute('query { lookup(lookup: {}) }');
91126

92127
$this->assertArrayNotHasKey('data', $result);
93128
$this->assertStringContainsString(

0 commit comments

Comments
 (0)