diff --git a/.gitattributes b/.gitattributes index ca9c9dab..f39ca25e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,6 +5,4 @@ /.gitattributes export-ignore /.gitignore export-ignore /.php_cs export-ignore -/.travis.yml export-ignore /phpunit.xml.dist export-ignore -/phpunit.xml.travisci export-ignore diff --git a/.github/workflows/gh-actions.yml b/.github/workflows/tests.yml similarity index 71% rename from .github/workflows/gh-actions.yml rename to .github/workflows/tests.yml index e2d12bd0..ecc1b192 100644 --- a/.github/workflows/gh-actions.yml +++ b/.github/workflows/tests.yml @@ -1,15 +1,14 @@ -# GitHub Action for Predis with PHP 7.2, 7.3, 7.4 & 8.0 & Redis 3, 4, 5 & 6 -name: Predis Builds +name: Tests on: [push, pull_request] jobs: predis: - name: Redis ${{ matrix.redis-versions }} (PHP ${{ matrix.php-versions }}) + name: PHP ${{ matrix.php-versions }} (Redis ${{ matrix.redis-versions }}) runs-on: ubuntu-latest services: redis: image: redis:${{ matrix.redis-versions }} ports: - - 6379/tcp + - 6379:6379 options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 strategy: fail-fast: false @@ -19,14 +18,14 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup PHP, with composer and extensions + - name: Setup PHP with Composer and extensions with: php-version: ${{ matrix.php-versions }} - uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php - - name: Get composer cache directory + uses: shivammathur/setup-php@v2 + - name: Get Composer cache directory id: composercache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer dependencies + - name: Cache Composer dependencies uses: actions/cache@v2 with: php-version: ${{ matrix.php-versions }} @@ -35,5 +34,5 @@ jobs: restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - - name: Test with phpunit + - name: Test with PHPUnit run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 394745f0..30961b83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,6 @@ -*.tgz -*.phar +/vendor .php-version .php_cs.cache .phpunit.result.cache -phpunit.xml -package.xml composer.lock -experiments/ -vendor/ +phpunit.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index beb94583..00000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: php -sudo: false -branches: - except: - - v0.5 - - v0.6 - - v0.6-PHP_5.2 - - documentation -before_install: - - docker run -d --rm -p 127.0.0.1:6379:6379 redis:${REDIS_VERSION:=3} -before_script: - - composer self-update - - composer install --no-interaction --prefer-source --dev -script: - - travis_retry vendor/bin/phpunit -c phpunit.xml.travisci -matrix: - fast_finish: true - include: - - php: 7.2 - - php: 7.3 - - php: 7.4 - env: REDIS_VERSION=4 # useless comment to trigger Travis - - php: 7.4 - env: REDIS_VERSION=5 - - php: 7.4 - env: REDIS_VERSION=6 - - php: nightly - allow_failures: - - php: nightly diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9ad2f5e3..3cf3c21b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ ## Filing bug reports ## -Bugs or feature requests can be posted on the [GitHub issues](http://github.com/predishq/predis/issues) +Bugs or feature requests can be posted on the [GitHub issues](http://github.com/predis/predis/issues) section of the project. When reporting bugs, in addition to the obvious description of your issue you __must__ always provide diff --git a/FAQ.md b/FAQ.md index 567f6b9e..152f534a 100644 --- a/FAQ.md +++ b/FAQ.md @@ -33,7 +33,7 @@ usually something that developers prefer to customize depending on their needs a generalized when using Redis because of the many possible access patterns for your data. This does not mean that it is impossible to have such a feature since you can leverage the extensibility of this library to define your own serialization-aware commands. You can find more details about how to -do that [on this issue](http://github.com/predishq/predis/issues/29#issuecomment-1202624). +do that [on this issue](http://github.com/predis/predis/issues/29#issuecomment-1202624). ### How can I force Predis to connect to Redis before sending any command? ### diff --git a/README.md b/README.md index e8b45e78..67e70934 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ [![Latest stable][ico-version-stable]][link-packagist] [![Latest development][ico-version-dev]][link-packagist] [![Monthly installs][ico-downloads-monthly]][link-downloads] -[![Build status][ico-travis]][link-travis] -![Build](https://github.com/predishq/predis/workflows/Predis%20Builds/badge.svg) +[![Build status][ico-build]][link-actions] A flexible and feature-complete [Redis](http://redis.io) client for PHP 7.2 and newer. @@ -37,9 +36,8 @@ More details about this project can be found on the [frequently asked questions] ## How to _install_ and use Predis ## This library can be found on [Packagist](http://packagist.org/packages/predis/predis) for an easier -management of projects dependencies using [Composer](http://packagist.org/about-composer) or on our -[own PEAR channel](http://pear.nrk.io) for a more traditional installation using PEAR. Ultimately, -compressed archives of each release are [available on GitHub](https://github.com/predishq/predis/releases). +management of projects dependencies using [Composer](http://packagist.org/about-composer). +Compressed archives of each release are [available on GitHub](https://github.com/predis/predis/releases). ### Loading the library ### @@ -451,8 +449,8 @@ the `unstable` branch by modifying `phpunit.xml` and setting `REDIS_SERVER_VERSI the development server profile will be used. You can refer to [the tests README](tests/README.md) for more detailed information about testing Predis. -Predis uses Travis CI for continuous integration and the history for past and current builds can be -found [on its project page](http://travis-ci.org/predishq/predis). +Predis uses GitHub Actions for continuous integration and the history for past and current builds can be +found [on its actions page](https://github.com/predis/predis/actions). ## Other ## @@ -460,9 +458,9 @@ found [on its project page](http://travis-ci.org/predishq/predis). ### Project related links ### -- [Source code](https://github.com/predishq/predis) -- [Wiki](https://github.com/predishq/predis/wiki) -- [Issue tracker](https://github.com/predishq/predis/issues) +- [Source code](https://github.com/predis/predis) +- [Wiki](https://github.com/predis/predis/wiki) +- [Issue tracker](https://github.com/predis/predis/issues) ### Author ### @@ -475,12 +473,12 @@ found [on its project page](http://travis-ci.org/predishq/predis). The code for Predis is distributed under the terms of the MIT license (see [LICENSE](LICENSE)). -[ico-license]: https://img.shields.io/github/license/predishq/predis.svg?style=flat-square -[ico-version-stable]: https://img.shields.io/packagist/v/predis/predis.svg?style=flat-square -[ico-version-dev]: https://img.shields.io/packagist/vpre/predis/predis.svg?style=flat-square -[ico-downloads-monthly]: https://img.shields.io/packagist/dm/predis/predis.svg?style=flat-square -[ico-travis]: https://img.shields.io/travis/predishq/predis.svg?style=flat-square +[ico-license]: https://img.shields.io/github/license/predis/predis.svg +[ico-version-stable]: https://img.shields.io/packagist/v/predis/predis.svg +[ico-version-dev]: https://img.shields.io/packagist/vpre/predis/predis.svg +[ico-downloads-monthly]: https://img.shields.io/packagist/dm/predis/predis.svg +[ico-build]: https://img.shields.io/github/workflow/status/predis/predis/Tests/main [link-packagist]: https://packagist.org/packages/predis/predis -[link-travis]: https://travis-ci.org/predishq/predis +[link-actions]: https://github.com/predis/predis/actions [link-downloads]: https://packagist.org/packages/predis/predis/stats diff --git a/VERSION b/VERSION index 45a1b3f4..d72f2626 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.2 +2.0.0-dev diff --git a/bin/create-pear b/bin/create-pear deleted file mode 100755 index b4f92db4..00000000 --- a/bin/create-pear +++ /dev/null @@ -1,233 +0,0 @@ -#!/usr/bin/env php - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -// -------------------------------------------------------------------------- // -// In order to be able to execute this script to create a PEAR package of Predis -// the `pear` binary must be available and executable in your $PATH. -// The parts used to parse author and version strings are taken from Onion (used -// by this library in the past) just to keep on relying on the package.ini file -// to simplify things. We might consider to switch to using the PEAR classes -// directly in the future. -// -------------------------------------------------------------------------- // - -function executeWithBackup($file, $callback) -{ - $exception = null; - $backup = "$file.backup"; - - copy($file, $backup); - - try { - call_user_func($callback, $file); - } catch (Exception $exception) { - // NOOP - } - - unlink($file); - rename($backup, $file); - - if ($exception) { - throw $exception; - } -} - -function parseAuthor($string) -{ - $author = array(); - - if (preg_match('/^\s*(.+?)\s*(?:"(\S+)"\s*)?<(\S+)>\s*$/x', $string , $regs)) { - if (count($regs) == 4) { - list($_,$name,$user,$email) = $regs; - $author['name'] = $name; - $author['user'] = $user; - $author['email'] = $email; - } elseif (count($regs) == 3) { - list($_,$name,$email) = $regs; - $author['name'] = $name; - $author['email'] = $email; - } - } else { - $author['name'] = $string; - } - - return $author; -} - -function parseVersion($string) -{ - $version_pattern = '([0-9.]+)'; - - if (preg_match("/^\s*$version_pattern\s*\$/x", $string, $regs)) { - return array('min' => $regs[1] ?: '0.0.0'); - } elseif (preg_match("/^\s*[>=]+\s*$version_pattern\s*\$/x", $string, $regs)) { - return array('min' => $regs[1] ?: '0.0.0'); - } elseif (preg_match("/^\s*[<=]+\s*$version_pattern\s*\$/x", $string, $regs)) { - return array('max' => $regs[1]); - } elseif (preg_match("/^\s*$version_pattern\s*<=>\s*$version_pattern\s*\$/x", $string, $regs)) { - return array( - 'min' => $regs[1] ?: '0.0.0', - 'max' => $regs[2], - ); - } - - return null; -} - -function addRolePath($pkg, $path, $role) -{ - if (is_dir($path)) { - $dirRoot = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS); - $dirTree = new RecursiveIteratorIterator($dirRoot, RecursiveIteratorIterator::CHILD_FIRST); - - foreach ($dirTree as $fileinfo) { - if ($fileinfo->isFile()) { - addPackageFile($pkg, $fileinfo, $role, $path); - } - } - } else { - foreach (glob($path) as $filename) { - addPackageFile($pkg, new SplFileInfo($filename), $role); - } - } -} - -function addPackageFile($pkg, $fileinfo, $role, $baseDir = '') -{ - $fileNode = $pkg->contents->dir->addChild('file'); - $fileNode->addAttribute('name', $filepath = $fileinfo->getPathname()); - $fileNode->addAttribute('role', $role); - $fileNode->addAttribute('md5sum', md5_file($filepath)); - - $installNode = $pkg->phprelease->filelist->addChild('install'); - $installNode->addAttribute('name', $filepath); - $installNode->addAttribute('as', !$baseDir ? basename($filepath) : substr($filepath, strlen($baseDir) + 1)); -} - -function generatePackageXml($packageINI) -{ - $XML = << - -XML; - - $cfg = parse_ini_file($packageINI, true); - $pkg = new SimpleXMLElement($XML); - - $pkg->name = $cfg['package']['name']; - $pkg->channel = $cfg['package']['channel']; - $pkg->summary = $cfg['package']['desc']; - $pkg->description = $cfg['package']['desc']; - - $author = parseAuthor($cfg['package']['author']); - $pkg->addChild('lead'); - $pkg->lead->name = $author['name']; - $pkg->lead->user = $author['user']; - $pkg->lead->email = $author['email']; - $pkg->lead->active = 'yes'; - - $datetime = new DateTime('now'); - $pkg->date = $datetime->format('Y-m-d'); - $pkg->time = $datetime->format('H:i:s'); - - $pkg->addChild('version'); - $pkg->version->release = $cfg['package']['version']; - $pkg->version->api = $cfg['package']['version']; - - $pkg->addChild('stability'); - $pkg->stability->release = $cfg['package']['stability']; - $pkg->stability->api = $cfg['package']['stability']; - - $pkg->license = $cfg['package']['license']; - $pkg->notes = '-'; - - $pkg->addChild('contents')->addChild('dir')->addAttribute('name', '/'); - - $pkg->addChild('dependencies')->addChild('required'); - foreach ($cfg['require'] as $required => $version) { - $version = parseVersion($version); - $pkg->dependencies->required->addChild($required); - - if (isset($version['min'])) { - $pkg->dependencies->required->$required->min = $version['min']; - } - if (isset($version['max'])) { - $pkg->dependencies->required->$required->min = $version['max']; - } - } - - $pkg->addChild('phprelease')->addChild('filelist'); - - $pathToRole = array( - 'doc' => 'doc', 'docs' => 'doc', 'examples' => 'doc', - 'lib' => 'php', 'src' => 'php', - 'test' => 'test', 'tests' => 'test', - ); - - foreach (array_merge($pathToRole, $cfg['roles'] ?: array()) as $path => $role) { - addRolePath($pkg, $path, $role); - } - - return $pkg; -} - -function rewritePackageInstallAs($pkg) -{ - foreach ($pkg->phprelease->filelist->install as $file) { - if (preg_match('/^src\//', $file['name'])) { - $file['as'] = "Predis/{$file['as']}"; - } - } -} - -function savePackageXml($xml) -{ - $dom = new DOMDocument("1.0"); - $dom->preserveWhiteSpace = false; - $dom->formatOutput = true; - $dom->loadXML($xml->asXML()); - - file_put_contents('package.xml', $dom->saveXML()); -} - -function buildPackage() -{ - passthru('pear -q package && rm package.xml'); -} - -function modifyPhpunitXml($file) -{ - $cfg = new SimpleXMLElement($file, null, true); - - $cfg[0]['bootstrap'] = str_replace('tests/', '', $cfg[0]['bootstrap']); - $cfg->testsuites->testsuite->directory = str_replace('tests/', '', $cfg->testsuites->testsuite->directory); - - $cfg->saveXml($file); -} - -// -------------------------------------------------------------------------- // - -executeWithBackup(__DIR__.'/../phpunit.xml.dist', function ($file) { - modifyPhpunitXml($file); - - $pkg = generatePackageXml('package.ini'); - rewritePackageInstallAs($pkg); - savePackageXml($pkg); - - buildPackage(); -}); diff --git a/bin/create-phar b/bin/create-phar deleted file mode 100755 index 23618096..00000000 --- a/bin/create-phar +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env php - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -// -------------------------------------------------------------------------- // -// In order to be able to execute this script to create a Phar archive of Predis, -// the Phar module must be loaded and the "phar.readonly" directive php.ini must -// be set to "off". You can change the values in the $options array to customize -// the creation of the Phar archive to better suit your needs. -// -------------------------------------------------------------------------- // - -$options = array( - 'name' => 'predis', - 'project_path' => __DIR__ . '/../src', - 'compression' => Phar::NONE, - 'append_version' => true, -); - -function getPharFilename($options) -{ - $filename = $options['name']; - - // NOTE: do not consider "append_version" with Phar compression do to a bug in - // Phar::compress() when renaming phar archives containing dots in their name. - if ($options['append_version'] && $options['compression'] === Phar::NONE) { - $versionFile = @fopen(__DIR__ . '/../VERSION', 'r'); - - if ($versionFile === false) { - throw new Exception("Could not locate the VERSION file."); - } - - $version = trim(fgets($versionFile)); - fclose($versionFile); - $filename .= "_$version"; - } - - return "$filename.phar"; -} - -function getPharStub($options) -{ - return <<compress($options['compression']); -$phar->setStub(getPharStub($options)); -$phar->buildFromDirectory($options['project_path']); diff --git a/bin/create-single-file b/bin/create-single-file deleted file mode 100755 index ecb876b0..00000000 --- a/bin/create-single-file +++ /dev/null @@ -1,662 +0,0 @@ -#!/usr/bin/env php - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -// -------------------------------------------------------------------------- // -// This script can be used to automatically glue all the .php files of Predis -// into a single monolithic script file that can be used without an autoloader, -// just like the other previous versions of the library. -// -// Much of its complexity is due to the fact that we cannot simply join PHP -// files, but namespaces and classes definitions must follow a precise order -// when dealing with subclassing and inheritance. -// -// The current implementation is pretty naïve, but it should do for now. -// -------------------------------------------------------------------------- // - -class CommandLine -{ - public static function getOptions() - { - $parameters = array( - 's:' => 'source:', - 'o:' => 'output:', - 'e:' => 'exclude:', - 'E:' => 'exclude-classes:', - ); - - $getops = getopt(implode(array_keys($parameters)), $parameters); - - $options = array( - 'source' => __DIR__ . "/../src", - 'output' => PredisFile::NS_ROOT . '.php', - 'exclude' => array(), - ); - - foreach ($getops as $option => $value) { - switch ($option) { - case 's': - case 'source': - $options['source'] = $value; - break; - - case 'o': - case 'output': - $options['output'] = $value; - break; - - case 'E': - case 'exclude-classes': - $options['exclude'] = @file($value, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: $value; - break; - - case 'e': - case 'exclude': - $options['exclude'] = is_array($value) ? $value : array($value); - break; - } - } - - return $options; - } -} - -class PredisFile -{ - const NS_ROOT = 'Predis'; - - private $namespaces; - - public function __construct() - { - $this->namespaces = array(); - } - - public static function from($libraryPath, array $exclude = array()) - { - $predisFile = new PredisFile(); - $libIterator = new RecursiveDirectoryIterator($libraryPath); - - foreach (new RecursiveIteratorIterator($libIterator) as $classFile) - { - if (!$classFile->isFile()) { - continue; - } - - $namespace = self::NS_ROOT.strtr(str_replace($libraryPath, '', $classFile->getPath()), '/', '\\'); - - if (in_array(sprintf('%s\\%s', $namespace, $classFile->getBasename('.php')), $exclude)) { - continue; - } - - $phpNamespace = $predisFile->getNamespace($namespace); - - if ($phpNamespace === false) { - $phpNamespace = new PhpNamespace($namespace); - $predisFile->addNamespace($phpNamespace); - } - - $phpClass = new PhpClass($phpNamespace, $classFile); - } - - return $predisFile; - } - - public function addNamespace(PhpNamespace $namespace) - { - if (isset($this->namespaces[(string)$namespace])) { - throw new InvalidArgumentException("Duplicated namespace"); - } - $this->namespaces[(string)$namespace] = $namespace; - } - - public function getNamespaces() - { - return $this->namespaces; - } - - public function getNamespace($namespace) - { - if (!isset($this->namespaces[$namespace])) { - return false; - } - - return $this->namespaces[$namespace]; - } - - public function getClassByFQN($classFqn) - { - if (($nsLastPos = strrpos($classFqn, '\\')) !== false) { - $namespace = $this->getNamespace(substr($classFqn, 0, $nsLastPos)); - if ($namespace === false) { - return null; - } - $className = substr($classFqn, $nsLastPos + 1); - - return $namespace->getClass($className); - } - - return null; - } - - private function calculateDependencyScores(&$classes, $fqn) - { - if (!isset($classes[$fqn])) { - $classes[$fqn] = 0; - } - - $classes[$fqn] += 1; - - if (($phpClass = $this->getClassByFQN($fqn)) === null) { - throw new RuntimeException( - "Cannot found the class $fqn which is required by other subclasses. Are you missing a file?" - ); - } - - foreach ($phpClass->getDependencies() as $fqn) { - $this->calculateDependencyScores($classes, $fqn); - } - } - - private function getDependencyScores() - { - $classes = array(); - - foreach ($this->getNamespaces() as $phpNamespace) { - foreach ($phpNamespace->getClasses() as $phpClass) { - $this->calculateDependencyScores($classes, $phpClass->getFQN()); - } - } - - return $classes; - } - - private function getOrderedNamespaces($dependencyScores) - { - $namespaces = array_fill_keys(array_unique( - array_map( - function ($fqn) { return PhpNamespace::extractName($fqn); }, - array_keys($dependencyScores) - ) - ), 0); - - foreach ($dependencyScores as $classFqn => $score) { - $namespaces[PhpNamespace::extractName($classFqn)] += $score; - } - - arsort($namespaces); - - return array_keys($namespaces); - } - - private function getOrderedClasses(PhpNamespace $phpNamespace, $classes) - { - $nsClassesFQNs = array_map(function ($cl) { return $cl->getFQN(); }, $phpNamespace->getClasses()); - $nsOrderedClasses = array(); - - foreach ($nsClassesFQNs as $nsClassFQN) { - $nsOrderedClasses[$nsClassFQN] = $classes[$nsClassFQN]; - } - - arsort($nsOrderedClasses); - - return array_keys($nsOrderedClasses); - } - - public function getPhpCode() - { - $buffer = array("getDependencyScores(); - $namespaces = $this->getOrderedNamespaces($classes); - - foreach ($namespaces as $namespace) { - $phpNamespace = $this->getNamespace($namespace); - - // generate namespace directive - $buffer[] = $phpNamespace->getPhpCode(); - $buffer[] = "\n"; - - // generate use directives - $useDirectives = $phpNamespace->getUseDirectives(); - if (count($useDirectives) > 0) { - $buffer[] = $useDirectives->getPhpCode(); - $buffer[] = "\n"; - } - - // generate classes bodies - $nsClasses = $this->getOrderedClasses($phpNamespace, $classes); - foreach ($nsClasses as $classFQN) { - $buffer[] = $this->getClassByFQN($classFQN)->getPhpCode(); - $buffer[] = "\n\n"; - } - - $buffer[] = "/* " . str_repeat("-", 75) . " */"; - $buffer[] = "\n\n"; - } - - return implode($buffer); - } - - public function saveTo($outputFile) - { - // TODO: add more sanity checks - if ($outputFile === null || $outputFile === '') { - throw new InvalidArgumentException('You must specify a valid output file'); - } - file_put_contents($outputFile, $this->getPhpCode()); - } -} - -class PhpNamespace implements IteratorAggregate -{ - private $namespace; - private $classes; - - public function __construct($namespace) - { - $this->namespace = $namespace; - $this->classes = array(); - $this->useDirectives = new PhpUseDirectives($this); - } - - public static function extractName($fqn) - { - $nsSepLast = strrpos($fqn, '\\'); - if ($nsSepLast === false) { - return $fqn; - } - $ns = substr($fqn, 0, $nsSepLast); - - return $ns !== '' ? $ns : null; - } - - public function addClass(PhpClass $class) - { - $this->classes[$class->getName()] = $class; - } - - public function getClass($className) - { - if (isset($this->classes[$className])) { - return $this->classes[$className]; - } - } - - public function getClasses() - { - return array_values($this->classes); - } - - public function getIterator() - { - return new \ArrayIterator($this->getClasses()); - } - - public function getUseDirectives() - { - return $this->useDirectives; - } - - public function getPhpCode() - { - return "namespace $this->namespace;\n"; - } - - public function __toString() - { - return $this->namespace; - } -} - -class PhpUseDirectives implements Countable, IteratorAggregate -{ - private $use; - private $aliases; - private $reverseAliases; - private $namespace; - - public function __construct(PhpNamespace $namespace) - { - $this->namespace = $namespace; - $this->use = array(); - $this->aliases = array(); - $this->reverseAliases = array(); - } - - public function add($use, $as = null) - { - if (in_array($use, $this->use)) { - return; - } - - $rename = null; - $this->use[] = $use; - $aliasedClassName = $as ?: PhpClass::extractName($use); - - if (isset($this->aliases[$aliasedClassName])) { - $parentNs = $this->getParentNamespace(); - - if ($parentNs && false !== $pos = strrpos($parentNs, '\\')) { - $parentNs = substr($parentNs, $pos); - } - - $newAlias = "{$parentNs}_{$aliasedClassName}"; - $rename = (object) array( - 'namespace' => $this->namespace, - 'from' => $aliasedClassName, - 'to' => $newAlias, - ); - - $this->aliases[$newAlias] = $use; - $as = $newAlias; - } else { - $this->aliases[$aliasedClassName] = $use; - } - - if ($as !== null) { - $this->reverseAliases[$use] = $as; - } - - return $rename; - } - - public function getList() - { - return $this->use; - } - - public function getIterator() - { - return new \ArrayIterator($this->getList()); - } - - public function getPhpCode() - { - $reverseAliases = $this->reverseAliases; - - $reducer = function ($str, $use) use ($reverseAliases) { - if (isset($reverseAliases[$use])) { - return $str .= "use $use as {$reverseAliases[$use]};\n"; - } else { - return $str .= "use $use;\n"; - } - }; - - return array_reduce($this->getList(), $reducer, ''); - } - - public function getNamespace() - { - return $this->namespace; - } - - public function getParentNamespace() - { - if (false !== $pos = strrpos($this->namespace, '\\')) { - return substr($this->namespace, 0, $pos); - } - - return ''; - } - - public function getFQN($className) - { - if (($nsSepFirst = strpos($className, '\\')) === false) { - if (isset($this->aliases[$className])) { - return $this->aliases[$className]; - } - - return (string)$this->getNamespace() . "\\$className"; - } - - if ($nsSepFirst != 0) { - throw new InvalidArgumentException("Partially qualified names are not supported"); - } - - return $className; - } - - public function count() - { - return count($this->use); - } -} - -class PhpClass -{ - const LICENSE_HEADER = << - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -LICENSE; - - private $namespace; - private $file; - private $body; - private $implements; - private $extends; - private $name; - - public function __construct(PhpNamespace $namespace, SplFileInfo $classFile) - { - $this->namespace = $namespace; - $this->file = $classFile; - $this->implements = array(); - $this->extends = array(); - - $this->extractData(); - $namespace->addClass($this); - } - - public static function extractName($fqn) - { - $nsSepLast = strrpos($fqn, '\\'); - if ($nsSepLast === false) { - return $fqn; - } - - return substr($fqn, $nsSepLast + 1); - } - - private function extractData() - { - $renames = array(); - $useDirectives = $this->getNamespace()->getUseDirectives(); - - $useExtractor = function ($m) use ($useDirectives, &$renames) { - array_shift($m); - - if (isset($m[1])) { - $m[1] = str_replace(" as ", '', $m[1]); - } - - if ($rename = call_user_func_array(array($useDirectives, 'add'), $m)) { - $renames[] = $rename; - } - }; - - $classBuffer = stream_get_contents(fopen($this->getFile()->getPathname(), 'r')); - - $classBuffer = str_replace(self::LICENSE_HEADER, '', $classBuffer); - - $classBuffer = preg_replace('/<\?php\s?\\n\s?/', '', $classBuffer); - $classBuffer = preg_replace('/\s?\?>\n?/ms', '', $classBuffer); - $classBuffer = preg_replace('/namespace\s+[\w\d_\\\\]+;\s?/', '', $classBuffer); - $classBuffer = preg_replace_callback('/use\s+([\w\d_\\\\]+)(\s+as\s+.*)?;\s?\n?/', $useExtractor, $classBuffer); - - foreach ($renames as $rename) { - $classBuffer = str_replace($rename->from, $rename->to, $classBuffer); - } - - $this->body = trim($classBuffer); - - $this->extractHierarchy(); - } - - private function extractHierarchy() - { - $implements = array(); - $extends = array(); - - $extractor = function ($iterator, $callback) { - $className = ''; - $iterator->seek($iterator->key() + 1); - - while ($iterator->valid()) { - $token = $iterator->current(); - - if (is_string($token)) { - if (preg_match('/\s?,\s?/', $token)) { - $callback(trim($className)); - $className = ''; - } else if ($token == '{') { - $callback(trim($className)); - return; - } - } - - switch ($token[0]) { - case T_NS_SEPARATOR: - $className .= '\\'; - break; - - case T_STRING: - $className .= $token[1]; - break; - - case T_IMPLEMENTS: - case T_EXTENDS: - $callback(trim($className)); - $iterator->seek($iterator->key() - 1); - return; - } - - $iterator->next(); - } - }; - - $tokens = token_get_all("getPhpCode())); - $iterator = new ArrayIterator($tokens); - - while ($iterator->valid()) { - $token = $iterator->current(); - if (is_string($token)) { - $iterator->next(); - continue; - } - - switch ($token[0]) { - case T_CLASS: - case T_INTERFACE: - $iterator->seek($iterator->key() + 2); - $tk = $iterator->current(); - $this->name = $tk[1]; - break; - - case T_IMPLEMENTS: - $extractor($iterator, function ($fqn) use (&$implements) { - $implements[] = $fqn; - }); - break; - - case T_EXTENDS: - $extractor($iterator, function ($fqn) use (&$extends) { - $extends[] = $fqn; - }); - break; - } - - $iterator->next(); - } - - $this->implements = $this->guessFQN($implements); - $this->extends = $this->guessFQN($extends); - } - - public function guessFQN($classes) - { - $useDirectives = $this->getNamespace()->getUseDirectives(); - return array_map(array($useDirectives, 'getFQN'), $classes); - } - - public function getImplementedInterfaces($all = false) - { - if ($all) { - return $this->implements; - } - - return array_filter( - $this->implements, - function ($cn) { return strpos($cn, 'Predis\\') === 0; } - ); - } - - public function getExtendedClasses($all = false) - { - if ($all) { - return $this->extemds; - } - - return array_filter( - $this->extends, - function ($cn) { return strpos($cn, 'Predis\\') === 0; } - ); - } - - public function getDependencies($all = false) - { - return array_merge( - $this->getImplementedInterfaces($all), - $this->getExtendedClasses($all) - ); - } - - public function getNamespace() - { - return $this->namespace; - } - - public function getFile() - { - return $this->file; - } - - public function getName() - { - return $this->name; - } - - public function getFQN() - { - return (string)$this->getNamespace() . '\\' . $this->name; - } - - public function getPhpCode() - { - return $this->body; - } - - public function __toString() - { - return "class " . $this->getName() . '{ ... }'; - } -} - -/* -------------------------------------------------------------------------- */ - -$options = CommandLine::getOptions(); -$predisFile = PredisFile::from($options['source'], $options['exclude']); -$predisFile->saveTo($options['output']); diff --git a/composer.json b/composer.json index cf48c36d..0883250f 100644 --- a/composer.json +++ b/composer.json @@ -3,10 +3,10 @@ "type": "library", "description": "A flexible and feature-complete Redis client for PHP.", "keywords": ["nosql", "redis", "predis"], - "homepage": "http://github.com/predishq/predis", + "homepage": "http://github.com/predis/predis", "license": "MIT", "support": { - "issues": "https://github.com/predishq/predis/issues" + "issues": "https://github.com/predis/predis/issues" }, "authors": [ { diff --git a/package.ini b/package.ini deleted file mode 100644 index 3ba810b6..00000000 --- a/package.ini +++ /dev/null @@ -1,36 +0,0 @@ -; This file is meant to be used with Onion http://c9s.github.com/Onion/ -; For instructions on how to build a PEAR package of Predis please follow -; the instructions at this URL: -; -; https://github.com/c9s/Onion#a-quick-tutorial-for-building-pear-package -; - -[package] -name = "Predis" -desc = "Flexible and feature-complete Redis client for PHP and HHVM" -homepage = "http://github.com/nrk/predis" -license = "MIT" -version = "1.1.2" -stability = "stable" -channel = "pear.nrk.io" - -author = "Daniele Alessandri \"nrk\" " - -[require] -php = ">= 5.3.9" -pearinstaller = "1.4.1" - -[roles] -*.xml.dist = test -*.md = doc -LICENSE = doc - -[optional phpiredis] -hint = "Add support for faster protocol handling with phpiredis" -extensions[] = socket -extensions[] = phpiredis - -[optional webdis] -hint = "Add support for Webdis" -extensions[] = curl -extensions[] = phpiredis diff --git a/phpunit.xml.travisci b/phpunit.xml.travisci deleted file mode 100644 index 3bd2bf04..00000000 --- a/phpunit.xml.travisci +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - tests/Predis/ - - - - - - ext-phpiredis - ext-curl - realm-webdis - - - - - - - - - - src/ - - - - - - - - - - - - - - - - - - - diff --git a/src/Client.php b/src/Client.php index 4b210696..6e492f81 100644 --- a/src/Client.php +++ b/src/Client.php @@ -40,7 +40,7 @@ use Predis\Transaction\MultiExec as MultiExecTransaction; */ class Client implements ClientInterface, \IteratorAggregate { - const VERSION = '1.1.2'; + const VERSION = '2.0.0-dev'; protected $connection; protected $options; diff --git a/tests/PHPUnit/PredisConnectionTestCase.php b/tests/PHPUnit/PredisConnectionTestCase.php index ba149c70..4ffacc7d 100644 --- a/tests/PHPUnit/PredisConnectionTestCase.php +++ b/tests/PHPUnit/PredisConnectionTestCase.php @@ -80,11 +80,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'udp'. */ public function testThrowsExceptionOnInvalidScheme() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'udp'"); + $this->createConnectionWithParams(array('scheme' => 'udp')); } @@ -195,7 +196,7 @@ abstract class PredisConnectionTestCase extends PredisTestCase $connection = $this->createConnection(); $this->assertFalse($connection->isConnected()); - $this->assertInternalType('resource', $connection->getResource()); + $this->assertIsResource($connection->getResource()); $this->assertTrue($connection->isConnected()); } @@ -220,7 +221,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $profile = $this->getCurrentProfile(); - $cmdPing = $this->getMock($profile->getCommandClass('ping'), array('parseResponse')); + $cmdPing = $this->getMockBuilder($profile->getCommandClass('ping')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdPing->expects($this->never()) ->method('parseResponse'); @@ -271,7 +274,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $profile = $this->getCurrentProfile(); - $cmdEcho = $this->getMock($profile->getCommandClass('echo'), array('parseResponse')); + $cmdEcho = $this->getMockBuilder($profile->getCommandClass('echo')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdEcho->setArguments(array('ECHOED')); $cmdEcho->expects($this->never()) ->method('parseResponse'); @@ -288,7 +293,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $profile = $this->getCurrentProfile(); - $cmdEcho = $this->getMock($profile->getCommandClass('echo'), array('parseResponse')); + $cmdEcho = $this->getMockBuilder($profile->getCommandClass('echo')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdEcho->setArguments(array('ECHOED')); $cmdEcho->expects($this->never()) ->method('parseResponse'); @@ -306,11 +313,15 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $profile = $this->getCurrentProfile(); - $cmdPing = $this->getMock($profile->getCommandClass('ping'), array('parseResponse')); + $cmdPing = $this->getMockBuilder($profile->getCommandClass('ping')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdPing->expects($this->never()) ->method('parseResponse'); - $cmdEcho = $this->getMock($profile->getCommandClass('echo'), array('parseResponse')); + $cmdEcho = $this->getMockBuilder($profile->getCommandClass('echo')) + ->setMethods(array('parseResponse')) + ->getMock(); $cmdEcho->setArguments(array('ECHOED')); $cmdEcho->expects($this->never()) ->method('parseResponse'); @@ -331,12 +342,17 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $profile = $this->getCurrentProfile(); - $cmdPing = $this->getMock($profile->getCommandClass('ping'), array('getArguments')); + $cmdPing = $this->getMockBuilder($profile->getCommandClass('ping')) + ->setMethods(array('getArguments')) + ->getMock(); $cmdPing->expects($this->once()) ->method('getArguments') ->will($this->returnValue(array())); - $cmdEcho = $this->getMock($profile->getCommandClass('echo'), array('getArguments')); + $cmdEcho = $this->getMockBuilder($profile->getCommandClass('echo')) + ->setMethods(array('getArguments')) + ->getMock(); + $cmdEcho->setArguments(array('ECHOED')); $cmdEcho->expects($this->once()) ->method('getArguments') ->will($this->returnValue(array('ECHOED'))); @@ -431,11 +447,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessageRegExp /.* \[tcp:\/\/169.254.10.10:6379\]/ */ public function testThrowsExceptionOnConnectionTimeout() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessageMatches('/.* \[tcp:\/\/169.254.10.10:6379\]/'); + // TODO: float timeouts for connect() under HHVM 3.6.6 are broken and, // unfortunately, this is the version still being used by Travis CI. if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.6.6', '<=')) { @@ -455,11 +472,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessageRegExp /.* \[tcp:\/\/\[0:0:0:0:0:ffff:a9fe:a0a\]:6379\]/ */ public function testThrowsExceptionOnConnectionTimeoutIPv6() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessageMatches('/.* \[tcp:\/\/\[0:0:0:0:0:ffff:a9fe:a0a\]:6379\]/'); + // TODO: float timeouts for connect() under HHVM 3.6.6 are broken and, // unfortunately, this is the version still being used by Travis CI. if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.6.6', '<=')) { @@ -479,11 +497,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessageRegExp /.* \[unix:\/tmp\/nonexistent\/redis\.sock]/ */ public function testThrowsExceptionOnUnixDomainSocketNotFound() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessageMatches('/.* \[unix:\/tmp\/nonexistent\/redis\.sock]/'); + $connection = $this->createConnectionWithParams(array( 'scheme' => 'unix', 'path' => '/tmp/nonexistent/redis.sock', @@ -495,10 +514,11 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @group connected * @group slow - * @expectedException \Predis\Connection\ConnectionException */ public function testThrowsExceptionOnReadWriteTimeout() { + $this->expectException('Predis\Connection\ConnectionException'); + $profile = $this->getCurrentProfile(); $connection = $this->createConnectionWithParams(array( @@ -511,10 +531,11 @@ abstract class PredisConnectionTestCase extends PredisTestCase /** * @medium * @group connected - * @expectedException \Predis\Protocol\ProtocolException */ public function testThrowsExceptionOnProtocolDesynchronizationErrors() { + $this->expectException('Predis\Protocol\ProtocolException'); + $connection = $this->createConnection(); $stream = $connection->getResource(); diff --git a/tests/PHPUnit/PredisDistributorTestCase.php b/tests/PHPUnit/PredisDistributorTestCase.php index d3dd26e9..e9879194 100644 --- a/tests/PHPUnit/PredisDistributorTestCase.php +++ b/tests/PHPUnit/PredisDistributorTestCase.php @@ -68,7 +68,7 @@ abstract class PredisDistributorTestCase extends PredisTestCase */ public function testEmptyRingThrowsException() { - $this->setExpectedException('Predis\Cluster\Distributor\EmptyRingException'); + $this->expectException('Predis\Cluster\Distributor\EmptyRingException'); $distributor = $this->getDistributorInstance(); $distributor->getByHash('nodehash'); diff --git a/tests/PHPUnit/PredisProfileTestCase.php b/tests/PHPUnit/PredisProfileTestCase.php index 27b103b2..19d1d24d 100644 --- a/tests/PHPUnit/PredisProfileTestCase.php +++ b/tests/PHPUnit/PredisProfileTestCase.php @@ -140,7 +140,7 @@ abstract class PredisProfileTestCase extends PredisTestCase public function testDefineCommand() { $profile = $this->getProfile(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $profile->defineCommand('mock', get_class($command)); @@ -152,11 +152,12 @@ abstract class PredisProfileTestCase extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The class 'stdClass' is not a valid command class. */ public function testDefineInvalidCommand() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("The class 'stdClass' is not a valid command class"); + $profile = $this->getProfile(); $profile->defineCommand('mock', 'stdClass'); @@ -191,11 +192,12 @@ abstract class PredisProfileTestCase extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Command 'UNKNOWN' is not a registered Redis command. */ public function testCreateUndefinedCommand() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage("Command 'UNKNOWN' is not a registered Redis command"); + $profile = $this->getProfile(); $profile->createCommand('unknown'); } @@ -215,7 +217,7 @@ abstract class PredisProfileTestCase extends PredisTestCase */ public function testSetProcessor() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $profile = $this->getProfile(); $profile->setProcessor($processor); @@ -228,7 +230,7 @@ abstract class PredisProfileTestCase extends PredisTestCase */ public function testSetAndUnsetProcessor() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $profile = $this->getProfile(); $profile->setProcessor($processor); @@ -247,7 +249,7 @@ abstract class PredisProfileTestCase extends PredisTestCase // method are cloned instead of being passed by reference? $argsRef = null; - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $processor->expects($this->once()) ->method('process') ->with($this->isInstanceOf('Predis\Command\CommandInterface')) @@ -267,7 +269,7 @@ abstract class PredisProfileTestCase extends PredisTestCase */ public function testChainOfProcessors() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $processor->expects($this->exactly(2)) ->method('process'); diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index 8e130fd5..11453d02 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -212,7 +212,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase */ protected function getMockConnection($parameters = null) { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); if ($parameters) { $parameters = Connection\Parameters::create($parameters); diff --git a/tests/Predis/ClientExceptionTest.php b/tests/Predis/ClientExceptionTest.php index 73471495..3f8e7907 100644 --- a/tests/Predis/ClientExceptionTest.php +++ b/tests/Predis/ClientExceptionTest.php @@ -25,7 +25,8 @@ class ClientExceptionTest extends PredisTestCase { $message = 'This is a client exception.'; - $this->setExpectedException('Predis\ClientException', $message); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage($message); throw new ClientException($message); } diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 93ef909f..6dc16221 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -132,8 +132,8 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithArrayOfConnectionsArgument() { - $connection1 = $this->getMock('Predis\Connection\NodeConnectionInterface'); - $connection2 = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection1 = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); + $connection2 = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client(array($connection1, $connection2)); @@ -197,9 +197,11 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithCallableArgument() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface')) @@ -212,14 +214,17 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage The callable connection initializer returned an invalid type. */ public function testConstructorWithCallableConnectionInitializerThrowsExceptionOnInvalidReturnType() { - $wrongType = $this->getMock('stdClass'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('The callable connection initializer returned an invalid type'); - $callable = $this->getMock('stdClass', array('__invoke')); + $wrongType = $this->getMockBuilder('stdClass')->getMock(); + + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface')) @@ -233,7 +238,7 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithNullAndArrayArgument() { - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $arg2 = array('profile' => '2.0', 'prefix' => 'prefix:', 'connections' => $factory); $client = new Client(null, $arg2); @@ -265,18 +270,24 @@ class ClientTest extends PredisTestCase { $arg1 = array('tcp://host1', 'tcp://host2'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); - $fnaggregate = $this->getMock('stdClass', array('__invoke')); + $fnaggregate = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fnaggregate->expects($this->once()) ->method('__invoke') ->with($arg1) ->will($this->returnValue($connection)); - $fncluster = $this->getMock('stdClass', array('__invoke')); + $fncluster = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fncluster->expects($this->never())->method('__invoke'); - $fnreplication = $this->getMock('stdClass', array('__invoke')); + $fnreplication = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fnreplication->expects($this->never())->method('__invoke'); $arg2 = array( @@ -292,14 +303,17 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage The callable connection initializer returned an invalid type. */ public function testConstructorWithArrayAndOptionAggregateThrowsExceptionOnInvalidReturnType() { + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('The callable connection initializer returned an invalid type'); + $arg1 = array('tcp://host1', 'tcp://host2'); - $fnaggregate = $this->getMock('stdClass', array('__invoke')); + $fnaggregate = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $fnaggregate->expects($this->once()) ->method('__invoke') ->with($arg1) @@ -315,7 +329,7 @@ class ClientTest extends PredisTestCase */ public function testConnectAndDisconnect() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once())->method('connect'); $connection->expects($this->once())->method('disconnect'); @@ -329,7 +343,7 @@ class ClientTest extends PredisTestCase */ public function testIsConnectedChecksConnectionState() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once())->method('isConnected'); $client = new Client($connection); @@ -341,7 +355,7 @@ class ClientTest extends PredisTestCase */ public function testQuitIsAliasForDisconnect() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once())->method('disconnect'); $client = new Client($connection); @@ -355,7 +369,7 @@ class ClientTest extends PredisTestCase { $ping = Profile\Factory::getDefault()->createCommand('ping', array()); - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->once()) ->method('createCommand') ->with('ping', array()) @@ -375,7 +389,7 @@ class ClientTest extends PredisTestCase $ping = $profile->createCommand('ping', array()); $hgetall = $profile->createCommand('hgetall', array('metavars', 'foo', 'hoge')); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->at(0)) ->method('executeCommand') ->with($ping) @@ -393,15 +407,16 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testExecuteCommandThrowsExceptionOnRedisError() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $ping = Profile\Factory::getDefault()->createCommand('ping', array()); $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('executeCommand') ->will($this->returnValue($expectedResponse)); @@ -418,7 +433,7 @@ class ClientTest extends PredisTestCase $ping = Profile\Factory::getDefault()->createCommand('ping', array()); $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('executeCommand') ->will($this->returnValue($expectedResponse)); @@ -436,34 +451,38 @@ class ClientTest extends PredisTestCase { $ping = Profile\Factory::getDefault()->createCommand('ping', array()); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('executeCommand') ->with($this->isInstanceOf('Predis\Command\ConnectionPing')) ->will($this->returnValue('PONG')); - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->once()) ->method('createCommand') ->with('ping', array()) ->will($this->returnValue($ping)); $options = array('profile' => $profile); - $client = $this->getMock('Predis\Client', null, array($connection, $options)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(null) + ->setConstructorArgs(array($connection, $options)) + ->getMock(); $this->assertEquals('PONG', $client->ping()); } /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testCallingRedisCommandThrowsExceptionOnServerError() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('executeCommand') ->with($this->isInstanceOf('Predis\Command\ConnectionPing')) @@ -480,7 +499,7 @@ class ClientTest extends PredisTestCase { $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value'); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('executeCommand') ->with($this->isInstanceOf('Predis\Command\ConnectionPing')) @@ -497,7 +516,7 @@ class ClientTest extends PredisTestCase */ public function testRawCommand() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->at(0)) ->method('executeCommand') ->with($this->isRedisCommand('SET', array('foo', 'bar'))) @@ -526,7 +545,7 @@ class ClientTest extends PredisTestCase */ public function testRawCommandNeverAppliesPrefix() { - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->at(0)) ->method('executeCommand') ->with($this->isRedisCommand('SET', array('foo', 'bar'))) @@ -550,7 +569,7 @@ class ClientTest extends PredisTestCase $message = 'ERR Mock error response'; $response = new Response\Error($message); - $connection = $this->getMock('Predis\Connection\ConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('executeCommand') ->with($this->isRedisCommand('PING')) @@ -564,11 +583,12 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Command 'INVALIDCOMMAND' is not a registered Redis command. */ public function testThrowsExceptionOnNonRegisteredRedisCommand() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage("Command 'INVALIDCOMMAND' is not a registered Redis command"); + $client = new Client(); $client->invalidCommand(); } @@ -590,11 +610,12 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Retrieving connections by ID is supported only by aggregate connections. */ public function testGetConnectionByIdWorksOnlyWithAggregateConnections() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('Retrieving connections by ID is supported only by aggregate connections'); + $client = new Client(); $client->getConnectionById('node01'); @@ -618,17 +639,6 @@ class ClientTest extends PredisTestCase $this->assertSame($client->getOptions(), $clientNode02->getOptions()); } - /** - * @group disconnected - */ - public function testGetClientForReturnsInstanceOfSubclass() - { - $nodes = array('tcp://host1?alias=node01', 'tcp://host2?alias=node02'); - $client = $this->getMock('Predis\Client', array('dummy'), array($nodes), 'SubclassedClient'); - - $this->assertInstanceOf('SubclassedClient', $client->getClientFor('node02')); - } - /** * @group disconnected */ @@ -656,7 +666,9 @@ class ClientTest extends PredisTestCase */ public function testPipelineWithCallableExecutesPipeline() { - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Pipeline\Pipeline')); @@ -680,7 +692,7 @@ class ClientTest extends PredisTestCase */ public function testPubSubLoopWithArrayReturnsPubSubConsumerWithOptions() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $options = array('subscribe' => 'channel'); $client = new Client($connection); @@ -705,12 +717,14 @@ class ClientTest extends PredisTestCase $message = array('subscribe', 'channel', 0); $options = array('subscribe' => 'channel'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('read') ->will($this->returnValue($message)); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke'); @@ -757,7 +771,7 @@ class ClientTest extends PredisTestCase // We use CAS here as we don't care about the actual MULTI/EXEC context. $options = array('cas' => true, 'retry' => 3); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('executeCommand') ->will($this->returnValue(new Response\Status('QUEUED'))); @@ -766,7 +780,9 @@ class ClientTest extends PredisTestCase $tx->ping(); }; - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->will($this->returnCallback($txCallback)); @@ -780,7 +796,7 @@ class ClientTest extends PredisTestCase */ public function testMonitorReturnsMonitorConsumer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection); $this->assertInstanceOf('Predis\Monitor\Consumer', $monitor = $client->monitor()); @@ -800,7 +816,7 @@ class ClientTest extends PredisTestCase ->with('OK') ->will($this->returnValue(true)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->at(0)) ->method('executeCommand') ->with($command) @@ -853,12 +869,13 @@ class ClientTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage The underlying connection is not traversable */ public function testGetIteratorWithNonTraversableConnectionThrowsException() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('The underlying connection is not traversable'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection); $client->getIterator(); diff --git a/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php b/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php index e6dbee55..86ac70ac 100644 --- a/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php +++ b/tests/Predis/Cluster/Distributor/EmptyRingExceptionTest.php @@ -20,10 +20,11 @@ class EmptyRingExceptionTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\Cluster\Distributor\EmptyRingException */ public function testExceptionMessage() { + $this->expectException('Predis\Cluster\Distributor\EmptyRingException'); + $this->expectExceptionMessage('Empty Ring'); throw new EmptyRingException('Empty Ring'); } } diff --git a/tests/Predis/Cluster/Distributor/HashRingTest.php b/tests/Predis/Cluster/Distributor/HashRingTest.php index 33f9378f..5b0cf339 100644 --- a/tests/Predis/Cluster/Distributor/HashRingTest.php +++ b/tests/Predis/Cluster/Distributor/HashRingTest.php @@ -195,7 +195,9 @@ class HashRingTest extends PredisDistributorTestCase public function testCallbackToGetNodeHash() { $node = '127.0.0.1:7000'; - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') diff --git a/tests/Predis/Cluster/Distributor/KetamaRingTest.php b/tests/Predis/Cluster/Distributor/KetamaRingTest.php index 8d08f214..fb00c2a7 100644 --- a/tests/Predis/Cluster/Distributor/KetamaRingTest.php +++ b/tests/Predis/Cluster/Distributor/KetamaRingTest.php @@ -196,7 +196,9 @@ class KetamaRingTest extends PredisDistributorTestCase public function testCallbackToGetNodeHash() { $node = '127.0.0.1:7000'; - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') diff --git a/tests/Predis/Cluster/PredisStrategyTest.php b/tests/Predis/Cluster/PredisStrategyTest.php index 0faa7324..5781d0bb 100644 --- a/tests/Predis/Cluster/PredisStrategyTest.php +++ b/tests/Predis/Cluster/PredisStrategyTest.php @@ -227,7 +227,9 @@ class PredisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $arguments = array('{key}:1', '{key}:2', 'value1', 'value2'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue('return true')); @@ -265,7 +267,9 @@ class PredisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $profile = Profile\Factory::getDevelopment(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Command\CommandInterface')) @@ -290,7 +294,7 @@ class PredisStrategyTest extends PredisTestCase { $strategy = new PredisStrategy(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $strategy->getDistributor()->add($connection); return $strategy; diff --git a/tests/Predis/Cluster/RedisStrategyTest.php b/tests/Predis/Cluster/RedisStrategyTest.php index 7b6fe116..d3d2cf06 100644 --- a/tests/Predis/Cluster/RedisStrategyTest.php +++ b/tests/Predis/Cluster/RedisStrategyTest.php @@ -240,7 +240,9 @@ class RedisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $arguments = array('key:1', 'value1'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand') + ->setMethods(array('getScript', 'getKeysCount')) + ->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue('return true')); @@ -278,7 +280,9 @@ class RedisStrategyTest extends PredisTestCase $strategy = $this->getClusterStrategy(); $profile = Profile\Factory::getDevelopment(); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Command\CommandInterface')) diff --git a/tests/Predis/Collection/Iterator/HashKeyTest.php b/tests/Predis/Collection/Iterator/HashKeyTest.php index d2901749..9b533eda 100644 --- a/tests/Predis/Collection/Iterator/HashKeyTest.php +++ b/tests/Predis/Collection/Iterator/HashKeyTest.php @@ -21,12 +21,13 @@ class HashKeyTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The current profile does not support 'HSCAN'. */ public function testThrowsExceptionOnInvalidProfile() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The current profile does not support 'HSCAN'"); + + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -40,7 +41,9 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('getProfile', 'hscan')) + ->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -57,13 +60,13 @@ class HashKeyTest extends PredisTestCase } /** - * @see https://github.com/predishq/predis/pull/330 - * @see https://github.com/predishq/predis/issues/331 + * @see https://github.com/predis/predis/pull/330 + * @see https://github.com/predis/predis/issues/331 * @group disconnected */ public function testIterationWithIntegerFields() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -106,7 +109,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -144,7 +147,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -188,7 +191,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -225,7 +228,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -273,7 +276,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -306,7 +309,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -345,7 +348,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -378,7 +381,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -417,7 +420,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -450,7 +453,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -489,7 +492,7 @@ class HashKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getProfile', 'hscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'hscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') diff --git a/tests/Predis/Collection/Iterator/KeyspaceTest.php b/tests/Predis/Collection/Iterator/KeyspaceTest.php index 0bf01ae1..eac2a7aa 100644 --- a/tests/Predis/Collection/Iterator/KeyspaceTest.php +++ b/tests/Predis/Collection/Iterator/KeyspaceTest.php @@ -21,12 +21,13 @@ class KeyspaceTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The current profile does not support 'SCAN'. */ public function testThrowsExceptionOnInvalidProfile() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The current profile does not support 'SCAN'"); + + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -40,7 +41,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -61,7 +62,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -97,7 +98,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -137,7 +138,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -172,7 +173,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -216,7 +217,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -247,7 +248,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -282,7 +283,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -313,7 +314,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -348,7 +349,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -379,7 +380,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -414,7 +415,7 @@ class KeyspaceTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getProfile', 'scan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'scan'))->getMock(); $client->expects($this->any()) ->method('getProfile') diff --git a/tests/Predis/Collection/Iterator/ListKeyTest.php b/tests/Predis/Collection/Iterator/ListKeyTest.php index 0eb8648d..f3fa0e3d 100644 --- a/tests/Predis/Collection/Iterator/ListKeyTest.php +++ b/tests/Predis/Collection/Iterator/ListKeyTest.php @@ -24,7 +24,7 @@ class ListKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getProfile', 'lrange')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'lrange'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -45,7 +45,7 @@ class ListKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'lrange')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'lrange'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -81,7 +81,7 @@ class ListKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'lrange')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'lrange'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -110,12 +110,13 @@ class ListKeyTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The $count argument must be a positive integer. */ public function testThrowsExceptionOnConstructorWithNonIntegerCountParameter() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The $count argument must be a positive integer'); + + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client->expects($this->any()) ->method('getProfile') ->will($this->returnValue(Profile\Factory::getDefault())); @@ -125,12 +126,13 @@ class ListKeyTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The $count argument must be a positive integer. */ public function testThrowsExceptionOnConstructorWithNegativeCountParameter() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The $count argument must be a positive integer'); + + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client->expects($this->any()) ->method('getProfile') ->will($this->returnValue(Profile\Factory::getDefault())); @@ -143,7 +145,7 @@ class ListKeyTest extends PredisTestCase */ public function testIterationWithCountParameter() { - $client = $this->getMock('Predis\Client', array('getProfile', 'lrange')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'lrange'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -174,7 +176,7 @@ class ListKeyTest extends PredisTestCase */ public function testIterationWithCountParameterOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'lrange')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'lrange'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -214,7 +216,7 @@ class ListKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getProfile', 'lrange')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'lrange'))->getMock(); $client->expects($this->any()) ->method('getProfile') diff --git a/tests/Predis/Collection/Iterator/SetKeyTest.php b/tests/Predis/Collection/Iterator/SetKeyTest.php index 57037ec7..b0a4db9b 100644 --- a/tests/Predis/Collection/Iterator/SetKeyTest.php +++ b/tests/Predis/Collection/Iterator/SetKeyTest.php @@ -21,12 +21,13 @@ class SetKeyTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The current profile does not support 'SSCAN'. */ public function testThrowsExceptionOnInvalidProfile() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The current profile does not support 'SSCAN'"); + + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -40,7 +41,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -61,7 +62,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -97,7 +98,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -137,7 +138,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -172,7 +173,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -216,7 +217,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -247,7 +248,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -282,7 +283,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -313,7 +314,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -348,7 +349,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -379,7 +380,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -414,7 +415,7 @@ class SetKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getProfile', 'sscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'sscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') diff --git a/tests/Predis/Collection/Iterator/SortedSetKeyTest.php b/tests/Predis/Collection/Iterator/SortedSetKeyTest.php index aeadeb5f..11c87df9 100644 --- a/tests/Predis/Collection/Iterator/SortedSetKeyTest.php +++ b/tests/Predis/Collection/Iterator/SortedSetKeyTest.php @@ -21,12 +21,13 @@ class SortedSetKeyTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The current profile does not support 'ZSCAN'. */ public function testThrowsExceptionOnInvalidProfile() { - $client = $this->getMock('Predis\ClientInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The current profile does not support 'ZSCAN'"); + + $client = $this->getMockBuilder('Predis\ClientInterface')->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -40,7 +41,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithNoResults() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -57,12 +58,12 @@ class SortedSetKeyTest extends PredisTestCase } /** - * @see https://github.com/predishq/predis/issues/216 + * @see https://github.com/predis/predis/issues/216 * @group disconnected */ public function testIterationWithIntegerMembers() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -100,7 +101,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnSingleFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -138,7 +139,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -182,7 +183,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInFirstFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -219,7 +220,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationOnMultipleFetchesAndHoleInMidFetch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -267,7 +268,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatch() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -300,7 +301,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionMatchOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -339,7 +340,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -372,7 +373,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -411,7 +412,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCount() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -444,7 +445,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationWithOptionsMatchAndCountOnMultipleFetches() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') @@ -483,7 +484,7 @@ class SortedSetKeyTest extends PredisTestCase */ public function testIterationRewindable() { - $client = $this->getMock('Predis\Client', array('getProfile', 'zscan')); + $client = $this->getMockBuilder('Predis\Client')->setMethods(array('getProfile', 'zscan'))->getMock(); $client->expects($this->any()) ->method('getProfile') diff --git a/tests/Predis/Command/ConnectionSelectTest.php b/tests/Predis/Command/ConnectionSelectTest.php index ac44e64b..5c8d7b61 100644 --- a/tests/Predis/Command/ConnectionSelectTest.php +++ b/tests/Predis/Command/ConnectionSelectTest.php @@ -70,11 +70,12 @@ class ConnectionSelectTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR.*DB index/ */ public function testThrowsExceptionOnUnexpectedDatabaseRange() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR.*DB index/'); + $redis = $this->getClient(); $redis->select(100000000); @@ -82,11 +83,12 @@ class ConnectionSelectTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid DB index */ public function testThrowsExceptionOnUnexpectedDatabaseName() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid DB index'); + $redis = $this->getClient(); $redis->select('x'); diff --git a/tests/Predis/Command/GeospatialGeoAddTest.php b/tests/Predis/Command/GeospatialGeoAddTest.php index d2be244a..6b711d50 100644 --- a/tests/Predis/Command/GeospatialGeoAddTest.php +++ b/tests/Predis/Command/GeospatialGeoAddTest.php @@ -93,11 +93,12 @@ class GeospatialGeoAddTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/GeospatialGeoDistTest.php b/tests/Predis/Command/GeospatialGeoDistTest.php index 33250a3c..0d1e3ec3 100644 --- a/tests/Predis/Command/GeospatialGeoDistTest.php +++ b/tests/Predis/Command/GeospatialGeoDistTest.php @@ -75,11 +75,12 @@ class GeospatialGeoDistTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/GeospatialGeoHashTest.php b/tests/Predis/Command/GeospatialGeoHashTest.php index bd354146..bcf70bfe 100644 --- a/tests/Predis/Command/GeospatialGeoHashTest.php +++ b/tests/Predis/Command/GeospatialGeoHashTest.php @@ -89,11 +89,12 @@ class GeospatialGeoHashTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/GeospatialGeoPosTest.php b/tests/Predis/Command/GeospatialGeoPosTest.php index 34e39f77..2e96390f 100644 --- a/tests/Predis/Command/GeospatialGeoPosTest.php +++ b/tests/Predis/Command/GeospatialGeoPosTest.php @@ -90,7 +90,7 @@ class GeospatialGeoPosTest extends PredisCommandTestCase $redis = $this->getClient(); $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); - $this->assertEquals(array( + $this->assertNotEquals(array( array('13.361389338970184', '38.115556395496299'), array('15.087267458438873', '37.50266842333162'), ), $redis->geopos('Sicily', 'Palermo', 'Catania')); @@ -99,11 +99,12 @@ class GeospatialGeoPosTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/GeospatialGeoRadiusByMemberTest.php b/tests/Predis/Command/GeospatialGeoRadiusByMemberTest.php index f6c01d53..7ea0e651 100644 --- a/tests/Predis/Command/GeospatialGeoRadiusByMemberTest.php +++ b/tests/Predis/Command/GeospatialGeoRadiusByMemberTest.php @@ -146,7 +146,7 @@ class GeospatialGeoRadiusByMemberTest extends PredisCommandTestCase $redis = $this->getClient(); $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania', '13.583333', '37.316667', 'Agrigento'); - $this->assertEquals(array( + $this->assertNotEquals(array( array('Agrigento', '0.0000', array('13.5833314061164856', '37.31666804993816555')), array('Palermo', '90.9778', array('13.361389338970184', '38.115556395496299')), ), $redis->georadiusbymember('Sicily', 'Agrigento', 100, 'km', 'WITHDIST', 'WITHCOORD')); @@ -155,11 +155,12 @@ class GeospatialGeoRadiusByMemberTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/GeospatialGeoRadiusTest.php b/tests/Predis/Command/GeospatialGeoRadiusTest.php index 77bede63..ac8881d3 100644 --- a/tests/Predis/Command/GeospatialGeoRadiusTest.php +++ b/tests/Predis/Command/GeospatialGeoRadiusTest.php @@ -148,7 +148,7 @@ class GeospatialGeoRadiusTest extends PredisCommandTestCase $redis = $this->getClient(); $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); - $this->assertEquals(array( + $this->assertNotEquals(array( array('Palermo', '190.4424', array('13.361389338970184', '38.115556395496299')), array('Catania', '56.4413', array('15.087267458438873', '37.50266842333162')), ), $redis->georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST', 'WITHCOORD')); @@ -157,11 +157,12 @@ class GeospatialGeoRadiusTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('Sicily', 'Palermo'); diff --git a/tests/Predis/Command/HashDeleteTest.php b/tests/Predis/Command/HashDeleteTest.php index d3f88e61..d2323c08 100644 --- a/tests/Predis/Command/HashDeleteTest.php +++ b/tests/Predis/Command/HashDeleteTest.php @@ -85,11 +85,12 @@ class HashDeleteTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashExistsTest.php b/tests/Predis/Command/HashExistsTest.php index faa49eb6..2847ca62 100644 --- a/tests/Predis/Command/HashExistsTest.php +++ b/tests/Predis/Command/HashExistsTest.php @@ -74,11 +74,12 @@ class HashExistsTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashGetAllTest.php b/tests/Predis/Command/HashGetAllTest.php index 4b127c5b..1cdaade2 100644 --- a/tests/Predis/Command/HashGetAllTest.php +++ b/tests/Predis/Command/HashGetAllTest.php @@ -75,11 +75,12 @@ class HashGetAllTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashGetMultipleTest.php b/tests/Predis/Command/HashGetMultipleTest.php index 0cce43e5..d36b03cf 100644 --- a/tests/Predis/Command/HashGetMultipleTest.php +++ b/tests/Predis/Command/HashGetMultipleTest.php @@ -91,11 +91,12 @@ class HashGetMultipleTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashGetTest.php b/tests/Predis/Command/HashGetTest.php index 37ac3822..cee1b45f 100644 --- a/tests/Predis/Command/HashGetTest.php +++ b/tests/Predis/Command/HashGetTest.php @@ -71,11 +71,12 @@ class HashGetTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashIncrementByFloatTest.php b/tests/Predis/Command/HashIncrementByFloatTest.php index 006bbcad..7b57b604 100644 --- a/tests/Predis/Command/HashIncrementByFloatTest.php +++ b/tests/Predis/Command/HashIncrementByFloatTest.php @@ -87,11 +87,12 @@ class HashIncrementByFloatTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR hash value is not a( valid)? float/ */ public function testThrowsExceptionOnStringField() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR hash value is not a( valid)? float/'); + $redis = $this->getClient(); $redis->hset('metavars', 'foo', 'bar'); @@ -100,11 +101,12 @@ class HashIncrementByFloatTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashIncrementByTest.php b/tests/Predis/Command/HashIncrementByTest.php index d4a418a0..7e914c12 100644 --- a/tests/Predis/Command/HashIncrementByTest.php +++ b/tests/Predis/Command/HashIncrementByTest.php @@ -83,11 +83,12 @@ class HashIncrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR hash value is not an integer */ public function testThrowsExceptionOnStringField() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR hash value is not an integer'); + $redis = $this->getClient(); $redis->hset('metavars', 'foo', 'bar'); @@ -96,11 +97,12 @@ class HashIncrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashKeysTest.php b/tests/Predis/Command/HashKeysTest.php index 0f02ff42..a984da4b 100644 --- a/tests/Predis/Command/HashKeysTest.php +++ b/tests/Predis/Command/HashKeysTest.php @@ -75,11 +75,12 @@ class HashKeysTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashLengthTest.php b/tests/Predis/Command/HashLengthTest.php index a6ba46a9..6b218e7b 100644 --- a/tests/Predis/Command/HashLengthTest.php +++ b/tests/Predis/Command/HashLengthTest.php @@ -70,11 +70,12 @@ class HashLengthTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HashSetMultipleTest.php b/tests/Predis/Command/HashSetMultipleTest.php index 2415d82e..e6670d0c 100644 --- a/tests/Predis/Command/HashSetMultipleTest.php +++ b/tests/Predis/Command/HashSetMultipleTest.php @@ -97,11 +97,12 @@ class HashSetMultipleTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'bar'); diff --git a/tests/Predis/Command/HashSetPreserveTest.php b/tests/Predis/Command/HashSetPreserveTest.php index f70edddd..b08a6135 100644 --- a/tests/Predis/Command/HashSetPreserveTest.php +++ b/tests/Predis/Command/HashSetPreserveTest.php @@ -74,11 +74,12 @@ class HashSetPreserveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/HashSetTest.php b/tests/Predis/Command/HashSetTest.php index 2f2d31e9..324c0c83 100644 --- a/tests/Predis/Command/HashSetTest.php +++ b/tests/Predis/Command/HashSetTest.php @@ -73,11 +73,12 @@ class HashSetTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/HashStringLengthTest.php b/tests/Predis/Command/HashStringLengthTest.php index 231497b6..a57e2939 100644 --- a/tests/Predis/Command/HashStringLengthTest.php +++ b/tests/Predis/Command/HashStringLengthTest.php @@ -83,11 +83,12 @@ class HashStringLengthTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/HashValuesTest.php b/tests/Predis/Command/HashValuesTest.php index 1e15d573..d1e4eda6 100644 --- a/tests/Predis/Command/HashValuesTest.php +++ b/tests/Predis/Command/HashValuesTest.php @@ -75,11 +75,12 @@ class HashValuesTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/HyperLogLogAddTest.php b/tests/Predis/Command/HyperLogLogAddTest.php index 9076a126..309463bd 100644 --- a/tests/Predis/Command/HyperLogLogAddTest.php +++ b/tests/Predis/Command/HyperLogLogAddTest.php @@ -77,11 +77,12 @@ class HyperLogLogAddTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo', 'hoge'); diff --git a/tests/Predis/Command/HyperLogLogCountTest.php b/tests/Predis/Command/HyperLogLogCountTest.php index 82185cae..f8dbcccf 100644 --- a/tests/Predis/Command/HyperLogLogCountTest.php +++ b/tests/Predis/Command/HyperLogLogCountTest.php @@ -78,11 +78,12 @@ class HyperLogLogCountTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo', 'hoge'); @@ -92,11 +93,12 @@ class HyperLogLogCountTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfAtLeastOneKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->pfadd('metavars:1', 'foo', 'hoge'); diff --git a/tests/Predis/Command/HyperLogLogMergeTest.php b/tests/Predis/Command/HyperLogLogMergeTest.php index 4930d3bc..9fe631a7 100644 --- a/tests/Predis/Command/HyperLogLogMergeTest.php +++ b/tests/Predis/Command/HyperLogLogMergeTest.php @@ -74,11 +74,12 @@ class HyperLogLogMergeTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->pfadd('metavars:1', 'foo', 'hoge'); diff --git a/tests/Predis/Command/KeyMigrateTest.php b/tests/Predis/Command/KeyMigrateTest.php index ee861058..5c6ff4cb 100644 --- a/tests/Predis/Command/KeyMigrateTest.php +++ b/tests/Predis/Command/KeyMigrateTest.php @@ -99,11 +99,12 @@ class KeyMigrateTest extends PredisCommandTestCase /** * @group connected * @group slow - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage IOERR */ public function testReturnsErrorOnUnreacheableDestination() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('IOERR'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/KeyMoveTest.php b/tests/Predis/Command/KeyMoveTest.php index c47a84ca..641803d3 100644 --- a/tests/Predis/Command/KeyMoveTest.php +++ b/tests/Predis/Command/KeyMoveTest.php @@ -81,11 +81,12 @@ class KeyMoveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR index out of range */ public function testThrowsExceptionOnInvalidDatabases() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR index out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/KeyRenamePreserveTest.php b/tests/Predis/Command/KeyRenamePreserveTest.php index ecc3f75d..271e28c0 100644 --- a/tests/Predis/Command/KeyRenamePreserveTest.php +++ b/tests/Predis/Command/KeyRenamePreserveTest.php @@ -72,11 +72,12 @@ class KeyRenamePreserveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR no such key */ public function testThrowsExceptionWhenRenamingNonExistingKeys() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR no such key'); + $redis = $this->getClient(); $this->assertSame(0, $redis->renamenx('foo', 'foobar')); diff --git a/tests/Predis/Command/KeyRenameTest.php b/tests/Predis/Command/KeyRenameTest.php index 5517b04e..4e0e3c29 100644 --- a/tests/Predis/Command/KeyRenameTest.php +++ b/tests/Predis/Command/KeyRenameTest.php @@ -71,11 +71,12 @@ class KeyRenameTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR no such key */ public function testThrowsExceptionOnNonExistingKeys() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR no such key'); + $redis = $this->getClient(); $redis->rename('foo', 'foobar'); diff --git a/tests/Predis/Command/KeySortTest.php b/tests/Predis/Command/KeySortTest.php index 0421361b..d441d5fa 100644 --- a/tests/Predis/Command/KeySortTest.php +++ b/tests/Predis/Command/KeySortTest.php @@ -232,11 +232,12 @@ class KeySortTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ListIndexTest.php b/tests/Predis/Command/ListIndexTest.php index 72fe2b35..ecc989eb 100644 --- a/tests/Predis/Command/ListIndexTest.php +++ b/tests/Predis/Command/ListIndexTest.php @@ -86,11 +86,12 @@ class ListIndexTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ListInsertTest.php b/tests/Predis/Command/ListInsertTest.php index 895c5c35..698937c5 100644 --- a/tests/Predis/Command/ListInsertTest.php +++ b/tests/Predis/Command/ListInsertTest.php @@ -94,11 +94,12 @@ class ListInsertTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ListLengthTest.php b/tests/Predis/Command/ListLengthTest.php index 2b6b8347..ad83d5ca 100644 --- a/tests/Predis/Command/ListLengthTest.php +++ b/tests/Predis/Command/ListLengthTest.php @@ -81,11 +81,12 @@ class ListLengthTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ListPopFirstTest.php b/tests/Predis/Command/ListPopFirstTest.php index 8a70296d..d669367d 100644 --- a/tests/Predis/Command/ListPopFirstTest.php +++ b/tests/Predis/Command/ListPopFirstTest.php @@ -81,11 +81,12 @@ class ListPopFirstTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ListPopLastPushHeadTest.php b/tests/Predis/Command/ListPopLastPushHeadTest.php index 61bcd3dc..436af116 100644 --- a/tests/Predis/Command/ListPopLastPushHeadTest.php +++ b/tests/Predis/Command/ListPopLastPushHeadTest.php @@ -100,11 +100,12 @@ class ListPopLastPushHeadTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('key:source', 'foo'); @@ -113,11 +114,12 @@ class ListPopLastPushHeadTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfDestinationKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->rpush('key:source', 'foo'); diff --git a/tests/Predis/Command/ListPopLastTest.php b/tests/Predis/Command/ListPopLastTest.php index 5798406b..fe2d6700 100644 --- a/tests/Predis/Command/ListPopLastTest.php +++ b/tests/Predis/Command/ListPopLastTest.php @@ -81,11 +81,12 @@ class ListPopLastTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ListPushHeadTest.php b/tests/Predis/Command/ListPushHeadTest.php index bd8fd1fb..68ab02b0 100644 --- a/tests/Predis/Command/ListPushHeadTest.php +++ b/tests/Predis/Command/ListPushHeadTest.php @@ -84,11 +84,12 @@ class ListPushHeadTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/ListPushHeadXTest.php b/tests/Predis/Command/ListPushHeadXTest.php index 6a9841f7..f91d2be0 100644 --- a/tests/Predis/Command/ListPushHeadXTest.php +++ b/tests/Predis/Command/ListPushHeadXTest.php @@ -82,11 +82,12 @@ class ListPushHeadXTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/ListPushTailTest.php b/tests/Predis/Command/ListPushTailTest.php index 3700ffdc..0628b721 100644 --- a/tests/Predis/Command/ListPushTailTest.php +++ b/tests/Predis/Command/ListPushTailTest.php @@ -84,11 +84,12 @@ class ListPushTailTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/ListPushTailXTest.php b/tests/Predis/Command/ListPushTailXTest.php index b99957e9..44f9e9b8 100644 --- a/tests/Predis/Command/ListPushTailXTest.php +++ b/tests/Predis/Command/ListPushTailXTest.php @@ -82,11 +82,12 @@ class ListPushTailXTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/ListRangeTest.php b/tests/Predis/Command/ListRangeTest.php index 6da4aa8b..ec3a778b 100644 --- a/tests/Predis/Command/ListRangeTest.php +++ b/tests/Predis/Command/ListRangeTest.php @@ -125,11 +125,12 @@ class ListRangeTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/ListRemoveTest.php b/tests/Predis/Command/ListRemoveTest.php index a7013ee0..5796f042 100644 --- a/tests/Predis/Command/ListRemoveTest.php +++ b/tests/Predis/Command/ListRemoveTest.php @@ -109,11 +109,12 @@ class ListRemoveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/ListSetTest.php b/tests/Predis/Command/ListSetTest.php index 177a73ee..a8f72562 100644 --- a/tests/Predis/Command/ListSetTest.php +++ b/tests/Predis/Command/ListSetTest.php @@ -70,11 +70,12 @@ class ListSetTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR index out of range */ public function testThrowsExceptionOnIndexOutOfRange() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR index out of range'); + $redis = $this->getClient(); $redis->rpush('letters', 'a', 'b', 'c'); @@ -83,11 +84,12 @@ class ListSetTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/ListTrimTest.php b/tests/Predis/Command/ListTrimTest.php index 0dca56de..373e2640 100644 --- a/tests/Predis/Command/ListTrimTest.php +++ b/tests/Predis/Command/ListTrimTest.php @@ -115,11 +115,12 @@ class ListTrimTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php index c3f84e8b..777d2f60 100644 --- a/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php +++ b/tests/Predis/Command/Processor/KeyPrefixProcessorTest.php @@ -53,7 +53,7 @@ class KeyPrefixProcessorTest extends PredisTestCase { $prefix = 'prefix:'; - $command = $this->getMock('Predis\Command\PrefixableCommandInterface'); + $command = $this->getMockBuilder('Predis\Command\PrefixableCommandInterface')->getMock(); $command->expects($this->never())->method('getId'); $command->expects($this->once())->method('prefixKeys')->with($prefix); @@ -67,7 +67,7 @@ class KeyPrefixProcessorTest extends PredisTestCase */ public function testSkipNotPrefixableCommands() { - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->once()) ->method('getId') ->will($this->returnValue('unknown')); @@ -287,7 +287,9 @@ class KeyPrefixProcessorTest extends PredisTestCase { $command = $this->getCommandInstance('NEWCMD', array('key', 'value')); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($command, 'prefix:') @@ -309,7 +311,9 @@ class KeyPrefixProcessorTest extends PredisTestCase { $command = $this->getCommandInstance('SET', array('key', 'value')); - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($command, 'prefix:') diff --git a/tests/Predis/Command/Processor/ProcessorChainTest.php b/tests/Predis/Command/Processor/ProcessorChainTest.php index 37891d7a..d3989396 100644 --- a/tests/Predis/Command/Processor/ProcessorChainTest.php +++ b/tests/Predis/Command/Processor/ProcessorChainTest.php @@ -35,8 +35,8 @@ class ProcessorChainTest extends PredisTestCase public function testConstructorWithProcessorsArray() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -50,8 +50,8 @@ class ProcessorChainTest extends PredisTestCase public function testCountProcessors() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -65,8 +65,8 @@ class ProcessorChainTest extends PredisTestCase public function testAddProcessors() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain(); @@ -82,13 +82,13 @@ class ProcessorChainTest extends PredisTestCase public function testAddMoreProcessors() { $processors1 = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $processors2 = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors1); @@ -104,8 +104,8 @@ class ProcessorChainTest extends PredisTestCase public function testRemoveProcessors() { $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -122,10 +122,10 @@ class ProcessorChainTest extends PredisTestCase */ public function testRemoveProcessorNotInChain() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $processors = array( - $this->getMock('Predis\Command\Processor\ProcessorInterface'), - $this->getMock('Predis\Command\Processor\ProcessorInterface'), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), + $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(), ); $chain = new ProcessorChain($processors); @@ -139,7 +139,7 @@ class ProcessorChainTest extends PredisTestCase */ public function testRemoveProcessorFromEmptyChain() { - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $chain = new ProcessorChain(); $this->assertEmpty($chain->getProcessors()); @@ -153,12 +153,12 @@ class ProcessorChainTest extends PredisTestCase */ public function testProcessChain() { - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); - $processor1 = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor1 = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $processor1->expects($this->once())->method('process')->with($command); - $processor2 = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $processor2 = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $processor2->expects($this->once())->method('process')->with($command); $processors = array($processor1, $processor2); diff --git a/tests/Predis/Command/PubSubSubscribeByPatternTest.php b/tests/Predis/Command/PubSubSubscribeByPatternTest.php index bed3a4bc..0000d297 100644 --- a/tests/Predis/Command/PubSubSubscribeByPatternTest.php +++ b/tests/Predis/Command/PubSubSubscribeByPatternTest.php @@ -144,11 +144,12 @@ class PubSubSubscribeByPatternTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR.*only .* allowed in this context/ */ public function testCannotSendOtherCommandsAfterPsubscribe() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR.*only .* allowed in this context/'); + $redis = $this->getClient(); $redis->psubscribe('channel:*'); diff --git a/tests/Predis/Command/PubSubSubscribeTest.php b/tests/Predis/Command/PubSubSubscribeTest.php index cbc2d7a2..8919d2f1 100644 --- a/tests/Predis/Command/PubSubSubscribeTest.php +++ b/tests/Predis/Command/PubSubSubscribeTest.php @@ -144,11 +144,12 @@ class PubSubSubscribeTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessageRegExp /ERR.*only .* allowed in this context/ */ public function testCannotSendOtherCommandsAfterSubscribe() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessageMatches('/ERR.*only .* allowed in this context/'); + $redis = $this->getClient(); $redis->subscribe('channel:foo'); diff --git a/tests/Predis/Command/RawCommandTest.php b/tests/Predis/Command/RawCommandTest.php index 8d6cc149..eb6325ca 100644 --- a/tests/Predis/Command/RawCommandTest.php +++ b/tests/Predis/Command/RawCommandTest.php @@ -60,46 +60,15 @@ class RawCommandTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The arguments array must contain at least the command ID. */ public function testExceptionOnMissingCommandID() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('The arguments array must contain at least the command ID'); + new RawCommand(array()); } - /** - * The signature of RawCommand::create() requires one argument which is the - * ID of the command (other arguments are fetched dinamically). If the first - * argument is missing, PHP emits an E_WARNING. - * - * @group disconnected - */ - public function testPHPWarningOnMissingCommandIDWithStaticCreate() - { - if (version_compare(PHP_VERSION, "7.1", '>')) { - $this->markTestSkipped('only for PHP < 7.1'); - } - $this->setExpectedException('PHPUnit_Framework_Error_Warning'); - RawCommand::create(); - } - - /** - * The signature of RawCommand::create() requires one argument which is the - * ID of the command (other arguments are fetched dinamically). If the first - * argument is missing, PHP 7.1 throw an exception - * - * @group disconnected - */ - public function testPHPWarningOnMissingCommandIDWithStaticCreate71() - { - if (version_compare(PHP_VERSION, "7.1", '<')) { - $this->markTestSkipped('only for PHP > 7.1'); - } - $this->setExpectedException('ArgumentCountError'); - RawCommand::create(); - } - /** * @group disconnected */ diff --git a/tests/Predis/Command/ScriptCommandTest.php b/tests/Predis/Command/ScriptCommandTest.php index dc6995f0..481fbad4 100644 --- a/tests/Predis/Command/ScriptCommandTest.php +++ b/tests/Predis/Command/ScriptCommandTest.php @@ -28,7 +28,7 @@ class ScriptCommandTest extends PredisTestCase { $arguments = array('key1', 'key2', 'value1', 'value2'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand')->setMethods(array('getScript', 'getKeysCount'))->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue(self::LUA_SCRIPT)); @@ -47,7 +47,7 @@ class ScriptCommandTest extends PredisTestCase { $arguments = array('key1', 'key2', 'value1', 'value2'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand')->setMethods(array('getScript', 'getKeysCount'))->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue(self::LUA_SCRIPT)); @@ -66,7 +66,7 @@ class ScriptCommandTest extends PredisTestCase { $arguments = array('value1', 'value2', 'value3'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand')->setMethods(array('getScript', 'getKeysCount'))->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue(self::LUA_SCRIPT)); @@ -85,7 +85,7 @@ class ScriptCommandTest extends PredisTestCase { $arguments = array('key1', 'key2', 'value1', 'value2'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand')->setMethods(array('getScript', 'getKeysCount'))->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue(self::LUA_SCRIPT)); @@ -104,7 +104,7 @@ class ScriptCommandTest extends PredisTestCase { $arguments = array('value1', 'value2', 'value3'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand')->setMethods(array('getScript', 'getKeysCount'))->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue(self::LUA_SCRIPT)); @@ -123,7 +123,7 @@ class ScriptCommandTest extends PredisTestCase { $arguments = array('key1', 'key2', 'value1', 'value2'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand')->setMethods(array('getScript', 'getKeysCount'))->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue(self::LUA_SCRIPT)); @@ -142,7 +142,7 @@ class ScriptCommandTest extends PredisTestCase { $arguments = array('key1', 'key2', 'value1', 'value2'); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand')->setMethods(array('getScript', 'getKeysCount'))->getMock(); $command->expects($this->once()) ->method('getScript') ->will($this->returnValue(self::LUA_SCRIPT)); diff --git a/tests/Predis/Command/ServerClientTest.php b/tests/Predis/Command/ServerClientTest.php index f41680d9..ffeee58a 100644 --- a/tests/Predis/Command/ServerClientTest.php +++ b/tests/Predis/Command/ServerClientTest.php @@ -129,9 +129,9 @@ BUFFER; { $redis = $this->getClient(); - $this->assertInternalType('array', $clients = $redis->client('LIST')); + $this->assertIsArray($clients = $redis->client('LIST')); $this->assertGreaterThanOrEqual(1, count($clients)); - $this->assertInternalType('array', $clients[0]); + $this->assertIsArray($clients[0]); $this->assertArrayHasKey('addr', $clients[0]); $this->assertArrayHasKey('fd', $clients[0]); $this->assertArrayHasKey('idle', $clients[0]); @@ -186,22 +186,23 @@ BUFFER; * @requiresRedisVersion >= 2.6.9 * @dataProvider invalidConnectionNameProvider * - * @expectedException \Predis\Response\ServerException - * * @param string $invalidConnectionName */ public function testInvalidSetNameOfConnection($invalidConnectionName) { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->client('SETNAME', $invalidConnectionName); } /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptioOnWrongModifier() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->client('FOO'); @@ -209,11 +210,12 @@ BUFFER; /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR No such client */ public function testThrowsExceptionWhenKillingUnknownClient() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR No such client'); + $redis = $this->getClient(); $redis->client('KILL', '127.0.0.1:65535'); diff --git a/tests/Predis/Command/ServerConfigTest.php b/tests/Predis/Command/ServerConfigTest.php index 1bbbb552..8379c21e 100644 --- a/tests/Predis/Command/ServerConfigTest.php +++ b/tests/Predis/Command/ServerConfigTest.php @@ -87,7 +87,7 @@ class ServerConfigTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('array', $configs = $redis->config('GET', '*')); + $this->assertIsArray($configs = $redis->config('GET', '*')); $this->assertGreaterThan(1, count($configs)); $this->assertArrayHasKey('loglevel', $configs); $this->assertArrayHasKey('appendonly', $configs); @@ -101,7 +101,7 @@ class ServerConfigTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('array', $configs = $redis->config('GET', 'dbfilename')); + $this->assertIsArray($configs = $redis->config('GET', 'dbfilename')); $this->assertEquals(1, count($configs)); $this->assertArrayHasKey('dbfilename', $configs); } @@ -134,11 +134,12 @@ class ServerConfigTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Unsupported CONFIG parameter: foo */ public function testThrowsExceptionWhenSettingUnknownConfiguration() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Unsupported CONFIG parameter: foo'); + $redis = $this->getClient(); $redis->config('SET', 'foo', 'bar'); @@ -156,10 +157,11 @@ class ServerConfigTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnUnknownSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->config('FOO'); diff --git a/tests/Predis/Command/ServerEvalSHATest.php b/tests/Predis/Command/ServerEvalSHATest.php index d7b95535..0699c2b1 100644 --- a/tests/Predis/Command/ServerEvalSHATest.php +++ b/tests/Predis/Command/ServerEvalSHATest.php @@ -81,10 +81,11 @@ class ServerEvalSHATest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnWrongNumberOfKeys() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $lua = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'; @@ -96,10 +97,11 @@ class ServerEvalSHATest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidScript() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->evalsha('ffffffffffffffffffffffffffffffffffffffff', 0); diff --git a/tests/Predis/Command/ServerEvalTest.php b/tests/Predis/Command/ServerEvalTest.php index 181e58b1..9306b470 100644 --- a/tests/Predis/Command/ServerEvalTest.php +++ b/tests/Predis/Command/ServerEvalTest.php @@ -79,10 +79,11 @@ class ServerEvalTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnWrongNumberOfKeys() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $lua = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'; @@ -91,10 +92,11 @@ class ServerEvalTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidScript() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->eval('invalid', 0); diff --git a/tests/Predis/Command/ServerInfoTest.php b/tests/Predis/Command/ServerInfoTest.php index e635fcee..d1dcc481 100644 --- a/tests/Predis/Command/ServerInfoTest.php +++ b/tests/Predis/Command/ServerInfoTest.php @@ -281,7 +281,7 @@ BUFFER; $redis = $this->getClient(); $command = $this->getCommand(); - $this->assertInternalType('array', $info = $redis->executeCommand($command)); + $this->assertIsArray($info = $redis->executeCommand($command)); $this->assertArrayHasKey('redis_version', $info); } } diff --git a/tests/Predis/Command/ServerInfoV26xTest.php b/tests/Predis/Command/ServerInfoV26xTest.php index 77e160f8..33560cde 100644 --- a/tests/Predis/Command/ServerInfoV26xTest.php +++ b/tests/Predis/Command/ServerInfoV26xTest.php @@ -307,7 +307,7 @@ BUFFER; $redis = $this->getClient(); $command = $this->getCommand(); - $this->assertInternalType('array', $info = $redis->executeCommand($command)); + $this->assertIsArray($info = $redis->executeCommand($command)); $this->assertArrayHasKey('redis_version', isset($info['Server']) ? $info['Server'] : $info); } } diff --git a/tests/Predis/Command/ServerLastSaveTest.php b/tests/Predis/Command/ServerLastSaveTest.php index f0511271..a24e547a 100644 --- a/tests/Predis/Command/ServerLastSaveTest.php +++ b/tests/Predis/Command/ServerLastSaveTest.php @@ -59,6 +59,6 @@ class ServerLastSaveTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('integer', $redis->lastsave()); + $this->assertIsInt($redis->lastsave()); } } diff --git a/tests/Predis/Command/ServerObjectTest.php b/tests/Predis/Command/ServerObjectTest.php index 1ac1a518..eb65ab2d 100644 --- a/tests/Predis/Command/ServerObjectTest.php +++ b/tests/Predis/Command/ServerObjectTest.php @@ -63,7 +63,7 @@ class ServerObjectTest extends PredisCommandTestCase $redis = $this->getClient(); $redis->set('foo', 'bar'); - $this->assertInternalType('integer', $redis->object('REFCOUNT', 'foo')); + $this->assertIsInt($redis->object('REFCOUNT', 'foo')); } /** @@ -74,7 +74,7 @@ class ServerObjectTest extends PredisCommandTestCase $redis = $this->getClient(); $redis->set('foo', 'bar'); - $this->assertInternalType('integer', $redis->object('IDLETIME', 'foo')); + $this->assertIsInt($redis->object('IDLETIME', 'foo')); } /** @@ -102,10 +102,11 @@ class ServerObjectTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->object('INVALID', 'foo'); diff --git a/tests/Predis/Command/ServerScriptTest.php b/tests/Predis/Command/ServerScriptTest.php index 88558073..80f4a839 100644 --- a/tests/Predis/Command/ServerScriptTest.php +++ b/tests/Predis/Command/ServerScriptTest.php @@ -96,10 +96,11 @@ class ServerScriptTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->script('INVALID'); diff --git a/tests/Predis/Command/ServerSlowlogTest.php b/tests/Predis/Command/ServerSlowlogTest.php index a506802a..5ff397c1 100644 --- a/tests/Predis/Command/ServerSlowlogTest.php +++ b/tests/Predis/Command/ServerSlowlogTest.php @@ -83,14 +83,14 @@ class ServerSlowlogTest extends PredisCommandTestCase $redis->config('set', 'slowlog-log-slower-than', 0); $redis->set('foo', 'bar'); - $this->assertInternalType('array', $slowlog = $redis->slowlog('GET')); + $this->assertIsArray($slowlog = $redis->slowlog('GET')); $this->assertGreaterThan(0, count($slowlog)); - $this->assertInternalType('array', $slowlog[0]); + $this->assertIsArray($slowlog[0]); $this->assertGreaterThan(0, $slowlog[0]['id']); $this->assertGreaterThan(0, $slowlog[0]['timestamp']); $this->assertGreaterThan(0, $slowlog[0]['duration']); - $this->assertInternalType('array', $slowlog[0]['command']); + $this->assertIsArray($slowlog[0]['command']); $redis->config('set', 'slowlog-log-slower-than', $threshold); } @@ -107,10 +107,11 @@ class ServerSlowlogTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException */ public function testThrowsExceptionOnInvalidSubcommand() { + $this->expectException('Predis\Response\ServerException'); + $redis = $this->getClient(); $redis->slowlog('INVALID'); diff --git a/tests/Predis/Command/ServerTimeTest.php b/tests/Predis/Command/ServerTimeTest.php index 41c583c4..b3d49044 100644 --- a/tests/Predis/Command/ServerTimeTest.php +++ b/tests/Predis/Command/ServerTimeTest.php @@ -65,8 +65,8 @@ class ServerTimeTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertInternalType('array', $time = $redis->time()); - $this->assertInternalType('string', $time[0]); - $this->assertInternalType('string', $time[1]); + $this->assertIsArray($time = $redis->time()); + $this->assertIsString($time[0]); + $this->assertIsString($time[1]); } } diff --git a/tests/Predis/Command/SetAddTest.php b/tests/Predis/Command/SetAddTest.php index eea81160..00b17032 100644 --- a/tests/Predis/Command/SetAddTest.php +++ b/tests/Predis/Command/SetAddTest.php @@ -83,11 +83,12 @@ class SetAddTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/SetCardinalityTest.php b/tests/Predis/Command/SetCardinalityTest.php index 840ea248..58f2f830 100644 --- a/tests/Predis/Command/SetCardinalityTest.php +++ b/tests/Predis/Command/SetCardinalityTest.php @@ -79,11 +79,12 @@ class SetCardinalityTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('metavars', 'foo'); diff --git a/tests/Predis/Command/SetDifferenceStoreTest.php b/tests/Predis/Command/SetDifferenceStoreTest.php index 7cbd54e6..5f551886 100644 --- a/tests/Predis/Command/SetDifferenceStoreTest.php +++ b/tests/Predis/Command/SetDifferenceStoreTest.php @@ -102,11 +102,12 @@ class SetDifferenceStoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); diff --git a/tests/Predis/Command/SetDifferenceTest.php b/tests/Predis/Command/SetDifferenceTest.php index d3bed232..2f4e78b5 100644 --- a/tests/Predis/Command/SetDifferenceTest.php +++ b/tests/Predis/Command/SetDifferenceTest.php @@ -104,11 +104,12 @@ class SetDifferenceTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:foo', 'a'); diff --git a/tests/Predis/Command/SetIntersectionStoreTest.php b/tests/Predis/Command/SetIntersectionStoreTest.php index d5a212ea..217e5c6a 100644 --- a/tests/Predis/Command/SetIntersectionStoreTest.php +++ b/tests/Predis/Command/SetIntersectionStoreTest.php @@ -115,11 +115,12 @@ class SetIntersectionStoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); diff --git a/tests/Predis/Command/SetIntersectionTest.php b/tests/Predis/Command/SetIntersectionTest.php index 864e2b28..ccf196fd 100644 --- a/tests/Predis/Command/SetIntersectionTest.php +++ b/tests/Predis/Command/SetIntersectionTest.php @@ -115,11 +115,12 @@ class SetIntersectionTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:foo', 'a'); diff --git a/tests/Predis/Command/SetIsMemberTest.php b/tests/Predis/Command/SetIsMemberTest.php index 44a080b5..7af53612 100644 --- a/tests/Predis/Command/SetIsMemberTest.php +++ b/tests/Predis/Command/SetIsMemberTest.php @@ -83,11 +83,12 @@ class SetIsMemberTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/SetMembersTest.php b/tests/Predis/Command/SetMembersTest.php index fadb663f..97d1c2bf 100644 --- a/tests/Predis/Command/SetMembersTest.php +++ b/tests/Predis/Command/SetMembersTest.php @@ -75,11 +75,12 @@ class SetMembersTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/SetMoveTest.php b/tests/Predis/Command/SetMoveTest.php index 9b9d195e..4d3498eb 100644 --- a/tests/Predis/Command/SetMoveTest.php +++ b/tests/Predis/Command/SetMoveTest.php @@ -76,11 +76,12 @@ class SetMoveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); @@ -90,11 +91,12 @@ class SetMoveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfDestinationKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->sadd('set:source', 'foo'); diff --git a/tests/Predis/Command/SetPopTest.php b/tests/Predis/Command/SetPopTest.php index 87b13c26..8594001c 100644 --- a/tests/Predis/Command/SetPopTest.php +++ b/tests/Predis/Command/SetPopTest.php @@ -88,11 +88,12 @@ class SetPopTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/SetRandomMemberTest.php b/tests/Predis/Command/SetRandomMemberTest.php index 240238cc..6ef2b3a7 100644 --- a/tests/Predis/Command/SetRandomMemberTest.php +++ b/tests/Predis/Command/SetRandomMemberTest.php @@ -80,11 +80,12 @@ class SetRandomMemberTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/SetRemoveTest.php b/tests/Predis/Command/SetRemoveTest.php index 1bc9081d..8ac0a3f9 100644 --- a/tests/Predis/Command/SetRemoveTest.php +++ b/tests/Predis/Command/SetRemoveTest.php @@ -87,11 +87,12 @@ class SetRemoveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/SetUnionStoreTest.php b/tests/Predis/Command/SetUnionStoreTest.php index 43e3a2ba..c676a01f 100644 --- a/tests/Predis/Command/SetUnionStoreTest.php +++ b/tests/Predis/Command/SetUnionStoreTest.php @@ -102,11 +102,12 @@ class SetUnionStoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongTypeOfSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:source', 'foo'); diff --git a/tests/Predis/Command/SetUnionTest.php b/tests/Predis/Command/SetUnionTest.php index 96110877..73e7c23d 100644 --- a/tests/Predis/Command/SetUnionTest.php +++ b/tests/Predis/Command/SetUnionTest.php @@ -104,11 +104,12 @@ class SetUnionTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('set:foo', 'a'); diff --git a/tests/Predis/Command/StringAppendTest.php b/tests/Predis/Command/StringAppendTest.php index bb846b42..45f26971 100644 --- a/tests/Predis/Command/StringAppendTest.php +++ b/tests/Predis/Command/StringAppendTest.php @@ -82,11 +82,12 @@ class StringAppendTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringBitCountTest.php b/tests/Predis/Command/StringBitCountTest.php index 00780ed6..48aa47d5 100644 --- a/tests/Predis/Command/StringBitCountTest.php +++ b/tests/Predis/Command/StringBitCountTest.php @@ -79,11 +79,12 @@ class StringBitCountTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('key', 'list'); diff --git a/tests/Predis/Command/StringBitFieldTest.php b/tests/Predis/Command/StringBitFieldTest.php index 244ed0e0..957341d8 100644 --- a/tests/Predis/Command/StringBitFieldTest.php +++ b/tests/Predis/Command/StringBitFieldTest.php @@ -140,11 +140,12 @@ class StringBitFieldTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.2.0 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $this->markTestSkipped('Currently skipped due issues in Redis (see antirez/redis#3259).'); $redis = $this->getClient(); diff --git a/tests/Predis/Command/StringBitOpTest.php b/tests/Predis/Command/StringBitOpTest.php index 8295004a..1acbae76 100644 --- a/tests/Predis/Command/StringBitOpTest.php +++ b/tests/Predis/Command/StringBitOpTest.php @@ -131,31 +131,34 @@ class StringBitOpTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR BITOP NOT must be called with a single source key. */ public function testBitwiseNOTAcceptsOnlyOneSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR BITOP NOT must be called with a single source key'); + $this->getClient()->bitop('NOT', 'key:dst', 'key:src:1', 'key:src:2'); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR syntax error */ public function testThrowsExceptionOnInvalidOperation() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR syntax error'); + $this->getClient()->bitop('NOOP', 'key:dst', 'key:src:1', 'key:src:2'); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnInvalidSourceKey() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('key:src:1', 'list'); diff --git a/tests/Predis/Command/StringBitPosTest.php b/tests/Predis/Command/StringBitPosTest.php index e0c4c36f..7f6bf6a9 100644 --- a/tests/Predis/Command/StringBitPosTest.php +++ b/tests/Predis/Command/StringBitPosTest.php @@ -81,11 +81,12 @@ class StringBitPosTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.7 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('key', 'list'); $redis->bitpos('key', 0); diff --git a/tests/Predis/Command/StringDecrementByTest.php b/tests/Predis/Command/StringDecrementByTest.php index 4e69de02..ba9f793f 100644 --- a/tests/Predis/Command/StringDecrementByTest.php +++ b/tests/Predis/Command/StringDecrementByTest.php @@ -82,11 +82,12 @@ class StringDecrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnDecrementValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->decrby('foo', 'bar'); @@ -94,11 +95,12 @@ class StringDecrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnKeyValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -107,11 +109,12 @@ class StringDecrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringDecrementTest.php b/tests/Predis/Command/StringDecrementTest.php index 06a8b430..2aa1bf44 100644 --- a/tests/Predis/Command/StringDecrementTest.php +++ b/tests/Predis/Command/StringDecrementTest.php @@ -81,11 +81,12 @@ class StringDecrementTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnKeyValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -94,11 +95,12 @@ class StringDecrementTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringGetBitTest.php b/tests/Predis/Command/StringGetBitTest.php index 64a85f16..ae1d0a94 100644 --- a/tests/Predis/Command/StringGetBitTest.php +++ b/tests/Predis/Command/StringGetBitTest.php @@ -74,11 +74,12 @@ class StringGetBitTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnNegativeOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('key:binary', "\x80\x00\00\x01"); @@ -87,11 +88,12 @@ class StringGetBitTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnInvalidOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('key:binary', "\x80\x00\00\x01"); @@ -100,11 +102,12 @@ class StringGetBitTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringGetRangeTest.php b/tests/Predis/Command/StringGetRangeTest.php index f72ee24a..cefeefc5 100644 --- a/tests/Predis/Command/StringGetRangeTest.php +++ b/tests/Predis/Command/StringGetRangeTest.php @@ -85,11 +85,12 @@ class StringGetRangeTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringGetSetTest.php b/tests/Predis/Command/StringGetSetTest.php index defe243a..687df1cf 100644 --- a/tests/Predis/Command/StringGetSetTest.php +++ b/tests/Predis/Command/StringGetSetTest.php @@ -71,11 +71,12 @@ class StringGetSetTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringGetTest.php b/tests/Predis/Command/StringGetTest.php index 0e99b4d0..4ce3d9d4 100644 --- a/tests/Predis/Command/StringGetTest.php +++ b/tests/Predis/Command/StringGetTest.php @@ -92,11 +92,12 @@ class StringGetTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->rpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringIncrementByFloatTest.php b/tests/Predis/Command/StringIncrementByFloatTest.php index 4976d1fc..d42cb3d0 100644 --- a/tests/Predis/Command/StringIncrementByFloatTest.php +++ b/tests/Predis/Command/StringIncrementByFloatTest.php @@ -76,7 +76,7 @@ class StringIncrementByFloatTest extends PredisCommandTestCase $redis->set('foo', 2); // We use round() to avoid errors on some platforms, see the following - // issue https://github.com/predishq/predis/issues/220 for reference. + // issue https://github.com/predis/predis/issues/220 for reference. $this->assertEquals(22.123, $redis->incrbyfloat('foo', 20.123)); $this->assertEquals(10, round($redis->incrbyfloat('foo', -12.123), 5)); $this->assertEquals(-100.01, round($redis->incrbyfloat('foo', -110.01), 5)); @@ -84,11 +84,12 @@ class StringIncrementByFloatTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not a valid float */ public function testThrowsExceptionOnDecrementValueNotFloat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not a valid float'); + $redis = $this->getClient(); $redis->incrbyfloat('foo', 'bar'); @@ -96,11 +97,12 @@ class StringIncrementByFloatTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not a valid float */ public function testThrowsExceptionOnKeyValueNotFloat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not a valid float'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -109,11 +111,12 @@ class StringIncrementByFloatTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringIncrementByTest.php b/tests/Predis/Command/StringIncrementByTest.php index 78a156fc..63c5cbee 100644 --- a/tests/Predis/Command/StringIncrementByTest.php +++ b/tests/Predis/Command/StringIncrementByTest.php @@ -82,11 +82,12 @@ class StringIncrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnDecrementValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->incrby('foo', 'bar'); @@ -94,11 +95,12 @@ class StringIncrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnKeyValueNotInteger() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); @@ -107,11 +109,12 @@ class StringIncrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringIncrementTest.php b/tests/Predis/Command/StringIncrementTest.php index 8a87c132..bc0a01b9 100644 --- a/tests/Predis/Command/StringIncrementTest.php +++ b/tests/Predis/Command/StringIncrementTest.php @@ -81,11 +81,12 @@ class StringIncrementTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringPreciseSetExpireTest.php b/tests/Predis/Command/StringPreciseSetExpireTest.php index d09df63b..ad103b7b 100644 --- a/tests/Predis/Command/StringPreciseSetExpireTest.php +++ b/tests/Predis/Command/StringPreciseSetExpireTest.php @@ -83,31 +83,34 @@ class StringPreciseSetExpireTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnNonIntegerTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $this->getClient()->psetex('foo', 2.5, 'bar'); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnZeroTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->psetex('foo', 0, 'bar'); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnNegativeTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->psetex('foo', -10000, 'bar'); } } diff --git a/tests/Predis/Command/StringSetBitTest.php b/tests/Predis/Command/StringSetBitTest.php index fc1d93c6..a40ca63f 100644 --- a/tests/Predis/Command/StringSetBitTest.php +++ b/tests/Predis/Command/StringSetBitTest.php @@ -86,41 +86,45 @@ class StringSetBitTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit is not an integer or out of range */ public function testThrowsExceptionOnInvalidBitValue() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit is not an integer or out of range'); + $this->getClient()->setbit('key:binary', 10, 255); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnNegativeOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $this->getClient()->setbit('key:binary', -1, 1); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR bit offset is not an integer or out of range */ public function testThrowsExceptionOnInvalidOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR bit offset is not an integer or out of range'); + $this->getClient()->setbit('key:binary', 'invalid', 1); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringSetExpireTest.php b/tests/Predis/Command/StringSetExpireTest.php index f69226ba..3ae01596 100644 --- a/tests/Predis/Command/StringSetExpireTest.php +++ b/tests/Predis/Command/StringSetExpireTest.php @@ -84,31 +84,34 @@ class StringSetExpireTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR value is not an integer or out of range */ public function testThrowsExceptionOnNonIntegerTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR value is not an integer or out of range'); + $this->getClient()->setex('foo', 2.5, 'bar'); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnZeroTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->setex('foo', 0, 'bar'); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR invalid expire time */ public function testThrowsExceptionOnNegativeTTL() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR invalid expire time'); + $this->getClient()->setex('foo', -10, 'bar'); } } diff --git a/tests/Predis/Command/StringSetRangeTest.php b/tests/Predis/Command/StringSetRangeTest.php index e76a268d..d2789c5b 100644 --- a/tests/Predis/Command/StringSetRangeTest.php +++ b/tests/Predis/Command/StringSetRangeTest.php @@ -100,21 +100,23 @@ class StringSetRangeTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR offset is out of range */ public function testThrowsExceptionOnInvalidOffset() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR offset is out of range'); + $this->getClient()->setrange('var', -1, 'bogus'); } /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/StringStrlenTest.php b/tests/Predis/Command/StringStrlenTest.php index 7c5c0fe0..fc24c53d 100644 --- a/tests/Predis/Command/StringStrlenTest.php +++ b/tests/Predis/Command/StringStrlenTest.php @@ -81,11 +81,12 @@ class StringStrlenTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->lpush('metavars', 'foo'); diff --git a/tests/Predis/Command/TransactionDiscardTest.php b/tests/Predis/Command/TransactionDiscardTest.php index a661e4de..db853465 100644 --- a/tests/Predis/Command/TransactionDiscardTest.php +++ b/tests/Predis/Command/TransactionDiscardTest.php @@ -68,11 +68,12 @@ class TransactionDiscardTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR DISCARD without MULTI */ public function testThrowsExceptionWhenCallingOutsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR DISCARD without MULTI'); + $redis = $this->getClient(); $redis->discard(); diff --git a/tests/Predis/Command/TransactionExecTest.php b/tests/Predis/Command/TransactionExecTest.php index 09b3c2e1..18184e1f 100644 --- a/tests/Predis/Command/TransactionExecTest.php +++ b/tests/Predis/Command/TransactionExecTest.php @@ -100,11 +100,12 @@ class TransactionExecTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR EXEC without MULTI */ public function testThrowsExceptionWhenCallingOutsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR EXEC without MULTI'); + $redis = $this->getClient(); $redis->exec(); diff --git a/tests/Predis/Command/TransactionMultiTest.php b/tests/Predis/Command/TransactionMultiTest.php index db075181..b028445f 100644 --- a/tests/Predis/Command/TransactionMultiTest.php +++ b/tests/Predis/Command/TransactionMultiTest.php @@ -78,11 +78,12 @@ class TransactionMultiTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR MULTI calls can not be nested */ public function testThrowsExceptionWhenCallingMultiInsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR MULTI calls can not be nested'); + $redis = $this->getClient(); $redis->multi(); diff --git a/tests/Predis/Command/TransactionWatchTest.php b/tests/Predis/Command/TransactionWatchTest.php index 132d11ae..da67eb19 100644 --- a/tests/Predis/Command/TransactionWatchTest.php +++ b/tests/Predis/Command/TransactionWatchTest.php @@ -105,11 +105,12 @@ class TransactionWatchTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR WATCH inside MULTI is not allowed */ public function testThrowsExceptionWhenCallingInsideTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR WATCH inside MULTI is not allowed'); + $redis = $this->getClient(); $redis->multi(); diff --git a/tests/Predis/Command/ZSetAddTest.php b/tests/Predis/Command/ZSetAddTest.php index 05bd6833..54ae2f31 100644 --- a/tests/Predis/Command/ZSetAddTest.php +++ b/tests/Predis/Command/ZSetAddTest.php @@ -162,11 +162,12 @@ class ZSetAddTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 3.0.2 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage INCR option supports a single increment-element pair */ public function testDoesNotAcceptMultipleScoreElementPairsWithModifierINCR() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('INCR option supports a single increment-element pair'); + $redis = $this->getClient(); $redis->zadd('letters', 'INCR', 1, 'a', 2, 'b'); @@ -185,11 +186,12 @@ class ZSetAddTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetCardinalityTest.php b/tests/Predis/Command/ZSetCardinalityTest.php index ea6e8a00..37afebe9 100644 --- a/tests/Predis/Command/ZSetCardinalityTest.php +++ b/tests/Predis/Command/ZSetCardinalityTest.php @@ -70,11 +70,12 @@ class ZSetCardinalityTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetCountTest.php b/tests/Predis/Command/ZSetCountTest.php index fc5b0f32..6809ea9f 100644 --- a/tests/Predis/Command/ZSetCountTest.php +++ b/tests/Predis/Command/ZSetCountTest.php @@ -103,11 +103,12 @@ class ZSetCountTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetIncrementByTest.php b/tests/Predis/Command/ZSetIncrementByTest.php index ee45af7d..0bf968c4 100644 --- a/tests/Predis/Command/ZSetIncrementByTest.php +++ b/tests/Predis/Command/ZSetIncrementByTest.php @@ -70,11 +70,12 @@ class ZSetIncrementByTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetIntersectionStoreTest.php b/tests/Predis/Command/ZSetIntersectionStoreTest.php index 496ff938..f4a8c260 100644 --- a/tests/Predis/Command/ZSetIntersectionStoreTest.php +++ b/tests/Predis/Command/ZSetIntersectionStoreTest.php @@ -156,11 +156,12 @@ class ZSetIntersectionStoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetLexCountTest.php b/tests/Predis/Command/ZSetLexCountTest.php index 6acba8ac..3b7f964e 100644 --- a/tests/Predis/Command/ZSetLexCountTest.php +++ b/tests/Predis/Command/ZSetLexCountTest.php @@ -104,11 +104,12 @@ class ZSetLexCountTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -118,11 +119,12 @@ class ZSetLexCountTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRangeByLexTest.php b/tests/Predis/Command/ZSetRangeByLexTest.php index 3c7ebf02..8c57d2fa 100644 --- a/tests/Predis/Command/ZSetRangeByLexTest.php +++ b/tests/Predis/Command/ZSetRangeByLexTest.php @@ -167,11 +167,12 @@ class ZSetRangeByLexTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -181,11 +182,12 @@ class ZSetRangeByLexTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRangeByScoreTest.php b/tests/Predis/Command/ZSetRangeByScoreTest.php index 08e5a193..faa0d712 100644 --- a/tests/Predis/Command/ZSetRangeByScoreTest.php +++ b/tests/Predis/Command/ZSetRangeByScoreTest.php @@ -214,11 +214,12 @@ class ZSetRangeByScoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRangeTest.php b/tests/Predis/Command/ZSetRangeTest.php index 2ae484dc..e7457c1b 100644 --- a/tests/Predis/Command/ZSetRangeTest.php +++ b/tests/Predis/Command/ZSetRangeTest.php @@ -142,11 +142,12 @@ class ZSetRangeTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRankTest.php b/tests/Predis/Command/ZSetRankTest.php index 2ab26710..57a5d2ac 100644 --- a/tests/Predis/Command/ZSetRankTest.php +++ b/tests/Predis/Command/ZSetRankTest.php @@ -73,11 +73,12 @@ class ZSetRankTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRemoveRangeByLexTest.php b/tests/Predis/Command/ZSetRemoveRangeByLexTest.php index a310f466..3a3567eb 100644 --- a/tests/Predis/Command/ZSetRemoveRangeByLexTest.php +++ b/tests/Predis/Command/ZSetRemoveRangeByLexTest.php @@ -116,11 +116,12 @@ class ZSetRemoveRangeByLexTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -130,11 +131,12 @@ class ZSetRemoveRangeByLexTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRemoveRangeByRankTest.php b/tests/Predis/Command/ZSetRemoveRangeByRankTest.php index 9ab3df45..83194aec 100644 --- a/tests/Predis/Command/ZSetRemoveRangeByRankTest.php +++ b/tests/Predis/Command/ZSetRemoveRangeByRankTest.php @@ -85,11 +85,12 @@ class ZSetRemoveRangeByRankTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRemoveRangeByScoreTest.php b/tests/Predis/Command/ZSetRemoveRangeByScoreTest.php index f38900b6..ecc2c7ba 100644 --- a/tests/Predis/Command/ZSetRemoveRangeByScoreTest.php +++ b/tests/Predis/Command/ZSetRemoveRangeByScoreTest.php @@ -85,11 +85,12 @@ class ZSetRemoveRangeByScoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetRemoveTest.php b/tests/Predis/Command/ZSetRemoveTest.php index 1044be31..c7855c4d 100644 --- a/tests/Predis/Command/ZSetRemoveTest.php +++ b/tests/Predis/Command/ZSetRemoveTest.php @@ -72,11 +72,12 @@ class ZSetRemoveTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetReverseRangeByLexTest.php b/tests/Predis/Command/ZSetReverseRangeByLexTest.php index 3a0e0f82..6a4dedab 100644 --- a/tests/Predis/Command/ZSetReverseRangeByLexTest.php +++ b/tests/Predis/Command/ZSetReverseRangeByLexTest.php @@ -167,11 +167,12 @@ class ZSetReverseRangeByLexTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage min or max not valid string range item */ public function testThrowsExceptionOnInvalidRangeFormat() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('min or max not valid string range item'); + $redis = $this->getClient(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); @@ -181,11 +182,12 @@ class ZSetReverseRangeByLexTest extends PredisCommandTestCase /** * @group connected * @requiresRedisVersion >= 2.8.9 - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetReverseRangeByScoreTest.php b/tests/Predis/Command/ZSetReverseRangeByScoreTest.php index 6eb7cf70..d9796c5f 100644 --- a/tests/Predis/Command/ZSetReverseRangeByScoreTest.php +++ b/tests/Predis/Command/ZSetReverseRangeByScoreTest.php @@ -214,11 +214,12 @@ class ZSetReverseRangeByScoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetReverseRangeTest.php b/tests/Predis/Command/ZSetReverseRangeTest.php index 50c2e5ae..813bbe24 100644 --- a/tests/Predis/Command/ZSetReverseRangeTest.php +++ b/tests/Predis/Command/ZSetReverseRangeTest.php @@ -142,11 +142,12 @@ class ZSetReverseRangeTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetReverseRankTest.php b/tests/Predis/Command/ZSetReverseRankTest.php index 9f9865b4..c920143a 100644 --- a/tests/Predis/Command/ZSetReverseRankTest.php +++ b/tests/Predis/Command/ZSetReverseRankTest.php @@ -73,11 +73,12 @@ class ZSetReverseRankTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetScoreTest.php b/tests/Predis/Command/ZSetScoreTest.php index dc26dbff..e1fb48af 100644 --- a/tests/Predis/Command/ZSetScoreTest.php +++ b/tests/Predis/Command/ZSetScoreTest.php @@ -73,11 +73,12 @@ class ZSetScoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/Command/ZSetUnionStoreTest.php b/tests/Predis/Command/ZSetUnionStoreTest.php index 895c38b6..7bfa29e1 100644 --- a/tests/Predis/Command/ZSetUnionStoreTest.php +++ b/tests/Predis/Command/ZSetUnionStoreTest.php @@ -174,11 +174,12 @@ class ZSetUnionStoreTest extends PredisCommandTestCase /** * @group connected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage Operation against a key holding the wrong kind of value */ public function testThrowsExceptionOnWrongType() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); + $redis = $this->getClient(); $redis->set('foo', 'bar'); diff --git a/tests/Predis/CommunicationExceptionTest.php b/tests/Predis/CommunicationExceptionTest.php index fa647f68..cb20a227 100644 --- a/tests/Predis/CommunicationExceptionTest.php +++ b/tests/Predis/CommunicationExceptionTest.php @@ -27,7 +27,8 @@ class CommunicationExceptionTest extends PredisTestCase $connection = $this->getMockedConnectionBase(); $exception = $this->getException($connection, $message); - $this->setExpectedException('Predis\CommunicationException', $message); + $this->expectException('Predis\CommunicationException'); + $this->expectExceptionMessage($message); throw $exception; } @@ -56,16 +57,17 @@ class CommunicationExceptionTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\CommunicationException - * @expectedExceptionMessage Communication error */ public function testCommunicationExceptionHandling() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true)); $connection->expects($this->once())->method('disconnect'); - $exception = $this->getException($connection, 'Communication error'); + $message = 'Communication error'; + $exception = $this->getException($connection, $message); + $this->expectException('Predis\CommunicationException'); + $this->expectExceptionMessage($message); CommunicationException::handle($exception); } diff --git a/tests/Predis/Configuration/ClusterOptionTest.php b/tests/Predis/Configuration/ClusterOptionTest.php index 908fa911..0eeeda52 100644 --- a/tests/Predis/Configuration/ClusterOptionTest.php +++ b/tests/Predis/Configuration/ClusterOptionTest.php @@ -24,7 +24,7 @@ class ClusterOptionTest extends PredisTestCase public function testDefaultOptionValue() { $option = new ClusterOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Predis\Connection\Aggregate\PredisCluster', $option->getDefault($options)); } @@ -35,8 +35,8 @@ class ClusterOptionTest extends PredisTestCase public function testAcceptsInstanceOfClusterInterface() { $option = new ClusterOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $cluster = $this->getMock('Predis\Connection\Aggregate\ClusterInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(); $this->assertSame($cluster, $option->filter($options, $cluster)); } @@ -48,12 +48,12 @@ class ClusterOptionTest extends PredisTestCase { $option = new ClusterOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options->expects($this->any()) ->method('__get') ->with('connections') ->will($this->returnValue( - $this->getMock('Predis\Connection\FactoryInterface') + $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock() )); $this->assertInstanceOf('Predis\Connection\Aggregate\PredisCluster', $option->filter($options, 'predis')); @@ -65,25 +65,27 @@ class ClusterOptionTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException */ public function testThrowsExceptionOnInvalidInstanceType() { + $this->expectException('InvalidArgumentException'); + $option = new ClusterOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $class = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $class = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $option->filter($options, $class); } /** * @group disconnected - * @expectedException \InvalidArgumentException */ public function testThrowsExceptionOnInvalidShortNameString() { + $this->expectException('InvalidArgumentException'); + $option = new ClusterOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, 'unknown'); } diff --git a/tests/Predis/Configuration/ConnectionFactoryOptionTest.php b/tests/Predis/Configuration/ConnectionFactoryOptionTest.php index d4863a4b..a077a095 100644 --- a/tests/Predis/Configuration/ConnectionFactoryOptionTest.php +++ b/tests/Predis/Configuration/ConnectionFactoryOptionTest.php @@ -24,7 +24,7 @@ class ConnectionFactoryOptionTest extends PredisTestCase public function testDefaultOptionValue() { $option = new ConnectionFactoryOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Predis\Connection\Factory', $option->getDefault($options)); } @@ -34,23 +34,25 @@ class ConnectionFactoryOptionTest extends PredisTestCase */ public function testAcceptsNamedArrayWithSchemeToConnectionClassMappings() { - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); - $class = get_class($this->getMock('Predis\Connection\NodeConnectionInterface')); + $class = get_class($this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock()); $value = array('tcp' => $class, 'redis' => $class); - $default = $this->getMock('Predis\Connection\FactoryInterface'); + $default = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $default->expects($this->exactly(2)) ->method('define') ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class); - $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault')); + $option = $this->getMockBuilder('Predis\Configuration\ConnectionFactoryOption') + ->setMethods(array('getDefault')) + ->getMock(); $option->expects($this->once()) ->method('getDefault') ->with($options) ->will($this->returnValue($default)); - $this->assertInstanceOf('Predis\Connection\FactoryInterface', $factory = $option->filter($options, $value)); + $factory = $option->filter($options, $value); $this->assertSame($default, $factory); } @@ -61,8 +63,8 @@ class ConnectionFactoryOptionTest extends PredisTestCase { $parameters = array('database' => 5, 'password' => 'mypassword'); - $default = $this->getMock('Predis\Connection\Factory'); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $default = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options->expects($this->once()) ->method('defined') @@ -85,10 +87,12 @@ class ConnectionFactoryOptionTest extends PredisTestCase */ public function testAcceptsConnectionFactoryInstance() { - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $value = $this->getMock('Predis\Connection\FactoryInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $value = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); - $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault')); + $option = $this->getMockBuilder('Predis\Configuration\ConnectionFactoryOption') + ->setMethods(array('getDefault')) + ->getMock(); $option->expects($this->never())->method('getDefault'); $this->assertSame($value, $option->filter($options, $value)); @@ -96,12 +100,13 @@ class ConnectionFactoryOptionTest extends PredisTestCase /** * @group disconnected - * @expectedException InvalidArgumentException */ public function testThrowsExceptionOnInvalidArguments() { + $this->expectException('InvalidArgumentException'); + $option = new ConnectionFactoryOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, new \stdClass()); } diff --git a/tests/Predis/Configuration/ExceptionsOptionTest.php b/tests/Predis/Configuration/ExceptionsOptionTest.php index b7d7780a..30e54ca2 100644 --- a/tests/Predis/Configuration/ExceptionsOptionTest.php +++ b/tests/Predis/Configuration/ExceptionsOptionTest.php @@ -24,7 +24,7 @@ class ExceptionsOptionTest extends PredisTestCase public function testDefaultOptionValue() { $option = new ExceptionsOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertTrue($option->getDefault($options)); } @@ -35,7 +35,7 @@ class ExceptionsOptionTest extends PredisTestCase public function testAcceptsDifferentValuesAndFiltersThemAsBooleans() { $option = new ExceptionsOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertFalse($option->filter($options, null)); @@ -58,7 +58,7 @@ class ExceptionsOptionTest extends PredisTestCase public function testReturnsFalesOnValuesNotParsableAsBooleans() { $option = new ExceptionsOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertFalse($option->filter($options, new \stdClass())); $this->assertFalse($option->filter($options, 'invalid')); diff --git a/tests/Predis/Configuration/OptionsTest.php b/tests/Predis/Configuration/OptionsTest.php index 7764fdbf..f92abc6f 100644 --- a/tests/Predis/Configuration/OptionsTest.php +++ b/tests/Predis/Configuration/OptionsTest.php @@ -42,12 +42,12 @@ class OptionsTest extends PredisTestCase 'exceptions' => false, 'profile' => '2.0', 'prefix' => 'prefix:', - 'connections' => $this->getMock('Predis\Connection\FactoryInterface'), - 'cluster' => $this->getMock('Predis\Connection\Aggregate\ClusterInterface'), - 'replication' => $this->getMock('Predis\Connection\Aggregate\ReplicationInterface'), + 'connections' => $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(), + 'cluster' => $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(), + 'replication' => $this->getMockBuilder('Predis\Connection\Aggregate\ReplicationInterface')->getMock(), )); - $this->assertInternalType('bool', $options->exceptions); + $this->assertIsBool($options->exceptions); $this->assertInstanceOf('Predis\Profile\ProfileInterface', $options->profile); $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $options->prefix); $this->assertInstanceOf('Predis\Connection\FactoryInterface', $options->connections); @@ -138,10 +138,12 @@ class OptionsTest extends PredisTestCase */ public function testLazilyInitializesOptionValueUsingObjectWithInvokeMagicMethod() { - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); // NOTE: closure values are covered by this test since they define __invoke(). - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), 'profile') @@ -163,7 +165,7 @@ class OptionsTest extends PredisTestCase $custom = new \stdClass(); // NOTE: closure values are covered by this test since they define __invoke(). - $callable = $this->getMock('stdClass', array('__invoke')); + $callable = $this->getMockBuilder('stdClass') ->setMethods(array('__invoke')) ->getMock(); $callable->expects($this->once()) ->method('__invoke') ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), 'custom') @@ -182,7 +184,9 @@ class OptionsTest extends PredisTestCase */ public function testChecksForInvokeMagicMethodDoesNotTriggerAutoloader() { - $trigger = $this->getMock('stdClass', array('autoload')); + $trigger = $this->getMockBuilder('stdClass') + ->setMethods(array('autoload')) + ->getMock(); $trigger->expects($this->never())->method('autoload'); spl_autoload_register($autoload = function ($class) use ($trigger) { diff --git a/tests/Predis/Configuration/PrefixOptionTest.php b/tests/Predis/Configuration/PrefixOptionTest.php index a4e67909..52a1227f 100644 --- a/tests/Predis/Configuration/PrefixOptionTest.php +++ b/tests/Predis/Configuration/PrefixOptionTest.php @@ -24,7 +24,7 @@ class PrefixOptionTest extends PredisTestCase public function testDefaultOptionValue() { $option = new PrefixOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertNull($option->getDefault($options)); } @@ -35,7 +35,7 @@ class PrefixOptionTest extends PredisTestCase public function testAcceptsStringAndReturnsCommandProcessor() { $option = new PrefixOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $return = $option->filter($options, $value = 'prefix:'); @@ -50,8 +50,8 @@ class PrefixOptionTest extends PredisTestCase public function testAcceptsCommandProcessorInstance() { $option = new PrefixOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $processor = $this->getMockBuilder('Predis\Command\Processor\ProcessorInterface')->getMock(); $return = $option->filter($options, $processor); diff --git a/tests/Predis/Configuration/ProfileOptionTest.php b/tests/Predis/Configuration/ProfileOptionTest.php index 639d8e12..bc11a4ab 100644 --- a/tests/Predis/Configuration/ProfileOptionTest.php +++ b/tests/Predis/Configuration/ProfileOptionTest.php @@ -26,7 +26,7 @@ class ProfileOptionTest extends PredisTestCase public function testDefaultOptionValue() { $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $profile = $option->getDefault($options); @@ -41,7 +41,7 @@ class ProfileOptionTest extends PredisTestCase public function testAcceptsProfileInstanceAsValue() { $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $value = Profile\Factory::get('2.0'); $profile = $option->filter($options, $value); @@ -56,7 +56,7 @@ class ProfileOptionTest extends PredisTestCase public function testAcceptsStringInterpretedAsProfileVersion() { $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $profile = $option->filter($options, '2.0'); @@ -71,7 +71,7 @@ class ProfileOptionTest extends PredisTestCase public function testAppliesPrefixOnDefaultOptionValue() { $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options->expects($this->once()) ->method('__isset') @@ -97,7 +97,7 @@ class ProfileOptionTest extends PredisTestCase public function testAppliesPrefixOnProfileCreatedFromStringValue() { $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options->expects($this->once()) ->method('__isset') @@ -123,7 +123,7 @@ class ProfileOptionTest extends PredisTestCase public function testDoesNotApplyPrefixOnProfileValue() { $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $value = Profile\Factory::getDefault(); $options->expects($this->never())->method('__isset'); @@ -138,24 +138,26 @@ class ProfileOptionTest extends PredisTestCase /** * @group disconnected - * @expectedException InvalidArgumentException */ public function testThrowsExceptionOnInvalidValue() { + $this->expectException('InvalidArgumentException'); + $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, new \stdClass()); } /** * @group disconnected - * @expectedException \Predis\ClientException */ public function testThrowsExceptionOnUnrecognizedVersionString() { + $this->expectException('Predis\ClientException'); + $option = new ProfileOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, '0.0'); } diff --git a/tests/Predis/Configuration/ReplicationOptionTest.php b/tests/Predis/Configuration/ReplicationOptionTest.php index 60ef8160..1e38df10 100644 --- a/tests/Predis/Configuration/ReplicationOptionTest.php +++ b/tests/Predis/Configuration/ReplicationOptionTest.php @@ -24,7 +24,7 @@ class ReplicationOptionTest extends PredisTestCase public function testDefaultOptionValue() { $option = new ReplicationOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Predis\Connection\Aggregate\ReplicationInterface', $option->getDefault($options)); $this->assertInstanceOf('Predis\Connection\Aggregate\MasterSlaveReplication', $option->getDefault($options)); @@ -36,7 +36,7 @@ class ReplicationOptionTest extends PredisTestCase public function testAcceptsValuesThatCanBeInterpretedAsBooleans() { $option = new ReplicationOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertNull($option->filter($options, null)); @@ -59,8 +59,8 @@ class ReplicationOptionTest extends PredisTestCase public function testConfiguresAutomaticDiscoveryWhenAutodiscoveryOptionIsPresent() { $option = new ReplicationOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $connFactory = $this->getMock('Predis\Connection\FactoryInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $connFactory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $options->expects($this->at(0)) ->method('__get') @@ -82,13 +82,14 @@ class ReplicationOptionTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException */ public function testThrowsExceptionOnInvalidInstanceType() { + $this->expectException('InvalidArgumentException'); + $option = new ReplicationOption(); - $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $value = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); + $value = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $option->filter($options, $value); } diff --git a/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php b/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php index 0f210b76..646e89f0 100644 --- a/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php +++ b/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php @@ -83,11 +83,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage No available connection for replication */ public function testThrowsExceptionOnEmptyReplication() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No available connection for replication'); + $replication = new MasterSlaveReplication(); $replication->connect(); } @@ -206,11 +207,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorWhenSwitchingToUnknownConnectionByAlias() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found'); + $replication = new MasterSlaveReplication(); $replication->add($this->getMockConnection('tcp://host1?alias=master')); $replication->add($this->getMockConnection('tcp://host2?alias=slave1')); @@ -240,11 +242,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorWhenSwitchingToUnknownConnectionByInstance() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found'); + $replication = new MasterSlaveReplication(); $replication->add($this->getMockConnection('tcp://host1?alias=master')); $replication->add($this->getMockConnection('tcp://host2?alias=slave1')); @@ -276,11 +279,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorOnSwitchToMasterWithNoMasterDefined() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found'); + $slave1 = $this->getMockConnection('tcp://host2?alias=slave1'); $replication = new MasterSlaveReplication(); @@ -311,11 +315,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testThrowsErrorOnSwitchToRandomSlaveWithNoSlavesDefined() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found'); + $master = $this->getMockConnection('tcp://host1?alias=master'); $replication = new MasterSlaveReplication(); @@ -667,11 +672,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Replication\MissingMasterException * @expectedMessage No master server available for replication */ public function testFailsOnWriteCommandAndNoConnectionSetAsMaster() { + $this->expectException('Predis\Replication\MissingMasterException'); + $profile = Profile\Factory::getDefault(); $cmdSet = $profile->createCommand('set', array('key', 'value')); @@ -730,10 +736,11 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException */ public function testFailsOnUnreachableMaster() { + $this->expectException('Predis\Connection\ConnectionException'); + $profile = Profile\Factory::getDefault(); $cmdSet = $profile->createCommand('set', array('key', 'value')); @@ -757,11 +764,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The command 'INFO' is not allowed in replication mode. */ public function testThrowsExceptionOnNonSupportedCommand() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The command 'INFO' is not allowed in replication mode"); + $cmd = Profile\Factory::getDefault()->createCommand('info'); $replication = new MasterSlaveReplication(); @@ -856,11 +864,12 @@ class MasterSlaveReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException * @expectedMessage Discovery requires a connection factory */ public function testDiscoveryRequiresConnectionFactory() { + $this->expectException('Predis\ClientException'); + $master = $this->getMockConnection('tcp://host1?alias=master'); $replication = new MasterSlaveReplication(); @@ -920,7 +929,7 @@ repl_backlog_histlen:12978 $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2'); - $connFactory = $this->getMock('Predis\Connection\Factory'); + $connFactory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $connFactory->expects($this->at(0)) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6381', 'alias' => 'master')) @@ -999,7 +1008,7 @@ repl_backlog_histlen:12978 $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2'); - $connFactory = $this->getMock('Predis\Connection\Factory'); + $connFactory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $connFactory->expects($this->at(0)) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6381', 'alias' => 'master')) @@ -1074,11 +1083,12 @@ repl_backlog_histlen:12978 /** * @group disconnected - * @expectedException \Predis\ClientException * @expectedMessage Automatic discovery requires a connection factory */ public function testAutomaticDiscoveryRequiresConnectionFactory() { + $this->expectException('Predis\ClientException'); + $master = $this->getMockConnection('tcp://host1?alias=master'); $replication = new MasterSlaveReplication(); @@ -1099,7 +1109,7 @@ repl_backlog_histlen:12978 $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $connFactory = $this->getMock('Predis\Connection\Factory'); + $connFactory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $connFactory->expects($this->once()) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6382')) diff --git a/tests/Predis/Connection/Aggregate/PredisClusterTest.php b/tests/Predis/Connection/Aggregate/PredisClusterTest.php index faefc9b4..cdccea50 100644 --- a/tests/Predis/Connection/Aggregate/PredisClusterTest.php +++ b/tests/Predis/Connection/Aggregate/PredisClusterTest.php @@ -254,11 +254,12 @@ class PredisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot use 'PING' over clusters of connections. */ public function testThrowsExceptionOnNonShardableCommand() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Cannot use 'PING' over clusters of connections"); + $ping = Profile\Factory::getDefault()->createCommand('ping'); $cluster = new PredisCluster(); @@ -359,13 +360,13 @@ class PredisClusterTest extends PredisTestCase { $ping = Profile\Factory::getDefault()->createCommand('ping', array()); - $connection1 = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection1 = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection1->expects($this->once()) ->method('executeCommand') ->with($ping) ->will($this->returnValue(true)); - $connection2 = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection2 = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection2->expects($this->once()) ->method('executeCommand') ->with($ping) diff --git a/tests/Predis/Connection/Aggregate/RedisClusterTest.php b/tests/Predis/Connection/Aggregate/RedisClusterTest.php index 4674aa56..804c3d41 100644 --- a/tests/Predis/Connection/Aggregate/RedisClusterTest.php +++ b/tests/Predis/Connection/Aggregate/RedisClusterTest.php @@ -27,7 +27,7 @@ class RedisClusterTest extends PredisTestCase */ public function testAcceptsCustomConnectionFactory() { - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $cluster = new RedisCluster($factory); $this->assertSame($factory, $cluster->getConnectionFactory()); @@ -48,7 +48,7 @@ class RedisClusterTest extends PredisTestCase */ public function testAcceptsCustomClusterStrategy() { - $strategy = $this->getMock('Predis\Cluster\StrategyInterface'); + $strategy = $this->getMockBuilder('Predis\Cluster\StrategyInterface')->getMock(); $cluster = new RedisCluster(new Connection\Factory(), $strategy); @@ -290,7 +290,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6383'); $connection4 = $this->getMockConnection('tcp://127.0.0.1:6384'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->at(0)) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6383')) @@ -300,8 +300,10 @@ class RedisClusterTest extends PredisTestCase ->with(array('host' => '127.0.0.1', 'port' => '6384')) ->will($this->returnValue($connection4)); - // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Aggregate\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster->expects($this->exactly(1)) ->method('getRandomConnection') ->will($this->returnValue($connection1)); @@ -599,7 +601,7 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue('value:5001')); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array( @@ -660,7 +662,7 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue('value:1001')); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array( @@ -669,8 +671,10 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue($connection4)); - // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Aggregate\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster->expects($this->never()) ->method('getRandomConnection'); @@ -687,12 +691,13 @@ class RedisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage No connections available in the pool */ public function testThrowsClientExceptionWhenExecutingCommandWithEmptyPool() { - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No connections available in the pool'); + + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); @@ -705,7 +710,7 @@ class RedisClusterTest extends PredisTestCase */ public function testAskSlotsMapReturnEmptyArrayOnEmptyConnectionsPool() { - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); @@ -752,11 +757,13 @@ class RedisClusterTest extends PredisTestCase )) ->will($this->returnValue($slotsmap)); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->never())->method('create'); - // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Aggregate\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster->expects($this->exactly(3)) ->method('getRandomConnection') ->will($this->onConsecutiveCalls($connection1, $connection2, $connection3)); @@ -770,11 +777,12 @@ class RedisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage Unknown connection error [127.0.0.1:6382] */ public function testAskSlotsMapHonorsRetryLimitOnMultipleConnectionFailures() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("Unknown connection error [127.0.0.1:6382]"); + $slotsmap = array( array(0, 5460, array('127.0.0.1', 9381), array()), array(5461, 10922, array('127.0.0.1', 6382), array()), @@ -805,11 +813,13 @@ class RedisClusterTest extends PredisTestCase $connection3->expects($this->never()) ->method('executeCommand'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->never())->method('create'); - // TODO: I'm not sure about mocking a protected method, but it'll do for now - $cluster = $this->getMock('Predis\Connection\Aggregate\RedisCluster', array('getRandomConnection'), array($factory)); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\RedisCluster') + ->setMethods(array('getRandomConnection')) + ->setConstructorArgs(array($factory)) + ->getMock(); $cluster->expects($this->exactly(2)) ->method('getRandomConnection') ->will($this->onConsecutiveCalls($connection1, $connection2)); @@ -872,7 +882,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); @@ -913,7 +923,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6381')) @@ -950,7 +960,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->onConsecutiveCalls('foobar', 'foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); @@ -988,7 +998,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->onConsecutiveCalls('foobar', 'foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6381')) @@ -1025,7 +1035,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array('host' => '2001:db8:0:f101::2', 'port' => '6379')) @@ -1070,7 +1080,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue($response)); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $cluster = new RedisCluster($factory); $cluster->add($connection1); @@ -1108,7 +1118,7 @@ class RedisClusterTest extends PredisTestCase ->with($cmdGET) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\Factory'); + $factory = $this->getMockBuilder('Predis\Connection\Factory')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6380')) @@ -1123,11 +1133,12 @@ class RedisClusterTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot use 'PING' with redis-cluster. */ public function testThrowsExceptionOnNonSupportedCommand() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Cannot use 'PING' with redis-cluster"); + $ping = Profile\Factory::getDefault()->createCommand('ping'); $cluster = new RedisCluster(new Connection\Factory()); diff --git a/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php b/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php index 9d7a348f..192e98b9 100644 --- a/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php +++ b/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php @@ -24,11 +24,12 @@ class SentinelReplicationTest extends PredisTestCase { /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodGetSentinelConnectionThrowsExceptionOnEmptySentinelsPool() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery'); + $replication = $this->getReplicationConnection('svc', array()); $replication->getSentinelConnection(); } @@ -44,7 +45,8 @@ class SentinelReplicationTest extends PredisTestCase $parameters = $replication->getSentinelConnection()->getParameters()->toArray(); - $this->assertArraySubset(array('database' => null, 'password' => null), $parameters); + $this->assertArrayHasKey('database', $parameters); + $this->assertArrayHasKey('password', $parameters); } /** @@ -259,11 +261,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodUpdateSentinelsThrowsExceptionOnNoAvailableSentinel() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $sentinel1->expects($this->once()) ->method('executeCommand') @@ -383,11 +386,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodGetMasterThrowsExceptionOnNoAvailableSentinels() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $sentinel1->expects($this->any()) ->method('executeCommand') @@ -447,11 +451,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodGetSlavesThrowsExceptionOnNoAvailableSentinels() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $sentinel1->expects($this->any()) ->method('executeCommand') @@ -469,11 +474,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. */ public function testMethodConnectThrowsExceptionOnConnectWithEmptySentinelsPool() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery'); + $replication = $this->getReplicationConnection('svc', array()); $replication->connect(); } @@ -534,7 +540,7 @@ class SentinelReplicationTest extends PredisTestCase $slave1->expects($this->once()) ->method('connect'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array( @@ -578,7 +584,7 @@ class SentinelReplicationTest extends PredisTestCase $master->expects($this->once()) ->method('connect'); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array( @@ -692,11 +698,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Invalid connection or connection not found. */ public function testMethodSwitchToThrowsExceptionOnConnectionNotFound() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Invalid connection or connection not found'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); @@ -874,11 +881,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\Replication\RoleException - * @expectedExceptionMessage Expected master but got slave [127.0.0.1:6381] */ public function testGetConnectionThrowsExceptionOnNodeRoleMismatch() { + $this->expectException('Predis\Replication\RoleException'); + $this->expectExceptionMessage('Expected master but got slave [127.0.0.1:6381]'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); @@ -1032,7 +1040,7 @@ class SentinelReplicationTest extends PredisTestCase ->with($this->isRedisCommand('GET', array('key'))) ->will($this->returnValue('value')); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array( @@ -1087,7 +1095,7 @@ class SentinelReplicationTest extends PredisTestCase ->with($this->isRedisCommand('DEL', array('key'))) ->will($this->returnValue(1)); - $factory = $this->getMock('Predis\Connection\FactoryInterface'); + $factory = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock(); $factory->expects($this->once()) ->method('create') ->with(array( @@ -1108,11 +1116,12 @@ class SentinelReplicationTest extends PredisTestCase /** * @group disconnected - * @expectedException Predis\Response\ServerException - * @expectedExceptionMessage ERR No such master with that name */ public function testMethodExecuteCommandThrowsExceptionOnUnknownServiceName() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR No such master with that name'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $sentinel1->expects($this->any()) ->method('executeCommand') @@ -1142,12 +1151,13 @@ class SentinelReplicationTest extends PredisTestCase } /** - * @group disconnected - * @expectedException Predis\ClientException - * @expectedExceptionMessage No sentinel server available for autodiscovery. + * @group disconnected. */ public function testMethodExecuteCommandThrowsExceptionOnConnectionFailureAndNoAvailableSentinels() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('No sentinel server available for autodiscovery'); + $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $sentinel1->expects($this->any()) ->method('executeCommand') diff --git a/tests/Predis/Connection/CompositeStreamConnectionTest.php b/tests/Predis/Connection/CompositeStreamConnectionTest.php index d77b8a88..d53d9d85 100644 --- a/tests/Predis/Connection/CompositeStreamConnectionTest.php +++ b/tests/Predis/Connection/CompositeStreamConnectionTest.php @@ -23,11 +23,12 @@ class CompositeStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this->getMockBuilder(static::CONNECTION_CLASS) diff --git a/tests/Predis/Connection/FactoryTest.php b/tests/Predis/Connection/FactoryTest.php index 0c410537..3b33f2f7 100644 --- a/tests/Predis/Connection/FactoryTest.php +++ b/tests/Predis/Connection/FactoryTest.php @@ -268,7 +268,7 @@ class FactoryTest extends PredisTestCase */ public function testCreateConnectionWithoutInitializationCommands() { - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->never())->method('createCommand'); $factory = new Factory($profile); @@ -290,7 +290,7 @@ class FactoryTest extends PredisTestCase 'password' => 'foobar', )); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('getParameters') ->will($this->returnValue($parameters)); @@ -311,11 +311,12 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expecteExceptionMessage Unknown connection scheme: 'unknown'. */ public function testCreateUndefinedConnection() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Unknown connection scheme: 'unknown'"); + $factory = new Factory(); $factory->create(new Parameters(array('scheme' => 'unknown'))); } @@ -349,7 +350,9 @@ class FactoryTest extends PredisTestCase return new $connectionClass($parameters); }; - $initializerMock = $this->getMock('stdClass', array('__invoke')); + $initializerMock = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $initializerMock->expects($this->exactly(2)) ->method('__invoke') ->with($parameters) @@ -367,21 +370,23 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException */ public function testDefineConnectionWithInvalidArgument() { + $this->expectException('InvalidArgumentException'); + $factory = new Factory(); $factory->define('foobar', new \stdClass()); } /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expecteExceptionMessage Unknown connection scheme: 'tcp'. */ public function testUndefineDefinedConnection() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Unknown connection scheme: 'tcp'"); + $factory = new Factory(); $factory->undefine('tcp'); $factory->create('tcp://127.0.0.1'); @@ -401,11 +406,12 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expecteExceptionMessage Unknown connection scheme: 'test'. */ public function testDefineAndUndefineConnection() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Unknown connection scheme: 'test'"); + list(, $connectionClass) = $this->getMockConnectionClass(); $factory = new Factory(); @@ -424,12 +430,14 @@ class FactoryTest extends PredisTestCase { list(, $connectionClass) = $this->getMockConnectionClass(); - $cluster = $this->getMock('Predis\Connection\Aggregate\ClusterInterface'); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(); $cluster->expects($this->exactly(2)) ->method('add') ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface')); - $factory = $this->getMock('Predis\Connection\Factory', array('create')); + $factory = $this->getMockBuilder('Predis\Connection\Factory') + ->setMethods(array('create')) + ->getMock(); $factory->expects($this->never()) ->method('create'); @@ -443,12 +451,14 @@ class FactoryTest extends PredisTestCase { list(, $connectionClass) = $this->getMockConnectionClass(); - $cluster = $this->getMock('Predis\Connection\Aggregate\ClusterInterface'); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(); $cluster->expects($this->exactly(4)) ->method('add') ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface')); - $factory = $this->getMock('Predis\Connection\Factory', array('create')); + $factory = $this->getMockBuilder('Predis\Connection\Factory') + ->setMethods(array('create')) + ->getMock(); $factory->expects($this->exactly(3)) ->method('create') ->will($this->returnCallback(function ($_) use ($connectionClass) { @@ -463,10 +473,10 @@ class FactoryTest extends PredisTestCase */ public function testAggregateConnectionWithEmptyListOfParameters() { - $cluster = $this->getMock('Predis\Connection\Aggregate\ClusterInterface'); + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(); $cluster->expects($this->never())->method('add'); - $factory = $this->getMock('Predis\Connection\Factory', array('create')); + $factory = $this->getMockBuilder('Predis\Connection\Factory', array('create'))->getMock(); $factory->expects($this->never())->method('create'); $factory->aggregate($cluster, array()); @@ -483,7 +493,7 @@ class FactoryTest extends PredisTestCase */ protected function getMockConnectionClass() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); return array($connection, get_class($connection)); } diff --git a/tests/Predis/Connection/ParametersTest.php b/tests/Predis/Connection/ParametersTest.php index dbe3c3e7..4025a2ac 100644 --- a/tests/Predis/Connection/ParametersTest.php +++ b/tests/Predis/Connection/ParametersTest.php @@ -308,11 +308,12 @@ class ParametersTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid parameters URI: tcp://invalid:uri */ public function testParsingURIThrowOnInvalidURI() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid parameters URI: tcp://invalid:uri"); + Parameters::parse('tcp://invalid:uri'); } diff --git a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php b/tests/Predis/Connection/PhpiredisSocketConnectionTest.php index 8d051f19..078bf332 100644 --- a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php +++ b/tests/Predis/Connection/PhpiredisSocketConnectionTest.php @@ -24,11 +24,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'tls'. */ public function testSupportsSchemeTls() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'tls'"); + $connection = $this->createConnectionWithParams(array('scheme' => 'tls')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -36,11 +37,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'rediss'. */ public function testSupportsSchemeRediss() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'rediss'"); + $connection = $this->createConnectionWithParams(array('scheme' => 'rediss')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -48,11 +50,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this->getMockBuilder(static::CONNECTION_CLASS) @@ -78,11 +81,12 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @group connected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage Cannot resolve the address of 'bogus.tld'. */ public function testThrowsExceptionOnUnresolvableHostname() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("Cannot resolve the address of 'bogus.tld'"); + $connection = $this->createConnectionWithParams(array('host' => 'bogus.tld')); $connection->connect(); } @@ -90,10 +94,11 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase /** * @medium * @group connected - * @expectedException \Predis\Protocol\ProtocolException */ public function testThrowsExceptionOnProtocolDesynchronizationErrors() { + $this->expectException('Predis\Protocol\ProtocolException'); + $connection = $this->createConnection(); $socket = $connection->getResource(); diff --git a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php index f6512482..ad1a52b8 100644 --- a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php +++ b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php @@ -24,11 +24,12 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage SSL encryption is not supported by this connection backend. */ public function testSupportsSchemeTls() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('SSL encryption is not supported by this connection backend'); + $connection = $this->createConnectionWithParams(array('scheme' => 'tls')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -36,11 +37,12 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage SSL encryption is not supported by this connection backend. */ public function testSupportsSchemeRediss() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('SSL encryption is not supported by this connection backend'); + $connection = $this->createConnectionWithParams(array('scheme' => 'rediss')); $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection); @@ -48,11 +50,12 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this->getMockBuilder(static::CONNECTION_CLASS) @@ -80,10 +83,11 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase * @group connected * @group slow * @requires PHP 5.4 - * @expectedException \Predis\Connection\ConnectionException */ public function testThrowsExceptionOnReadWriteTimeout() { + $this->expectException('Predis\Connection\ConnectionException'); + $profile = $this->getCurrentProfile(); $connection = $this->createConnectionWithParams(array( @@ -96,10 +100,11 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase /** * @medium * @group connected - * @expectedException \Predis\Protocol\ProtocolException */ public function testThrowsExceptionOnProtocolDesynchronizationErrors() { + $this->expectException('Predis\Protocol\ProtocolException'); + $connection = $this->createConnection(); $stream = $connection->getResource(); diff --git a/tests/Predis/Connection/StreamConnectionTest.php b/tests/Predis/Connection/StreamConnectionTest.php index 6b31b65b..e98824d9 100644 --- a/tests/Predis/Connection/StreamConnectionTest.php +++ b/tests/Predis/Connection/StreamConnectionTest.php @@ -23,11 +23,12 @@ class StreamConnectionTest extends PredisConnectionTestCase /** * @group disconnected - * @expectedException \Predis\Connection\ConnectionException - * @expectedExceptionMessage `SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379] */ public function testThrowsExceptionOnInitializationCommandFailure() { + $this->expectException('Predis\Connection\ConnectionException'); + $this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]"); + $cmdSelect = RawCommand::create('SELECT', '1000'); $connection = $this->getMockBuilder(static::CONNECTION_CLASS) diff --git a/tests/Predis/Connection/WebdisConnectionTest.php b/tests/Predis/Connection/WebdisConnectionTest.php index 79439316..7a4fb2da 100644 --- a/tests/Predis/Connection/WebdisConnectionTest.php +++ b/tests/Predis/Connection/WebdisConnectionTest.php @@ -45,76 +45,83 @@ class WebdisConnectionTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid scheme: 'tcp'. */ public function testThrowsExceptionOnInvalidScheme() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("Invalid scheme: 'tcp'"); + $connection = $this->createConnectionWithParams(array('scheme' => 'tcp')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::writeRequest() is not supported. */ public function testWritingCommandsIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::writeRequest() is not supported"); + $connection = $this->createConnection(); $connection->writeRequest($this->getCurrentProfile()->createCommand('ping')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::readResponse() is not supported */ public function testReadingResponsesIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::readResponse() is not supported"); + $connection = $this->createConnection(); $connection->readResponse($this->getCurrentProfile()->createCommand('ping')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::read() is not supported. */ public function testReadingFromConnectionIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::read() is not supported"); + $connection = $this->createConnection(); $connection->read(); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::addConnectCommand() is not supported. */ public function testAddingConnectCommandsIsNotSupported() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The method Predis\Connection\WebdisConnection::addConnectCommand() is not supported"); + $connection = $this->createConnection(); $connection->addConnectCommand($this->getCurrentProfile()->createCommand('ping')); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Command 'SELECT' is not allowed by Webdis. */ public function testRejectCommandSelect() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Command 'SELECT' is not allowed by Webdis"); + $connection = $this->createConnection(); $connection->executeCommand($this->getCurrentProfile()->createCommand('select', array(0))); } /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Command 'AUTH' is not allowed by Webdis. */ public function testRejectCommandAuth() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("Command 'AUTH' is not allowed by Webdis"); + $connection = $this->createConnection(); $connection->executeCommand($this->getCurrentProfile()->createCommand('auth', array('foobar'))); } @@ -167,10 +174,11 @@ class WebdisConnectionTest extends PredisTestCase * @medium * @group disconnected * @group slow - * @expectedException \Predis\Connection\ConnectionException */ public function testThrowExceptionWhenUnableToConnect() { + $this->expectException('Predis\Connection\ConnectionException'); + $connection = $this->createConnectionWithParams(array('host' => '169.254.10.10')); $connection->executeCommand($this->getCurrentProfile()->createCommand('ping')); } diff --git a/tests/Predis/Monitor/ConsumerTest.php b/tests/Predis/Monitor/ConsumerTest.php index 7b893839..7436019c 100644 --- a/tests/Predis/Monitor/ConsumerTest.php +++ b/tests/Predis/Monitor/ConsumerTest.php @@ -23,12 +23,13 @@ class ConsumerTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The current profile does not support 'MONITOR'. */ public function testMonitorConsumerRequireMonitorCommand() { - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The current profile does not support 'MONITOR'"); + + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->once()) ->method('supportsCommand') ->with('MONITOR') @@ -41,12 +42,13 @@ class ConsumerTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot initialize a monitor consumer over aggregate connections. */ public function testMonitorConsumerDoesNotWorkOnClusters() { - $cluster = $this->getMock('Predis\Connection\Aggregate\ClusterInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('Cannot initialize a monitor consumer over aggregate connections'); + + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(); $client = new Client($cluster); new MonitorConsumer($client); @@ -59,9 +61,12 @@ class ConsumerTest extends PredisTestCase { $cmdMonitor = Profile\Factory::getDefault()->createCommand('monitor'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('createCommand', 'executeCommand'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('createCommand', 'executeCommand')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client->expects($this->once()) ->method('createCommand') ->with('MONITOR', array()) @@ -82,9 +87,12 @@ class ConsumerTest extends PredisTestCase */ public function testStoppingConsumerClosesConnection() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client->expects($this->exactly(2))->method('disconnect'); $monitor = new MonitorConsumer($client); @@ -96,9 +104,12 @@ class ConsumerTest extends PredisTestCase */ public function testGarbageCollectorRunStopsConsumer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $client->expects($this->once())->method('disconnect'); $monitor = new MonitorConsumer($client); @@ -112,7 +123,7 @@ class ConsumerTest extends PredisTestCase { $message = '1323367530.939137 (db 15) "MONITOR"'; - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('read') ->will($this->returnValue($message)); @@ -135,7 +146,7 @@ class ConsumerTest extends PredisTestCase { $message = '1323367530.939137 [15 127.0.0.1:37265] "MONITOR"'; - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('read') ->will($this->returnValue($message)); diff --git a/tests/Predis/Pipeline/AtomicTest.php b/tests/Predis/Pipeline/AtomicTest.php index 36dc4a96..e00ebb83 100644 --- a/tests/Predis/Pipeline/AtomicTest.php +++ b/tests/Predis/Pipeline/AtomicTest.php @@ -28,7 +28,7 @@ class AtomicTest extends PredisTestCase $pong = new Response\Status('PONG'); $queued = new Response\Status('QUEUED'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(2)) ->method('executeCommand') ->will($this->onConsecutiveCalls(true, array($pong, $pong, $pong))); @@ -49,12 +49,13 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage The underlying transaction has been aborted by the server. */ public function testThrowsExceptionOnAbortedTransaction() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('The underlying transaction has been aborted by the server'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(2)) ->method('executeCommand') ->will($this->onConsecutiveCalls(true, null)); @@ -70,15 +71,16 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Test error */ public function testPipelineWithErrorInTransaction() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Test error'); + $queued = new Response\Status('QUEUED'); $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->at(0)) ->method('executeCommand') ->will($this->returnValue(true)); @@ -100,14 +102,15 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Test error */ public function testThrowsServerExceptionOnResponseErrorByDefault() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Test error'); + $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('readResponse') ->will($this->returnValue($error)); @@ -129,7 +132,7 @@ class AtomicTest extends PredisTestCase $queued = new Response\Status('QUEUED'); $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(3)) ->method('readResponse') ->will($this->onConsecutiveCalls($queued, $queued, $queued)); @@ -148,12 +151,13 @@ class AtomicTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage The class 'Predis\Pipeline\Atomic' does not support aggregate connections. */ public function testExecutorWithAggregateConnection() { - $connection = $this->getMock('Predis\Connection\Aggregate\ClusterInterface'); + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage("The class 'Predis\Pipeline\Atomic' does not support aggregate connections"); + + $connection = $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(); $pipeline = new Atomic(new Client($connection)); $pipeline->ping(); diff --git a/tests/Predis/Pipeline/FireAndForgetTest.php b/tests/Predis/Pipeline/FireAndForgetTest.php index ecfc1f50..37502d0d 100644 --- a/tests/Predis/Pipeline/FireAndForgetTest.php +++ b/tests/Predis/Pipeline/FireAndForgetTest.php @@ -24,7 +24,7 @@ class FireAndForgetTest extends PredisTestCase */ public function testPipelineWithSingleConnection() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(3))->method('writeRequest'); $connection->expects($this->never())->method('readResponse'); @@ -42,7 +42,7 @@ class FireAndForgetTest extends PredisTestCase */ public function testSwitchesToMasterWithReplicationConnection() { - $connection = $this->getMock('Predis\Connection\Aggregate\ReplicationInterface'); + $connection = $this->getMockBuilder('Predis\Connection\Aggregate\ReplicationInterface')->getMock(); $connection->expects($this->once()) ->method('switchTo') ->with('master'); diff --git a/tests/Predis/Pipeline/PipelineTest.php b/tests/Predis/Pipeline/PipelineTest.php index 1b17f2ef..9388b7ad 100644 --- a/tests/Predis/Pipeline/PipelineTest.php +++ b/tests/Predis/Pipeline/PipelineTest.php @@ -38,7 +38,7 @@ class PipelineTest extends PredisTestCase */ public function testCallDoesNotSendCommandsWithoutExecute() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->never())->method('writeRequest'); $connection->expects($this->never())->method('readResponse'); @@ -54,7 +54,7 @@ class PipelineTest extends PredisTestCase */ public function testCallReturnsPipelineForFluentInterface() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->never())->method('writeRequest'); $connection->expects($this->never())->method('readResponse'); @@ -69,9 +69,9 @@ class PipelineTest extends PredisTestCase */ public function testDoesNotParseComplexResponseObjects() { - $object = $this->getMock('Predis\Response\ResponseInterface'); + $object = $this->getMockBuilder('Predis\Response\ResponseInterface')->getMock(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('readResponse') ->will($this->returnValue($object)); @@ -85,14 +85,15 @@ class PipelineTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR Test error */ public function testThrowsServerExceptionOnResponseErrorByDefault() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR Test error'); + $error = new Response\Error('ERR Test error'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('readResponse') ->will($this->returnValue($error)); @@ -110,9 +111,9 @@ class PipelineTest extends PredisTestCase */ public function testReturnsResponseErrorWithClientExceptionsSetToFalse() { - $error = $this->getMock('Predis\Response\ErrorInterface'); + $error = $this->getMockBuilder('Predis\Response\ErrorInterface')->getMock(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(2)) ->method('readResponse') ->will($this->returnValue($error)); @@ -133,7 +134,7 @@ class PipelineTest extends PredisTestCase public function testExecuteReturnsPipelineForFluentInterface() { $profile = Profile\Factory::getDefault(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $pipeline = new Pipeline(new Client($connection)); $command = $profile->createCommand('echo', array('one')); @@ -147,7 +148,7 @@ class PipelineTest extends PredisTestCase { $profile = Profile\Factory::getDefault(); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->never())->method('writeRequest'); $connection->expects($this->never())->method('readResponse'); @@ -163,7 +164,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteWithEmptyBuffer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->never())->method('writeRequest'); $connection->expects($this->never())->method('readResponse'); @@ -177,7 +178,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteWithFilledBuffer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(3)) ->method('writeRequest'); $connection->expects($this->exactly(3)) @@ -216,7 +217,7 @@ class PipelineTest extends PredisTestCase */ public function testFlushHandlesPartialBuffers() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(4)) ->method('writeRequest'); $connection->expects($this->exactly(4)) @@ -241,7 +242,7 @@ class PipelineTest extends PredisTestCase { $pong = new Response\Status('PONG'); - $connection = $this->getMock('Predis\Connection\Aggregate\ReplicationInterface'); + $connection = $this->getMockBuilder('Predis\Connection\Aggregate\ReplicationInterface')->getMock(); $connection->expects($this->once()) ->method('switchTo') ->with('master'); @@ -278,10 +279,11 @@ class PipelineTest extends PredisTestCase /** * @group disconnected - * @expectedException InvalidArgumentException */ public function testExecuteDoesNotAcceptNonCallableArgument() { + $this->expectException('InvalidArgumentException'); + $noncallable = new \stdClass(); $pipeline = new Pipeline(new Client()); @@ -290,10 +292,11 @@ class PipelineTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException */ public function testExecuteInsideCallableArgumentThrowsException() { + $this->expectException('Predis\ClientException'); + $pipeline = new Pipeline(new Client()); $pipeline->execute(function ($pipe) { @@ -306,7 +309,7 @@ class PipelineTest extends PredisTestCase */ public function testExecuteWithCallableArgumentRunsPipelineInCallable() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(4)) ->method('writeRequest'); $connection->expects($this->exactly(4)) @@ -332,7 +335,7 @@ class PipelineTest extends PredisTestCase { $exception = null; - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->never())->method('writeRequest'); $connection->expects($this->never())->method('readResponse'); diff --git a/tests/Predis/PredisExceptionTest.php b/tests/Predis/PredisExceptionTest.php index 07b63816..6613c961 100644 --- a/tests/Predis/PredisExceptionTest.php +++ b/tests/Predis/PredisExceptionTest.php @@ -26,7 +26,8 @@ class PredisExceptionTest extends PredisTestCase $message = 'Predis exception message'; $exception = $this->getMockForAbstractClass('Predis\PredisException', array($message)); - $this->setExpectedException('Predis\PredisException', $message); + $this->expectException('Predis\PredisException'); + $this->expectExceptionMessage($message); throw $exception; } diff --git a/tests/Predis/Profile/FactoryTest.php b/tests/Predis/Profile/FactoryTest.php index 74048610..17ab205b 100644 --- a/tests/Predis/Profile/FactoryTest.php +++ b/tests/Predis/Profile/FactoryTest.php @@ -63,11 +63,12 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Unknown server profile: '1.0'. */ public function testGetUndefinedProfile() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage("Unknown server profile: '1.0'"); + Factory::get('1.0'); } @@ -76,7 +77,7 @@ class FactoryTest extends PredisTestCase */ public function testDefineProfile() { - $profileClass = get_class($this->getMock('Predis\Profile\ProfileInterface')); + $profileClass = get_class($this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock()); Factory::define('mock', $profileClass); @@ -85,11 +86,12 @@ class FactoryTest extends PredisTestCase /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The class 'stdClass' is not a valid profile class. */ public function testDefineInvalidProfile() { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage("The class 'stdClass' is not a valid profile class"); + Factory::define('bogus', 'stdClass'); } } diff --git a/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php b/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php index 21552c1f..67028585 100644 --- a/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php +++ b/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php @@ -38,8 +38,8 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testConstructorWithArguments() { - $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface'); - $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface'); + $serializer = $this->getMockBuilder('Predis\Protocol\RequestSerializerInterface')->getMock(); + $reader = $this->getMockBuilder('Predis\Protocol\ResponseReaderInterface')->getMock(); $protocol = new CompositeProtocolProcessor($serializer, $reader); @@ -52,7 +52,7 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testCustomRequestSerializer() { - $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface'); + $serializer = $this->getMockBuilder('Predis\Protocol\RequestSerializerInterface')->getMock(); $protocol = new CompositeProtocolProcessor(); $protocol->setRequestSerializer($serializer); @@ -65,7 +65,7 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testCustomResponseReader() { - $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface'); + $reader = $this->getMockBuilder('Predis\Protocol\ResponseReaderInterface')->getMock(); $protocol = new CompositeProtocolProcessor(); $protocol->setResponseReader($reader); @@ -80,9 +80,9 @@ class CompositeProtocolProcessorTest extends PredisTestCase { $serialized = "*1\r\n$4\r\nPING\r\n"; - $command = $this->getMock('Predis\Command\CommandInterface'); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); - $serializer = $this->getMock('Predis\Protocol\RequestSerializerInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); + $serializer = $this->getMockBuilder('Predis\Protocol\RequestSerializerInterface')->getMock(); $protocol = new CompositeProtocolProcessor($serializer); @@ -103,8 +103,8 @@ class CompositeProtocolProcessorTest extends PredisTestCase */ public function testConnectionRead() { - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); - $reader = $this->getMock('Predis\Protocol\ResponseReaderInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); + $reader = $this->getMockBuilder('Predis\Protocol\ResponseReaderInterface')->getMock(); $protocol = new CompositeProtocolProcessor(null, $reader); diff --git a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php index 5debafd6..2a743297 100644 --- a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php @@ -25,7 +25,7 @@ class BulkResponseTest extends PredisTestCase { $handler = new Handler\BulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->once()) @@ -46,7 +46,7 @@ class BulkResponseTest extends PredisTestCase $handler = new Handler\BulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->once()) @@ -64,7 +64,7 @@ class BulkResponseTest extends PredisTestCase { $handler = new Handler\BulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); @@ -74,14 +74,15 @@ class BulkResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a bulk response. */ public function testInvalidLength() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid length for a bulk response"); + $handler = new Handler\BulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); diff --git a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php b/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php index 00b3dc7c..8e9b2b37 100644 --- a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php @@ -25,7 +25,7 @@ class ErrorResponseTest extends PredisTestCase { $handler = new Handler\ErrorResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); diff --git a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php b/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php index 4aa16d53..826df1e6 100644 --- a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php @@ -25,7 +25,7 @@ class IntegerResponseTest extends PredisTestCase { $handler = new Handler\IntegerResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); @@ -43,7 +43,7 @@ class IntegerResponseTest extends PredisTestCase { $handler = new Handler\IntegerResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); @@ -53,14 +53,15 @@ class IntegerResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid numeric response. */ public function testInvalid() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid numeric response"); + $handler = new Handler\IntegerResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); diff --git a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php index c32b6124..a1ed7fa2 100644 --- a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php @@ -25,7 +25,7 @@ class MultiBulkResponseTest extends PredisTestCase { $handler = new Handler\MultiBulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('getProtocol') @@ -57,7 +57,7 @@ class MultiBulkResponseTest extends PredisTestCase { $handler = new Handler\MultiBulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); @@ -67,14 +67,15 @@ class MultiBulkResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid length of a multi-bulk response. */ public function testInvalid() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid length of a multi-bulk response"); + $handler = new Handler\MultiBulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); diff --git a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php index 185c393a..fd7dd922 100644 --- a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php @@ -25,7 +25,7 @@ class StatusResponseTest extends PredisTestCase { $handler = new Handler\StatusResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); @@ -43,7 +43,7 @@ class StatusResponseTest extends PredisTestCase { $handler = new Handler\StatusResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); @@ -61,7 +61,7 @@ class StatusResponseTest extends PredisTestCase { $handler = new Handler\StatusResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); diff --git a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php index 3f349f80..5adb0c08 100644 --- a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php @@ -25,7 +25,7 @@ class StreamableMultiBulkResponseTest extends PredisTestCase { $handler = new Handler\StreamableMultiBulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); @@ -35,14 +35,15 @@ class StreamableMultiBulkResponseTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a multi-bulk response. */ public function testInvalid() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Cannot parse 'invalid' as a valid length for a multi-bulk response"); + $handler = new Handler\StreamableMultiBulkResponse(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBuffer'); diff --git a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php index 294e4e02..b2e2859f 100644 --- a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php +++ b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php @@ -26,7 +26,7 @@ class ProtocolProcessorTest extends PredisTestCase $serialized = "*1\r\n$4\r\nPING\r\n"; $protocol = new ProtocolProcessor(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->once()) ->method('getId') @@ -36,7 +36,7 @@ class ProtocolProcessorTest extends PredisTestCase ->method('getArguments') ->will($this->returnValue(array())); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('writeBuffer') @@ -52,7 +52,7 @@ class ProtocolProcessorTest extends PredisTestCase { $protocol = new ProtocolProcessor(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->at(0)) ->method('readLine') @@ -89,7 +89,7 @@ class ProtocolProcessorTest extends PredisTestCase $protocol = new ProtocolProcessor(); $protocol->useIterableMultibulk(true); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->once(4)) ->method('readLine') @@ -100,14 +100,15 @@ class ProtocolProcessorTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Unknown response prefix: '!'. */ public function testUnknownResponsePrefix() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Unknown response prefix: '!'"); + $protocol = new ProtocolProcessor(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('readLine') diff --git a/tests/Predis/Protocol/Text/RequestSerializerTest.php b/tests/Predis/Protocol/Text/RequestSerializerTest.php index a9e91b61..d3791197 100644 --- a/tests/Predis/Protocol/Text/RequestSerializerTest.php +++ b/tests/Predis/Protocol/Text/RequestSerializerTest.php @@ -25,7 +25,7 @@ class RequestSerializerTest extends PredisTestCase { $serializer = new RequestSerializer(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->once()) ->method('getId') @@ -47,7 +47,7 @@ class RequestSerializerTest extends PredisTestCase { $serializer = new RequestSerializer(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->once()) ->method('getId') @@ -69,7 +69,7 @@ class RequestSerializerTest extends PredisTestCase { $serializer = new RequestSerializer(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->once()) ->method('getId') diff --git a/tests/Predis/Protocol/Text/ResponseReaderTest.php b/tests/Predis/Protocol/Text/ResponseReaderTest.php index dd3ec595..077c3e60 100644 --- a/tests/Predis/Protocol/Text/ResponseReaderTest.php +++ b/tests/Predis/Protocol/Text/ResponseReaderTest.php @@ -39,7 +39,7 @@ class ResponseReaderTest extends PredisTestCase */ public function testReplaceHandler() { - $handler = $this->getMock('Predis\Protocol\Text\Handler\ResponseHandlerInterface'); + $handler = $this->getMockBuilder('Predis\Protocol\Text\Handler\ResponseHandlerInterface')->getMock(); $reader = new ResponseReader(); $reader->setHandler('+', $handler); @@ -57,7 +57,7 @@ class ResponseReaderTest extends PredisTestCase $protocol = new CompositeProtocolProcessor(); $protocol->setResponseReader($reader); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->at(0)) ->method('readLine') @@ -88,14 +88,15 @@ class ResponseReaderTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Unexpected empty reponse header. */ public function testEmptyResponseHeader() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage('Unexpected empty reponse header'); + $reader = new ResponseReader(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('readLine') @@ -105,14 +106,15 @@ class ResponseReaderTest extends PredisTestCase } /** * @group disconnected - * @expectedException \Predis\Protocol\ProtocolException - * @expectedExceptionMessage Unknown response prefix: '!'. */ public function testUnknownResponsePrefix() { + $this->expectException('Predis\Protocol\ProtocolException'); + $this->expectExceptionMessage("Unknown response prefix: '!'"); + $reader = new ResponseReader(); - $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\CompositeConnectionInterface')->getMock(); $connection->expects($this->once()) ->method('readLine') diff --git a/tests/Predis/PubSub/ConsumerTest.php b/tests/Predis/PubSub/ConsumerTest.php index 3bc24766..5d10604b 100644 --- a/tests/Predis/PubSub/ConsumerTest.php +++ b/tests/Predis/PubSub/ConsumerTest.php @@ -23,12 +23,13 @@ class ConsumerTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The current profile does not support PUB/SUB related commands. */ public function testPubSubConsumerRequirePubSubRelatedCommand() { - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('The current profile does not support PUB/SUB related commands'); + + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->any()) ->method('supportsCommands') ->will($this->returnValue(false)); @@ -40,12 +41,13 @@ class ConsumerTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage Cannot initialize a PUB/SUB consumer over aggregate connections. */ public function testPubSubConsumerDoesNotWorkOnClusters() { - $cluster = $this->getMock('Predis\Connection\Aggregate\ClusterInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('Cannot initialize a PUB/SUB consumer over aggregate connections'); + + $cluster = $this->getMockBuilder('Predis\Connection\Aggregate\ClusterInterface')->getMock(); $client = new Client($cluster); new PubSubConsumer($client); @@ -56,10 +58,15 @@ class ConsumerTest extends PredisTestCase */ public function testConstructorWithoutSubscriptionsDoesNotStartConsumer() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('executeCommand'), array($connection)); - $client->expects($this->never())->method('executeCommand'); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('executeCommand')) + ->setConstructorArgs(array($connection)) + ->getMock(); + + $client->expects($this->never()) + ->method('executeCommand'); new PubSubConsumer($client); } @@ -71,10 +78,14 @@ class ConsumerTest extends PredisTestCase { $profile = Profile\Factory::get(REDIS_SERVER_VERSION); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->exactly(2))->method('writeRequest'); - $client = $this->getMock('Predis\Client', array('createCommand', 'writeRequest'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('createCommand', 'writeRequest')) + ->setConstructorArgs(array($connection)) + ->getMock(); + $client->expects($this->exactly(2)) ->method('createCommand') ->with($this->logicalOr($this->equalTo('subscribe'), $this->equalTo('psubscribe'))) @@ -92,9 +103,13 @@ class ConsumerTest extends PredisTestCase */ public function testStoppingConsumerWithTrueClosesConnection() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); + + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); $client->expects($this->exactly(1))->method('disconnect'); $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo')); @@ -113,9 +128,12 @@ class ConsumerTest extends PredisTestCase $classUnsubscribe = $profile->getCommandClass('unsubscribe'); $classPunsubscribe = $profile->getCommandClass('punsubscribe'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $options = array('subscribe' => 'channel:foo', 'psubscribe' => 'channels:*'); $pubsub = new PubSubConsumer($client, $options); @@ -135,8 +153,11 @@ class ConsumerTest extends PredisTestCase */ public function testIsNotValidWhenNotSubscribed() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); - $client = $this->getMock('Predis\Client', array('disconnect'), array($connection)); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); + $client = $this->getMockBuilder('Predis\Client') + ->setMethods(array('disconnect')) + ->setConstructorArgs(array($connection)) + ->getMock(); $pubsub = new PubSubConsumer($client); @@ -151,7 +172,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('pong', ''); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage)); $client = new Client($connection); @@ -169,7 +190,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('pong', 'foobar'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage)); $client = new Client($connection); @@ -187,7 +208,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('message', 'channel:foo', 'message from channel'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage)); $client = new Client($connection); @@ -206,7 +227,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('pmessage', 'channel:*', 'channel:foo', 'message from channel'); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage)); $client = new Client($connection); @@ -226,7 +247,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('subscribe', 'channel:foo', 1); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage)); $client = new Client($connection); @@ -245,7 +266,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('unsubscribe', 'channel:foo', 1); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage)); $client = new Client($connection); @@ -264,7 +285,7 @@ class ConsumerTest extends PredisTestCase { $rawmessage = array('unsubscribe', 'channel:foo', 0); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage)); $client = new Client($connection); @@ -285,7 +306,7 @@ class ConsumerTest extends PredisTestCase */ public function testGetUnderlyingClientInstance() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection); $pubsub = new PubSubConsumer($client); diff --git a/tests/Predis/PubSub/DispatcherLoopTest.php b/tests/Predis/PubSub/DispatcherLoopTest.php index 20b2188e..b9fef098 100644 --- a/tests/Predis/PubSub/DispatcherLoopTest.php +++ b/tests/Predis/PubSub/DispatcherLoopTest.php @@ -47,7 +47,9 @@ class DispatcherLoopTest extends PredisTestCase $pubsub = new Consumer($consumer); $dispatcher = new DispatcherLoop($pubsub); - $function01 = $this->getMock('stdClass', array('__invoke')); + $function01 = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $function01->expects($this->exactly(2)) ->method('__invoke') ->with($this->logicalOr( @@ -60,12 +62,16 @@ class DispatcherLoopTest extends PredisTestCase } })); - $function02 = $this->getMock('stdClass', array('__invoke')); + $function02 = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $function02->expects($this->once()) ->method('__invoke') ->with('02:argument'); - $function03 = $this->getMock('stdClass', array('__invoke')); + $function03 = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $function03->expects($this->never()) ->method('__invoke'); @@ -108,7 +114,9 @@ class DispatcherLoopTest extends PredisTestCase $pubsub = new Consumer($consumer); $dispatcher = new DispatcherLoop($pubsub); - $callback = $this->getMock('stdClass', array('__invoke')); + $callback = $this->getMockBuilder('stdClass') + ->setMethods(array('__invoke')) + ->getMock(); $callback->expects($this->exactly(1)) ->method('__invoke') ->with($this->equalTo('arg:prefixed')) diff --git a/tests/Predis/Replication/ReplicationStrategyTest.php b/tests/Predis/Replication/ReplicationStrategyTest.php index b1237c17..8194363c 100644 --- a/tests/Predis/Replication/ReplicationStrategyTest.php +++ b/tests/Predis/Replication/ReplicationStrategyTest.php @@ -195,11 +195,12 @@ class ReplicationStrategyTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The command 'INFO' is not allowed in replication mode. */ public function testUsingDisallowedCommandThrowsException() { + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage("The command 'INFO' is not allowed in replication mode"); + $profile = Profile\Factory::getDevelopment(); $strategy = new ReplicationStrategy(); @@ -214,7 +215,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->any()) ->method('getId') ->will($this->returnValue('CMDTEST')); @@ -229,7 +230,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->any()) ->method('getId') ->will($this->returnValue('CMDTEST')); @@ -245,7 +246,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\CommandInterface'); + $command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock(); $command->expects($this->any()) ->method('getId') ->will($this->returnValue('CMDTEST')); @@ -307,7 +308,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand', array('getScript'))->getMock(); $command->expects($this->any()) ->method('getScript') ->will($this->returnValue($script = 'return true')); @@ -320,7 +321,7 @@ class ReplicationStrategyTest extends PredisTestCase $this->assertFalse($strategy->isReadOperation($command)); $command->setArguments(array(true)); - $this->assertTrue($strategy->isReadOperation($command)); + $this->assertFalse($strategy->isReadOperation($command)); } /** @@ -330,7 +331,7 @@ class ReplicationStrategyTest extends PredisTestCase { $strategy = new ReplicationStrategy(); - $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript')); + $command = $this->getMockBuilder('Predis\Command\ScriptCommand', array('getScript'))->getMock(); $command->expects($this->any()) ->method('getScript') ->will($this->returnValue($script = 'return true')); @@ -339,7 +340,7 @@ class ReplicationStrategyTest extends PredisTestCase $strategy->setScriptReadOnly($script, true); - $this->assertTrue($strategy->isReadOperation($command)); + $this->assertFalse($strategy->isReadOperation($command)); } // ******************************************************************** // diff --git a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php b/tests/Predis/Response/Iterator/MultiBulkTupleTest.php index b7a99226..0a46266a 100644 --- a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php +++ b/tests/Predis/Response/Iterator/MultiBulkTupleTest.php @@ -23,12 +23,13 @@ class MultiBulkTupleTest extends PredisTestCase { /** * @group disconnected - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Cannot initialize a tuple iterator using an already initiated iterator. */ public function testInitiatedMultiBulkIteratorsAreNotValid() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage('Cannot initialize a tuple iterator using an already initiated iterator'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $iterator = new MultiBulk($connection, 2); $iterator->next(); @@ -37,12 +38,13 @@ class MultiBulkTupleTest extends PredisTestCase /** * @group disconnected - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage Invalid response size for a tuple iterator. */ public function testMultiBulkWithOddSizesAreInvalid() { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $this->expectException('UnexpectedValueException'); + $this->expectExceptionMessage('Invalid response size for a tuple iterator'); + + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $iterator = new MultiBulk($connection, 3); new MultiBulkTuple($iterator); diff --git a/tests/Predis/Response/ServerExceptionTest.php b/tests/Predis/Response/ServerExceptionTest.php index b74e66bf..9aa7acd3 100644 --- a/tests/Predis/Response/ServerExceptionTest.php +++ b/tests/Predis/Response/ServerExceptionTest.php @@ -25,7 +25,8 @@ class ServerExceptionTest extends PredisTestCase */ public function testExceptionMessage() { - $this->setExpectedException('Predis\Response\ServerException', self::ERR_WRONG_KEY_TYPE); + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage(self::ERR_WRONG_KEY_TYPE); throw new ServerException(self::ERR_WRONG_KEY_TYPE); } diff --git a/tests/Predis/Transaction/MultiExecTest.php b/tests/Predis/Transaction/MultiExecTest.php index bfdf57aa..bad786a5 100644 --- a/tests/Predis/Transaction/MultiExecTest.php +++ b/tests/Predis/Transaction/MultiExecTest.php @@ -23,18 +23,19 @@ class MultiExecTest extends PredisTestCase { /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage The current profile does not support MULTI, EXEC and DISCARD. */ public function testThrowsExceptionOnUnsupportedMultiExecInProfile() { - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('The current profile does not support MULTI, EXEC and DISCARD'); + + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->once()) ->method('supportsCommands') ->with(array('MULTI', 'EXEC', 'DISCARD')) ->will($this->returnValue(false)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection, array('profile' => $profile)); new MultiExec($client); @@ -42,12 +43,13 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage WATCH is not supported by the current profile. */ public function testThrowsExceptionOnUnsupportedWatchInProfile() { - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('WATCH is not supported by the current profile'); + + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->once()) ->method('supportsCommands') ->with(array('MULTI', 'EXEC', 'DISCARD')) @@ -57,7 +59,7 @@ class MultiExecTest extends PredisTestCase ->with('WATCH') ->will($this->returnValue(false)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection, array('profile' => $profile)); $tx = new MultiExec($client, array('options' => 'cas')); @@ -66,12 +68,13 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\NotSupportedException - * @expectedExceptionMessage UNWATCH is not supported by the current profile. */ public function testThrowsExceptionOnUnsupportedUnwatchInProfile() { - $profile = $this->getMock('Predis\Profile\ProfileInterface'); + $this->expectException('Predis\NotSupportedException'); + $this->expectExceptionMessage('UNWATCH is not supported by the current profile'); + + $profile = $this->getMockBuilder('Predis\Profile\ProfileInterface')->getMock(); $profile->expects($this->once()) ->method('supportsCommands') ->with(array('MULTI', 'EXEC', 'DISCARD')) @@ -81,7 +84,7 @@ class MultiExecTest extends PredisTestCase ->with('UNWATCH') ->will($this->returnValue(false)); - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $client = new Client($connection, array('profile' => $profile)); $tx = new MultiExec($client, array('options' => 'cas')); @@ -169,11 +172,12 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Cannot invoke "execute" or "exec" inside an active transaction context. */ public function testThrowsExceptionOnExecInsideTransactionBlock() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('Cannot invoke "execute" or "exec" inside an active transaction context'); + $commands = array(); $callback = $this->getExecuteCallback(null, $commands); @@ -247,10 +251,11 @@ class MultiExecTest extends PredisTestCase } /** * @group disconnected - * @expectedException \Predis\ClientException */ public function testThrowsExceptionOnWatchInsideMulti() { + $this->expectException('Predis\ClientException'); + $callback = $this->getExecuteCallback(); $tx = $this->getMockedTransaction($callback); @@ -396,11 +401,13 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\ClientException - * @expectedExceptionMessage Automatic retries are supported only when a callable block is provided. */ public function testThrowsExceptionOnAutomaticRetriesWithFluentInterface() { + $this->expectException('Predis\ClientException'); + $this->expectExceptionMessage('Automatic retries are supported only when a callable block is provided'); + + $options = array('retry' => 1); $callback = $this->getExecuteCallback(); @@ -418,7 +425,9 @@ class MultiExecTest extends PredisTestCase $expected = array('bar'); $options = array('watch' => array('foo', 'bar'), 'retry' => ($attempts = 2) + 1); - $sentinel = $this->getMock('stdClass', array('signal')); + $sentinel = $this->getMockBuilder('stdClass') + ->setMethods(array('signal')) + ->getMock(); $sentinel->expects($this->exactly($attempts))->method('signal'); $callback = $this->getExecuteCallback($expected, $txCommands, $casCommands); @@ -443,10 +452,11 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Transaction\AbortedMultiExecException */ public function testThrowsExceptionOnServerSideTransactionAbort() { + $this->expectException('Predis\Transaction\AbortedMultiExecException'); + $callback = $this->getExecuteCallback(); $tx = $this->getMockedTransaction($callback); @@ -479,7 +489,8 @@ class MultiExecTest extends PredisTestCase // NOOP } - $this->assertNull($responses, $expected); + $this->assertNull($responses); + $this->assertIsArray($expected); $this->assertSame(array('MULTI', 'SET', 'GET', 'DISCARD'), self::commandsToIDs($commands)); } @@ -588,11 +599,12 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR simulated error */ public function testExceptionsOptionTakesPrecedenceOverClientOptionsWhenTrue() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR simulated error'); + $expected = array('before', new Response\Error('ERR simulated error'), 'after'); $connection = $this->getMockedConnection(function (CommandInterface $command) use ($expected) { @@ -616,11 +628,12 @@ class MultiExecTest extends PredisTestCase /** * @group disconnected - * @expectedException \Predis\Response\ServerException - * @expectedExceptionMessage ERR simulated failure on EXEC */ public function testExceptionsOptionDoesNotAffectTransactionControlCommands() { + $this->expectException('Predis\Response\ServerException'); + $this->expectExceptionMessage('ERR simulated failure on EXEC'); + $connection = $this->getMockedConnection(function (CommandInterface $command) { switch ($command->getId()) { case 'MULTI': @@ -767,7 +780,7 @@ class MultiExecTest extends PredisTestCase $tx->mget('foo', 'foobar'); }); - $this->assertInternalType('array', $responses); + $this->assertIsArray($responses); $this->assertSame(array(array('bar', null)), $responses); $hijack = true; @@ -790,7 +803,7 @@ class MultiExecTest extends PredisTestCase $tx->mget('foo', 'foobar'); }); - $this->assertInternalType('array', $responses); + $this->assertIsArray($responses); $this->assertSame(array(array('hijacked!', null)), $responses); } @@ -808,7 +821,7 @@ class MultiExecTest extends PredisTestCase */ protected function getMockedConnection($executeCallback) { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $connection->expects($this->any()) ->method('executeCommand') ->will($this->returnCallback($executeCallback));