-
-
Notifications
You must be signed in to change notification settings - Fork 970
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
227 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Nwidart\Modules\Tests\Commands; | ||
|
||
use Nwidart\Modules\Contracts\RepositoryInterface; | ||
use Nwidart\Modules\Tests\BaseTestCase; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
|
||
class ObserverMakeCommandTest extends BaseTestCase | ||
{ | ||
use MatchesSnapshots; | ||
/** | ||
* @var \Illuminate\Filesystem\Filesystem | ||
*/ | ||
private $finder; | ||
/** | ||
* @var string | ||
*/ | ||
private $modulePath; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->modulePath = base_path('modules/Blog'); | ||
$this->finder = $this->app['files']; | ||
$this->artisan('module:make', ['name' => ['Blog']]); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
$this->app[RepositoryInterface::class]->delete('Blog'); | ||
parent::tearDown(); | ||
} | ||
|
||
/** @test */ | ||
public function it_makes_observer() | ||
{ | ||
$code = $this->artisan('module:make-observer', ['name' => 'Post', 'module' => 'Blog']); | ||
|
||
$observerFile = $this->modulePath . '/Observers/PostObserver.php'; | ||
// dd($observerFile); | ||
|
||
$this->assertTrue(is_file($observerFile), 'Observer file was not created.'); | ||
$this->assertMatchesSnapshot($this->finder->get($observerFile)); | ||
$this->assertSame(0, $code); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/Commands/__snapshots__/ObserverMakeCommandTest__it_makes_observer__1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php return '<?php | ||
namespace Modules\Blog\Observers; | ||
use Modules\Blog\Entities\Post; | ||
class PostObserver | ||
{ | ||
/** | ||
* Handle the Post "created" event. | ||
*/ | ||
public function created(Post $post): void | ||
{ | ||
// | ||
} | ||
/** | ||
* Handle the Post "updated" event. | ||
*/ | ||
public function updated(Post $post): void | ||
{ | ||
// | ||
} | ||
/** | ||
* Handle the Post "deleted" event. | ||
*/ | ||
public function deleted(Post $post): void | ||
{ | ||
// | ||
} | ||
/** | ||
* Handle the Post "restored" event. | ||
*/ | ||
public function restored(Post $post): void | ||
{ | ||
// | ||
} | ||
/** | ||
* Handle the Post "force deleted" event. | ||
*/ | ||
public function forceDeleted(Post $post): void | ||
{ | ||
// | ||
} | ||
} | ||
'; |
48 changes: 48 additions & 0 deletions
48
tests/Commands/__snapshots__/ObserverMakeCommandTest__it_makes_observer__1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Modules\Blog\Observers; | ||
|
||
use Modules\Blog\Entities\Post; | ||
|
||
class PostObserver | ||
{ | ||
/** | ||
* Handle the Post "created" event. | ||
*/ | ||
public function created(Post $post): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the Post "updated" event. | ||
*/ | ||
public function updated(Post $post): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the Post "deleted" event. | ||
*/ | ||
public function deleted(Post $post): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the Post "restored" event. | ||
*/ | ||
public function restored(Post $post): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the Post "force deleted" event. | ||
*/ | ||
public function forceDeleted(Post $post): void | ||
{ | ||
// | ||
} | ||
} |