Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Illuminate\Tests\Support; use Illuminate\Cache\CacheManager; use Illumin..
Decoded Output download
<?php
namespace Illuminate\Tests\Support;
use Illuminate\Cache\CacheManager;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Cache\Events\RetrievingKey;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Container\Container;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Testing\Fakes\EventFake;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class SupportFacadesEventTest extends TestCase
{
private $events;
protected function setUp(): void
{
parent::setUp();
$this->events = m::mock(Dispatcher::class);
$container = new Container;
$container->instance('events', $this->events);
$container->alias('events', DispatcherContract::class);
$container->instance('cache', new CacheManager($container));
$container->instance('config', new ConfigRepository($this->getCacheConfig()));
Facade::setFacadeApplication($container);
}
protected function tearDown(): void
{
Event::clearResolvedInstances();
Event::setFacadeApplication(null);
m::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()
{
$arrayRepository = Cache::store('array');
Event::fakeFor(function () use ($arrayRepository) {
$this->assertInstanceOf(EventFake::class, Event::getFacadeRoot());
$this->assertInstanceOf(EventFake::class, Model::getEventDispatcher());
$this->assertInstanceOf(EventFake::class, $arrayRepository->getEventDispatcher());
});
$this->assertSame($this->events, Event::getFacadeRoot());
$this->assertSame($this->events, Model::getEventDispatcher());
$this->assertSame($this->events, $arrayRepository->getEventDispatcher());
}
public function testFakeSwapsDispatchersInResolvedCacheRepositories()
{
$arrayRepository = Cache::store('array');
$this->events->shouldReceive('dispatch')->times(2);
$arrayRepository->get('foo');
Event::fake();
$arrayRepository->get('bar');
Event::assertDispatched(RetrievingKey::class);
Event::assertDispatched(CacheMissed::class);
}
protected function getCacheConfig()
{
return [
'cache' => [
'stores' => [
'array' => [
'driver' => 'array',
],
],
],
];
}
}
class FakeForStub
{
public function dispatch()
{
Event::dispatch(EventStub::class);
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace Illuminate\Tests\Support;
use Illuminate\Cache\CacheManager;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Cache\Events\RetrievingKey;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Container\Container;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Testing\Fakes\EventFake;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class SupportFacadesEventTest extends TestCase
{
private $events;
protected function setUp(): void
{
parent::setUp();
$this->events = m::mock(Dispatcher::class);
$container = new Container;
$container->instance('events', $this->events);
$container->alias('events', DispatcherContract::class);
$container->instance('cache', new CacheManager($container));
$container->instance('config', new ConfigRepository($this->getCacheConfig()));
Facade::setFacadeApplication($container);
}
protected function tearDown(): void
{
Event::clearResolvedInstances();
Event::setFacadeApplication(null);
m::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()
{
$arrayRepository = Cache::store('array');
Event::fakeFor(function () use ($arrayRepository) {
$this->assertInstanceOf(EventFake::class, Event::getFacadeRoot());
$this->assertInstanceOf(EventFake::class, Model::getEventDispatcher());
$this->assertInstanceOf(EventFake::class, $arrayRepository->getEventDispatcher());
});
$this->assertSame($this->events, Event::getFacadeRoot());
$this->assertSame($this->events, Model::getEventDispatcher());
$this->assertSame($this->events, $arrayRepository->getEventDispatcher());
}
public function testFakeSwapsDispatchersInResolvedCacheRepositories()
{
$arrayRepository = Cache::store('array');
$this->events->shouldReceive('dispatch')->times(2);
$arrayRepository->get('foo');
Event::fake();
$arrayRepository->get('bar');
Event::assertDispatched(RetrievingKey::class);
Event::assertDispatched(CacheMissed::class);
}
protected function getCacheConfig()
{
return [
'cache' => [
'stores' => [
'array' => [
'driver' => 'array',
],
],
],
];
}
}
class FakeForStub
{
public function dispatch()
{
Event::dispatch(EventStub::class);
}
}
Function Calls
None |
Stats
MD5 | 320cbdc380e0d5eb0071a426b6750fd0 |
Eval Count | 0 |
Decode Time | 88 ms |