-
-
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.
Adding some new `apiato:generate:test:*` commands
- Loading branch information
Showing
13 changed files
with
567 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?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 TestTestCaseGenerator | ||
* | ||
* @author Johannes Schobel <[email protected]> | ||
*/ | ||
class TestTestCaseGenerator extends GeneratorCommand implements ComponentsGenerator | ||
{ | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'apiato:generate:test:testcase'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create the TestCase file.'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $fileType = 'TestCase'; | ||
|
||
/** | ||
* The structure of the file path. | ||
* | ||
* @var string | ||
*/ | ||
protected $pathStructure = '{container-name}/Tests/*'; | ||
|
||
/** | ||
* The structure of the file name. | ||
* | ||
* @var string | ||
*/ | ||
protected $nameStructure = '{file-name}'; | ||
|
||
/** | ||
* The name of the stub file. | ||
* | ||
* @var string | ||
*/ | ||
protected $stubName = 'tests/testcase/generic.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 TestCase for.'], | ||
]; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getUserInputs() | ||
{ | ||
// we manually set the filename to TestCase as this is the preferred name within apiato | ||
$this->fileName = 'TestCase'; | ||
|
||
$ui = Str::lower($this->checkParameterOrChoice('ui', 'Select the UI for the controller', ['Generic', 'API', 'WEB', 'CLI'], 0)); | ||
|
||
// we need to generate the generic testcase first! | ||
if ($ui != 'generic') { | ||
$this->call('apiato:generate:test:testcase', [ | ||
'--container' => $this->containerName, | ||
'--file' => 'TestCase', | ||
'--ui' => 'generic', | ||
]); | ||
|
||
// however, as this generator here is NOT the one for the generic TestCase, we need to prepend the UI before | ||
// this results in something like ApiTestCase | ||
$this->fileName = Str::ucfirst($ui) . $this->fileName; | ||
} | ||
|
||
$this->stubName = 'tests/testcase/' . $ui . '.stub'; | ||
|
||
return [ | ||
'path-parameters' => [ | ||
'container-name' => $this->containerName, | ||
], | ||
'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 'TestCase'; | ||
} | ||
|
||
} | ||
|
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,101 @@ | ||
<?php | ||
|
||
namespace Apiato\Core\Generator\Commands; | ||
|
||
use Apiato\Core\Generator\GeneratorCommand; | ||
use Apiato\Core\Generator\Interfaces\ComponentsGenerator; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* Class TestUnitTestGenerator | ||
* | ||
* @author Johannes Schobel <[email protected]> | ||
*/ | ||
class TestUnitTestGenerator extends GeneratorCommand implements ComponentsGenerator | ||
{ | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'apiato:generate:test:unit'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a Unit Test file.'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $fileType = 'Unit Test'; | ||
|
||
/** | ||
* The structure of the file path. | ||
* | ||
* @var string | ||
*/ | ||
protected $pathStructure = '{container-name}/Tests/Unit/*'; | ||
|
||
/** | ||
* The structure of the file name. | ||
* | ||
* @var string | ||
*/ | ||
protected $nameStructure = '{file-name}'; | ||
|
||
/** | ||
* The name of the stub file. | ||
* | ||
* @var string | ||
*/ | ||
protected $stubName = 'tests/unit/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 = [ | ||
]; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getUserInputs() | ||
{ | ||
// we need to generate the TestCase class before | ||
$this->call('apiato:generate:test:testcase', [ | ||
'--container' => $this->containerName, | ||
'--file' => 'TestCase', | ||
'--ui' => 'generic', | ||
]); | ||
|
||
return [ | ||
'path-parameters' => [ | ||
'container-name' => $this->containerName, | ||
], | ||
'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 'DefaultUnitTest'; | ||
} | ||
|
||
} | ||
|
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 | ||
} | ||
|
||
} |
Oops, something went wrong.