Skip to content

Commit

Permalink
moving things around
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schobel committed Jan 28, 2018
1 parent 2f94e4d commit e01d252
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 14 deletions.
24 changes: 23 additions & 1 deletion Generator/Commands/TestTestCaseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Apiato\Core\Generator\GeneratorCommand;
use Apiato\Core\Generator\Interfaces\ComponentsGenerator;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

/**
* Class TestTestCaseGenerator
Expand Down Expand Up @@ -54,7 +55,7 @@ class TestTestCaseGenerator extends GeneratorCommand implements ComponentsGenera
*
* @var string
*/
protected $stubName = 'tests/testcase.stub';
protected $stubName = 'tests/testcase/generic.stub';

/**
* User required/optional inputs expected to be passed while calling the command.
Expand All @@ -63,13 +64,34 @@ class TestTestCaseGenerator extends GeneratorCommand implements ComponentsGenera
* @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,
Expand Down
5 changes: 3 additions & 2 deletions Generator/Commands/TestUnitTestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestUnitTestGenerator extends GeneratorCommand implements ComponentsGenera
*
* @var string
*/
protected $fileType = 'Tests';
protected $fileType = 'Unit Test';

/**
* The structure of the file path.
Expand All @@ -54,7 +54,7 @@ class TestUnitTestGenerator extends GeneratorCommand implements ComponentsGenera
*
* @var string
*/
protected $stubName = 'tests/unittest.stub';
protected $stubName = 'tests/unit/general.stub';

/**
* User required/optional inputs expected to be passed while calling the command.
Expand All @@ -74,6 +74,7 @@ public function getUserInputs()
$this->call('apiato:generate:test:testcase', [
'--container' => $this->containerName,
'--file' => 'TestCase',
'--ui' => 'generic',
]);

return [
Expand Down
15 changes: 15 additions & 0 deletions Generator/Stubs/tests/testcase/api.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Containers\{{container-name}}\Tests;

use App\Containers\{{container-name}}\Tests\TestCase as BaseTestCase;

/**
* Class {{class-name}}.
*
* This is the container API TestCase class. Use this class to add your container specific API related helper functions.
*/
class {{class-name}} extends BaseTestCase
{
// ..
}
15 changes: 15 additions & 0 deletions Generator/Stubs/tests/testcase/cli.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Containers\{{container-name}}\Tests;

use App\Containers\{{container-name}}\Tests\TestCase as BaseTestCase;

/**
* Class {{class-name}}.
*
* This is the container CLI TestCase class. Use this class to add your container specific CLI related helper functions.
*/
class {{class-name}} extends BaseTestCase
{
// ..
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use App\Ship\Parents\Tests\PhpUnit\TestCase as ShipTestCase;
/**
* Class {{class-name}}.
*
* This is the container TestCase class. Use this class to add your container specific helper functions.
* This is the container Main TestCase class. Use this class to add your container specific helper functions.
*/
class {{class-name}} extends ShipTestCase
{
Expand Down
15 changes: 15 additions & 0 deletions Generator/Stubs/tests/testcase/web.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Containers\{{container-name}}\Tests;

use App\Containers\{{container-name}}\Tests\TestCase as BaseTestCase;

/**
* Class {{class-name}}.
*
* This is the container WEB TestCase class. Use this class to add your container specific WEB related helper functions.
*/
class {{class-name}} extends BaseTestCase
{
// ..
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Containers\{{container-name}}\Tests\Unit;

use App\Containers\{{container-name}}\Tests\TestCase;
use App\Ship\Transporters\DataTransporter;
use Illuminate\Support\Facades\App;

/**
* Class {{class-name}}.
Expand All @@ -25,14 +23,15 @@ class {{class-name}} extends TestCase
// 'key' => 'value',
];

// create a new Transporter with the data
$transporter = new DataTransporter($data);

// create the Action to be called
$action = App::make(XXXAction::class);

// and call it
$entity = $action->run($transporter);
/**
* you may want to do something like:
*
* 1) create a new Transporter with this data
* 2) create a specific Action or Task
* 3) pass the Transporter to the Action / Task
* 4) assert that everything is correct!
*
*/

// assert something here
$this->assertEquals(true, true);
Expand Down

0 comments on commit e01d252

Please sign in to comment.