This repository was archived by the owner on Feb 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests + removed namespaces in tests
- Loading branch information
Showing
22 changed files
with
297 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="PHP_CodeSniffer"> | ||
<description>The coding standard for laravel package</description> | ||
|
||
<file>src</file> | ||
|
||
<exclude-pattern>*.json</exclude-pattern> | ||
<exclude-pattern>*.xml</exclude-pattern> | ||
|
||
<rule ref="PSR2"/> | ||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Folklore\GraphQL\Console; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class MutationMakeCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'make:graphql:mutation {name}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new GraphQL mutation class'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Mutation'; | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
return __DIR__.'/stubs/mutation.stub'; | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.'\GraphQL\Mutation'; | ||
} | ||
|
||
/** | ||
* Build the class with the given name. | ||
* | ||
* @param string $name | ||
* @return string | ||
*/ | ||
protected function buildClass($name) | ||
{ | ||
$stub = parent::buildClass($name); | ||
|
||
return $this->replaceType($stub, $name); | ||
} | ||
|
||
/** | ||
* Replace the namespace for the given stub. | ||
* | ||
* @param string $stub | ||
* @param string $name | ||
* @return $this | ||
*/ | ||
protected function replaceType($stub, $name) | ||
{ | ||
preg_match('/([^\\\]+)$/', $name, $matches); | ||
$stub = str_replace( | ||
'DummyMutation', | ||
$matches[1], | ||
$stub | ||
); | ||
|
||
return $stub; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,98 @@ | ||
<?php | ||
|
||
namespace Folklore\GraphQL\Tests; | ||
|
||
use GraphQL; | ||
use Artisan; | ||
use GraphQL\Schema; | ||
use GraphQL\Type\Definition\ObjectType; | ||
|
||
use Folklore\GraphQL\Console\QueryMakeCommand; | ||
use Folklore\GraphQL\Console\TypeMakeCommand; | ||
|
||
class ConsoleTest extends TestCase | ||
{ | ||
|
||
protected function getEnvironmentSetUp($app) | ||
{ | ||
Artisan::registerCommand($app->make(QueryMakeCommand::class)); | ||
Artisan::registerCommand($app->make(TypeMakeCommand::class)); | ||
$app->setBasePath(__DIR__.'/fixture'); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
unlink(app_path('GraphQL/Query/TestQuery.php')); | ||
rmdir(app_path('GraphQL/Query')); | ||
rmdir(app_path('GraphQL')); | ||
if (file_exists(app_path('GraphQL/Query/TestQuery.php'))) { | ||
unlink(app_path('GraphQL/Query/TestQuery.php')); | ||
} | ||
if (file_exists(app_path('GraphQL/Type/TestType.php'))) { | ||
unlink(app_path('GraphQL/Type/TestType.php')); | ||
} | ||
if (file_exists(app_path('GraphQL/Mutation/TestMutation.php'))) { | ||
unlink(app_path('GraphQL/Mutation/TestMutation.php')); | ||
} | ||
|
||
if (file_exists(app_path('GraphQL/Type'))) { | ||
rmdir(app_path('GraphQL/Type')); | ||
} | ||
if (file_exists(app_path('GraphQL/Query'))) { | ||
rmdir(app_path('GraphQL/Query')); | ||
} | ||
if (file_exists(app_path('GraphQL/Mutation'))) { | ||
rmdir(app_path('GraphQL/Mutation')); | ||
} | ||
if (file_exists(app_path('GraphQL'))) { | ||
rmdir(app_path('GraphQL')); | ||
} | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Test | ||
* Test make query | ||
* | ||
* @test | ||
*/ | ||
public function testMakeQuery() | ||
{ | ||
Artisan::call('make:graphql_query', [ | ||
Artisan::call('make:graphql:query', [ | ||
'name' => 'TestQuery' | ||
]); | ||
|
||
$queryPath = app_path('GraphQL/Query/TestQuery.php'); | ||
$this->assertTrue(file_exists($queryPath)); | ||
$path = app_path('GraphQL/Query/TestQuery.php'); | ||
$this->assertTrue(file_exists($path)); | ||
|
||
$content = file_get_contents($path); | ||
$this->assertRegExp('/class TestQuery extends Query/', $content); | ||
$this->assertRegExp('/'.preg_quote('\'name\' => \'TestQuery\'').'/', $content); | ||
} | ||
|
||
/** | ||
* Test make type | ||
* | ||
* @test | ||
*/ | ||
public function testMakeType() | ||
{ | ||
Artisan::call('make:graphql:type', [ | ||
'name' => 'TestType' | ||
]); | ||
|
||
$path = app_path('GraphQL/Type/TestType.php'); | ||
$this->assertTrue(file_exists($path)); | ||
|
||
$content = file_get_contents($path); | ||
$this->assertRegExp('/class TestType extends Type/', $content); | ||
$this->assertRegExp('/'.preg_quote('\'name\' => \'TestType\'').'/', $content); | ||
} | ||
|
||
/** | ||
* Test make mutation | ||
* | ||
* @test | ||
*/ | ||
public function testMakeMutation() | ||
{ | ||
Artisan::call('make:graphql:mutation', [ | ||
'name' => 'TestMutation' | ||
]); | ||
|
||
$path = app_path('GraphQL/Mutation/TestMutation.php'); | ||
$this->assertTrue(file_exists($path)); | ||
|
||
$content = file_get_contents($path); | ||
$this->assertRegExp('/class TestMutation extends Mutation/', $content); | ||
$this->assertRegExp('/'.preg_quote('\'name\' => \'TestMutation\'').'/', $content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.