From 1251f63d0b702ccaa9da70bf32741e6a9488ac4a Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 16 May 2018 15:28:52 +0200 Subject: [PATCH] Added tests --- tests/Support/SupportFacadesEventTest.php | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/Support/SupportFacadesEventTest.php diff --git a/tests/Support/SupportFacadesEventTest.php b/tests/Support/SupportFacadesEventTest.php new file mode 100644 index 000000000000..0933b4e3ace8 --- /dev/null +++ b/tests/Support/SupportFacadesEventTest.php @@ -0,0 +1,66 @@ +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); + } +}