/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Support/SupportFacadesEventTest.php
132 строки
4 KB
Jason McCreary
[13.x] Mockery cleanup (#61117)
10 авг 2026, 20:23
Не верифицирован
10 авг 2026, 20:23
2ee40ee
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Support; use Illuminate\Cache\CacheManager; use Illuminate\Cache\Events\CacheFlushed; use Illuminate\Cache\Events\CacheFlushing; use Illuminate\Cache\Events\CacheLocksFlushed; use Illuminate\Cache\Events\CacheLocksFlushing; 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; use PHPUnit\Framework\TestCase; class SupportFacadesEventTest extends TestCase { private $events; protected function setUp(): void { $this->events = Mockery::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 { Facade::clearResolvedInstances(); Facade::setFacadeApplication(null); } public function testFakeFor() { Event::fakeFor(function () { (new FakeForStub)->dispatch(); Event::assertDispatched(EventStub::class); }); $this->events->expects('dispatch'); (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->expects('dispatch')->times(2); $arrayRepository->get('foo'); Event::fake(); $arrayRepository->get('bar'); Event::assertDispatched(RetrievingKey::class); Event::assertDispatched(CacheMissed::class); } public function testCacheFlushDispatchesEvent() { $arrayRepository = Cache::store('array'); Event::fake(); $arrayRepository->clear(); Event::assertDispatched(CacheFlushing::class); Event::assertDispatched(CacheFlushed::class); } public function testCacheFlushLocksDispatchesEvent() { $arrayRepository = Cache::store('array'); Event::fake(); $arrayRepository->flushLocks(); Event::assertDispatched(CacheLocksFlushing::class); Event::assertDispatched(CacheLocksFlushed::class); } protected function getCacheConfig() { return [ 'cache' => [ 'stores' => [ 'array' => [ 'driver' => 'array', ], ], ], ]; } } class FakeForStub { public function dispatch() { Event::dispatch(EventStub::class); } }