Skip to content

Commit e6d006a

Browse files
authored
Merge pull request #18 from mcg-web/tests
Add new modes tests
2 parents 7ee5852 + 49719c9 commit e6d006a

4 files changed

+81
-4
lines changed

tests/AbstractStarWarsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function setUp()
4545
*/
4646
protected function assertValidQuery($query, $expected, $variables = null)
4747
{
48-
$actual = GraphQL::execute($this->schema, $query, null, null, $variables);
48+
$actual = GraphQL::executeQuery($this->schema, $query, null, null, $variables)->toArray();
4949
$expected = ['data' => $expected];
5050
$this->assertEquals($expected, $actual, json_encode($actual));
5151
}

tests/Generator/AbstractTypeGeneratorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function tearDown()
4545
$this->filesystem->remove($this->tmpDir);
4646
}
4747

48-
protected function generateClasses(array $typeConfigs = null, $tmpDir = null, $regenerateIfExists = true)
48+
protected function generateClasses(array $typeConfigs = null, $tmpDir = null, $mode = true)
4949
{
5050
if (null === $typeConfigs) {
5151
$typeConfigs = $this->typeConfigs;
@@ -55,7 +55,7 @@ protected function generateClasses(array $typeConfigs = null, $tmpDir = null, $r
5555
$tmpDir = $this->tmpDir;
5656
}
5757

58-
$classes = $this->typeGenerator->generateClasses($typeConfigs, $tmpDir, $regenerateIfExists);
58+
$classes = $this->typeGenerator->generateClasses($typeConfigs, $tmpDir, $mode);
5959

6060
$this->classLoader->addClassMap($classes);
6161

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the OverblogGraphQLPhpGenerator package.
5+
*
6+
* (c) Overblog <http://github.com/overblog/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Overblog\GraphQLGenerator\Tests\Generator;
13+
14+
use Overblog\GraphQLGenerator\Generator\TypeGenerator;
15+
use Overblog\GraphQLGenerator\Tests\TestCase;
16+
17+
class TypeGeneratorModeTest extends TestCase
18+
{
19+
/** @var string */
20+
private $dir;
21+
22+
/** @var TypeGenerator|\PHPUnit_Framework_MockObject_MockObject */
23+
private $typeGenerator;
24+
25+
private static $configs = [
26+
'Query' => [
27+
'type' => 'object',
28+
'config' => [
29+
'fields' => [
30+
'sayHello' => ['type' => 'String!'],
31+
],
32+
],
33+
]
34+
];
35+
36+
public function setUp()
37+
{
38+
$this->dir = sys_get_temp_dir() . '/mcgweb-graphql-generator-modes';
39+
$this->typeGenerator = $this->getMockBuilder(TypeGenerator::class)
40+
->setMethods(['processPlaceHoldersReplacements', 'processTemplatePlaceHoldersReplacements'])
41+
->getMock()
42+
;
43+
}
44+
45+
public function testDryRunMode()
46+
{
47+
$this->typeGenerator->expects($this->once())->method('processPlaceHoldersReplacements');
48+
$this->typeGenerator->expects($this->once())->method('processTemplatePlaceHoldersReplacements');
49+
$this->assertGenerateClassesMode(TypeGenerator::MODE_DRY_RUN);
50+
}
51+
52+
public function testMappingOnlyMode()
53+
{
54+
$this->typeGenerator->expects($this->never())->method('processPlaceHoldersReplacements');
55+
$this->typeGenerator->expects($this->never())->method('processTemplatePlaceHoldersReplacements');
56+
$this->assertGenerateClassesMode(TypeGenerator::MODE_MAPPING_ONLY);
57+
}
58+
59+
private function assertGenerateClassesMode($mode)
60+
{
61+
$classes = $this->typeGenerator->generateClasses(self::$configs, $this->dir, $mode);
62+
$file = $this->dir.'/QueryType.php';
63+
$this->assertEquals(['Overblog\CG\GraphQLGenerator\__Schema__\QueryType' => $this->dir.'/QueryType.php'], $classes);
64+
if (method_exists($this, 'assertDirectoryNotExists')) {
65+
$this->assertDirectoryNotExists($this->dir);
66+
} else { // for phpunit 4
67+
$this->assertFalse(file_exists($this->dir));
68+
$this->assertFalse(is_dir($this->dir));
69+
}
70+
if (method_exists($this, 'assertFileNotExists')) {
71+
$this->assertFileNotExists($file);
72+
} else { // for phpunit 4
73+
$this->assertFalse(file_exists($file));
74+
$this->assertFalse(is_file($file));
75+
}
76+
}
77+
}

tests/StarWarsIntrospectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testAllowsQueryingTheSchemaForTypes()
5656
]
5757
];
5858

59-
$actual = GraphQL::execute($this->schema, $query);
59+
$actual = GraphQL::executeQuery($this->schema, $query)->toArray();
6060
$this->sortSchemaEntry($actual, 'types', 'name');
6161
$this->sortSchemaEntry($expected, 'types', 'name');
6262
$expected = ['data' => $expected];

0 commit comments

Comments
 (0)