-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johannes Schobel
committed
Jan 28, 2018
1 parent
e01d252
commit 0ba3a80
Showing
6 changed files
with
247 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace Apiato\Core\Generator\Commands; | ||
|
||
use Apiato\Core\Generator\GeneratorCommand; | ||
use Apiato\Core\Generator\Interfaces\ComponentsGenerator; | ||
use Illuminate\Support\Str; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* Class TestFunctionalTestGenerator | ||
* | ||
* @author Johannes Schobel <[email protected]> | ||
*/ | ||
class TestFunctionalTestGenerator extends GeneratorCommand implements ComponentsGenerator | ||
{ | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'apiato:generate:test:functional'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a Functional Test file.'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $fileType = 'Functional Test'; | ||
|
||
/** | ||
* The structure of the file path. | ||
* | ||
* @var string | ||
*/ | ||
protected $pathStructure = '{container-name}/UI/{user-interface}/Tests/Functional/*'; | ||
|
||
/** | ||
* The structure of the file name. | ||
* | ||
* @var string | ||
*/ | ||
protected $nameStructure = '{file-name}'; | ||
|
||
/** | ||
* The name of the stub file. | ||
* | ||
* @var string | ||
*/ | ||
protected $stubName = 'tests/functional/general.stub'; | ||
|
||
/** | ||
* User required/optional inputs expected to be passed while calling the command. | ||
* This is a replacement of the `getArguments` function "which reads whenever it's called". | ||
* | ||
* @var array | ||
*/ | ||
public $inputs = [ | ||
['ui', null, InputOption::VALUE_OPTIONAL, 'The user-interface to generate the Test for.'], | ||
]; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getUserInputs() | ||
{ | ||
$ui = Str::lower($this->checkParameterOrChoice('ui', 'Select the UI for the Test', ['API', 'WEB', 'CLI'], 0)); | ||
|
||
// set the stub file accordingly | ||
$this->stubName = 'tests/functional/' . $ui . '.stub'; | ||
|
||
// we need to generate the TestCase class before | ||
$this->call('apiato:generate:test:testcase', [ | ||
'--container' => $this->containerName, | ||
'--file' => 'TestCase', | ||
'--ui' => $ui, | ||
]); | ||
|
||
return [ | ||
'path-parameters' => [ | ||
'container-name' => $this->containerName, | ||
'user-interface' => Str::upper($ui), | ||
], | ||
'stub-parameters' => [ | ||
'_container-name' => Str::lower($this->containerName), | ||
'container-name' => $this->containerName, | ||
'class-name' => $this->fileName, | ||
], | ||
'file-parameters' => [ | ||
'file-name' => $this->fileName, | ||
], | ||
]; | ||
} | ||
|
||
public function getDefaultFileName() | ||
{ | ||
return 'DefaultFunctionalTest'; | ||
} | ||
|
||
} | ||
|
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,43 @@ | ||
<?php | ||
|
||
namespace App\Containers\{{container-name}}\UI\API\Tests\Functional; | ||
|
||
use App\Containers\{{container-name}}\Tests\ApiTestCase; | ||
|
||
/** | ||
* Class {{class-name}}. | ||
* | ||
* @group {{_container-name}} | ||
* @group api | ||
*/ | ||
class {{class-name}} extends ApiTestCase | ||
{ | ||
|
||
// the endpoint to be called within this test (e.g., get@v1/users) | ||
protected $endpoint = 'method@endpoint'; | ||
|
||
// fake some access rights | ||
protected $access = [ | ||
'permissions' => '', | ||
'roles' => '', | ||
]; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_() | ||
{ | ||
$data = [ | ||
// 'key' => 'value', | ||
]; | ||
|
||
// send the HTTP request | ||
$response = $this->makeCall($data); | ||
|
||
// assert the response status | ||
$response->assertStatus(200); | ||
|
||
// make other asserts here | ||
} | ||
|
||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace App\Containers\{{container-name}}\UI\CLI\Tests\Functional; | ||
|
||
use App\Containers\{{container-name}}\Tests\CliTestCase; | ||
|
||
/** | ||
* Class {{class-name}}. | ||
* | ||
* @group {{_container-name}} | ||
* @group cli | ||
*/ | ||
class {{class-name}} extends CliTestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_() | ||
{ | ||
// make something here | ||
|
||
// assert basic stuff here | ||
} | ||
|
||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace App\Containers\{{container-name}}\UI\API\Tests\Functional; | ||
|
||
use App\Containers\{{container-name}}\Tests\TestCase; | ||
|
||
/** | ||
* Class {{class-name}}. | ||
* | ||
* @group {{_container-name}} | ||
* @group general | ||
*/ | ||
class {{class-name}} extends TestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_() | ||
{ | ||
|
||
} | ||
|
||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace App\Containers\{{container-name}}\UI\WEB\Tests\Functional; | ||
|
||
use App\Containers\{{container-name}}\Tests\WebTestCase; | ||
|
||
/** | ||
* Class {{class-name}}. | ||
* | ||
* @group {{_container-name}} | ||
* @group web | ||
*/ | ||
class {{class-name}} extends WebTestCase | ||
{ | ||
|
||
// the endpoint to be called within this test (e.g., get@v1/users) | ||
protected $endpoint = 'method@endpoint'; | ||
|
||
// fake some access rights | ||
protected $access = [ | ||
'permissions' => '', | ||
'roles' => '', | ||
]; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_() | ||
{ | ||
$data = [ | ||
// 'key' => 'value', | ||
]; | ||
|
||
// send the HTTP request | ||
$response = $this->makeCall($data); | ||
|
||
// assert the response status | ||
$response->assertStatus(200); | ||
|
||
// make other asserts here | ||
} | ||
|
||
} |