/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

  1. <?php
  2. /*
  3. * This file is part of PHPUnit.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Constraint that checks whether a variable is empty().
  12. */
  13. class PHPUnit_Framework_Constraint_IsEmpty extends PHPUnit_Framework_Constraint
  14. {
  15. /**
  16. * Evaluates the constraint for parameter $other. Returns true if the
  17. * constraint is met, false otherwise.
  18. *
  19. * @param mixed $other Value or object to evaluate.
  20. *
  21. * @return bool
  22. */
  23. protected function matches($other)
  24. {
  25. if ($other instanceof Countable) {
  26. return count($other) === 0;
  27. }
  28. return empty($other);
  29. }
  30. /**
  31. * Returns a string representation of the constraint.
  32. *
  33. * @return string
  34. */
  35. public function toString()
  36. {
  37. return 'is empty';
  38. }
  39. /**
  40. * Returns the description of the failure
  41. *
  42. * The beginning of failure messages is "Failed asserting that" in most
  43. * cases. This method should return the second part of that sentence.
  44. *
  45. * @param mixed $other Evaluated value or object.
  46. *
  47. * @return string
  48. */
  49. protected function failureDescription($other)
  50. {
  51. $type = gettype($other);
  52. return sprintf(
  53. '%s %s %s',
  54. $type[0] == 'a' || $type[0] == 'o' ? 'an' : 'a',
  55. $type,
  56. $this->toString()
  57. );
  58. }
  59. }