Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanwestdorp committed May 16, 2018
1 parent 2ca07e8 commit 1251f63
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/Support/SupportFacadesEventTest.php
@@ -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);
}
}

0 comments on commit 1251f63

Please sign in to comment.