Skip to content

Commit

Permalink
Add generation new mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Nov 6, 2017
1 parent a919fa1 commit 49719c9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/Generator/AbstractTypeGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
77 changes: 77 additions & 0 deletions tests/Generator/TypeGeneratorModeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the OverblogGraphQLPhpGenerator package.
*
* (c) Overblog <http://github.com/overblog/>
*
* 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));
}
}
}

0 comments on commit 49719c9

Please sign in to comment.