Skip to content

Commit

Permalink
add tests for generating controller in model generator command
Browse files Browse the repository at this point in the history
  • Loading branch information
debuqer committed Aug 12, 2021
1 parent 25826e7 commit 44cbd9e
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/Commands/ModelMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ public function it_generates_migration_file_with_model_using_shortcut_option()
$this->assertSame(0, $code);
}

/** @test */
public function it_generates_controller_file_with_model()
{
$code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--controller' => true]);
$controllers = $this->finder->allFiles($this->modulePath . '/Http/Controllers');
$controllerFile = $controllers[1];
$controllerContent = $this->finder->get($this->modulePath . '/Http/Controllers/' . $controllerFile->getFilename());
$this->assertCount(2, $controllers);
$this->assertMatchesSnapshot($controllerContent);
$this->assertSame(0, $code);
}

/** @test */
public function it_generates_controller_file_with_model_using_shortcut_option()
{
$code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '-c' => true]);

$controllers = $this->finder->allFiles($this->modulePath . '/Http/Controllers');
$controllerFile = $controllers[1];
$controllerContent = $this->finder->get($this->modulePath . '/Http/Controllers/' . $controllerFile->getFilename());
$this->assertCount(2, $controllers);
$this->assertMatchesSnapshot($controllerContent);
$this->assertSame(0, $code);
}

/** @test */
public function it_generates_correct_migration_file_name_with_multiple_words_model()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php return '<?php
namespace Modules\\Blog\\Http\\Controllers;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\\Http\\Request;
use Illuminate\\Routing\\Controller;
class PostController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index()
{
return view(\'blog::index\');
}
/**
* Show the form for creating a new resource.
* @return Renderable
*/
public function create()
{
return view(\'blog::create\');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
{
//
}
/**
* Show the specified resource.
* @param int $id
* @return Renderable
*/
public function show($id)
{
return view(\'blog::show\');
}
/**
* Show the form for editing the specified resource.
* @param int $id
* @return Renderable
*/
public function edit($id)
{
return view(\'blog::edit\');
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
}
}
';
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php return '<?php
namespace Modules\\Blog\\Http\\Controllers;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\\Http\\Request;
use Illuminate\\Routing\\Controller;
class PostController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index()
{
return view(\'blog::index\');
}
/**
* Show the form for creating a new resource.
* @return Renderable
*/
public function create()
{
return view(\'blog::create\');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
{
//
}
/**
* Show the specified resource.
* @param int $id
* @return Renderable
*/
public function show($id)
{
return view(\'blog::show\');
}
/**
* Show the form for editing the specified resource.
* @param int $id
* @return Renderable
*/
public function edit($id)
{
return view(\'blog::edit\');
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
}
}
';

0 comments on commit 44cbd9e

Please sign in to comment.