diff --git a/tests/AbstractStarWarsTest.php b/tests/AbstractStarWarsTest.php index 519dd02..5bc148c 100644 --- a/tests/AbstractStarWarsTest.php +++ b/tests/AbstractStarWarsTest.php @@ -45,7 +45,7 @@ public function setUp() */ protected function assertValidQuery($query, $expected, $variables = null) { - $actual = GraphQL::execute($this->schema, $query, null, null, $variables); + $actual = GraphQL::executeQuery($this->schema, $query, null, null, $variables)->toArray(); $expected = ['data' => $expected]; $this->assertEquals($expected, $actual, json_encode($actual)); } diff --git a/tests/Generator/AbstractTypeGeneratorTest.php b/tests/Generator/AbstractTypeGeneratorTest.php index d0656fa..efd851e 100644 --- a/tests/Generator/AbstractTypeGeneratorTest.php +++ b/tests/Generator/AbstractTypeGeneratorTest.php @@ -45,7 +45,7 @@ public function tearDown() $this->filesystem->remove($this->tmpDir); } - protected function generateClasses(array $typeConfigs = null, $tmpDir = null, $regenerateIfExists = true) + protected function generateClasses(array $typeConfigs = null, $tmpDir = null, $mode = true) { if (null === $typeConfigs) { $typeConfigs = $this->typeConfigs; @@ -55,7 +55,7 @@ protected function generateClasses(array $typeConfigs = null, $tmpDir = null, $r $tmpDir = $this->tmpDir; } - $classes = $this->typeGenerator->generateClasses($typeConfigs, $tmpDir, $regenerateIfExists); + $classes = $this->typeGenerator->generateClasses($typeConfigs, $tmpDir, $mode); $this->classLoader->addClassMap($classes); diff --git a/tests/Generator/TypeGeneratorModeTest.php b/tests/Generator/TypeGeneratorModeTest.php new file mode 100644 index 0000000..65678c3 --- /dev/null +++ b/tests/Generator/TypeGeneratorModeTest.php @@ -0,0 +1,77 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Overblog\GraphQLGenerator\Tests\Generator; + +use Overblog\GraphQLGenerator\Generator\TypeGenerator; +use Overblog\GraphQLGenerator\Tests\TestCase; + +class TypeGeneratorModeTest extends TestCase +{ + /** @var string */ + private $dir; + + /** @var TypeGenerator|\PHPUnit_Framework_MockObject_MockObject */ + private $typeGenerator; + + private static $configs = [ + 'Query' => [ + 'type' => 'object', + 'config' => [ + 'fields' => [ + 'sayHello' => ['type' => 'String!'], + ], + ], + ] + ]; + + public function setUp() + { + $this->dir = sys_get_temp_dir() . '/mcgweb-graphql-generator-modes'; + $this->typeGenerator = $this->getMockBuilder(TypeGenerator::class) + ->setMethods(['processPlaceHoldersReplacements', 'processTemplatePlaceHoldersReplacements']) + ->getMock() + ; + } + + public function testDryRunMode() + { + $this->typeGenerator->expects($this->once())->method('processPlaceHoldersReplacements'); + $this->typeGenerator->expects($this->once())->method('processTemplatePlaceHoldersReplacements'); + $this->assertGenerateClassesMode(TypeGenerator::MODE_DRY_RUN); + } + + public function testMappingOnlyMode() + { + $this->typeGenerator->expects($this->never())->method('processPlaceHoldersReplacements'); + $this->typeGenerator->expects($this->never())->method('processTemplatePlaceHoldersReplacements'); + $this->assertGenerateClassesMode(TypeGenerator::MODE_MAPPING_ONLY); + } + + private function assertGenerateClassesMode($mode) + { + $classes = $this->typeGenerator->generateClasses(self::$configs, $this->dir, $mode); + $file = $this->dir.'/QueryType.php'; + $this->assertEquals(['Overblog\CG\GraphQLGenerator\__Schema__\QueryType' => $this->dir.'/QueryType.php'], $classes); + if (method_exists($this, 'assertDirectoryNotExists')) { + $this->assertDirectoryNotExists($this->dir); + } else { // for phpunit 4 + $this->assertFalse(file_exists($this->dir)); + $this->assertFalse(is_dir($this->dir)); + } + if (method_exists($this, 'assertFileNotExists')) { + $this->assertFileNotExists($file); + } else { // for phpunit 4 + $this->assertFalse(file_exists($file)); + $this->assertFalse(is_file($file)); + } + } +} diff --git a/tests/StarWarsIntrospectionTest.php b/tests/StarWarsIntrospectionTest.php index a682d2b..7b976e1 100644 --- a/tests/StarWarsIntrospectionTest.php +++ b/tests/StarWarsIntrospectionTest.php @@ -56,7 +56,7 @@ public function testAllowsQueryingTheSchemaForTypes() ] ]; - $actual = GraphQL::execute($this->schema, $query); + $actual = GraphQL::executeQuery($this->schema, $query)->toArray(); $this->sortSchemaEntry($actual, 'types', 'name'); $this->sortSchemaEntry($expected, 'types', 'name'); $expected = ['data' => $expected];