ConsecutiveParametersTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of the phpunit-mock-objects package.
  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. use PHPUnit\Framework\TestCase;
  11. use PHPUnit\Framework\ExpectationFailedException;
  12. class ConsecutiveParametersTest extends TestCase
  13. {
  14. public function testIntegration()
  15. {
  16. $mock = $this->getMockBuilder(stdClass::class)
  17. ->setMethods(['foo'])
  18. ->getMock();
  19. $mock->expects($this->any())
  20. ->method('foo')
  21. ->withConsecutive(
  22. ['bar'],
  23. [21, 42]
  24. );
  25. $this->assertNull($mock->foo('bar'));
  26. $this->assertNull($mock->foo(21, 42));
  27. }
  28. public function testIntegrationWithLessAssertionsThanMethodCalls()
  29. {
  30. $mock = $this->getMockBuilder(stdClass::class)
  31. ->setMethods(['foo'])
  32. ->getMock();
  33. $mock->expects($this->any())
  34. ->method('foo')
  35. ->withConsecutive(
  36. ['bar']
  37. );
  38. $this->assertNull($mock->foo('bar'));
  39. $this->assertNull($mock->foo(21, 42));
  40. }
  41. public function testIntegrationExpectingException()
  42. {
  43. $mock = $this->getMockBuilder(stdClass::class)
  44. ->setMethods(['foo'])
  45. ->getMock();
  46. $mock->expects($this->any())
  47. ->method('foo')
  48. ->withConsecutive(
  49. ['bar'],
  50. [21, 42]
  51. );
  52. $mock->foo('bar');
  53. $this->expectException(ExpectationFailedException::class);
  54. $mock->foo('invalid');
  55. }
  56. }