InvocationMockerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. class Framework_MockObject_Builder_InvocationMockerTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testWillReturnWithOneValue()
  5. {
  6. $mock = $this->getMockBuilder(stdClass::class)
  7. ->setMethods(['foo'])
  8. ->getMock();
  9. $mock->expects($this->any())
  10. ->method('foo')
  11. ->willReturn(1);
  12. $this->assertEquals(1, $mock->foo());
  13. }
  14. public function testWillReturnWithMultipleValues()
  15. {
  16. $mock = $this->getMockBuilder(stdClass::class)
  17. ->setMethods(['foo'])
  18. ->getMock();
  19. $mock->expects($this->any())
  20. ->method('foo')
  21. ->willReturn(1, 2, 3);
  22. $this->assertEquals(1, $mock->foo());
  23. $this->assertEquals(2, $mock->foo());
  24. $this->assertEquals(3, $mock->foo());
  25. }
  26. public function testWillReturnOnConsecutiveCalls()
  27. {
  28. $mock = $this->getMockBuilder(stdClass::class)
  29. ->setMethods(['foo'])
  30. ->getMock();
  31. $mock->expects($this->any())
  32. ->method('foo')
  33. ->willReturnOnConsecutiveCalls(1, 2, 3);
  34. $this->assertEquals(1, $mock->foo());
  35. $this->assertEquals(2, $mock->foo());
  36. $this->assertEquals(3, $mock->foo());
  37. }
  38. public function testWillReturnByReference()
  39. {
  40. $mock = $this->getMockBuilder(stdClass::class)
  41. ->setMethods(['foo'])
  42. ->getMock();
  43. $mock->expects($this->any())
  44. ->method('foo')
  45. ->willReturnReference($value);
  46. $this->assertSame(null, $mock->foo());
  47. $value = 'foo';
  48. $this->assertSame('foo', $mock->foo());
  49. $value = 'bar';
  50. $this->assertSame('bar', $mock->foo());
  51. }
  52. }