/vendor/phpunit/phpunit/src/Framework/Constraint/IsEmpty.php
https://bitbucket.org/alan_cordova/api-sb-map · PHP · 64 lines · 25 code · 5 blank · 34 comment · 4 complexity · 4492d6a0abd18c2d921f9405a1443140 MD5 · raw file
- <?php
- /*
- * This file is part of PHPUnit.
- *
- * (c) Sebastian Bergmann <sebastian@phpunit.de>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- * Constraint that checks whether a variable is empty().
- */
- class PHPUnit_Framework_Constraint_IsEmpty extends PHPUnit_Framework_Constraint
- {
- /**
- * Evaluates the constraint for parameter $other. Returns true if the
- * constraint is met, false otherwise.
- *
- * @param mixed $other Value or object to evaluate.
- *
- * @return bool
- */
- protected function matches($other)
- {
- if ($other instanceof Countable) {
- return count($other) === 0;
- }
- return empty($other);
- }
- /**
- * Returns a string representation of the constraint.
- *
- * @return string
- */
- public function toString()
- {
- return 'is empty';
- }
- /**
- * Returns the description of the failure
- *
- * The beginning of failure messages is "Failed asserting that" in most
- * cases. This method should return the second part of that sentence.
- *
- * @param mixed $other Evaluated value or object.
- *
- * @return string
- */
- protected function failureDescription($other)
- {
- $type = gettype($other);
- return sprintf(
- '%s %s %s',
- $type[0] == 'a' || $type[0] == 'o' ? 'an' : 'a',
- $type,
- $this->toString()
- );
- }
- }