-
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.
- Loading branch information
1 parent
2ca07e8
commit 1251f63
Showing
1 changed file
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Support; | ||
|
||
use Illuminate\Container\Container; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Events\Dispatcher; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Facade; | ||
use Illuminate\Support\Testing\Fakes\EventFake; | ||
use Mockery; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SupportFacadesEventTest extends TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->events = Mockery::spy(Dispatcher::class); | ||
|
||
$container = new Container; | ||
$container->instance('events', $this->events); | ||
|
||
Facade::setFacadeApplication($container); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
Event::clearResolvedInstances(); | ||
|
||
Mockery::close(); | ||
} | ||
|
||
public function testFakeFor() | ||
{ | ||
Event::fakeFor(function () { | ||
(new FakeForStub())->dispatch(); | ||
|
||
Event::assertDispatched(EventStub::class); | ||
}); | ||
|
||
$this->events->shouldReceive('dispatch')->once(); | ||
|
||
(new FakeForStub())->dispatch(); | ||
} | ||
|
||
public function testFakeForSwapsDispatchers() | ||
{ | ||
Event::fakeFor(function () { | ||
$this->assertInstanceOf(EventFake::class, Event::getFacadeRoot()); | ||
$this->assertInstanceOf(EventFake::class, Model::getEventDispatcher()); | ||
}); | ||
|
||
$this->assertSame($this->events, Event::getFacadeRoot()); | ||
$this->assertSame($this->events, Model::getEventDispatcher()); | ||
} | ||
} | ||
|
||
class FakeForStub | ||
{ | ||
public function dispatch() | ||
{ | ||
Event::dispatch(EventStub::class); | ||
} | ||
} |