LimeTesterString.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Lime framework.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. class LimeTesterString extends LimeTesterScalar
  12. {
  13. protected
  14. $type = 'string';
  15. public function __toString()
  16. {
  17. return "'".$this->value."'";
  18. }
  19. public function is(LimeTesterInterface $expected)
  20. {
  21. // allow comparison with objects that implement __toString()
  22. if ($expected instanceof LimeTesterObject)
  23. {
  24. $expected->is($this);
  25. }
  26. else
  27. {
  28. parent::is($expected);
  29. }
  30. }
  31. public function like(LimeTesterInterface $expected)
  32. {
  33. if (!preg_match($expected->value, $this->value))
  34. {
  35. throw new LimeAssertionFailedException($this, $expected);
  36. }
  37. }
  38. public function unlike(LimeTesterInterface $expected)
  39. {
  40. if (preg_match($expected->value, $this->value))
  41. {
  42. throw new LimeAssertionFailedException($this, $expected);
  43. }
  44. }
  45. }