ConsecutiveParametersTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class Framework_MockObject_Matcher_ConsecutiveParametersTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testIntegration()
  5. {
  6. $mock = $this->getMockBuilder(stdClass::class)
  7. ->setMethods(['foo'])
  8. ->getMock();
  9. $mock->expects($this->any())
  10. ->method('foo')
  11. ->withConsecutive(
  12. ['bar'],
  13. [21, 42]
  14. );
  15. $this->assertNull($mock->foo('bar'));
  16. $this->assertNull($mock->foo(21, 42));
  17. }
  18. public function testIntegrationWithLessAssertionsThanMethodCalls()
  19. {
  20. $mock = $this->getMockBuilder(stdClass::class)
  21. ->setMethods(['foo'])
  22. ->getMock();
  23. $mock->expects($this->any())
  24. ->method('foo')
  25. ->withConsecutive(
  26. ['bar']
  27. );
  28. $this->assertNull($mock->foo('bar'));
  29. $this->assertNull($mock->foo(21, 42));
  30. }
  31. public function testIntegrationExpectingException()
  32. {
  33. $mock = $this->getMockBuilder(stdClass::class)
  34. ->setMethods(['foo'])
  35. ->getMock();
  36. $mock->expects($this->any())
  37. ->method('foo')
  38. ->withConsecutive(
  39. ['bar'],
  40. [21, 42]
  41. );
  42. $mock->foo('bar');
  43. $this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
  44. $mock->foo('invalid');
  45. }
  46. }