Browse Source

Restructure test cases into individual generator test

Added namespaces to test cases
tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
c067900a67
  1. 5
      composer.json
  2. 234
      tests/CrudMakeCommandTest.php
  3. 89
      tests/Generators/ControllerGeneratorTest.php
  4. 43
      tests/Generators/FeatureTestGeneratorTest.php
  5. 58
      tests/Generators/MigrationGeneratorTest.php
  6. 34
      tests/Generators/ModelGeneratorTest.php
  7. 43
      tests/Generators/ModelTestGeneratorTest.php
  8. 13
      tests/TestCase.php

5
composer.json

@ -13,6 +13,11 @@
"Luthfi\\CrudGenerator\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"require": {
"php": ">=7.0",
"illuminate/support": "5.4.*"

234
tests/CrudMakeCommandTest.php

@ -1,14 +1,9 @@
<?php
use Orchestra\Testbench\TestCase;
namespace Tests;
class CrudMakeCommandTest extends TestCase
{
protected function getPackageProviders($app)
{
return ['Luthfi\CrudGenerator\ServiceProvider'];
}
/** @test */
public function it_can_generate_simple_crud_files()
{
@ -32,231 +27,4 @@ class CrudMakeCommandTest extends TestCase
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
/** @test */
public function it_creates_correct_model_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(app_path('Item.php'));
$modelClassContent = "<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
{
//
}
";
$this->assertEquals($modelClassContent, file_get_contents(app_path('Item.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
/** @test */
public function it_creates_correct_controller_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(app_path('Item.php'));
$ctrlClassContent = "<?php
namespace App\Http\Controllers;
use App\Item;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ItemsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request \$request
* @return \Illuminate\Http\Response
*/
public function store(Request \$request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Item \$item
* @return \Illuminate\Http\Response
*/
public function show(Item \$item)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request \$request
* @param \App\Item \$item
* @return \Illuminate\Http\Response
*/
public function update(Request \$request, Item \$item)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Item \$item
* @return \Illuminate\Http\Response
*/
public function destroy(Item \$item)
{
//
}
}
";
$this->assertEquals($ctrlClassContent, file_get_contents(app_path('Http/Controllers/ItemsController.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
/** @test */
public function it_creates_correct_feature_test_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(base_path('tests/Feature/ManageItemsTest.php'));
$modelClassContent = "<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ManageItemsTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
\$this->assertTrue(true);
}
}
";
$this->assertEquals($modelClassContent, file_get_contents(base_path('tests/Feature/ManageItemsTest.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
/** @test */
public function it_creates_correct_unit_test_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(base_path('tests/Unit/Models/ItemTest.php'));
$modelClassContent = "<?php
namespace DummyNamespace;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ItemTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
\$this->assertTrue(true);
}
}
";
$this->assertEquals($modelClassContent, file_get_contents(base_path('tests/Unit/Models/ItemTest.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
/** @test */
public function it_creates_correct_migration_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_items_table.php');
$this->assertFileExists($migrationFilePath);
$modelClassContent = "<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('items', function (Blueprint \$table) {
\$table->increments('id');
\$table->string('name', 60);
\$table->string('description');
\$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('items');
}
}
";
$this->assertEquals($modelClassContent, file_get_contents($migrationFilePath));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
}

89
tests/Generators/ControllerGeneratorTest.php

@ -0,0 +1,89 @@
<?php
namespace Tests\Generators;
use Tests\TestCase;
class ControllerGeneratorTest extends TestCase
{
/** @test */
public function it_creates_correct_controller_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(app_path('Item.php'));
$ctrlClassContent = "<?php
namespace App\Http\Controllers;
use App\Item;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ItemsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request \$request
* @return \Illuminate\Http\Response
*/
public function store(Request \$request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Item \$item
* @return \Illuminate\Http\Response
*/
public function show(Item \$item)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request \$request
* @param \App\Item \$item
* @return \Illuminate\Http\Response
*/
public function update(Request \$request, Item \$item)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Item \$item
* @return \Illuminate\Http\Response
*/
public function destroy(Item \$item)
{
//
}
}
";
$this->assertEquals($ctrlClassContent, file_get_contents(app_path('Http/Controllers/ItemsController.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
}

43
tests/Generators/FeatureTestGeneratorTest.php

@ -0,0 +1,43 @@
<?php
namespace Tests\Generators;
use Tests\TestCase;
class FeatureTestGeneratorTest extends TestCase
{
/** @test */
public function it_creates_correct_feature_test_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(base_path('tests/Feature/ManageItemsTest.php'));
$modelClassContent = "<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ManageItemsTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
\$this->assertTrue(true);
}
}
";
$this->assertEquals($modelClassContent, file_get_contents(base_path('tests/Feature/ManageItemsTest.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
}

58
tests/Generators/MigrationGeneratorTest.php

@ -0,0 +1,58 @@
<?php
namespace Tests\Generators;
use Tests\TestCase;
class MigrationGeneratorTest extends TestCase
{
/** @test */
public function it_creates_correct_migration_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_items_table.php');
$this->assertFileExists($migrationFilePath);
$modelClassContent = "<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('items', function (Blueprint \$table) {
\$table->increments('id');
\$table->string('name', 60);
\$table->string('description');
\$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('items');
}
}
";
$this->assertEquals($modelClassContent, file_get_contents($migrationFilePath));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
}

34
tests/Generators/ModelGeneratorTest.php

@ -0,0 +1,34 @@
<?php
namespace Tests\Generators;
use Tests\TestCase;
class ModelGeneratorTest extends TestCase
{
/** @test */
public function it_creates_correct_model_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(app_path('Item.php'));
$modelClassContent = "<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
{
//
}
";
$this->assertEquals($modelClassContent, file_get_contents(app_path('Item.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
}

43
tests/Generators/ModelTestGeneratorTest.php

@ -0,0 +1,43 @@
<?php
namespace Tests\Generators;
use Tests\TestCase;
class ModelTestGeneratorTest extends TestCase
{
/** @test */
public function it_creates_correct_unit_test_class_content()
{
$this->artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]);
$this->assertFileExists(base_path('tests/Unit/Models/ItemTest.php'));
$modelClassContent = "<?php
namespace DummyNamespace;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ItemTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
\$this->assertTrue(true);
}
}
";
$this->assertEquals($modelClassContent, file_get_contents(base_path('tests/Unit/Models/ItemTest.php')));
exec('rm '.app_path('Item.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.database_path('migrations/*'));
exec('rm -r '.resource_path('views/items'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));
}
}

13
tests/TestCase.php

@ -0,0 +1,13 @@
<?php
namespace Tests;
use Orchestra\Testbench\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
protected function getPackageProviders($app)
{
return ['Luthfi\CrudGenerator\ServiceProvider'];
}
}
Loading…
Cancel
Save