diff --git a/src/ModelCommand.php b/src/ModelCommand.php index 41a90cd..9153241 100644 --- a/src/ModelCommand.php +++ b/src/ModelCommand.php @@ -41,5 +41,6 @@ protected function generateConfig($name) File::put(config_path('smart.php'), $generator->print($models)); $this->call('config:clear'); + $this->info("Model {$name} generated."); } } diff --git a/tests/ModelCommandTest.php b/tests/ModelCommandTest.php new file mode 100644 index 0000000..844234b --- /dev/null +++ b/tests/ModelCommandTest.php @@ -0,0 +1,42 @@ + 'Dumb', + ]); + + $expected = file_get_contents(__DIR__.'/Snapshots/Dumb.php'); + $actual = file_get_contents(app_path('Dumb.php')); + + $this->assertEquals($expected, $actual); + $this->assertEquals("Configuration cache cleared!\nModel Dumb generated.\n", Artisan::output()); + } + + /** @test */ + public function it_throws_an_exception_when_model_already_exists() + { + File::put(app_path('Dumb.php'), 'somecontent'); + + Artisan::call('smart:model', [ + 'name' => 'Dumb', + ]); + + $this->assertEquals("This model already exists.\n", Artisan::output()); + } +} diff --git a/tests/ModelGeneratorTest.php b/tests/ModelGeneratorTest.php deleted file mode 100644 index 076b6db..0000000 --- a/tests/ModelGeneratorTest.php +++ /dev/null @@ -1,22 +0,0 @@ -assertEquals($generator->print('Product'), $expected); - } -} diff --git a/tests/Snapshots/model.txt b/tests/Snapshots/Dumb.php similarity index 87% rename from tests/Snapshots/model.txt rename to tests/Snapshots/Dumb.php index 96449a1..65d36f6 100644 --- a/tests/Snapshots/model.txt +++ b/tests/Snapshots/Dumb.php @@ -5,7 +5,7 @@ use Deiucanta\Smart\Field; use Deiucanta\Smart\Model; -class Product extends Model +class Dumb extends Model { public function fields() {