diff --git a/.gitattributes b/.gitattributes index 84d967a71..b1742eb27 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,3 +11,4 @@ /phpcs.xml export-ignore /phpunit.xml.dist export-ignore /test/ export-ignore +/stubs/ diff --git a/autoload/adapterPluginManagerPolyfill.php b/autoload/adapterPluginManagerPolyfill.php new file mode 100644 index 000000000..dd3da4aaf --- /dev/null +++ b/autoload/adapterPluginManagerPolyfill.php @@ -0,0 +1,17 @@ +fail("Can't create temporary cache directory: {$err['message']}"); } + ErrorHandler::start(E_USER_DEPRECATED); $this->storage = StorageFactory::adapterFactory('filesystem', [ 'cache_dir' => $this->tmpCacheDir, ]); + ErrorHandler::clean(); parent::__construct(); } diff --git a/benchmark/MemoryStorageAdapterBench.php b/benchmark/MemoryStorageAdapterBench.php index 957e9369f..eefcdc958 100644 --- a/benchmark/MemoryStorageAdapterBench.php +++ b/benchmark/MemoryStorageAdapterBench.php @@ -3,6 +3,7 @@ namespace ZendBench\Cache; use Zend\Cache\StorageFactory; +use Zend\Stdlib\ErrorHandler; /** * @Revs(100) @@ -13,8 +14,10 @@ class MemoryStorageAdapterBench extends CommonStorageAdapterBench { public function __construct() { + ErrorHandler::start(E_USER_DEPRECATED); // instantiate the storage adapter $this->storage = StorageFactory::adapterFactory('memory'); + ErrorHandler::clean(); parent::__construct(); } diff --git a/composer.json b/composer.json index 7d8f29faf..0dfdfc819 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,8 @@ }, "autoload": { "files": [ - "autoload/patternPluginManagerPolyfill.php" + "autoload/patternPluginManagerPolyfill.php", + "autoload/adapterPluginManagerPolyfill.php" ], "psr-4": { "Zend\\Cache\\": "src/" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 98938de96..2d6949788 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -55,5 +55,7 @@ + + diff --git a/src/PatternFactory.php b/src/PatternFactory.php index 61ded14cc..a1b5a3f5e 100644 --- a/src/PatternFactory.php +++ b/src/PatternFactory.php @@ -13,8 +13,12 @@ use Zend\Stdlib\ArrayUtils; use Zend\ServiceManager\ServiceManager; +/** + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. + */ abstract class PatternFactory { + /** * The pattern manager * @@ -25,13 +29,21 @@ abstract class PatternFactory /** * Instantiate a cache pattern * - * @param string|Pattern\PatternInterface $patternName + * @param string|Pattern\PatternInterface $patternName * @param array|Traversable|Pattern\PatternOptions $options + * * @return Pattern\PatternInterface * @throws Exception\InvalidArgumentException + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function factory($patternName, $options = []) { + trigger_error(sprintf( + '%s is deprecated; please use %s::get instead', + __METHOD__, + PatternPluginManager::class + ), E_USER_DEPRECATED); + if ($options instanceof Pattern\PatternOptions) { $options = $options->toArray(); } @@ -51,6 +63,7 @@ public static function factory($patternName, $options = []) if ($patternName instanceof Pattern\PatternInterface) { $patternName->setOptions(new Pattern\PatternOptions($options)); + return $patternName; } @@ -61,9 +74,15 @@ public static function factory($patternName, $options = []) * Get the pattern plugin manager * * @return PatternPluginManager + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function getPluginManager() { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + if (static::$plugins === null) { static::$plugins = new PatternPluginManager(new ServiceManager); } @@ -75,10 +94,17 @@ public static function getPluginManager() * Set the pattern plugin manager * * @param PatternPluginManager $plugins + * * @return void + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function setPluginManager(PatternPluginManager $plugins) { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + static::$plugins = $plugins; } @@ -86,9 +112,15 @@ public static function setPluginManager(PatternPluginManager $plugins) * Reset pattern plugin manager to default * * @return void + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function resetPluginManager() { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + static::$plugins = null; } } diff --git a/src/PatternPluginManager/PatternPluginManagerTrait.php b/src/PatternPluginManager/PatternPluginManagerTrait.php index d05160585..1cb5f35b7 100644 --- a/src/PatternPluginManager/PatternPluginManagerTrait.php +++ b/src/PatternPluginManager/PatternPluginManagerTrait.php @@ -12,7 +12,7 @@ use Zend\ServiceManager\Exception\InvalidServiceException; /** - * Trait providing common logic between FormElementManager implementations. + * Trait providing common logic between PatternPluginManager implementations. * * Trait does not define properties, as the properties common between the * two versions are originally defined in their parent class, causing a diff --git a/src/Storage/AdapterPluginManager/AdapterPluginManagerTrait.php b/src/Storage/AdapterPluginManager/AdapterPluginManagerTrait.php new file mode 100644 index 000000000..ea5b37103 --- /dev/null +++ b/src/Storage/AdapterPluginManager/AdapterPluginManagerTrait.php @@ -0,0 +1,145 @@ +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); + } + } + + private function parseOptions(array $options) + { + $plugins = []; + if (array_key_exists('plugins', $options)) { + $plugins = $options['plugins'] ?: []; + unset($options['plugins']); + } + + $adapter = $options; + + if (isset($options['options'])) { + $adapter = $options['options']; + } + + if (isset($options['adapter']['options']) && is_array($options['adapter']['options'])) { + $adapter = ArrayUtils::merge($adapter, $options['adapter']['options']); + } + + return [$adapter, $plugins]; + } + + /** + * Attaches plugins by using the provided plugin manager. + * + * @param StorageInterface $adapter + * @param PluginManager $pluginManager + * @param array $plugins + * + * @return void + * @throws Exception\RuntimeException if adapter does not implement `EventsCapableInterface` + * @throws Exception\InvalidArgumentException if the plugin configuration does not fit specification. + */ + private function attachPlugins(StorageInterface $adapter, PluginManager $pluginManager, array $plugins) + { + if (! $adapter instanceof EventsCapableInterface) { + throw new Exception\RuntimeException(sprintf( + "The adapter '%s' doesn't implement '%s' and therefore can't handle plugins", + get_class($adapter), + EventsCapableInterface::class + )); + } + + foreach ($plugins as $k => $v) { + $pluginPrio = 1; // default priority + + if (is_string($k)) { + if (! is_array($v)) { + throw new Exception\InvalidArgumentException( + "'plugins.{$k}' needs to be an array" + ); + } + $pluginName = $k; + $pluginOptions = $v; + } elseif (is_array($v)) { + if (! isset($v['name'])) { + throw new Exception\InvalidArgumentException( + "Invalid plugins[{$k}] or missing plugins[{$k}].name" + ); + } + $pluginName = (string) $v['name']; + + if (isset($v['options'])) { + $pluginOptions = $v['options']; + } else { + $pluginOptions = []; + } + + if (isset($v['priority'])) { + $pluginPrio = $v['priority']; + } + } else { + $pluginName = $v; + $pluginOptions = []; + } + + $plugin = $pluginManager->get($pluginName, $pluginOptions); + if (! $adapter->hasPlugin($plugin)) { + $adapter->addPlugin($plugin, $pluginPrio); + } + } + } +} diff --git a/src/Storage/AdapterPluginManager.php b/src/Storage/AdapterPluginManager/AdapterPluginManagerV2Polyfill.php similarity index 80% rename from src/Storage/AdapterPluginManager.php rename to src/Storage/AdapterPluginManager/AdapterPluginManagerV2Polyfill.php index 98b73f35d..272bdbac1 100644 --- a/src/Storage/AdapterPluginManager.php +++ b/src/Storage/AdapterPluginManager/AdapterPluginManagerV2Polyfill.php @@ -3,26 +3,28 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ +namespace Zend\Cache\Storage\AdapterPluginManager; -namespace Zend\Cache\Storage; - -use Zend\Cache\Exception\RuntimeException; +use Zend\Cache\Storage\PluginManager; +use Zend\Cache\Storage\StorageInterface; use Zend\ServiceManager\AbstractPluginManager; -use Zend\ServiceManager\Exception\InvalidServiceException; +use Zend\Cache\Storage\Adapter; use Zend\ServiceManager\Factory\InvokableFactory; /** - * Plugin manager implementation for cache storage adapters + * zend-servicemanager v2-compatible plugin manager implementation for cache pattern adapters. * - * Enforces that adapters retrieved are instances of - * StorageInterface. Additionally, it registers a number of default - * adapters available. + * Enforces that retrieved adapters are instances of + * Pattern\PatternInterface. Additionally, it registers a number of default + * patterns available. */ -class AdapterPluginManager extends AbstractPluginManager +class AdapterPluginManagerV2Polyfill extends AbstractPluginManager { + use AdapterPluginManagerTrait; + protected $aliases = [ 'apc' => Adapter\Apc::class, 'Apc' => Adapter\Apc::class, @@ -120,18 +122,18 @@ class AdapterPluginManager extends AbstractPluginManager ]; /** - * Do not share by default (v3) + * Don't share by default (v2) * - * @var array + * @var boolean */ - protected $sharedByDefault = false; + protected $shareByDefault = false; /** - * Don't share by default (v2) + * Don't share by default (v3) * * @var boolean */ - protected $shareByDefault = false; + protected $sharedByDefault = false; /** * @var string @@ -139,39 +141,29 @@ class AdapterPluginManager extends AbstractPluginManager protected $instanceOf = StorageInterface::class; /** - * Validate the plugin is of the expected type (v3). - * - * Validates against `$instanceOf`. + * Override get to inject options as AdapterOptions instance. * - * @param mixed $instance - * @throws InvalidServiceException + * {@inheritDoc} */ - public function validate($instance) + public function get($plugin, $options = [], $usePeeringServiceManagers = true) { - 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)) - )); + $adapter = parent::get($plugin, [], $usePeeringServiceManagers); + + if (empty($options)) { + return $adapter; } - } - /** - * 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); + list($options, $pluginConfiguration) = $this->parseOptions($options); + + if (! empty($pluginConfiguration)) { + $plugins = $this->serviceLocator->has(PluginManager::class) ? + $this->serviceLocator->get(PluginManager::class) : new PluginManager($this->serviceLocator); + $this->attachPlugins($adapter, $plugins, $pluginConfiguration); } + + /** @var StorageInterface $adapter */ + $adapter->setOptions(new Adapter\AdapterOptions($options)); + + return $adapter; } } diff --git a/src/Storage/AdapterPluginManager/AdapterPluginManagerV3Polyfill.php b/src/Storage/AdapterPluginManager/AdapterPluginManagerV3Polyfill.php new file mode 100644 index 000000000..9f5bf6308 --- /dev/null +++ b/src/Storage/AdapterPluginManager/AdapterPluginManagerV3Polyfill.php @@ -0,0 +1,150 @@ + Adapter\Apc::class, + 'Apc' => Adapter\Apc::class, + 'APC' => Adapter\Apc::class, + 'apcu' => Adapter\Apcu::class, + 'ApcU' => Adapter\Apcu::class, + 'Apcu' => Adapter\Apcu::class, + 'APCu' => Adapter\Apcu::class, + 'black_hole' => Adapter\BlackHole::class, + 'blackhole' => Adapter\BlackHole::class, + 'blackHole' => Adapter\BlackHole::class, + 'BlackHole' => Adapter\BlackHole::class, + 'dba' => Adapter\Dba::class, + 'Dba' => Adapter\Dba::class, + 'DBA' => Adapter\Dba::class, + 'ext_mongo_db' => Adapter\ExtMongoDb::class, + 'extmongodb' => Adapter\ExtMongoDb::class, + 'ExtMongoDb' => Adapter\ExtMongoDb::class, + 'ExtMongoDB' => Adapter\ExtMongoDb::class, + 'extMongoDb' => Adapter\ExtMongoDb::class, + 'extMongoDB' => Adapter\ExtMongoDb::class, + 'filesystem' => Adapter\Filesystem::class, + 'Filesystem' => Adapter\Filesystem::class, + 'memcache' => Adapter\Memcache::class, + 'Memcache' => Adapter\Memcache::class, + 'memcached' => Adapter\Memcached::class, + 'Memcached' => Adapter\Memcached::class, + 'memory' => Adapter\Memory::class, + 'Memory' => Adapter\Memory::class, + 'mongo_db' => Adapter\MongoDb::class, + 'mongodb' => Adapter\MongoDb::class, + 'MongoDb' => Adapter\MongoDb::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, + 'XCache' => Adapter\XCache::class, + 'win_cache' => Adapter\WinCache::class, + 'wincache' => Adapter\WinCache::class, + 'winCache' => Adapter\WinCache::class, + 'WinCache' => Adapter\WinCache::class, + 'zend_server_disk' => Adapter\ZendServerDisk::class, + 'zendserverdisk' => Adapter\ZendServerDisk::class, + 'zendServerDisk' => Adapter\ZendServerDisk::class, + 'ZendServerDisk' => Adapter\ZendServerDisk::class, + 'zend_server_shm' => Adapter\ZendServerShm::class, + 'zendservershm' => Adapter\ZendServerShm::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\Apcu::class => InvokableFactory::class, + Adapter\BlackHole::class => InvokableFactory::class, + Adapter\Dba::class => InvokableFactory::class, + Adapter\ExtMongoDb::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, + ]; + + /** + * Don't share by default (v2) + * + * @var boolean + */ + protected $shareByDefault = false; + + /** + * Don't share by default (v3) + * + * @var boolean + */ + protected $sharedByDefault = false; + + /** + * @var string + */ + protected $instanceOf = StorageInterface::class; + + /** + * Override build to inject options as PatternOptions instance. + * + * {@inheritDoc} + */ + public function build($plugin, array $options = null) + { + $adapter = parent::build($plugin); + + if (empty($options)) { + return $adapter; + } + + list ($options, $pluginConfiguration) = $this->parseOptions($options); + + if (! empty($pluginConfiguration)) { + $plugins = $this->creationContext->has(PluginManager::class) ? + $this->creationContext->get(PluginManager::class) : new PluginManager($this->creationContext); + $this->attachPlugins($adapter, $plugins, $pluginConfiguration); + } + + $adapter->setOptions(new Adapter\AdapterOptions($options)); + return $adapter; + } +} diff --git a/src/StorageFactory.php b/src/StorageFactory.php index 64fa6c268..ad0d6f5c4 100644 --- a/src/StorageFactory.php +++ b/src/StorageFactory.php @@ -11,9 +11,12 @@ use Traversable; use Zend\EventManager\EventsCapableInterface; -use Zend\Stdlib\ArrayUtils; use Zend\ServiceManager\ServiceManager; +use Zend\Stdlib\ArrayUtils; +/** + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. + */ abstract class StorageFactory { /** @@ -34,17 +37,24 @@ abstract class StorageFactory * The storage factory * This can instantiate storage adapters and plugins. * - * @param array|Traversable $cfg + * @param array|Traversable $config * @return Storage\StorageInterface * @throws Exception\InvalidArgumentException + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ - public static function factory($cfg) + public static function factory($config) { - if ($cfg instanceof Traversable) { - $cfg = ArrayUtils::iteratorToArray($cfg); + trigger_error(sprintf( + '%s is deprecated; please use %s::get instead', + __METHOD__, + Storage\AdapterPluginManager::class + ), E_USER_DEPRECATED); + + if ($config instanceof Traversable) { + $config = ArrayUtils::iteratorToArray($config); } - if (! is_array($cfg)) { + if (! is_array($config)) { throw new Exception\InvalidArgumentException( 'The factory needs an associative array ' . 'or a Traversable object as an argument' @@ -52,42 +62,43 @@ public static function factory($cfg) } // instantiate the adapter - if (! isset($cfg['adapter'])) { + if (! isset($config['adapter'])) { throw new Exception\InvalidArgumentException('Missing "adapter"'); } - $adapterName = $cfg['adapter']; + + $adapterName = $config['adapter']; $adapterOptions = []; - if (is_array($cfg['adapter'])) { - if (! isset($cfg['adapter']['name'])) { + if (is_array($config['adapter'])) { + if (! isset($config['adapter']['name'])) { throw new Exception\InvalidArgumentException('Missing "adapter.name"'); } - $adapterName = $cfg['adapter']['name']; - $adapterOptions = isset($cfg['adapter']['options']) ? $cfg['adapter']['options'] : []; + $adapterName = $config['adapter']['name']; + $adapterOptions = isset($config['adapter']['options']) ? $config['adapter']['options'] : []; } - if (isset($cfg['options'])) { - $adapterOptions = array_merge($adapterOptions, $cfg['options']); + if (isset($config['options'])) { + $adapterOptions = ArrayUtils::merge($adapterOptions, $config['options']); } - $adapter = static::adapterFactory((string) $adapterName, $adapterOptions); + $adapter = self::adapterFactory((string) $adapterName, $adapterOptions); // add plugins - if (isset($cfg['plugins'])) { + if (isset($config['plugins'])) { if (! $adapter instanceof EventsCapableInterface) { throw new Exception\RuntimeException(sprintf( "The adapter '%s' doesn't implement '%s' and therefore can't handle plugins", get_class($adapter), - 'Zend\EventManager\EventsCapableInterface' + EventsCapableInterface::class )); } - if (! is_array($cfg['plugins'])) { + if (! is_array($config['plugins'])) { throw new Exception\InvalidArgumentException( 'Plugins needs to be an array' ); } - foreach ($cfg['plugins'] as $k => $v) { + foreach ($config['plugins'] as $k => $v) { $pluginPrio = 1; // default priority if (is_string($k)) { @@ -137,13 +148,19 @@ public static function factory($cfg) * @param array|Traversable|Storage\Adapter\AdapterOptions $options * @return Storage\StorageInterface * @throws Exception\RuntimeException + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function adapterFactory($adapterName, $options = []) { - if ($adapterName instanceof Storage\StorageInterface) { - // $adapterName is already an adapter object - $adapter = $adapterName; - } else { + trigger_error(sprintf( + '%s is deprecated; please use %s::get instead', + __METHOD__, + Storage\AdapterPluginManager::class + ), E_USER_DEPRECATED); + + $adapter = $adapterName; + + if (! $adapterName instanceof Storage\StorageInterface) { $adapter = static::getAdapterPluginManager()->get($adapterName); } @@ -158,9 +175,15 @@ public static function adapterFactory($adapterName, $options = []) * Get the adapter plugin manager * * @return Storage\AdapterPluginManager + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function getAdapterPluginManager() { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + if (static::$adapters === null) { static::$adapters = new Storage\AdapterPluginManager(new ServiceManager); } @@ -172,9 +195,15 @@ public static function getAdapterPluginManager() * * @param Storage\AdapterPluginManager $adapters * @return void + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function setAdapterPluginManager(Storage\AdapterPluginManager $adapters) { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + static::$adapters = $adapters; } @@ -182,9 +211,15 @@ public static function setAdapterPluginManager(Storage\AdapterPluginManager $ada * Resets the internal adapter plugin manager * * @return void + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function resetAdapterPluginManager() { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + static::$adapters = null; } @@ -195,14 +230,19 @@ public static function resetAdapterPluginManager() * @param array|Traversable|Storage\Plugin\PluginOptions $options * @return Storage\Plugin\PluginInterface * @throws Exception\RuntimeException + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function pluginFactory($pluginName, $options = []) { - if ($pluginName instanceof Storage\Plugin\PluginInterface) { - // $pluginName is already a plugin object - $plugin = $pluginName; - } else { - $plugin = static::getPluginManager()->get($pluginName); + trigger_error(sprintf( + '%s is deprecated; please use %s::get instead', + __METHOD__, + Storage\PluginManager::class + ), E_USER_DEPRECATED); + + $plugin = $pluginName; + if (! $pluginName instanceof Storage\Plugin\PluginInterface) { + $plugin = self::getPluginManager()->get($pluginName); } if ($options) { @@ -219,9 +259,15 @@ public static function pluginFactory($pluginName, $options = []) * Get the plugin manager * * @return Storage\PluginManager + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function getPluginManager() { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + if (static::$plugins === null) { static::$plugins = new Storage\PluginManager(new ServiceManager); } @@ -233,9 +279,15 @@ public static function getPluginManager() * * @param Storage\PluginManager $plugins * @return void + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function setPluginManager(Storage\PluginManager $plugins) { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + static::$plugins = $plugins; } @@ -243,9 +295,15 @@ public static function setPluginManager(Storage\PluginManager $plugins) * Resets the internal plugin manager * * @return void + * @deprecated static factories are deprecated as of zendframework 2.9 and may be removed in future major versions. */ public static function resetPluginManager() { + trigger_error(sprintf( + '%s is deprecated', + __METHOD__ + ), E_USER_DEPRECATED); + static::$plugins = null; } } diff --git a/stubs/AdapterPluginManager.php b/stubs/AdapterPluginManager.php new file mode 100644 index 000000000..b7149f6f9 --- /dev/null +++ b/stubs/AdapterPluginManager.php @@ -0,0 +1,22 @@ +markTestSkipped('Enable TESTS_ZEND_CACHE_APC_ENABLED to run this test'); } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); // needed on test expirations @@ -59,6 +61,8 @@ protected function tearDown() // reset ini configurations ini_set('apc.use_request_time', $this->iniUseRequestTime); + + ErrorHandler::clean(); parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/ApcuIntegrationTest.php b/test/Psr/CacheItemPool/ApcuIntegrationTest.php index def88d1ef..e6ec76bdb 100644 --- a/test/Psr/CacheItemPool/ApcuIntegrationTest.php +++ b/test/Psr/CacheItemPool/ApcuIntegrationTest.php @@ -12,6 +12,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @requires extension apcu @@ -22,7 +23,7 @@ class ApcuIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * Restore 'apc.use_request_time' @@ -38,13 +39,14 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); // needed on test expirations $this->iniUseRequestTime = ini_get('apc.use_request_time'); ini_set('apc.use_request_time', 0); + ErrorHandler::start(E_USER_DEPRECATED); parent::setUp(); } @@ -59,6 +61,8 @@ protected function tearDown() // reset ini configurations ini_set('apc.use_request_time', $this->iniUseRequestTime); + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/BlackHoleIntegrationTest.php b/test/Psr/CacheItemPool/BlackHoleIntegrationTest.php index 18b1bbc7f..df6eb1a86 100644 --- a/test/Psr/CacheItemPool/BlackHoleIntegrationTest.php +++ b/test/Psr/CacheItemPool/BlackHoleIntegrationTest.php @@ -10,9 +10,22 @@ use PHPUnit\Framework\TestCase; use Zend\Cache\Psr\CacheItemPool\CacheItemPoolDecorator; use Zend\Cache\StorageFactory; +use Zend\Stdlib\ErrorHandler; class BlackHoleIntegrationTest extends TestCase { + protected function setUp() + { + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); + } + + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } + /** * @expectedException \Zend\Cache\Psr\CacheItemPool\CacheException */ diff --git a/test/Psr/CacheItemPool/CacheItemTest.php b/test/Psr/CacheItemPool/CacheItemTest.php index 857c4afcb..44a09a833 100644 --- a/test/Psr/CacheItemPool/CacheItemTest.php +++ b/test/Psr/CacheItemPool/CacheItemTest.php @@ -14,12 +14,12 @@ class CacheItemTest extends TestCase { - private $tz; + private $tz = 'UTC'; protected function setUp() { // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); } diff --git a/test/Psr/CacheItemPool/DbaIntegrationTest.php b/test/Psr/CacheItemPool/DbaIntegrationTest.php index fc529e1cb..41957b326 100644 --- a/test/Psr/CacheItemPool/DbaIntegrationTest.php +++ b/test/Psr/CacheItemPool/DbaIntegrationTest.php @@ -12,9 +12,22 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class DbaIntegrationTest extends TestCase { + protected function setUp() + { + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); + } + + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } + /** * The DBA adapter doesn't support TTL * diff --git a/test/Psr/CacheItemPool/ExtMongoDbIntegrationTest.php b/test/Psr/CacheItemPool/ExtMongoDbIntegrationTest.php index 3df4d81a1..5867c8cd2 100644 --- a/test/Psr/CacheItemPool/ExtMongoDbIntegrationTest.php +++ b/test/Psr/CacheItemPool/ExtMongoDbIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ExtMongoDbIntegrationTest extends CachePoolTest { @@ -21,7 +22,7 @@ class ExtMongoDbIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var ExtMongoDb @@ -30,6 +31,8 @@ class ExtMongoDbIntegrationTest extends CachePoolTest protected function setUp() { + ErrorHandler::start(E_USER_DEPRECATED); + if (! getenv('TESTS_ZEND_CACHE_EXTMONGODB_ENABLED')) { $this->markTestSkipped('Enable TESTS_ZEND_CACHE_EXTMONGODB_ENABLED to run this test'); } @@ -39,7 +42,7 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); parent::setUp(); @@ -52,7 +55,7 @@ protected function tearDown() if ($this->storage) { $this->storage->flush(); } - + ErrorHandler::clean(); parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/FilesystemIntegrationTest.php b/test/Psr/CacheItemPool/FilesystemIntegrationTest.php index ea641b71b..ab4500f70 100644 --- a/test/Psr/CacheItemPool/FilesystemIntegrationTest.php +++ b/test/Psr/CacheItemPool/FilesystemIntegrationTest.php @@ -11,9 +11,22 @@ use Zend\Cache\Psr\CacheItemPool\CacheItemPoolDecorator; use Zend\Cache\Storage\Plugin\Serializer; use Zend\Cache\StorageFactory; +use Zend\Stdlib\ErrorHandler; class FilesystemIntegrationTest extends TestCase { + protected function setUp() + { + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); + } + + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } + /** * @expectedException \Zend\Cache\Psr\CacheItemPool\CacheException */ diff --git a/test/Psr/CacheItemPool/MemcacheIntegrationTest.php b/test/Psr/CacheItemPool/MemcacheIntegrationTest.php index ed54bf675..0807c6529 100644 --- a/test/Psr/CacheItemPool/MemcacheIntegrationTest.php +++ b/test/Psr/CacheItemPool/MemcacheIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @require extension memcache @@ -24,7 +25,7 @@ class MemcacheIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var Memcache @@ -38,9 +39,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -52,6 +55,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/MemcachedIntegrationTest.php b/test/Psr/CacheItemPool/MemcachedIntegrationTest.php index d58264cb0..fad4d3634 100644 --- a/test/Psr/CacheItemPool/MemcachedIntegrationTest.php +++ b/test/Psr/CacheItemPool/MemcachedIntegrationTest.php @@ -13,6 +13,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @require extension memcached @@ -23,7 +24,7 @@ class MemcachedIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var Memcached @@ -37,9 +38,10 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); parent::setUp(); } @@ -51,6 +53,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/MemoryIntegrationTest.php b/test/Psr/CacheItemPool/MemoryIntegrationTest.php index 7c39b04c9..7c4ebea0e 100644 --- a/test/Psr/CacheItemPool/MemoryIntegrationTest.php +++ b/test/Psr/CacheItemPool/MemoryIntegrationTest.php @@ -10,9 +10,23 @@ use PHPUnit\Framework\TestCase; use Zend\Cache\Psr\CacheItemPool\CacheItemPoolDecorator; use Zend\Cache\StorageFactory; +use Zend\Stdlib\ErrorHandler; class MemoryIntegrationTest extends TestCase { + protected function setUp() + { + ErrorHandler::start(E_USER_DEPRECATED); + + parent::setUp(); + } + + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } + /** * The memory adapter calculates the TTL on reading which violates PSR-6 * diff --git a/test/Psr/CacheItemPool/MongoDbIntegrationTest.php b/test/Psr/CacheItemPool/MongoDbIntegrationTest.php index fe7935722..6a87b39b7 100644 --- a/test/Psr/CacheItemPool/MongoDbIntegrationTest.php +++ b/test/Psr/CacheItemPool/MongoDbIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class MongoDbIntegrationTest extends CachePoolTest { @@ -21,7 +22,7 @@ class MongoDbIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var MongoDb @@ -35,9 +36,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -49,6 +52,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/RedisIntegrationTest.php b/test/Psr/CacheItemPool/RedisIntegrationTest.php index 38b5d3bd8..3766fb716 100644 --- a/test/Psr/CacheItemPool/RedisIntegrationTest.php +++ b/test/Psr/CacheItemPool/RedisIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class RedisIntegrationTest extends CachePoolTest { @@ -21,7 +22,7 @@ class RedisIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var Redis @@ -35,9 +36,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -49,6 +52,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/SessionIntegrationTest.php b/test/Psr/CacheItemPool/SessionIntegrationTest.php index f4c082897..108be7c87 100644 --- a/test/Psr/CacheItemPool/SessionIntegrationTest.php +++ b/test/Psr/CacheItemPool/SessionIntegrationTest.php @@ -10,9 +10,22 @@ use PHPUnit\Framework\TestCase; use Zend\Cache\Psr\CacheItemPool\CacheItemPoolDecorator; use Zend\Cache\StorageFactory; +use Zend\Stdlib\ErrorHandler; class SessionIntegrationTest extends TestCase { + protected function setUp() + { + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); + } + + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } + /** * The session adapter doesn't support TTL * diff --git a/test/Psr/CacheItemPool/WinCacheIntegrationTest.php b/test/Psr/CacheItemPool/WinCacheIntegrationTest.php index b745ceeb2..b232c4bee 100644 --- a/test/Psr/CacheItemPool/WinCacheIntegrationTest.php +++ b/test/Psr/CacheItemPool/WinCacheIntegrationTest.php @@ -13,6 +13,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @requires extension wincache @@ -23,7 +24,7 @@ class WinCacheIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var WinCache @@ -37,9 +38,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -51,6 +54,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/XCacheIntegrationTest.php b/test/Psr/CacheItemPool/XCacheIntegrationTest.php index 7f3b79487..58dd2eafe 100644 --- a/test/Psr/CacheItemPool/XCacheIntegrationTest.php +++ b/test/Psr/CacheItemPool/XCacheIntegrationTest.php @@ -13,12 +13,24 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @requires extension xcache */ class XCacheIntegrationTest extends TestCase { + protected function setUp() + { + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); + } + + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } /** * XCache is using request time based TTL handling which violates PSR-6 diff --git a/test/Psr/CacheItemPool/ZendServerDiskIntegrationTest.php b/test/Psr/CacheItemPool/ZendServerDiskIntegrationTest.php index 62198e92b..b8506a7a0 100644 --- a/test/Psr/CacheItemPool/ZendServerDiskIntegrationTest.php +++ b/test/Psr/CacheItemPool/ZendServerDiskIntegrationTest.php @@ -12,6 +12,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ZendServerDiskIntegrationTest extends CachePoolTest { @@ -19,7 +20,7 @@ class ZendServerDiskIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; protected function setUp() { @@ -28,9 +29,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -42,6 +45,8 @@ protected function tearDown() zend_disk_cache_clear(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/CacheItemPool/ZendServerShmIntegrationTest.php b/test/Psr/CacheItemPool/ZendServerShmIntegrationTest.php index 571bc43aa..39036d22d 100644 --- a/test/Psr/CacheItemPool/ZendServerShmIntegrationTest.php +++ b/test/Psr/CacheItemPool/ZendServerShmIntegrationTest.php @@ -12,6 +12,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ZendServerShmIntegrationTest extends CachePoolTest { @@ -19,7 +20,7 @@ class ZendServerShmIntegrationTest extends CachePoolTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; protected function setUp() { @@ -32,9 +33,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -46,6 +49,8 @@ protected function tearDown() zend_disk_cache_clear(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/ApcIntegrationTest.php b/test/Psr/SimpleCache/ApcIntegrationTest.php index 89d846f83..f26c014c1 100644 --- a/test/Psr/SimpleCache/ApcIntegrationTest.php +++ b/test/Psr/SimpleCache/ApcIntegrationTest.php @@ -12,6 +12,7 @@ use Zend\Cache\Psr\SimpleCache\SimpleCacheDecorator; use Zend\Cache\StorageFactory; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ApcIntegrationTest extends SimpleCacheTest { @@ -19,7 +20,7 @@ class ApcIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * Restore 'apc.use_request_time' @@ -35,13 +36,15 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); // needed on test expirations $this->iniUseRequestTime = ini_get('apc.use_request_time'); ini_set('apc.use_request_time', 0); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -56,6 +59,8 @@ protected function tearDown() // reset ini configurations ini_set('apc.use_request_time', $this->iniUseRequestTime); + + ErrorHandler::clean(); parent::tearDown(); } diff --git a/test/Psr/SimpleCache/ApcuIntegrationTest.php b/test/Psr/SimpleCache/ApcuIntegrationTest.php index 47d868cab..9e5fef9e1 100644 --- a/test/Psr/SimpleCache/ApcuIntegrationTest.php +++ b/test/Psr/SimpleCache/ApcuIntegrationTest.php @@ -12,6 +12,7 @@ use Zend\Cache\Psr\SimpleCache\SimpleCacheDecorator; use Zend\Cache\StorageFactory; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ApcuIntegrationTest extends SimpleCacheTest { @@ -19,7 +20,7 @@ class ApcuIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * Restore 'apc.use_request_time' @@ -35,13 +36,15 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); // needed on test expirations $this->iniUseRequestTime = ini_get('apc.use_request_time'); ini_set('apc.use_request_time', 0); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -56,6 +59,7 @@ protected function tearDown() // reset ini configurations ini_set('apc.use_request_time', $this->iniUseRequestTime); + ErrorHandler::clean(); parent::tearDown(); } diff --git a/test/Psr/SimpleCache/ExtMongoDbIntegrationTest.php b/test/Psr/SimpleCache/ExtMongoDbIntegrationTest.php index a157bb387..3cfbfe435 100644 --- a/test/Psr/SimpleCache/ExtMongoDbIntegrationTest.php +++ b/test/Psr/SimpleCache/ExtMongoDbIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ExtMongoDbIntegrationTest extends SimpleCacheTest { @@ -21,7 +22,7 @@ class ExtMongoDbIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var ExtMongoDb @@ -39,9 +40,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -53,6 +56,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/MemcacheIntegrationTest.php b/test/Psr/SimpleCache/MemcacheIntegrationTest.php index 270352cdf..d995bff4f 100644 --- a/test/Psr/SimpleCache/MemcacheIntegrationTest.php +++ b/test/Psr/SimpleCache/MemcacheIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @require extension memcache @@ -24,7 +25,7 @@ class MemcacheIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var Memcache @@ -38,9 +39,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -52,6 +55,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/MemcachedIntegrationTest.php b/test/Psr/SimpleCache/MemcachedIntegrationTest.php index 19e874dc2..e36c03182 100644 --- a/test/Psr/SimpleCache/MemcachedIntegrationTest.php +++ b/test/Psr/SimpleCache/MemcachedIntegrationTest.php @@ -13,6 +13,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @require extension memcached @@ -23,7 +24,7 @@ class MemcachedIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var Memcached @@ -37,9 +38,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -51,6 +54,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/MemoryIntegrationTest.php b/test/Psr/SimpleCache/MemoryIntegrationTest.php index 5c09c7982..e10163c2b 100644 --- a/test/Psr/SimpleCache/MemoryIntegrationTest.php +++ b/test/Psr/SimpleCache/MemoryIntegrationTest.php @@ -10,6 +10,7 @@ use Cache\IntegrationTests\SimpleCacheTest; use Zend\Cache\Psr\SimpleCache\SimpleCacheDecorator; use Zend\Cache\StorageFactory; +use Zend\Stdlib\ErrorHandler; class MemoryIntegrationTest extends SimpleCacheTest { @@ -21,9 +22,18 @@ public function setUp() $this->skippedTests['testObjectDoesNotChangeInCache'] = 'Memory adapter stores objects in memory; so change in references is possible'; + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } + protected function tearDown() + { + ErrorHandler::clean(); + + parent::tearDown(); + } + public function createSimpleCache() { $storage = StorageFactory::adapterFactory('memory'); diff --git a/test/Psr/SimpleCache/MongoDbIntegrationTest.php b/test/Psr/SimpleCache/MongoDbIntegrationTest.php index 36bdbdfd8..d0ab3e49b 100644 --- a/test/Psr/SimpleCache/MongoDbIntegrationTest.php +++ b/test/Psr/SimpleCache/MongoDbIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class MongoDbIntegrationTest extends SimpleCacheTest { @@ -21,7 +22,7 @@ class MongoDbIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var MongoDb @@ -35,9 +36,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -49,6 +52,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/RedisIntegrationTest.php b/test/Psr/SimpleCache/RedisIntegrationTest.php index 1853782cf..ba68681b9 100644 --- a/test/Psr/SimpleCache/RedisIntegrationTest.php +++ b/test/Psr/SimpleCache/RedisIntegrationTest.php @@ -14,6 +14,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class RedisIntegrationTest extends SimpleCacheTest { @@ -21,7 +22,7 @@ class RedisIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var Redis @@ -35,9 +36,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -49,6 +52,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/SessionIntegrationTest.php b/test/Psr/SimpleCache/SessionIntegrationTest.php index d97247340..fea2fdc88 100644 --- a/test/Psr/SimpleCache/SessionIntegrationTest.php +++ b/test/Psr/SimpleCache/SessionIntegrationTest.php @@ -11,6 +11,7 @@ use Zend\Cache\Psr\SimpleCache\SimpleCacheDecorator; use Zend\Cache\StorageFactory; use Zend\Session\Container as SessionContainer; +use Zend\Stdlib\ErrorHandler; class SessionIntegrationTest extends SimpleCacheTest { @@ -28,6 +29,8 @@ public function setUp() $this->skippedTests['testObjectDoesNotChangeInCache'] = 'Session adapter stores objects in memory; so change in references is possible'; + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -40,6 +43,8 @@ public function tearDown() $_SESSION = []; SessionContainer::setDefaultManager(null); + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/WinCacheIntegrationTest.php b/test/Psr/SimpleCache/WinCacheIntegrationTest.php index 9c2464d30..b51a29f0b 100644 --- a/test/Psr/SimpleCache/WinCacheIntegrationTest.php +++ b/test/Psr/SimpleCache/WinCacheIntegrationTest.php @@ -13,6 +13,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @requires extension wincache @@ -23,7 +24,7 @@ class WinCacheIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; /** * @var WinCache @@ -37,9 +38,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -51,6 +54,8 @@ protected function tearDown() $this->storage->flush(); } + ErrorHandler::clean(); + parent::tearDown(); } diff --git a/test/Psr/SimpleCache/XCacheIntegrationTest.php b/test/Psr/SimpleCache/XCacheIntegrationTest.php index 134e8101c..ca5c3830d 100644 --- a/test/Psr/SimpleCache/XCacheIntegrationTest.php +++ b/test/Psr/SimpleCache/XCacheIntegrationTest.php @@ -13,6 +13,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; /** * @requires extension xcache @@ -55,9 +56,17 @@ public function setUp() $this->skippedTests['testSetTtl'] = 'XCache adapter does not honor TTL'; $this->skippedTests['testSetMultipleTtl'] = 'XCache adapter does not honor TTL'; + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } + public function createSimpleCache() { try { diff --git a/test/Psr/SimpleCache/ZendServerDiskIntegrationTest.php b/test/Psr/SimpleCache/ZendServerDiskIntegrationTest.php index 2dfeb140e..90b3d8965 100644 --- a/test/Psr/SimpleCache/ZendServerDiskIntegrationTest.php +++ b/test/Psr/SimpleCache/ZendServerDiskIntegrationTest.php @@ -12,6 +12,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ZendServerDiskIntegrationTest extends SimpleCacheTest { @@ -19,7 +20,7 @@ class ZendServerDiskIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; protected function setUp() { @@ -28,9 +29,11 @@ protected function setUp() } // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); + ErrorHandler::start(E_USER_DEPRECATED); + parent::setUp(); } @@ -42,6 +45,7 @@ protected function tearDown() zend_disk_cache_clear(); } + ErrorHandler::clean(); parent::tearDown(); } diff --git a/test/Psr/SimpleCache/ZendServerShmIntegrationTest.php b/test/Psr/SimpleCache/ZendServerShmIntegrationTest.php index e8c44bbc0..59e0ccaa2 100644 --- a/test/Psr/SimpleCache/ZendServerShmIntegrationTest.php +++ b/test/Psr/SimpleCache/ZendServerShmIntegrationTest.php @@ -12,6 +12,7 @@ use Zend\Cache\StorageFactory; use Zend\Cache\Exception; use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\Stdlib\ErrorHandler; class ZendServerShmIntegrationTest extends SimpleCacheTest { @@ -19,7 +20,7 @@ class ZendServerShmIntegrationTest extends SimpleCacheTest * Backup default timezone * @var string */ - private $tz; + private $tz = 'UTC'; protected function setUp() { @@ -31,8 +32,9 @@ protected function setUp() $this->markTestSkipped("Missing 'zend_shm_cache_*' functions or running from SAPI 'cli'"); } + ErrorHandler::start(E_USER_DEPRECATED); // set non-UTC timezone - $this->tz = date_default_timezone_get(); + $this->tz = date_default_timezone_get() ?: 'UTC'; date_default_timezone_set('America/Vancouver'); parent::setUp(); @@ -46,6 +48,7 @@ protected function tearDown() zend_disk_cache_clear(); } + ErrorHandler::clean(); parent::tearDown(); } diff --git a/test/Service/StorageCacheAbstractServiceFactoryTest.php b/test/Service/StorageCacheAbstractServiceFactoryTest.php index 923bd5c25..1f0e73cd2 100644 --- a/test/Service/StorageCacheAbstractServiceFactoryTest.php +++ b/test/Service/StorageCacheAbstractServiceFactoryTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Zend\Cache\Service\StorageCacheAbstractServiceFactory; +use Zend\Cache\Storage\Plugin\Serializer; use Zend\Cache\StorageFactory; use Zend\Cache\Storage\AdapterPluginManager; use Zend\Cache\Storage\Adapter\AbstractAdapter; @@ -22,6 +23,7 @@ use Zend\Cache\Storage\StorageInterface; use Zend\ServiceManager\Config; use Zend\ServiceManager\ServiceManager; +use Zend\Stdlib\ErrorHandler; /** * @covers Zend\Cache\StorageFactory @@ -32,8 +34,10 @@ class StorageCacheAbstractServiceFactoryTest extends TestCase public function setUp() { + ErrorHandler::start(E_USER_DEPRECATED); StorageFactory::resetAdapterPluginManager(); StorageFactory::resetPluginManager(); + $this->sm = new ServiceManager(); $config = [ 'services' => [ 'config' => [ @@ -51,9 +55,8 @@ public function setUp() ], 'abstract_factories' => [ StorageCacheAbstractServiceFactory::class - ] + ], ]; - $this->sm = new ServiceManager(); (new Config($config))->configureServiceManager($this->sm); } @@ -61,6 +64,7 @@ public function tearDown() { StorageFactory::resetAdapterPluginManager(); StorageFactory::resetPluginManager(); + ErrorHandler::clean(); } public function testCanLookupCacheByName() @@ -143,6 +147,7 @@ public function testSetsFactoryPluginManagerInstanceOnInvocation() ]); $factory = new StorageCacheAbstractServiceFactory(); + /** @var Memory $storage */ $factory($container->reveal(), 'Cache'); $this->assertSame($pluginManager->reveal(), StorageFactory::getPluginManager()); } diff --git a/test/Service/StorageCacheFactoryTest.php b/test/Service/StorageCacheFactoryTest.php index 4d489238b..dc7d3ebd0 100644 --- a/test/Service/StorageCacheFactoryTest.php +++ b/test/Service/StorageCacheFactoryTest.php @@ -22,6 +22,7 @@ use Zend\Cache\Storage\StorageInterface; use Zend\ServiceManager\Config; use Zend\ServiceManager\ServiceManager; +use Zend\Stdlib\ErrorHandler; /** * @covers Zend\Cache\Service\StorageCacheFactory @@ -32,6 +33,7 @@ class StorageCacheFactoryTest extends TestCase public function setUp() { + ErrorHandler::start(E_USER_DEPRECATED); StorageFactory::resetAdapterPluginManager(); StorageFactory::resetPluginManager(); $config = [ @@ -55,6 +57,7 @@ public function tearDown() { StorageFactory::resetAdapterPluginManager(); StorageFactory::resetPluginManager(); + ErrorHandler::clean(); } public function testCreateServiceCache() diff --git a/test/Storage/Adapter/BlackHoleTest.php b/test/Storage/Adapter/BlackHoleTest.php index f8d2f46b7..9849475d7 100644 --- a/test/Storage/Adapter/BlackHoleTest.php +++ b/test/Storage/Adapter/BlackHoleTest.php @@ -15,6 +15,7 @@ use Zend\Cache\Storage\Adapter\BlackHole; use Zend\Cache\StorageFactory; use Zend\ServiceManager\ServiceManager; +use Zend\Stdlib\ErrorHandler; /** * PHPUnit test case @@ -36,11 +37,18 @@ class BlackHoleTest extends TestCase */ protected $storage; - public function setUp() + protected function setUp() { + ErrorHandler::start(E_USER_DEPRECATED); $this->storage = StorageFactory::adapterFactory('BlackHole'); } + protected function tearDown() + { + ErrorHandler::clean(); + parent::tearDown(); + } + /** * A data provider for common storage adapter names */ diff --git a/test/Storage/AdapterPluginManagerTest.php b/test/Storage/AdapterPluginManagerTest.php index 02da8e2b3..94514a8ad 100644 --- a/test/Storage/AdapterPluginManagerTest.php +++ b/test/Storage/AdapterPluginManagerTest.php @@ -54,4 +54,76 @@ protected function getInstanceOf() { return StorageInterface::class; } + + public function testOptionsWillBeSet() + { + $options = [ + 'readable' => false, + 'ttl' => 9999, + 'namespace' => 'test', + ]; + + $storage = $this->getPluginManager()->get('Memory', $options); + + $adapterOptions = $storage->getOptions(); + $this->assertArraySubset($options, $adapterOptions->toArray()); + } + + /** + * @dataProvider complexConfigurationProvider + */ + public function testComplexConfigurationIsBeingParsed(array $options, array $adapter, array $plugins) + { + /** @var StorageInterface $storage */ + $storage = $this->getPluginManager()->get('Memory', $options); + + $this->assertArraySubset($adapter, $storage->getOptions()->toArray()); + $this->assertCount(count($plugins), $storage->getPluginRegistry()); + } + + public function complexConfigurationProvider() + { + $adapterOptions = [ + 'readable' => false, + 'ttl' => 9999, + 'namespace' => 'test', + ]; + + $pluginOptions = [ + 'Serializer' => [ + 'options' => [], + 'priority' => 1, + ], + 'ClearExpiredByFactor' => [ + 'options' => [], + 'priority' => 2, + ], + ]; + + return [ + 'default_options' => [ + 'options_provided_to_pluginmanager' => $adapterOptions, + 'adapter_options_for_comparison' => $adapterOptions, + 'plugin_configuration_for_comparison' => [], + ], + 'options_with_plugins' => [ + 'options_provided_to_pluginmanager' => [ + 'options' => $adapterOptions, + 'plugins' => array_keys($pluginOptions) + ], + 'adapter_options_for_comparison' => $adapterOptions, + 'plugin_configuration_for_comparison' => array_keys($pluginOptions), + ], + 'options_with_complex_plugins' => [ + 'options_provided_to_pluginmanager' => ['options' => $adapterOptions, 'plugins' => $pluginOptions], + 'adapter_options_for_comparison' => $adapterOptions, + 'plugin_configuration_for_comparison' => $pluginOptions, + ], + 'options_with_added_plugins' => [ + 'options_provided_to_pluginmanager' => array_merge($adapterOptions, ['plugins' => $pluginOptions]), + 'adapter_options_for_comparison' => $adapterOptions, + 'plugin_configuration_for_comparison' => $pluginOptions, + ], + ]; + } } diff --git a/test/StorageFactoryTest.php b/test/StorageFactoryTest.php index 95d7a5240..5785e90df 100644 --- a/test/StorageFactoryTest.php +++ b/test/StorageFactoryTest.php @@ -9,9 +9,11 @@ namespace ZendTest\Cache; +use const E_USER_DEPRECATED; use PHPUnit\Framework\TestCase; use Zend\Cache; use Zend\ServiceManager\ServiceManager; +use Zend\Stdlib\ErrorHandler; /** * @group Zend_Cache @@ -21,6 +23,7 @@ class StorageFactoryTest extends TestCase { public function setUp() { + ErrorHandler::start(E_USER_DEPRECATED); Cache\StorageFactory::resetAdapterPluginManager(); Cache\StorageFactory::resetPluginManager(); } @@ -29,6 +32,7 @@ public function tearDown() { Cache\StorageFactory::resetAdapterPluginManager(); Cache\StorageFactory::resetPluginManager(); + ErrorHandler::clean(); } public function testDefaultAdapterPluginManager()