diff --git a/composer.json b/composer.json index 3ec570c..3d8df00 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,11 @@ "Luthfi\\CrudGenerator\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, "require": { "php": ">=7.0", "illuminate/support": "5.4.*" diff --git a/tests/CrudMakeCommandTest.php b/tests/CrudMakeCommandTest.php index 949bb0e..5d4e143 100644 --- a/tests/CrudMakeCommandTest.php +++ b/tests/CrudMakeCommandTest.php @@ -1,14 +1,9 @@ artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]); - - $this->assertFileExists(app_path('Item.php')); - $modelClassContent = "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 = "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 = "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 = "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 = "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')); - } } diff --git a/tests/Generators/ControllerGeneratorTest.php b/tests/Generators/ControllerGeneratorTest.php new file mode 100644 index 0000000..3dbdbe4 --- /dev/null +++ b/tests/Generators/ControllerGeneratorTest.php @@ -0,0 +1,89 @@ +artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]); + + $this->assertFileExists(app_path('Item.php')); + $ctrlClassContent = "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')); + } +} diff --git a/tests/Generators/FeatureTestGeneratorTest.php b/tests/Generators/FeatureTestGeneratorTest.php new file mode 100644 index 0000000..302a614 --- /dev/null +++ b/tests/Generators/FeatureTestGeneratorTest.php @@ -0,0 +1,43 @@ +artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]); + + $this->assertFileExists(base_path('tests/Feature/ManageItemsTest.php')); + $modelClassContent = "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')); + } +} diff --git a/tests/Generators/MigrationGeneratorTest.php b/tests/Generators/MigrationGeneratorTest.php new file mode 100644 index 0000000..a17b69a --- /dev/null +++ b/tests/Generators/MigrationGeneratorTest.php @@ -0,0 +1,58 @@ +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 = "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')); + } +} diff --git a/tests/Generators/ModelGeneratorTest.php b/tests/Generators/ModelGeneratorTest.php new file mode 100644 index 0000000..e41e079 --- /dev/null +++ b/tests/Generators/ModelGeneratorTest.php @@ -0,0 +1,34 @@ +artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]); + + $this->assertFileExists(app_path('Item.php')); + $modelClassContent = "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')); + } +} diff --git a/tests/Generators/ModelTestGeneratorTest.php b/tests/Generators/ModelTestGeneratorTest.php new file mode 100644 index 0000000..18602eb --- /dev/null +++ b/tests/Generators/ModelTestGeneratorTest.php @@ -0,0 +1,43 @@ +artisan('make:crud', ['name' => 'Item', '--no-interaction' => true]); + + $this->assertFileExists(base_path('tests/Unit/Models/ItemTest.php')); + $modelClassContent = "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')); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..55e0567 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,13 @@ +