8000 [5.6] Allow faking events for only a specific part by arjanwestdorp · Pull Request #24230 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[5.6] Allow faking events for only a specific part #24230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 18, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests
  • Loading branch information
arjanwestdorp committed May 16, 2018
commit 1251f63d0b702ccaa9da70bf32741e6a9488ac4a
66 changes: 66 additions & 0 deletions tests/Support/SupportFacadesEventTest.php
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);
}
}
0