Tests are failing only for the new route options

This commit is contained in:
Josiah Dahl 2017-08-06 23:06:04 -07:00
parent 2817f3591b
commit 5e2c21855e
10 changed files with 401 additions and 56 deletions

View File

@ -1,7 +0,0 @@
<?php
/*
|------------------------------------------
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|------------------------------------------
*/

View File

@ -1,4 +1,4 @@
<?php //[STAMP] 6172d62f52ee53bf8d6f975a52df4f0d
<?php //[STAMP] d6606f78456705b0875c6b8343fc6a4a
namespace _generated;
// This class was automatically generated by build task
@ -17,6 +17,22 @@ trait AcceptanceTesterActions
abstract protected function getScenario();
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
@ -95,7 +111,7 @@ trait AcceptanceTesterActions
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @param $regex
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Cli::seeShellOutputMatches()
*/
@ -105,7 +121,7 @@ trait AcceptanceTesterActions
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @param $regex
* @see \Codeception\Module\Cli::seeShellOutputMatches()
*/
public function seeShellOutputMatches($regex) {
@ -113,13 +129,83 @@ trait AcceptanceTesterActions
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIs(0);
* ```
*
* @param $code
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Cli::seeResultCodeIs()
*/
public function canSeeResultCodeIs($code) {
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResultCodeIs', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIs(0);
* ```
*
* @param $code
* @see \Codeception\Module\Cli::seeResultCodeIs()
*/
public function seeResultCodeIs($code) {
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResultCodeIs', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIsNot(0);
* ```
*
* @param $code
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Cli::seeResultCodeIsNot()
*/
public function canSeeResultCodeIsNot($code) {
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResultCodeIsNot', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks result code
*
* ```php
* <?php
* $I->seeResultCodeIsNot(0);
* ```
*
* @param $code
* @see \Codeception\Module\Cli::seeResultCodeIsNot()
*/
public function seeResultCodeIsNot($code) {
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResultCodeIsNot', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Enters a directory In local filesystem.
* Project root directory is used by default
*
* @param $path
* @param string $path
* @see \Codeception\Module\Filesystem::amInPath()
*/
public function amInPath($path) {
@ -141,7 +227,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @see \Codeception\Module\Filesystem::openFile()
*/
public function openFile($filename) {
@ -160,7 +246,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @see \Codeception\Module\Filesystem::deleteFile()
*/
public function deleteFile($filename) {
@ -179,7 +265,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $dirname
* @param string $dirname
* @see \Codeception\Module\Filesystem::deleteDir()
*/
public function deleteDir($dirname) {
@ -198,8 +284,8 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $src
* @param $dst
* @param string $src
* @param string $dst
* @see \Codeception\Module\Filesystem::copyDir()
*/
public function copyDir($src, $dst) {
@ -221,7 +307,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeInThisFile()
*/
@ -242,7 +328,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* @see \Codeception\Module\Filesystem::seeInThisFile()
*/
public function seeInThisFile($text) {
@ -298,7 +384,7 @@ trait AcceptanceTesterActions
*
* Checks that contents of currently opened file matches $regex
*
* @param $regex
* @param string $regex
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
*/
@ -310,7 +396,7 @@ trait AcceptanceTesterActions
*
* Checks that contents of currently opened file matches $regex
*
* @param $regex
* @param string $regex
* @see \Codeception\Module\Filesystem::seeThisFileMatches()
*/
public function seeThisFileMatches($regex) {
@ -333,7 +419,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeFileContentsEqual()
*/
@ -355,7 +441,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* @see \Codeception\Module\Filesystem::seeFileContentsEqual()
*/
public function seeFileContentsEqual($text) {
@ -375,7 +461,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::dontSeeInThisFile()
*/
@ -394,7 +480,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $text
* @param string $text
* @see \Codeception\Module\Filesystem::dontSeeInThisFile()
*/
public function dontSeeInThisFile($text) {
@ -425,7 +511,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @param string $path
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::seeFileFound()
@ -445,7 +531,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $filename
* @param string $filename
* @param string $path
* @see \Codeception\Module\Filesystem::seeFileFound()
*/
@ -459,7 +545,7 @@ trait AcceptanceTesterActions
*
* Checks if file does not exist in path
*
* @param $filename
* @param string $filename
* @param string $path
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Filesystem::dontSeeFileFound()
@ -472,7 +558,7 @@ trait AcceptanceTesterActions
*
* Checks if file does not exist in path
*
* @param $filename
* @param string $filename
* @param string $path
* @see \Codeception\Module\Filesystem::dontSeeFileFound()
*/
@ -492,7 +578,7 @@ trait AcceptanceTesterActions
* ?>
* ```
*
* @param $dirname
* @param string $dirname
* @see \Codeception\Module\Filesystem::cleanDir()
*/
public function cleanDir($dirname) {
@ -505,8 +591,8 @@ trait AcceptanceTesterActions
*
* Saves contents to file
*
* @param $filename
* @param $contents
* @param string $filename
* @param string $contents
* @see \Codeception\Module\Filesystem::writeToFile()
*/
public function writeToFile($filename, $contents) {

View File

@ -1,4 +1,4 @@
<?php //[STAMP] 113b78942a9c8ce85a7c18397003b17c
<?php //[STAMP] d2a298893573661fdbd787dcfa27a7b0
namespace _generated;
// This class was automatically generated by build task
@ -15,4 +15,18 @@ trait FunctionalTesterActions
abstract protected function getScenario();
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
}

View File

@ -1,4 +1,4 @@
<?php //[STAMP] afa4f0350422fae145b4236dce66191a
<?php //[STAMP] 1467e0d5027bbc2413077351642a21f3
namespace _generated;
// This class was automatically generated by build task
@ -19,14 +19,29 @@ trait UnitTesterActions
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are equal.
* Checks that two variables are equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values equal.
*
* Regular example:
* ```php
* <?php
* $I->assertEquals($element->getChildrenCount(), 5);
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertEquals($calculator->add(0.1, 0.2), 0.3, 'Calculator should add the two numbers correctly.', 0.01);
* ```
*
* @param $expected
* @param $actual
* @param string $message
* @param float $delta
* @see \Codeception\Module\Asserts::assertEquals()
*/
public function assertEquals($expected, $actual, $message = null) {
public function assertEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
}
@ -34,14 +49,29 @@ trait UnitTesterActions
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are not equal
* Checks that two variables are not equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values not equal.
*
* Regular example:
* ```php
* <?php
* $I->assertNotEquals($element->getChildrenCount(), 0);
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertNotEquals($calculator->add(0.1, 0.2), 0.4, 'Calculator should add the two numbers correctly.', 0.01);
* ```
*
* @param $expected
* @param $actual
* @param string $message
* @param float $delta
* @see \Codeception\Module\Asserts::assertNotEquals()
*/
public function assertNotEquals($expected, $actual, $message = null) {
public function assertNotEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
}
@ -54,7 +84,6 @@ trait UnitTesterActions
* @param $expected
* @param $actual
* @param string $message
* @return mixed|void
* @see \Codeception\Module\Asserts::assertSame()
*/
public function assertSame($expected, $actual, $message = null) {
@ -197,6 +226,36 @@ trait UnitTesterActions
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string starts with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsWith()
*/
public function assertStringStartsWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string doesn't start with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsNotWith()
*/
public function assertStringStartsNotWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
@ -373,6 +432,22 @@ trait UnitTesterActions
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*

View File

@ -0,0 +1,121 @@
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('Generate RESTful resources from a file with Laravel Routes');
$I->runShellCommand('php artisan wn:resources tests/_data/ResourcesTest.yml --laravel=true');
// Checking the model
$I->seeInShellOutput('Author model generated');
$I->seeInShellOutput('Book model generated');
$I->seeInShellOutput('Library model generated');
$I->seeFileFound('./app/Author.php');
$I->seeFileFound('./app/Book.php');
$I->seeFileFound('./app/Library.php');
$I->deleteFile('./app/Author.php');
$I->deleteFile('./app/Book.php');
$I->deleteFile('./app/Library.php');
// Checking the migration
$I->seeInShellOutput('authors migration generated');
$I->seeInShellOutput('books migration generated');
$I->seeInShellOutput('libraries migration generated');
// Can't check for specific file names, so we'll just strip the directory
$I->cleanDir('database/migrations');
$I->writeToFile('database/migrations/.gitkeep', '');
// Checking the RESTActions trait
$I->seeFileFound('./app/Http/Controllers/RESTActions.php');
$I->deleteFile('./app/Http/Controllers/RESTActions.php');
// Checking the controller
$I->seeInShellOutput('AuthorsController generated');
$I->seeInShellOutput('LibrariesController generated');
$I->seeInShellOutput('BooksController generated');
$I->seeFileFound('./app/Http/Controllers/AuthorsController.php');
$I->seeFileFound('./app/Http/Controllers/LibrariesController.php');
$I->seeFileFound('./app/Http/Controllers/BooksController.php');
$I->deleteFile('./app/Http/Controllers/AuthorsController.php');
$I->deleteFile('./app/Http/Controllers/LibrariesController.php');
$I->deleteFile('./app/Http/Controllers/BooksController.php');
$I->seeFileFound('routes/api.php');
$I->seeInThisFile('
Route::get(\'author\', \'AuthorsController@all\');
Route::get(\'author/{id}\', \'AuthorsController@get\');
Route::post(\'author\', \'AuthorsController@add\');
Route::put(\'author/{id}\', \'AuthorsController@put\');
Route::delete(\'author/{id}\', \'AuthorsController@remove\');');
$I->seeInThisFile('
Route::get(\'book\', \'BooksController@all\');
Route::get(\'book/{id}\', \'BooksController@get\');
Route::post(\'book\', \'BooksController@add\');
Route::put(\'book/{id}\', \'BooksController@put\');
Route::delete(\'book/{id}\', \'BooksController@remove\');');
$I->seeInThisFile('
Route::get(\'library\', \'LibrariesController@all\');
Route::get(\'library/{id}\', \'LibrariesController@get\');
Route::post(\'library\', \'LibrariesController@add\');
Route::put(\'library/{id}\', \'LibrariesController@put\');
Route::delete(\'library/{id}\', \'LibrariesController@remove\');');
$I->writeToFile('./app/Http/routes.php', '<?php
/*
|------------------------------------------
| ***** DUMMY ROUTES FOR TESTING ONLY *****
|------------------------------------------
*/
');
// Checking model factory
// $I->openFile('./database/factories/ModelFactory.php');
// $I->seeInThisFile(
// "/**
// * Factory definition for model App\TaskCategory.
// */
// \$factory->define(App\TaskCategory::class, function (\$faker) {
// return [
// 'name' => \$faker->word,
// 'descr' => \$faker->paragraph,
// 'due' => \$faker->date,
// ];
// });");
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
");
// Checking database seeder
// $I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
// $I->seeInThisFile('
// use Illuminate\Database\Seeder;
// class TaskCategoriesTableSeeder extends Seeder
// {
// public function run()
// {
// factory(App\TaskCategory::class, 10)->create();
// }
// }');
// $I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');

View File

@ -62,7 +62,9 @@ $app->get("/", function () use ($app) {
$I->wantTo('run wn:routes in Lumen 5.3+');
mkdir('./routes');
if(!file_exists('./routes')) {
mkdir('./routes');
}
$I->writeToFile('./routes/web.php', '<?php
/*

View File

@ -1,6 +1,8 @@
<?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class ControllerCommand extends BaseCommand {
protected $signature = 'wn:controller
@ -8,7 +10,6 @@ class ControllerCommand extends BaseCommand {
{--no-routes= : without routes}
{--force= : override the existing files}
{--laravel= : Boolean (default false) Use Laravel style route definitions}
';
protected $description = 'Generates RESTful controller using the RESTActions trait';
@ -33,13 +34,20 @@ class ControllerCommand extends BaseCommand {
->get();
$this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
if(! $this->option('no-routes')){
$this->call('wn:route', [
$options = [
'resource' => snake_case($name, '-'),
'--controller' => $controller,
'--laravel' => $this->options('laravel')
]);
];
// try {
// if($this->option('laravel')) {
// $options['--laravel'] = true;
// };
// } catch (InvalidArgumentException $e) {
// // Do nothing
// }
$this->call('wn:route', $options);
}
}

View File

@ -1,6 +1,8 @@
<?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class ResourceCommand extends BaseCommand {
protected $signature = 'wn:resource
@ -64,12 +66,19 @@ class ResourceCommand extends BaseCommand {
}
// generating the controller and routes
$this->call('wn:controller', [
$controllerOptions = [
'model' => $modelName,
'--force' => $this->option('force'),
'--no-routes' => false,
'--laravel' => $this->option('laravel')
]);
];
try {
if($this->option('laravel')) {
$controllerOptions['--laravel'] = true;
};
} catch (InvalidArgumentException $e) {
// Do nothing
}
$this->call('wn:controller', $controllerOptions);
// generating model factory
$this->call('wn:factory', [

View File

@ -1,5 +1,6 @@
<?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
@ -25,7 +26,7 @@ class ResourcesCommand extends BaseCommand {
foreach ($content as $model => $i){
$i = $this->getResourceParams($model, $i);
$this->call('wn:resource', [
$options = [
'name' => $i['name'],
'fields' => $i['fields'],
'--add' => $i['add'],
@ -35,8 +36,17 @@ class ResourcesCommand extends BaseCommand {
'--belongs-to-many' => $i['belongsToMany'],
'--path' => $this->option('path'),
'--force' => $this->option('force'),
'--laravel' => $this->option('laravel')
]);
];
try {
if($this->option('laravel')) {
$options['--laravel'] = true;
};
} catch (InvalidArgumentException $e) {
// Do nothing
}
$this->call('wn:resource', $options);
}
// $this->call('migrate'); // actually needed for pivot seeders !

View File

@ -1,6 +1,8 @@
<?php namespace Wn\Generators\Commands;
use InvalidArgumentException;
class RouteCommand extends BaseCommand {
protected $signature = 'wn:route
@ -14,16 +16,41 @@ class RouteCommand extends BaseCommand {
public function handle()
{
$resource = $this->argument('resource');
$laravelRoutes = $this->option('laravel');
$templateFile = 'routes';
$laravelRoutes = $this->input->hasOption('laravel') ? $this->option('laravel') : false;
$routesPath = './routes/web.php';
$templateFile = 'routes';
$routesPath = 'routes/web.php';
if ($laravelRoutes) {
$routesPath = './routes/api.php';
$templateFile = 'routes-laravel';
$routesPath = 'routes/api.php';
if (!$this->fs->isFile($routesPath)) {
$this->fs->put($routesPath, "
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the \"api\" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
");
}
}
if(!$this->fs->isFile($routesPath)) {
$routesPath = 'app/Http/routes.php';
}
if (! $this->fs->exists($routesPath))
$routesPath = './app/Http/routes.php';
$content = $this->fs->get($routesPath);