|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Codeages\PluginBundle\Tests\Event; |
| 4 | + |
| 5 | +use Codeages\Biz\Framework\Event\Event; |
| 6 | +use Codeages\PluginBundle\Event\LazyDispatcher; |
| 7 | +use Codeages\PluginBundle\Event\LazySubscribers; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 10 | + |
| 11 | +class LazyDispatcherTest extends TestCase |
| 12 | +{ |
| 13 | + const CACHE_DIR = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'cache'; |
| 14 | + |
| 15 | + public function testDispatch() |
| 16 | + { |
| 17 | + $kernel = $this->mockKernel(); |
| 18 | + |
| 19 | + $container = new ContainerBuilder(); |
| 20 | + $container->set('kernel', $kernel); |
| 21 | + $container->set('codeags_plugin.event.lazy_subscribers', new LazySubscribers($container)); |
| 22 | + |
| 23 | + $lazyDispatcher = new LazyDispatcher($container); |
| 24 | + $lazyDispatcher->dispatch(new Event(), 'test4'); |
| 25 | + |
| 26 | + $this->assertTrue(true); |
| 27 | + |
| 28 | + unlink(self::CACHE_DIR.DIRECTORY_SEPARATOR.'event_map.php'); |
| 29 | + unlink(self::CACHE_DIR.DIRECTORY_SEPARATOR.'event_map.php.meta'); |
| 30 | + } |
| 31 | + |
| 32 | + private function mockKernel() |
| 33 | + { |
| 34 | + $testKernel = $this->getMockBuilder('Codeages\PluginBundle\Tests\Event\Fixture\TestKernel') |
| 35 | + ->setConstructorArgs(['test', false]) |
| 36 | + ->onlyMethods(['getCacheDir']) |
| 37 | + ->getMockForAbstractClass(); |
| 38 | + |
| 39 | + $testKernel->method('getCacheDir') |
| 40 | + ->willReturn(__DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'cache'); |
| 41 | + |
| 42 | + if (file_exists(self::CACHE_DIR.DIRECTORY_SEPARATOR.'event_map.php')) { |
| 43 | + unlink(self::CACHE_DIR.DIRECTORY_SEPARATOR.'event_map.php'); |
| 44 | + } |
| 45 | + |
| 46 | + if (file_exists(self::CACHE_DIR.DIRECTORY_SEPARATOR.'event_map.php.meta')) { |
| 47 | + unlink(self::CACHE_DIR.DIRECTORY_SEPARATOR.'event_map.php.meta'); |
| 48 | + } |
| 49 | + |
| 50 | + return $testKernel; |
| 51 | + } |
| 52 | +} |
0 commit comments