|
| 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 | +} |
0 commit comments