-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Non faked events should be properly dispatched (#25185)
- Loading branch information
1 parent
a86665a
commit 099b79a
Showing
2 changed files
with
99 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Events; | ||
|
||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Schema\Blueprint; | ||
|
||
class EventFakeTest extends TestCase | ||
{ | ||
/** | ||
* Define environment setup. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return void | ||
*/ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('app.debug', 'true'); | ||
|
||
// Database configuration | ||
$app['config']->set('database.default', 'testbench'); | ||
|
||
$app['config']->set('database.connections.testbench', [ | ||
'driver' => 'mysql', | ||
'host' => env('DB_HOST', '127.0.0.1'), | ||
'username' => 'root', | ||
'password' => '', | ||
'database' => 'forge', | ||
'prefix' => '', | ||
]); | ||
} | ||
|
||
/** | ||
* Setup the test environment. | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('posts', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('title'); | ||
$table->string('slug')->unique(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Clean up the testing environment before the next test. | ||
* | ||
* @return void | ||
*/ | ||
protected function tearDown() | ||
{ | ||
Schema::dropIfExists('posts'); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
public function testNonFakedEventGetsProperlyDispatched() | ||
{ | ||
Event::fake(NonImportantEvent::class); | ||
Post::observe([PostObserver::class]); | ||
|
||
$post = new Post(); | ||
$post->title = 'xyz'; | ||
$post->save(); | ||
|
||
$this->assertSame('xyz-Test', $post->slug); | ||
|
||
Event::assertNotDispatched(NonImportantEvent::class); | ||
} | ||
} | ||
|
||
class Post extends Model | ||
{ | ||
public $table = 'posts'; | ||
} | ||
|
||
class NonImportantEvent | ||
{ | ||
} | ||
|
||
class PostObserver | ||
{ | ||
public function saving(Post $post) | ||
{ | ||
$post->slug = sprintf('%s-Test', $post->title); | ||
} | ||
} |