Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
42 changes: 42 additions & 0 deletions tests/ModelCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Deiucanta\Smart\Tests;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;

class ModelCommandTest extends TestCase
{
protected function setUp()
{
parent::setUp();

File::delete(app_path('Dumb.php'));
}

/** @test */
public function it_generates_a_model()
{
Artisan::call('smart:model', [
'name' => '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());
}
}
22 changes: 0 additions & 22 deletions tests/ModelGeneratorTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Snapshots/model.txt → tests/Snapshots/Dumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Deiucanta\Smart\Field;
use Deiucanta\Smart\Model;

class Product extends Model
class Dumb extends Model
{
public function fields()
{
Expand Down