diff --git a/.travis.yml b/.travis.yml index a0e0b75f7..db845be85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,19 +18,19 @@ services: env: global: - - TESTS_ZEND_CACHE_APC_ENABLED=true - - TESTS_ZEND_CACHE_MEMCACHED_ENABLED=true - - TESTS_ZEND_CACHE_MEMCACHED_HOST='127.0.0.1' - - TESTS_ZEND_CACHE_MEMCACHED_PORT=11211 - - TESTS_ZEND_CACHE_MEMCACHE_ENABLED=true - - TESTS_ZEND_CACHE_MEMCACHE_HOST=$TESTS_ZEND_CACHE_MEMCACHED_HOST - - TESTS_ZEND_CACHE_MEMCACHE_PORT=$TESTS_ZEND_CACHE_MEMCACHED_PORT - - TESTS_ZEND_CACHE_MONGODB_ENABLED=true - - TESTS_ZEND_CACHE_REDIS_ENABLED=true - - TESTS_ZEND_CACHE_REDIS_HOST='127.0.0.1' - - TESTS_ZEND_CACHE_REDIS_PORT=6379 - - TESTS_ZEND_CACHE_REDIS_PASSWORD='' - - TESTS_ZEND_CACHE_REDIS_DATABASE=0 + - TESTS_ZEND_CACHE_APC_ENABLED: true + - TESTS_ZEND_CACHE_MEMCACHED_ENABLED: true + - TESTS_ZEND_CACHE_MEMCACHED_HOST: "127.0.0.1" + - TESTS_ZEND_CACHE_MEMCACHED_PORT: 11211 + - TESTS_ZEND_CACHE_MEMCACHE_ENABLED: true + - TESTS_ZEND_CACHE_MEMCACHE_HOST: $TESTS_ZEND_CACHE_MEMCACHED_HOST + - TESTS_ZEND_CACHE_MEMCACHE_PORT: $TESTS_ZEND_CACHE_MEMCACHED_PORT + - TESTS_ZEND_CACHE_MONGODB_ENABLED: true + - TESTS_ZEND_CACHE_REDIS_ENABLED: true + - TESTS_ZEND_CACHE_REDIS_HOST: "127.0.0.1" + - TESTS_ZEND_CACHE_REDIS_PORT: 6379 + - TESTS_ZEND_CACHE_REDIS_PASSWORD: "" + - TESTS_ZEND_CACHE_REDIS_DATABASE: 0 matrix: fast_finish: true @@ -39,15 +39,35 @@ matrix: env: - EXECUTE_CS_CHECK=true - PECL_INSTALL_APCU='apcu-4.0.8' + - php: 5.5 + env: + - SERVICE_MANAGER_VERSION="^2.7.5" + - EVENT_MANAGER_VERSION="^2.6.2" + - PECL_INSTALL_APCU='apcu-4.0.8' - php: 5.6 env: - EXECUTE_TEST_COVERALLS=true - PECL_INSTALL_APCU='apcu-4.0.8' + - php: 5.6 + env: + - SERVICE_MANAGER_VERSION="^2.7.5" + - EVENT_MANAGER_VERSION="^2.6.2" + - PECL_INSTALL_APCU='apcu-4.0.8' - php: 7 env: - PECL_INSTALL_APCU='apcu' - PECL_INSTALL_APCU_BC='apcu_bc-beta' + - php: 7 + env: + - SERVICE_MANAGER_VERSION="^2.7.5" + - EVENT_MANAGER_VERSION="^2.6.2" + - PECL_INSTALL_APCU='apcu' + - PECL_INSTALL_APCU_BC='apcu_bc-beta' - php: hhvm + - php: hhvm + env: + - SERVICE_MANAGER_VERSION="^2.7.5" + - EVENT_MANAGER_VERSION="^2.6.2" allow_failures: - php: 7 - php: hhvm @@ -60,11 +80,16 @@ before_install: - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi - composer self-update - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi + - if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi + - if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi + - if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer remove --dev --no-update zendframework/zend-session ; fi + - if [[ $EVENT_MANAGER_VERSION != '' ]]; then composer require --no-update "zendframework/zend-eventmanager:$EVENT_MANAGER_VERSION" ; fi + - if [[ $EVENT_MANAGER_VERSION == '' ]]; then composer require --no-update "zendframework/zend-eventmanager:^3.0" ; fi install: - travis_retry composer install --no-interaction --ignore-platform-reqs - if [[ $PECL_INSTALL_APCU != '' ]]; then echo "yes\nno\n" | pecl install $PECL_INSTALL_APCU || return 0 ; fi - + # see https://pear.php.net/bugs/bug.php?id=21007 # pecl install adds the "extension=*.so" directive on top of php.ini which results in wrong extension order # -> Attach another ini file loading the extension kind of solves the issue. diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2364899..fc27463d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 3.0.0 - TBD +## 2.6.0 - TBD ### Added @@ -18,10 +18,12 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- [#22](https://github.com/zendframework/zend-cache/pull/22) updates the - component to the v3 version of zend-servicemanager. -- [#22](https://github.com/zendframework/zend-cache/pull/22) updates the - component to the v3 version of zend-eventmanager. +- [#22](https://github.com/zendframework/zend-cache/pull/22), + [#64](https://github.com/zendframework/zend-cache/pull/64), + [#68](https://github.com/zendframework/zend-cache/pull/68), and + [#69](https://github.com/zendframework/zend-cache/pull/69) update the + component to be forwards-compatible with zend-eventmanager, + zend-servicemanager, and zend-stdlib v3. ## 2.5.4 - TBD diff --git a/composer.json b/composer.json index ff2960c15..8e224c92e 100644 --- a/composer.json +++ b/composer.json @@ -13,14 +13,14 @@ } }, "require": { - "php": ">=5.5", - "zendframework/zend-stdlib": "~2.5", - "zendframework/zend-servicemanager": "dev-develop as 2.7.0", - "zendframework/zend-eventmanager": "dev-develop as 2.7.0" + "php": "^5.5 || ^7.0", + "zendframework/zend-stdlib": "^2.7 || ^3.0", + "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", + "zendframework/zend-eventmanager": "^2.6.2 || ^3.0" }, "require-dev": { - "zendframework/zend-serializer": "dev-develop as 2.6.0", - "zendframework/zend-session": "~2.5", + "zendframework/zend-serializer": "^2.6", + "zendframework/zend-session": "^2.5", "fabpot/php-cs-fixer": "1.7.*", "phpunit/PHPUnit": "~4.0" }, @@ -42,7 +42,7 @@ "extra": { "branch-alias": { "dev-master": "2.5-dev", - "dev-develop": "3.0-dev" + "dev-develop": "2.6-dev" } }, "autoload-dev": { diff --git a/src/PatternPluginManager.php b/src/PatternPluginManager.php index fdb7c98b8..5d4fb474a 100644 --- a/src/PatternPluginManager.php +++ b/src/PatternPluginManager.php @@ -11,6 +11,7 @@ use Zend\ServiceManager\AbstractPluginManager; use Zend\ServiceManager\Factory\InvokableFactory; +use Zend\ServiceManager\Exception\InvalidServiceException; /** * Plugin manager implementation for cache pattern adapters @@ -23,26 +24,43 @@ class PatternPluginManager extends AbstractPluginManager { protected $aliases = [ 'callback' => Pattern\CallbackCache::class, + 'Callback' => Pattern\CallbackCache::class, 'capture' => Pattern\CaptureCache::class, + 'Capture' => Pattern\CaptureCache::class, 'class' => Pattern\ClassCache::class, + 'Class' => Pattern\ClassCache::class, 'object' => Pattern\ObjectCache::class, + 'Object' => Pattern\ObjectCache::class, 'output' => Pattern\OutputCache::class, - 'page' => Pattern\PageCache::class, + 'Output' => Pattern\OutputCache::class, ]; protected $factories = [ - Pattern\CallbackCache::class => InvokableFactory::class, - Pattern\CaptureCache::class => InvokableFactory::class, - Pattern\ClassCache::class => InvokableFactory::class, - Pattern\ObjectCache::class => InvokableFactory::class, - Pattern\OutputCache::class => InvokableFactory::class, - Pattern\PageCache::class => InvokableFactory::class, + Pattern\CallbackCache::class => InvokableFactory::class, + Pattern\CaptureCache::class => InvokableFactory::class, + Pattern\ClassCache::class => InvokableFactory::class, + Pattern\ObjectCache::class => InvokableFactory::class, + Pattern\OutputCache::class => InvokableFactory::class, + + // v2 normalized FQCNs + 'zendcachepatterncallbackcache' => InvokableFactory::class, + 'zendcachepatterncapturecache' => InvokableFactory::class, + 'zendcachepatternclasscache' => InvokableFactory::class, + 'zendcachepatternobjectcache' => InvokableFactory::class, + 'zendcachepatternoutputcache' => InvokableFactory::class, ]; /** * Don't share by default * - * @var array + * @var boolean + */ + protected $shareByDefault = false; + + /** + * Don't share by default + * + * @var boolean */ protected $sharedByDefault = false; @@ -50,4 +68,41 @@ class PatternPluginManager extends AbstractPluginManager * @var string */ protected $instanceOf = Pattern\PatternInterface::class; + + /** + * Validate the plugin is of the expected type (v3). + * + * Validates against `$instanceOf`. + * + * @param mixed $instance + * @throws InvalidServiceException + */ + public function validate($instance) + { + if (! $instance instanceof $this->instanceOf) { + throw new InvalidServiceException(sprintf( + '%s can only create instances of %s; %s is invalid', + get_class($this), + $this->instanceOf, + (is_object($instance) ? get_class($instance) : gettype($instance)) + )); + } + } + + /** + * Validate the plugin is of the expected type (v2). + * + * Proxies to `validate()`. + * + * @param mixed $plugin + * @throws Exception\RuntimeException if invalid + */ + public function validatePlugin($plugin) + { + try { + $this->validate($plugin); + } catch (InvalidServiceException $e) { + throw new Exception\RuntimeException($e->getMessage(), $e->getCode(), $e); + } + } } diff --git a/src/Service/StorageCacheAbstractServiceFactory.php b/src/Service/StorageCacheAbstractServiceFactory.php index e028f3c72..9a38d9a5e 100644 --- a/src/Service/StorageCacheAbstractServiceFactory.php +++ b/src/Service/StorageCacheAbstractServiceFactory.php @@ -10,8 +10,9 @@ namespace Zend\Cache\Service; use Zend\Cache\StorageFactory; -use Zend\ServiceManager\Factory\AbstractFactoryInterface; +use Zend\ServiceManager\AbstractFactoryInterface; use Interop\Container\ContainerInterface; +use Zend\ServiceManager\ServiceLocatorInterface; /** * Storage cache factory for multiple caches. @@ -35,7 +36,7 @@ class StorageCacheAbstractServiceFactory implements AbstractFactoryInterface * @param string $requestedName * @return boolean */ - public function canCreateServiceWithName(ContainerInterface $container, $requestedName) + public function canCreate(ContainerInterface $container, $requestedName) { $config = $this->getConfig($container); if (empty($config)) { @@ -44,6 +45,17 @@ public function canCreateServiceWithName(ContainerInterface $container, $request return (isset($config[$requestedName]) && is_array($config[$requestedName])); } + /** + * @param ServiceLocatorInterface $serviceLocator + * @param string $name + * @param string $requestedName + * @return boolean + */ + public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) + { + return $this->canCreate($serviceLocator, $requestedName); + } + /** * Create an object * @@ -58,6 +70,11 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o return StorageFactory::factory($config[$requestedName]); } + public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) + { + return $this($serviceLocator, $requestedName); + } + /** * Retrieve cache configuration, if any * diff --git a/src/Service/StorageCacheFactory.php b/src/Service/StorageCacheFactory.php index 8e21b49ee..3fe425262 100644 --- a/src/Service/StorageCacheFactory.php +++ b/src/Service/StorageCacheFactory.php @@ -9,9 +9,11 @@ namespace Zend\Cache\Service; +use Zend\Cache\Storage\StorageInterface; use Zend\Cache\StorageFactory; -use Zend\ServiceManager\Factory\FactoryInterface; +use Zend\ServiceManager\FactoryInterface; use Interop\Container\ContainerInterface; +use Zend\ServiceManager\ServiceLocatorInterface; /** * Storage cache factory. @@ -24,4 +26,9 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o $cacheConfig = isset($config['cache']) ? $config['cache'] : []; return StorageFactory::factory($cacheConfig); } + + public function createService(ServiceLocatorInterface $serviceLocator) + { + return $this($serviceLocator, StorageInterface::class); + } } diff --git a/src/Storage/AdapterPluginManager.php b/src/Storage/AdapterPluginManager.php index 5551d199e..bddc515e9 100644 --- a/src/Storage/AdapterPluginManager.php +++ b/src/Storage/AdapterPluginManager.php @@ -9,7 +9,9 @@ namespace Zend\Cache\Storage; +use Zend\Cache\Exception\RuntimeException; use Zend\ServiceManager\AbstractPluginManager; +use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\ServiceManager\Factory\InvokableFactory; /** @@ -25,6 +27,7 @@ class AdapterPluginManager extends AbstractPluginManager 'apc' => Adapter\Apc::class, 'Apc' => Adapter\Apc::class, 'blackhole' => Adapter\BlackHole::class, + 'blackHole' => Adapter\BlackHole::class, 'BlackHole' => Adapter\BlackHole::class, 'dba' => Adapter\Dba::class, 'Dba' => Adapter\Dba::class, @@ -37,47 +40,112 @@ class AdapterPluginManager extends AbstractPluginManager 'memory' => Adapter\Memory::class, 'Memory' => Adapter\Memory::class, 'mongodb' => Adapter\MongoDb::class, + 'mongoDb' => Adapter\MongoDb::class, 'MongoDb' => Adapter\MongoDb::class, 'redis' => Adapter\Redis::class, 'Redis' => Adapter\Redis::class, 'session' => Adapter\Session::class, 'Session' => Adapter\Session::class, 'xcache' => Adapter\XCache::class, + 'xCache' => Adapter\XCache::class, 'XCache' => Adapter\XCache::class, 'wincache' => Adapter\WinCache::class, + 'winCache' => Adapter\WinCache::class, 'WinCache' => Adapter\WinCache::class, 'zendserverdisk' => Adapter\ZendServerDisk::class, + 'zendServerDisk' => Adapter\ZendServerDisk::class, 'ZendServerDisk' => Adapter\ZendServerDisk::class, 'zendservershm' => Adapter\ZendServerShm::class, - 'ZendServerShm' => Adapter\ZendServerShm::class + 'zendServerShm' => Adapter\ZendServerShm::class, + 'ZendServerShm' => Adapter\ZendServerShm::class, ]; protected $factories = [ - Adapter\Apc::class => InvokableFactory::class, - Adapter\BlackHole::class => InvokableFactory::class, - Adapter\Dba::class => InvokableFactory::class, - Adapter\Filesystem::class => InvokableFactory::class, - Adapter\Memcache::class => InvokableFactory::class, - Adapter\Memcached::class => InvokableFactory::class, - Adapter\Memory::class => InvokableFactory::class, - Adapter\MongoDb::class => InvokableFactory::class, - Adapter\Redis::class => InvokableFactory::class, - Adapter\Session::class => InvokableFactory::class, - Adapter\XCache::class => InvokableFactory::class, - Adapter\WinCache::class => InvokableFactory::class, - Adapter\ZendServerDisk::class => InvokableFactory::class, - Adapter\ZendServerShm::class => InvokableFactory::class + Adapter\Apc::class => InvokableFactory::class, + Adapter\BlackHole::class => InvokableFactory::class, + Adapter\Dba::class => InvokableFactory::class, + Adapter\Filesystem::class => InvokableFactory::class, + Adapter\Memcache::class => InvokableFactory::class, + Adapter\Memcached::class => InvokableFactory::class, + Adapter\Memory::class => InvokableFactory::class, + Adapter\MongoDb::class => InvokableFactory::class, + Adapter\Redis::class => InvokableFactory::class, + Adapter\Session::class => InvokableFactory::class, + Adapter\WinCache::class => InvokableFactory::class, + Adapter\XCache::class => InvokableFactory::class, + Adapter\ZendServerDisk::class => InvokableFactory::class, + Adapter\ZendServerShm::class => InvokableFactory::class, + + // v2 normalized FQCNs + 'zendcachestorageadapterapc' => InvokableFactory::class, + 'zendcachestorageadapterblackhole' => InvokableFactory::class, + 'zendcachestorageadapterdba' => InvokableFactory::class, + 'zendcachestorageadapterfilesystem' => InvokableFactory::class, + 'zendcachestorageadaptermemcache' => InvokableFactory::class, + 'zendcachestorageadaptermemcached' => InvokableFactory::class, + 'zendcachestorageadaptermemory' => InvokableFactory::class, + 'zendcachestorageadaptermongodb' => InvokableFactory::class, + 'zendcachestorageadapterredis' => InvokableFactory::class, + 'zendcachestorageadaptersession' => InvokableFactory::class, + 'zendcachestorageadapterwincache' => InvokableFactory::class, + 'zendcachestorageadapterxcache' => InvokableFactory::class, + 'zendcachestorageadapterzendserverdisk' => InvokableFactory::class, + 'zendcachestorageadapterzendservershm' => InvokableFactory::class, ]; /** - * Do not share by default + * Do not share by default (v3) * * @var array */ protected $sharedByDefault = false; + /** + * Don't share by default (v2) + * + * @var boolean + */ + protected $shareByDefault = false; + /** * @var string */ protected $instanceOf = StorageInterface::class; + + /** + * Validate the plugin is of the expected type (v3). + * + * Validates against `$instanceOf`. + * + * @param mixed $instance + * @throws InvalidServiceException + */ + public function validate($instance) + { + if (! $instance instanceof $this->instanceOf) { + throw new InvalidServiceException(sprintf( + '%s can only create instances of %s; %s is invalid', + get_class($this), + $this->instanceOf, + (is_object($instance) ? get_class($instance) : gettype($instance)) + )); + } + } + + /** + * Validate the plugin is of the expected type (v2). + * + * Proxies to `validate()`. + * + * @param mixed $instance + * @throws InvalidServiceException + */ + public function validatePlugin($instance) + { + try { + $this->validate($instance); + } catch (InvalidServiceException $e) { + throw new RuntimeException($e->getMessage(), $e->getCode(), $e); + } + } } diff --git a/src/Storage/PluginManager.php b/src/Storage/PluginManager.php index 172f78be2..b22533d0f 100644 --- a/src/Storage/PluginManager.php +++ b/src/Storage/PluginManager.php @@ -9,7 +9,9 @@ namespace Zend\Cache\Storage; +use Zend\Cache\Exception; use Zend\ServiceManager\AbstractPluginManager; +use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\ServiceManager\Factory\InvokableFactory; /** @@ -23,34 +25,87 @@ class PluginManager extends AbstractPluginManager { protected $aliases = [ 'clearexpiredbyfactor' => Plugin\ClearExpiredByFactor::class, + 'clearExpiredByFactor' => Plugin\ClearExpiredByFactor::class, 'ClearExpiredByFactor' => Plugin\ClearExpiredByFactor::class, 'exceptionhandler' => Plugin\ExceptionHandler::class, + 'exceptionHandler' => Plugin\ExceptionHandler::class, 'ExceptionHandler' => Plugin\ExceptionHandler::class, 'ignoreuserabort' => Plugin\IgnoreUserAbort::class, + 'ignoreUserAbort' => Plugin\IgnoreUserAbort::class, 'IgnoreUserAbort' => Plugin\IgnoreUserAbort::class, 'optimizebyfactor' => Plugin\OptimizeByFactor::class, + 'optimizeByFactor' => Plugin\OptimizeByFactor::class, 'OptimizeByFactor' => Plugin\OptimizeByFactor::class, 'serializer' => Plugin\Serializer::class, 'Serializer' => Plugin\Serializer::class ]; protected $factories = [ - Plugin\ClearExpiredByFactor::class => InvokableFactory::class, - Plugin\ExceptionHandler::class => InvokableFactory::class, - Plugin\IgnoreUserAbort::class => InvokableFactory::class, - Plugin\OptimizeByFactor::class => InvokableFactory::class, - Plugin\Serializer::class => InvokableFactory::class + Plugin\ClearExpiredByFactor::class => InvokableFactory::class, + Plugin\ExceptionHandler::class => InvokableFactory::class, + Plugin\IgnoreUserAbort::class => InvokableFactory::class, + Plugin\OptimizeByFactor::class => InvokableFactory::class, + Plugin\Serializer::class => InvokableFactory::class, + + // v2 normalized FQCNs + 'zendcachestoragepluginclearexpiredbyfactor' => InvokableFactory::class, + 'zendcachestoragepluginexceptionhandler' => InvokableFactory::class, + 'zendcachestoragepluginignoreuserabort' => InvokableFactory::class, + 'zendcachestoragepluginoptimizebyfactor' => InvokableFactory::class, + 'zendcachestoragepluginserializer' => InvokableFactory::class, ]; /** - * Do not share by default + * Do not share by default (v3) * * @var array */ protected $sharedByDefault = false; + /** + * Do not share by default (v2) + * + * @var array + */ + protected $shareByDefault = false; + /** * @var string */ protected $instanceOf = Plugin\PluginInterface::class; + + /** + * {@inheritdoc} + */ + public function validate($instance) + { + if ($instance instanceof $this->instanceOf) { + // we're okay + return; + } + + throw new InvalidServiceException(sprintf( + 'Plugin of type %s is invalid; must implement %s\Plugin\PluginInterface', + (is_object($instance) ? get_class($instance) : gettype($instance)), + __NAMESPACE__ + )); + } + + /** + * Validate the plugin + * + * Checks that the plugin loaded is an instance of Plugin\PluginInterface. + * + * @param mixed $plugin + * @return void + * @throws Exception\RuntimeException if invalid + */ + public function validatePlugin($plugin) + { + try { + $this->validate($plugin); + } catch (InvalidServiceException $e) { + throw new Exception\RuntimeException($e->getMessage(), $e->getCode(), $e); + } + } } diff --git a/test/EventManagerIntrospectionTrait.php b/test/EventManagerIntrospectionTrait.php deleted file mode 100644 index 36c5ec7c5..000000000 --- a/test/EventManagerIntrospectionTrait.php +++ /dev/null @@ -1,136 +0,0 @@ -setAccessible(true); - $listeners = $r->getValue($events); - return array_keys($listeners); - } - - /** - * Retrieve an interable list of listeners for an event. - * - * Given an event and an event manager, returns an iterator with the - * listeners for that event, in priority order. - * - * If $withPriority is true, the key values will be the priority at which - * the given listener is attached. - * - * Do not pass $withPriority if you want to cast the iterator to an array, - * as many listeners will likely have the same priority, and thus casting - * will collapse to the last added. - * - * @param string $event - * @param EventManager $events - * @param bool $withPriority - * @return \Traversable - */ - private function getListenersForEvent($event, EventManager $events, $withPriority = false) - { - $r = new ReflectionProperty($events, 'events'); - $r->setAccessible(true); - $listeners = $r->getValue($events); - - if (! isset($listeners[$event])) { - return $this->traverseListeners([]); - } - - return $this->traverseListeners($listeners[$event], $withPriority); - } - - /** - * Assert that a given listener exists at the specified priority. - * - * @param callable $expectedListener - * @param int $expectedPriority - * @param string $event - * @param EventManager $events - * @param string $message Failure message to use, if any. - */ - private function assertListenerAtPriority( - callable $expectedListener, - $expectedPriority, - $event, - EventManager $events, - $message = '' - ) { - $message = $message ?: sprintf( - 'Listener not found for event "%s" and priority %d', - $event, - $expectedPriority - ); - $listeners = $this->getListenersForEvent($event, $events, true); - $found = false; - foreach ($listeners as $priority => $listener) { - if ($listener === $expectedListener - && $priority === $expectedPriority - ) { - $found = true; - break; - } - } - $this->assertTrue($found, $message); - } - - /** - * Returns an indexed array of listeners for an event. - * - * Returns an indexed array of listeners for an event, in priority order. - * Priority values will not be included; use this only for testing if - * specific listeners are present, or for a count of listeners. - * - * @param string $event - * @param EventManager $events - * @return callable[] - */ - private function getArrayOfListenersForEvent($event, EventManager $events) - { - return iterator_to_array($this->getListenersForEvent($event, $events)); - } - - /** - * Generator for traversing listeners in priority order. - * - * @param array $listeners - * @param bool $withPriority When true, yields priority as key. - */ - public function traverseListeners(array $queue, $withPriority = false) - { - krsort($queue, SORT_NUMERIC); - - foreach ($queue as $priority => $listeners) { - $priority = (int) $priority; - foreach ($listeners as $listener) { - if ($withPriority) { - yield $priority => $listener; - } else { - yield $listener; - } - } - } - } -} diff --git a/test/PatternPluginManagerTest.php b/test/PatternPluginManagerTest.php new file mode 100644 index 000000000..f619d7c64 --- /dev/null +++ b/test/PatternPluginManagerTest.php @@ -0,0 +1,37 @@ +sm = new ServiceManager([ + $config = [ 'services' => [ 'config' => [ 'caches' => [ @@ -42,7 +43,16 @@ public function setUp() 'abstract_factories' => [ 'Zend\Cache\Service\StorageCacheAbstractServiceFactory' ] - ]); + ]; + $this->sm = new ServiceManager(); + if (method_exists($this->sm, 'configure')) { + // v3 + $this->sm->configure($config); + } else { + // v2 + $config = new Config($config); + $config->configureServiceManager($this->sm); + } } public function tearDown() diff --git a/test/Service/StorageCacheFactoryTest.php b/test/Service/StorageCacheFactoryTest.php index 097aefd41..9c4bd7967 100644 --- a/test/Service/StorageCacheFactoryTest.php +++ b/test/Service/StorageCacheFactoryTest.php @@ -10,6 +10,7 @@ namespace ZendTest\Cache\Service; use Zend\Cache; +use Zend\ServiceManager\Config; use Zend\ServiceManager\ServiceManager; /** @@ -24,7 +25,7 @@ public function setUp() { Cache\StorageFactory::resetAdapterPluginManager(); Cache\StorageFactory::resetPluginManager(); - $this->sm = new ServiceManager([ + $config = [ 'services' => [ 'config' => [ 'cache' => [ @@ -36,7 +37,16 @@ public function setUp() 'factories' => [ 'CacheFactory' => \Zend\Cache\Service\StorageCacheFactory::class ] - ]); + ]; + $this->sm = new ServiceManager(); + if (method_exists($this->sm, 'configure')) { + // v3 + $this->sm->configure($config); + } else { + // v2 + $config = new Config($config); + $config->configureServiceManager($this->sm); + } } public function tearDown() diff --git a/test/Storage/Adapter/SessionTest.php b/test/Storage/Adapter/SessionTest.php index b2ad3d855..fba130d57 100644 --- a/test/Storage/Adapter/SessionTest.php +++ b/test/Storage/Adapter/SessionTest.php @@ -20,6 +20,14 @@ class SessionTest extends CommonAdapterTest { public function setUp() { + if (! class_exists(SessionContainer::class)) { + $this->markTestSkipped( + 'Skipping zend-session-related tests until that component is ' + . 'forwards-compatible with zend-stdlib, zend-servicemanager, ' + . 'and zend-eventmanager v3' + ); + } + $_SESSION = []; SessionContainer::setDefaultManager(null); $sessionContainer = new SessionContainer('Default'); @@ -35,6 +43,10 @@ public function setUp() public function tearDown() { + if (! class_exists(SessionContainer::class)) { + return; + } + $_SESSION = []; SessionContainer::setDefaultManager(null); } diff --git a/test/Storage/AdapterPluginManagerTest.php b/test/Storage/AdapterPluginManagerTest.php new file mode 100644 index 000000000..0a3322fd2 --- /dev/null +++ b/test/Storage/AdapterPluginManagerTest.php @@ -0,0 +1,56 @@ +commonPluginAliasesResolve($alias, $expected); + } catch (ServiceNotCreatedException $e) { + // if we get as far as "extension not loaded" we've hit the constructor: alias has resolved + if (! $e->getPrevious() instanceof ExtensionNotLoadedException) { + $this->fail($e->getMessage()); + } + } + } + + protected function getPluginManager() + { + return new AdapterPluginManager(new ServiceManager()); + } + + protected function getV2InvalidPluginException() + { + return RuntimeException::class; + } + + protected function getInstanceOf() + { + return StorageInterface::class; + } +} diff --git a/test/Storage/Plugin/ClearExpiredByFactorTest.php b/test/Storage/Plugin/ClearExpiredByFactorTest.php index a15d3d09e..87c52db0a 100644 --- a/test/Storage/Plugin/ClearExpiredByFactorTest.php +++ b/test/Storage/Plugin/ClearExpiredByFactorTest.php @@ -9,18 +9,18 @@ namespace ZendTest\Cache\Storage\Plugin; +use ArrayObject; use Zend\Cache; use Zend\Cache\Storage\PostEvent; +use Zend\EventManager\Test\EventListenerIntrospectionTrait; use ZendTest\Cache\Storage\TestAsset\ClearExpiredMockAdapter; -use ZendTest\Cache\EventManagerIntrospectionTrait; -use ArrayObject; /** * @covers Zend\Cache\Storage\Plugin\ClearExpiredByFactor */ class ClearExpiredByFactorTest extends CommonPluginTest { - use EventManagerIntrospectionTrait; + use EventListenerIntrospectionTrait; /** * The storage adapter diff --git a/test/Storage/Plugin/ExceptionHandlerTest.php b/test/Storage/Plugin/ExceptionHandlerTest.php index 2615a6519..da89ea7f9 100644 --- a/test/Storage/Plugin/ExceptionHandlerTest.php +++ b/test/Storage/Plugin/ExceptionHandlerTest.php @@ -9,18 +9,18 @@ namespace ZendTest\Cache\Storage\Plugin; +use ArrayObject; use Zend\Cache; use Zend\Cache\Storage\ExceptionEvent; +use Zend\EventManager\Test\EventListenerIntrospectionTrait; use ZendTest\Cache\Storage\TestAsset\MockAdapter; -use ArrayObject; -use ZendTest\Cache\EventManagerIntrospectionTrait; /** * @covers Zend\Cache\Storage\Plugin\ExceptionHandler */ class ExceptionHandlerTest extends CommonPluginTest { - use EventManagerIntrospectionTrait; + use EventListenerIntrospectionTrait; /** * The storage adapter diff --git a/test/Storage/Plugin/IgnoreUserAbortTest.php b/test/Storage/Plugin/IgnoreUserAbortTest.php index 8684e2a08..60c314ac0 100644 --- a/test/Storage/Plugin/IgnoreUserAbortTest.php +++ b/test/Storage/Plugin/IgnoreUserAbortTest.php @@ -11,7 +11,7 @@ use Zend\Cache; use Zend\Cache\Storage\Event; -use ZendTest\Cache\EventManagerIntrospectionTrait; +use Zend\EventManager\Test\EventListenerIntrospectionTrait; /** * @group Zend_Cache @@ -19,7 +19,7 @@ */ class IgnoreUserAbortTest extends CommonPluginTest { - use EventManagerIntrospectionTrait; + use EventListenerIntrospectionTrait; /** * The storage adapter diff --git a/test/Storage/Plugin/OptimizeByFactorTest.php b/test/Storage/Plugin/OptimizeByFactorTest.php index 2c78ff65d..7358a6fce 100644 --- a/test/Storage/Plugin/OptimizeByFactorTest.php +++ b/test/Storage/Plugin/OptimizeByFactorTest.php @@ -9,18 +9,18 @@ namespace ZendTest\Cache\Storage\Plugin; +use ArrayObject; use Zend\Cache; use Zend\Cache\Storage\PostEvent; +use Zend\EventManager\Test\EventListenerIntrospectionTrait; use ZendTest\Cache\Storage\TestAsset\OptimizableMockAdapter; -use ArrayObject; -use ZendTest\Cache\EventManagerIntrospectionTrait; /** * @covers Zend\Cache\Storage\Plugin\OptimizeByFactor */ class OptimizeByFactorTest extends CommonPluginTest { - use EventManagerIntrospectionTrait; + use EventListenerIntrospectionTrait; /** * The storage adapter diff --git a/test/Storage/Plugin/SerializerTest.php b/test/Storage/Plugin/SerializerTest.php index a3fada1c0..28b802683 100644 --- a/test/Storage/Plugin/SerializerTest.php +++ b/test/Storage/Plugin/SerializerTest.php @@ -9,11 +9,11 @@ namespace ZendTest\Cache\Storage\Plugin; +use ArrayObject; use Zend\Cache; use Zend\Cache\Storage\Event; use Zend\Cache\Storage\PostEvent; -use ArrayObject; -use ZendTest\Cache\EventManagerIntrospectionTrait; +use Zend\EventManager\Test\EventListenerIntrospectionTrait; /** * @group Zend_Cache @@ -21,7 +21,7 @@ */ class SerializerTest extends CommonPluginTest { - use EventManagerIntrospectionTrait; + use EventListenerIntrospectionTrait; /** * The storage adapter diff --git a/test/Storage/PluginManagerTest.php b/test/Storage/PluginManagerTest.php new file mode 100644 index 000000000..11a89b9c3 --- /dev/null +++ b/test/Storage/PluginManagerTest.php @@ -0,0 +1,37 @@ +