Skip to content
This repository was archived by the owner on Feb 10, 2019. It is now read-only.

Updated php-coveralls #377

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ before_script: phpenv config-add ~/xdebug.ini

script: vendor/bin/phpunit

after_success: sh -c "if [ ! -z ${COVERAGE+x} ]; then php vendor/bin/coveralls; fi"
after_success: sh -c "if [ ! -z ${COVERAGE+x} ]; then php vendor/bin/php-coveralls; fi"

notifications:
email: false
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"orchestra/testbench": "3.1.*|3.2.*|3.3.*|3.4.*|3.5.*",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"satooshi/php-coveralls": "^1.0",
"phpunit/phpunit": "~4.0|~5.0|~5.7|~6.0"
"phpunit/phpunit": "~4.0|~5.0|~5.7|~6.0",
"php-coveralls/php-coveralls": "^2.1"
},
"autoload": {
"psr-0": {
Expand Down
44 changes: 33 additions & 11 deletions src/Folklore/GraphQL/Console/TypeMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Folklore\GraphQL\Console;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class TypeMakeCommand extends GeneratorCommand
{
Expand All @@ -12,7 +11,9 @@ class TypeMakeCommand extends GeneratorCommand
*
* @var string
*/
protected $signature = 'make:graphql:type {name}';
protected $signature = 'make:graphql:type
{name : The name of the type class}
{--O|object : Create a new input object type}';

/**
* The console command description.
Expand Down Expand Up @@ -41,7 +42,8 @@ protected function getStub()
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
Expand All @@ -52,7 +54,8 @@ protected function getDefaultNamespace($rootNamespace)
/**
* Build the class with the given name.
*
* @param string $name
* @param string $name
*
* @return string
*/
protected function buildClass($name)
Expand All @@ -65,19 +68,38 @@ protected function buildClass($name)
/**
* Replace the namespace for the given stub.
*
* @param string $stub
* @param string $name
* @param string $stub
* @param string $name
*
* @return $this
*/
protected function replaceType($stub, $name)
private function replaceType($stub, $name)
{
preg_match('/([^\\\]+)$/', $name, $matches);
$stub = str_replace(
'DummyType',
$matches[1],

$search = ['DummyType', 'DummyInputObject'];
$replace = [$matches[1]];

$this->addInputObjectAttribute($replace);

return str_replace(
$search,
$replace,
$stub
);
}

return $stub;
/**
* Add input object attribute to replace type.
*
* @param array $replace
*/
private function addInputObjectAttribute(array &$replace)
{
if ($this->option('object')) {
array_push($replace, 'protected $inputObject = true;');
} else {
array_push($replace, '');
}
}
}
6 changes: 5 additions & 1 deletion src/Folklore/GraphQL/Console/stubs/type.stub
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use GraphQL;

class DummyClass extends BaseType
{
DummyInputObject
protected $attributes = [
'name' => 'DummyType',
'description' => 'A type'
Expand All @@ -16,7 +17,10 @@ class DummyClass extends BaseType
public function fields()
{
return [

'sampleField' => [
'type' => Type::string(),
'description' => 'Sample field description',
],
];
}
}
89 changes: 89 additions & 0 deletions tests/TypeMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

use Mockery as m;

class TypeMakeCommandTest extends TestCase
{
protected $command;

protected $tmpPath;

public function setUp()
{
parent::setUp();

$this->app->singleton('Illuminate\Contracts\Console\Kernel', TestKernel::class);

$this->tmpPath = __DIR__.'/appTest/GraphQL/Type/';

$this->command = m::mock(
'Folklore\GraphQL\Console\TypeMakeCommand[error,getPath,rootNamespace]',
[new \Illuminate\Filesystem\Filesystem()]
)->shouldAllowMockingProtectedMethods();

$this->command->shouldReceive('rootNamespace')->andReturn('AppTest');
}

public function tearDown()
{
parent::tearDown();

m::close();

exec('rm -rf '.__DIR__.'/appTest');
}

public function testItMakeANormalType()
{
$this->mockGetPath('TestNormalType');

$this->registerCommand();

$this->artisan('make:graphql:type', ['name'=>'TestNormalType']);

$this->assertFileExists($this->tmpPath.'TestNormalType.php');
}

public function testItMakeAInputObjectTypeWithObjectOption()
{
$this->mockGetPath('TestObjectInputType');

$this->registerCommand();

$this->artisan('make:graphql:type', ['name' => 'TestObjectInputType', '-O' => true]);

$this->assertFileExists($this->tmpPath.'TestObjectInputType.php');
}

public function testItErrorsIfTypeAlradyExists()
{
$this->command->shouldReceive('error')->with('Type already exists!');

$this->mockGetPath('TestExistsType');

$this->registerCommand();

$this->artisan('make:graphql:type', ['name'=>'TestExistsType']);
$this->artisan('make:graphql:type', ['name'=>'TestExistsType']);

$this->assertFileExists($this->tmpPath.'TestExistsType.php');
}

private function registerCommand()
{
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($this->command);
}

private function mockGetPath($name)
{
$this->command->shouldReceive('getPath')->andReturn($this->tmpPath.$name.'.php');
}
}

class TestKernel extends \Illuminate\Foundation\Console\Kernel
{
public function registerCommand($command)
{
$this->getArtisan()->add($command);
}
}