SwiftUnitTestCase.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. require_once 'Swift/Tests/IdenticalBinaryExpectation.php';
  3. /**
  4. * A base test case with some custom expectations.
  5. * @package Swift
  6. * @subpackage Tests
  7. * @author Chris Corbyn
  8. */
  9. class Swift_Tests_SwiftUnitTestCase extends UnitTestCase
  10. {
  11. /** An instance of the Yay_Mockery class */
  12. private $_mockery;
  13. /**
  14. * Decorates SimpleTest's implementation to auto-validate mock objects.
  15. */
  16. public function after($method)
  17. {
  18. try
  19. {
  20. $this->_mockery()->assertIsSatisfied();
  21. }
  22. catch (Yay_NotSatisfiedException $e)
  23. {
  24. $this->fail($e->getMessage());
  25. }
  26. $this->_mockery = null;
  27. return parent::after($method);
  28. }
  29. /**
  30. * Assert two binary strings are an exact match.
  31. * @param string $a
  32. * @param string $b
  33. * @param string $s formatted message
  34. */
  35. public function assertIdenticalBinary($a, $b, $s = '%s')
  36. {
  37. return $this->assert(new Swift_Tests_IdenticalBinaryExpectation($a), $b, $s);
  38. }
  39. // -- Protected methods
  40. /**
  41. * Returns a singleton-per-test method for Yay_Mockery.
  42. * @return Yay_Mockery
  43. */
  44. protected function _mockery()
  45. {
  46. if (!isset($this->_mockery))
  47. {
  48. $this->_mockery = new Yay_Mockery();
  49. }
  50. return $this->_mockery;
  51. }
  52. /**
  53. * Create a mock object.
  54. * @param string $class
  55. * @return Yay_Mock
  56. */
  57. protected function _mock($class)
  58. {
  59. return $this->_mockery()->mock($class);
  60. }
  61. /**
  62. * Add mock expectations.
  63. * @param Yay_Expectations $expectations
  64. */
  65. protected function _checking($expectations)
  66. {
  67. return $this->_mockery()->checking($expectations);
  68. }
  69. /**
  70. * Create a mock object which does nothing.
  71. * @param string $class
  72. * @return Yay_Mock
  73. */
  74. protected function _stub($class)
  75. {
  76. $stub = $this->_mockery()->mock($class);
  77. $this->_mockery()->checking(Yay_Expectations::create()
  78. -> ignoring($stub)
  79. );
  80. return $stub;
  81. }
  82. protected function _states($machineName)
  83. {
  84. return $this->_mockery()->states($machineName);
  85. }
  86. protected function _sequence($sequenceName)
  87. {
  88. return $this->_mockery()->sequence($sequenceName);
  89. }
  90. }