ProxyObjectTest.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. class ProxyObjectTest extends TestCase
  12. {
  13. public function testMockedMethodIsProxiedToOriginalMethod()
  14. {
  15. $proxy = $this->getMockBuilder(Bar::class)
  16. ->enableProxyingToOriginalMethods()
  17. ->getMock();
  18. $proxy->expects($this->once())
  19. ->method('doSomethingElse');
  20. $foo = new Foo;
  21. $this->assertEquals('result', $foo->doSomething($proxy));
  22. }
  23. public function testMockedMethodWithReferenceIsProxiedToOriginalMethod()
  24. {
  25. $proxy = $this->getMockBuilder(MethodCallbackByReference::class)
  26. ->enableProxyingToOriginalMethods()
  27. ->getMock();
  28. $a = $b = $c = 0;
  29. $proxy->callback($a, $b, $c);
  30. $this->assertEquals(1, $b);
  31. }
  32. }