How to use fooWithArgument method of PhakeTest_MockedClass class

Best Phake code snippet using PhakeTest_MockedClass.fooWithArgument

PhakeTest.php

Source:PhakeTest.php Github

copy

Full Screen

...202 */203 public function testVerifyCallWithEqualsMatcher()204 {205 $mock = Phake::mock('PhakeTest_MockedClass');206 $mock->fooWithArgument('bar');207 Phake::verify($mock)->fooWithArgument(Phake::equalTo('bar'));208 }209 /**210 * Tests passing a basic equals matcher to the verify method will correctly fail when matcher is not satisfied.211 *212 * @expectedException Phake_Exception_VerificationException213 */214 public function testVerifyCallWithEqualsMatcherFails()215 {216 $mock = Phake::mock('PhakeTest_MockedClass');217 $mock->fooWithArgument('test');218 Phake::verify($mock)->fooWithArgument(Phake::equalTo('bar'));219 }220 /**221 * Tests that we can implicitely indicate an equalTo matcher when we pass in a non-matcher value.222 */223 public function testVerifyCallWithDefaultMatcher()224 {225 $mock = Phake::mock('PhakeTest_MockedClass');226 $mock->fooWithArgument('bar');227 Phake::verify($mock)->fooWithArgument('bar');228 }229 /**230 * Tests passing a default matcher type to the verify method will correctly fail when matcher is not satisfied.231 *232 * @expectedException Phake_Exception_VerificationException233 */234 public function testVerifyCallWithDefaultMatcherFails()235 {236 $mock = Phake::mock('PhakeTest_MockedClass');237 $mock->fooWithArgument('test');238 Phake::verify($mock)->fooWithArgument('bar');239 }240 /**241 * Tests passing in a PHPUnit constraint to the verifier242 */243 public function testVerifyCallWithPHPUnitMatcher()244 {245 $mock = Phake::mock('PhakeTest_MockedClass');246 $mock->fooWithArgument('bar');247 Phake::verify($mock)->fooWithArgument($this->equalTo('bar'));248 }249 /**250 * Tests passing in a PHPUnit constraint to the verifier fails when constraint not met.251 *252 * @expectedException Phake_Exception_VerificationException253 */254 public function testVerifyCallWithPHPUnitMatcherFails()255 {256 $mock = Phake::mock('PhakeTest_MockedClass');257 $mock->fooWithArgument('test');258 Phake::verify($mock)->fooWithArgument($this->equalTo('bar'));259 }260 /**261 * Tests passing in a Hamcrest matcher to the verifier262 */263 public function testVerifyCallWithHamcrestMatcher()264 {265 $mock = Phake::mock('PhakeTest_MockedClass');266 $mock->fooWithArgument('bar');267 Phake::verify($mock)->fooWithArgument(equalTo('bar'));268 }269 /**270 * Tests passing in a Hamcrest matcher to the verifier fails when constraint not met.271 *272 * @expectedException Phake_Exception_VerificationException273 */274 public function testVerifyCallWithHamcrestMatcherFails()275 {276 $mock = Phake::mock('PhakeTest_MockedClass');277 $mock->fooWithArgument('test');278 Phake::verify($mock)->fooWithArgument(equalTo('bar'));279 }280 /**281 * Tests using an equalTo argument matcher with a method stub282 */283 public function testStubWithEqualsMatcher()284 {285 $mock = Phake::mock('PhakeTest_MockedClass');286 Phake::when($mock)->fooWithArgument(Phake::equalTo('bar'))->thenReturn(42);287 $this->assertEquals(42, $mock->fooWithArgument('bar'));288 $this->assertNull($mock->fooWithArgument('test'));289 }290 /**291 * Tests using an implicit equalTo argument matcher with a method stub292 */293 public function testStubWithDefaultMatcher()294 {295 $mock = Phake::mock('PhakeTest_MockedClass');296 Phake::when($mock)->fooWithArgument('bar')->thenReturn(42);297 $this->assertEquals(42, $mock->fooWithArgument('bar'));298 $this->assertNull($mock->fooWithArgument('test'));299 }300 /**301 * Tests using a phpunit constraint with a method stub302 */303 public function testStubWithPHPUnitConstraint()304 {305 $mock = Phake::mock('PhakeTest_MockedClass');306 Phake::when($mock)->fooWithArgument($this->equalTo('bar'))->thenReturn(42);307 $this->assertEquals(42, $mock->fooWithArgument('bar'));308 $this->assertNull($mock->fooWithArgument('test'));309 }310 /**311 * Tests using a hamcrest matcher with a method stub312 */313 public function testStubWithHamcrestConstraint()314 {315 $mock = Phake::mock('PhakeTest_MockedClass');316 Phake::when($mock)->fooWithArgument(equalTo('bar'))->thenReturn(42);317 $this->assertEquals(42, $mock->fooWithArgument('bar'));318 $this->assertNull($mock->fooWithArgument('test'));319 }320 /**321 * Tests that resetting a mock clears the call recorder322 */323 public function testResettingCallRecorder()324 {325 $mock = Phake::mock('PhakeTest_MockedClass');326 $mock->foo();327 Phake::verify($mock)->foo();328 Phake::reset($mock);329 $this->setExpectedException('Phake_Exception_VerificationException');330 Phake::verify($mock)->foo();331 }332 /**333 * Tests that resetting a mock clears the stubber334 */335 public function testResettingStubMapper()336 {337 $mock = Phake::mock('PhakeTest_MockedClass');338 Phake::when($mock)->foo()->thenReturn(42);339 $this->assertEquals(42, $mock->foo());340 Phake::reset($mock);341 $this->assertNull($mock->foo());342 }343 /**344 * Tests that resetting a mock clears the call recorder345 */346 public function testResettingStaticCallRecorder()347 {348 $mock = Phake::mock('PhakeTest_StaticInterface');349 $mock::staticMethod();350 Phake::verifyStatic($mock)->staticMethod();351 Phake::resetStatic($mock);352 $this->setExpectedException('Phake_Exception_VerificationException');353 Phake::verifyStatic($mock)->staticMethod();354 }355 public function testMockingPhar()356 {357 if (!class_exists('Phar'))358 {359 $this->markTestSkipped('Phar class does not exist');360 }361 $phar = Phake::mock('Phar');362 $this->assertInstanceOf('Phar', $phar);363 }364 /**365 * Tests that resetting a mock clears the stubber366 */367 public function testResettingStaticStubMapper()368 {369 $mock = Phake::mock('PhakeTest_StaticInterface');370 Phake::whenStatic($mock)->staticMethod()->thenReturn(42);371 $this->assertEquals(42, $mock::staticMethod());372 Phake::resetStatic($mock);373 $this->assertNull($mock::staticMethod());374 }375 /**376 * Tests setting a default answer for stubs377 */378 public function testDefaultAnswerForStubs()379 {380 $mock = Phake::mock('PhakeTest_MockedClass', Phake::ifUnstubbed()->thenReturn(42));381 $this->assertEquals(42, $mock->foo());382 }383 /**384 * Tests setting a default answer for stubs385 */386 public function testDefaultAnswerForInterfaces()387 {388 $mock = Phake::mock('PhakeTest_MockedInterface', Phake::ifUnstubbed()->thenReturn(42));389 $this->assertEquals(42, $mock->foo());390 }391 /**392 * Tests setting a default answer for only the __call magic method393 */394 public function testDefaultAnswerForStubsOfCall()395 {396 $mock = Phake::mock('PhakeTest_MagicClass');397 Phake::whenCallMethodWith(Phake::anyParameters())->isCalledOn($mock)->thenReturn(42);398 $this->assertEquals(42, $mock->foo());399 }400 /**401 * Tests setting a default answer for only the __call magic method402 */403 public function testDefaultAnswerForStaticStubsOfCall()404 {405 $mock = Phake::mock('PhakeTest_MagicClass');406 Phake::whenStaticCallMethodWith(Phake::anyParameters())->isCalledOn($mock)->thenReturn(42);407 $this->assertEquals(42, $mock::foo());408 }409 /**410 * Tests validating calls to __call411 */412 public function testVerificationOfCall()413 {414 $mock = Phake::mock('PhakeTest_MagicClass');415 $mock->foo();416 Phake::verifyCallMethodWith(Phake::anyParameters())->isCalledOn($mock);417 }418 /**419 * Tests validating calls to __callStatic420 */421 public function testVerificationOfStaticCall()422 {423 $mock = Phake::mock('PhakeTest_MagicClass');424 $mock::foo();425 Phake::verifyStaticCallMethodWith(Phake::anyParameters())->isCalledOn($mock);426 }427 /**428 * Tests stubbing a mocked method to call its parent.429 */430 public function testStubbingMethodToCallParent()431 {432 $mock = Phake::mock('PhakeTest_MockedClass');433 Phake::when($mock)->fooWithReturnValue()->thenCallParent();434 $this->assertEquals('blah', $mock->fooWithReturnValue());435 }436 /**437 * Tests calling through a chain of calls438 */439 public function testStubbingChainedMethodsToCallParent()440 {441 $mock = Phake::mock('PhakeTest_MockedClass', Phake::ifUnstubbed()->thenCallParent());442 $this->assertEquals('test', $mock->callInnerFunc());443 }444 /**445 * Tests partial mock functionality to make sure original method is called.446 */447 public function testPartialMockCallsOriginal()448 {449 $pmock = Phake::partialMock('PhakeTest_MockedClass');450 $this->assertEquals('blah', $pmock->fooWithReturnValue());451 }452 /**453 * Tests partial mock calls are recorded454 */455 public function testPartialMockRecordsCall()456 {457 $pmock = Phake::partialMock('PhakeTest_MockedClass');458 $pmock->foo();459 Phake::verify($pmock)->foo();460 }461 /**462 * Tests that partial mock calls can chain properly463 */464 public function testPartialMockInternalMethodCalls()465 {466 $pmock = Phake::partialMock('PhakeTest_MockedClass');467 Phake::when($pmock)->innerFunc()->thenReturn('blah');468 $this->assertEquals('blah', $pmock->chainedCall());469 }470 /**471 * Tests that partial mock can overwrite methods472 * so that they don't do anything when they get called473 */474 public function testPartialMockCanReturnNothing()475 {476 $pmock = Phake::partialMock('PhakeTest_MockedClass');477 Phake::when($pmock)->innerFunc()->thenDoNothing();478 $this->assertNull($pmock->chainedCall());479 }480 /**481 * Tests that partial mocks listen to the constructor args given482 */483 public function testPartialMockCallsConstructor()484 {485 $pmock = Phake::partialMock('PhakeTest_MockedConstructedClass', 'val1', 'val2', 'val3');486 $this->assertEquals('val1', $pmock->getProp1());487 $this->assertEquals('val2', $pmock->getProp2());488 $this->assertEquals('val3', $pmock->getProp3());489 }490 /**491 * Tests that partial mocks with constructors higher in the chain have their constructors called492 */493 public function testPartialMockCallsParentConstructor()494 {495 $pmock = Phake::partialMock('PhakeTest_ExtendedMockedConstructedClass', 'val1', 'val2', 'val3');496 $this->assertEquals('val1', $pmock->getProp1());497 $this->assertEquals('val2', $pmock->getProp2());498 $this->assertEquals('val3', $pmock->getProp3());499 }500 /**501 * Tests that the deprecated partMock works502 */503 public function testPartMock()504 {505 $pmock = Phake::partMock('PhakeTest_ExtendedMockedConstructedClass', 'val1', 'val2', 'val3');506 $this->assertEquals('val1', $pmock->getProp1());507 $this->assertEquals('val2', $pmock->getProp2());508 $this->assertEquals('val3', $pmock->getProp3());509 }510 /**511 * Tests mocking of an interface512 */513 public function testMockingInterface()514 {515 $mock = Phake::mock('PhakeTest_MockedInterface');516 Phake::when($mock)->foo()->thenReturn('bar');517 $this->assertEquals('bar', $mock->foo());518 }519 /**520 * Tests mocking of an abstract class521 */522 public function testMockingAbstract()523 {524 $mock = Phake::mock('PhakeTest_AbstractClass');525 Phake::when($mock)->foo()->thenReturn('bar');526 $this->assertEquals('bar', $mock->foo());527 }528 /**529 * Tests verifying the call order of particular methods within an object530 */531 public function testCallOrderInObject()532 {533 $mock = Phake::mock('PhakeTest_MockedClass');534 $mock->foo();535 $mock->fooWithReturnValue();536 $mock->callInnerFunc();537 Phake::inOrder(538 Phake::verify($mock)->foo(),539 Phake::verify($mock)->fooWithReturnValue(),540 Phake::verify($mock)->callInnerFunc()541 );542 }543 /**544 * Tests verifying the call order of particular methods within an object545 */546 public function testCallOrderInObjectFails()547 {548 $mock = Phake::mock('PhakeTest_MockedClass');549 $mock->foo();550 $mock->callInnerFunc();551 $mock->fooWithReturnValue();552 $this->setExpectedException('Phake_Exception_VerificationException');553 Phake::inOrder(554 Phake::verify($mock)->foo(),555 Phake::verify($mock)->fooWithReturnValue(),556 Phake::verify($mock)->callInnerFunc()557 );558 }559 /**560 * Tests verifying the call order of particular methods across objects561 */562 public function testCallOrderAccrossObjects()563 {564 $mock1 = Phake::mock('PhakeTest_MockedClass');565 $mock2 = Phake::mock('PhakeTest_MockedClass');566 $mock1->foo();567 $mock2->foo();568 $mock1->fooWithReturnValue();569 $mock2->fooWithReturnValue();570 $mock1->callInnerFunc();571 $mock2->callInnerFunc();572 Phake::inOrder(573 Phake::verify($mock1)->foo(),574 Phake::verify($mock2)->foo(),575 Phake::verify($mock2)->fooWithReturnValue(),576 Phake::verify($mock1)->callInnerFunc()577 );578 }579 /**580 * Tests verifying the call order of particular methods across objects581 */582 public function testCallOrderAccrossObjectsFail()583 {584 $mock1 = Phake::mock('PhakeTest_MockedClass');585 $mock2 = Phake::mock('PhakeTest_MockedClass');586 $mock1->foo();587 $mock2->foo();588 $mock1->fooWithReturnValue();589 $mock1->callInnerFunc();590 $mock2->fooWithReturnValue();591 $mock2->callInnerFunc();592 $this->setExpectedException('Phake_Exception_VerificationException');593 Phake::inOrder(594 Phake::verify($mock2)->fooWithReturnValue(),595 Phake::verify($mock1)->callInnerFunc()596 );597 }598 public function testCallOrderWithStatics()599 {600 $mock1 = Phake::mock('PhakeTest_MockedClass');601 $mock2 = Phake::mock('PhakeTest_StaticInterface');602 $mock1->foo();603 $mock2::staticMethod();604 $mock1->fooWithReturnValue();605 $mock1->callInnerFunc();606 Phake::inOrder(607 Phake::verify($mock1)->foo(),608 Phake::verifyStatic($mock2)->staticMethod(),609 Phake::verify($mock1)->callInnerFunc()610 );611 }612 /**613 * Tests freezing mocks614 */615 public function testMockFreezing()616 {617 $mock = Phake::mock('PhakeTest_MockedClass');618 $mock->foo();619 Phake::verifyNoFurtherInteraction($mock);620 $this->setExpectedException('Phake_Exception_VerificationException');621 $mock->foo();622 }623 public function testStaticMockFreezing()624 {625 $mock = Phake::mock('PhakeTest_StaticInterface');626 $mock::staticMethod();627 Phake::verifyNoFurtherInteraction($mock);628 $this->setExpectedException('Phake_Exception_VerificationException');629 $mock::staticMethod();630 }631 /**632 * Tests freezing mocks633 */634 public function testMockFreezingWithMultipleMocks()635 {636 $mock1 = Phake::mock('PhakeTest_MockedClass');637 $mock2 = Phake::mock('PhakeTest_MockedClass');638 $mock1->foo();639 $mock2->foo();640 Phake::verifyNoFurtherInteraction($mock1, $mock2);641 $this->setExpectedException('Phake_Exception_VerificationException');642 $mock2->foo();643 }644 /**645 * Tests verifying that no interaction occured646 */647 public function testVerifyingZeroInteraction()648 {649 $mock = Phake::mock('PhakeTest_MockedClass');650 Phake::verifyNoInteraction($mock);651 $mock->foo();652 $this->setExpectedException('Phake_Exception_VerificationException');653 Phake::verifyNoInteraction($mock);654 }655 /**656 * Tests verifying that no interaction occured657 */658 public function testVerifyingZeroInteractionIncludesStatic()659 {660 $mock = Phake::mock('PhakeTest_StaticInterface');661 Phake::verifyNoInteraction($mock);662 $mock::staticMethod();663 $this->setExpectedException('Phake_Exception_VerificationException');664 Phake::verifyNoInteraction($mock);665 }666 /**667 * Tests verifying that no interaction occured668 */669 public function testVerifyingZeroInteractionWithMultipleArgs()670 {671 $mock1 = Phake::mock('PhakeTest_MockedClass');672 $mock2 = Phake::mock('PhakeTest_MockedClass');673 Phake::verifyNoInteraction($mock1, $mock2);674 $mock2->foo();675 $this->setExpectedException('Phake_Exception_VerificationException');676 Phake::verifyNoInteraction($mock1, $mock2);677 }678 /**679 * Tests argument capturing680 */681 public function testArugmentCapturing()682 {683 $mock = Phake::mock('PhakeTest_MockedClass');684 $mock->fooWithArgument('TEST');685 Phake::verify($mock)->fooWithArgument(Phake::capture($toArgument));686 $this->assertSame('TEST', $toArgument);687 }688 /**689 * Tests conditional argument capturing690 */691 public function testConditionalArugmentCapturing()692 {693 $mock = Phake::mock('PhakeTest_MockedClass');694 $mock->fooWithArgument('FOO');695 $mock->fooWithArgument('BAR');696 Phake::verify($mock)->fooWithArgument(Phake::capture($toArgument)->when('BAR'));697 $this->assertSame('BAR', $toArgument);698 }699 /**700 * Make sure arguments aren't captured if the conditions don't match701 */702 public function testConditionalArugmentCapturingFails()703 {704 $mock = Phake::mock('PhakeTest_MockedClass');705 $mock->fooWithArgument('FOO');706 $this->setExpectedException('Phake_Exception_VerificationException');707 Phake::verify($mock)->fooWithArgument(Phake::capture($toArgument)->when('BAR'));708 }709 /**710 * Make sure arguments are captured with no issues711 */712 public function testArgumentCapturingWorksOnObjects()713 {714 $mock = Phake::mock('PhakeTest_MockedClass');715 $obj = new stdClass;716 $mock->fooWithArgument($obj);717 Phake::verify($mock)->fooWithArgument(Phake::capture($toArgument));718 $this->assertSame($obj, $toArgument);719 }720 /**721 * Make sure arguments are captured with no issues722 */723 public function testArgumentCapturingWorksOnStubbing()724 {725 $mock = Phake::mock('PhakeTest_MockedClass');726 $obj = new stdClass;727 Phake::when($mock)->fooWithArgument(Phake::capture($toArgument))->thenReturn(true);728 $mock->fooWithArgument($obj);729 $this->assertSame($obj, $toArgument);730 }731 public function testArgumentCapturingAllValls()732 {733 $mock = Phake::mock('PhakeTest_MockedClass');734 $obj1 = new stdClass;735 $obj2 = new stdClass;736 $obj3 = new stdClass;737 $mock->fooWithArgument($obj1);738 $mock->fooWithArgument($obj2);739 $mock->fooWithArgument($obj3);740 Phake::verify($mock, Phake::atLeast(1))->fooWithArgument(Phake::captureAll($toArgument));741 $this->assertSame(array($obj1, $obj2, $obj3), $toArgument);742 }743 /**744 * Make sure stub return value capturing returns the parent value745 */746 public function testCaptureAnswerReturnsParentValue()747 {748 $mock = Phake::mock('PhakeTest_MockedClass');749 Phake::when($mock)->fooWithReturnValue()->captureReturnTo($return);750 $this->assertEquals('blah', $mock->fooWithReturnValue());751 }752 /**753 * Make sure stub return value capturing returns the parent value754 */755 public function testCaptureAnswerCapturesParentValue()756 {757 $mock = Phake::mock('PhakeTest_MockedClass');758 Phake::when($mock)->fooWithReturnValue()->captureReturnTo($return);759 $mock->fooWithReturnValue();760 $this->assertEquals('blah', $return);761 }762 /**763 * Tests setting reference parameters764 */765 public function testSettingReferenceParameters()766 {767 $mock = Phake::mock('PhakeTest_MockedClass');768 Phake::when($mock)->fooWithRefParm('test', Phake::setReference(42))->thenReturn(null);769 $mock->fooWithRefParm('test', $value);770 $this->assertSame(42, $value);771 }772 /**773 * Tests conditional reference parameter setting774 */775 public function testConditionalReferenceParameterSetting()776 {777 $mock = Phake::mock('PhakeTest_MockedClass');778 Phake::when($mock)->fooWithRefParm('test', Phake::setReference(42)->when(24))->thenReturn(null);779 $value = 24;780 $mock->fooWithRefParm('test', $value);781 $this->assertSame(42, $value);782 }783 /**784 * Make sure reference parameters aren't set if the conditions don't match785 */786 public function testConditionalReferenceParameterSettingFails()787 {788 $mock = Phake::mock('PhakeTest_MockedClass');789 Phake::when($mock)->fooWithRefParm('test', Phake::setReference(42)->when(24))->thenReturn(null);790 $value = 25;791 $mock->fooWithRefParm('test', $value);792 $this->assertSame(25, $value);793 }794 /**795 * Make sure paremeters are set to objects with no issues796 */797 public function testReferenceParameterSettingWorksOnObjects()798 {799 $mock = Phake::mock('PhakeTest_MockedClass');800 $obj = new stdClass;801 Phake::when($mock)->fooWithRefParm('test', Phake::setReference($obj))->thenReturn(null);802 $value = 25;803 $mock->fooWithRefParm('test', $value);804 $this->assertSame($obj, $value);805 }806 /**807 * Tests times matches exactly808 */809 public function testVerifyTimesExact()810 {811 $mock = Phake::mock('PhakeTest_MockedClass');812 $mock->foo();813 $mock->foo();814 Phake::verify($mock, Phake::times(2))->foo();815 }816 /**817 * Tests times doesn't match818 * @expectedException Phake_Exception_VerificationException819 */820 public function testVerifyTimesMismatch()821 {822 $mock = Phake::mock('PhakeTest_MockedClass');823 $mock->foo();824 $mock->foo();825 Phake::verify($mock)->foo();826 }827 /**828 * Tests at least matches with exact calls829 */830 public function testVerifyAtLeastExact()831 {832 $mock = Phake::mock('PhakeTest_MockedClass');833 $mock->foo();834 Phake::verify($mock, Phake::atLeast(1))->foo();835 }836 /**837 * Tests at least matches with greater calls838 */839 public function testVerifyAtLeastGreater()840 {841 $mock = Phake::mock('PhakeTest_MockedClass');842 $mock->foo();843 $mock->foo();844 Phake::verify($mock, Phake::atLeast(1))->foo();845 }846 /**847 * Tests that at least doesn't match848 * @expectedException Phake_Exception_VerificationException849 */850 public function testVerifyAtLeastMismatch()851 {852 $mock = Phake::mock('PhakeTest_MockedClass');853 Phake::verify($mock, Phake::atLeast(1))->foo();854 }855 /**856 * Tests that never matches857 */858 public function testNeverMatches()859 {860 $mock = Phake::mock('PhakeTest_MockedClass');861 Phake::verify($mock, Phake::never())->foo();862 }863 /**864 * Tests that never catches an invocation865 * @expectedException Phake_Exception_VerificationException866 */867 public function testNeverMismatch()868 {869 $mock = Phake::mock('PhakeTest_MockedClass');870 $mock->foo();871 Phake::verify($mock, Phake::never())->foo();872 }873 /**874 * Tests that atMost passes with exact875 */876 public function testAtMostExactly()877 {878 $mock = Phake::mock('PhakeTest_MockedClass');879 $mock->foo();880 Phake::verify($mock, Phake::atMost(1))->foo();881 }882 /**883 * Tests that atMost passes with under expected calls884 */885 public function testAtMostUnder()886 {887 $mock = Phake::mock('PhakeTest_MockedClass');888 Phake::verify($mock, Phake::atMost(1))->foo();889 }890 /**891 * Tests that atMost fails on over calls892 * @expectedException Phake_Exception_VerificationException893 */894 public function testAtMostOver()895 {896 $mock = Phake::mock('PhakeTest_MockedClass');897 $mock->foo();898 $mock->foo();899 Phake::verify($mock, Phake::atMost(1))->foo();900 }901 /**902 * Tests that the given exception is thrown on thenThrow.903 * @expectedException Phake_Exception_VerificationException904 */905 public function testStubThenThrow()906 {907 $mock = Phake::mock('PhakeTest_MockedClass');908 Phake::when($mock)->foo()->thenThrow(new Phake_Exception_VerificationException());909 $mock->foo();910 }911 /**912 * Tests that Phake::anyParameters() returns an instance of Phake_Matchers_AnyParameters913 */914 public function testAnyParameters()915 {916 $matcher = Phake::anyParameters();917 $this->assertInstanceOf("Phake_Matchers_AnyParameters", $matcher);918 }919 /**920 * Tests that Phake::anyParameters() really matches any invocation921 */922 public function testAnyParametersMatchesEverything()923 {924 $mock = Phake::mock('PhakeTest_MockedClass');925 $mock->fooWithLotsOfParameters(1, 2, 3);926 $mock->fooWithLotsOfParameters(1, 3, 2);927 $mock->fooWithLotsOfParameters(2, 1, 3);928 $mock->fooWithLotsOfParameters(2, 3, 1);929 $mock->fooWithLotsOfParameters(3, 1, 2);930 $mock->fooWithLotsOfParameters(3, 2, 1);931 Phake::verify($mock, Phake::times(6))->fooWithLotsOfParameters(Phake::anyParameters());932 }933 public function testAnyParametersThrowsAnErrorWithTrailingParameters()934 {935 $mock = Phake::mock('PhakeTest_MockedClass');936 $mock->fooWithLotsOfParameters(3, 2, 1);937 $this->setExpectedException('InvalidArgumentException', 'Other matchers cannot be passed with any '938 . 'parameters. It will not work the way you think it works');939 Phake::verify($mock)->fooWithLotsOfParameters(Phake::anyParameters(), 1);940 }941 public function testAnyParametersThrowsAnErrorWithPrecedingParameters()942 {943 $mock = Phake::mock('PhakeTest_MockedClass');944 $mock->fooWithLotsOfParameters(3, 2, 1);945 $this->setExpectedException('InvalidArgumentException', 'Other matchers cannot be passed with any '946 . 'parameters. It will not work the way you think it works');947 Phake::verify($mock)->fooWithLotsOfParameters(3, Phake::anyParameters());948 }949 public function testIgnoreRemainingMatchesEverything()950 {951 $mock = Phake::mock('PhakeTest_MockedClass');952 $mock->fooWithLotsOfParameters(1, 2, 3);953 $mock->fooWithLotsOfParameters(1, 3, 2);954 $mock->fooWithLotsOfParameters(1, 1, 3);955 $mock->fooWithLotsOfParameters(1, 3, 1);956 $mock->fooWithLotsOfParameters(1, 1, 2);957 $mock->fooWithLotsOfParameters(1, 2, 1);958 Phake::verify($mock, Phake::times(6))->fooWithLotsOfParameters(1, Phake::ignoreRemaining());959 }960 public function testIgnoreRemainingThrowsAnErrorWithTrailingParameters()961 {962 $mock = Phake::mock('PhakeTest_MockedClass');963 $mock->fooWithLotsOfParameters(3, 2, 1);964 $this->setExpectedException('InvalidArgumentException', 'Other matchers cannot be checked after you ignore remaining parameters.');965 Phake::verify($mock)->fooWithLotsOfParameters(Phake::ignoreRemaining(), 1);966 }967 /**968 * Tests that when stubs are defined, they're matched in reverse order.969 */970 public function testMatchesInReverseOrder()971 {972 $mock = Phake::mock('PhakeTest_MockedClass');973 Phake::when($mock)->fooWithArgument($this->anything())->thenReturn(false);974 Phake::when($mock)->fooWithArgument('foo')->thenReturn(true);975 $this->assertTrue($mock->fooWithArgument('foo'));976 }977 public function testFailedVerificationWithNoMockInteractions()978 {979 $mock = Phake::mock('PhakeTest_MockedClass');980 $this->setExpectedException(981 'Phake_Exception_VerificationException',982 'Expected PhakeTest_MockedClass->foo() to be called exactly <1> times, actually called <0> times. In fact, there are no interactions with this mock.'983 );984 Phake::verify($mock)->foo();985 }986 public function testFailedVerificationWithNonmatchingMethodCalls()987 {988 $mock = Phake::mock('PhakeTest_MockedClass');989 $mock->foo('test');990 $this->setExpectedException(991 'Phake_Exception_VerificationException',992 'Expected PhakeTest_MockedClass->foo() to be called exactly <1> times, actually called <0> times.' . "\n"993 . "Other Invocations:\n"994 . "===\n"995 . " PhakeTest_MockedClass->foo(<string:test>)\n"996 . " No matchers were given to Phake::when(), but arguments were received by this method.\n"997 . "==="998 );999 Phake::verify($mock)->foo();1000 }1001 public function testStubbingMagicCallMethod()1002 {1003 $mock = Phake::mock('PhakeTest_MagicClass');1004 Phake::when($mock)->magicCall()->thenReturn('magicCalled');1005 $this->assertEquals('magicCalled', $mock->magicCall());1006 }1007 public function testVerifyingMagicCallMethod()1008 {1009 $mock = Phake::mock('PhakeTest_MagicClass');1010 $mock->magicCall();1011 Phake::verify($mock)->magicCall();1012 }1013 public function testStubbingMagicMethodsAlsoResortsToCallIfNoStubsDefined()1014 {1015 $expected = '__call';1016 $mock = Phake::partialMock('PhakeTest_MagicClass');1017 Phake::when($mock)->magicCall()->thenReturn('magicCalled');1018 $this->assertEquals('magicCalled', $mock->magicCall());1019 $this->assertEquals($expected, $mock->unStubbedCall());1020 }1021 public function testStubbingMagicStaticCallMethod()1022 {1023 $mock = Phake::mock('PhakeTest_MagicClass');1024 Phake::whenStatic($mock)->magicCall()->thenReturn('magicCalled');1025 $this->assertEquals('magicCalled', $mock::magicCall());1026 }1027 public function testMockingSoapClient()1028 {1029 // This test requires that E_STRICT be on1030 // It will fail with it on, otherwise it wont' complain1031 $mock = Phake::mock('SoapClient');1032 $this->addToAssertionCount(1);1033 }1034 public function testDefaultClient()1035 {1036 $original_client = Phake::getClient();1037 Phake::setClient(null);1038 $this->assertInstanceOf('Phake_Client_Default', Phake::getClient());1039 Phake::setClient($original_client);1040 }1041 public function testSettingClient()1042 {1043 $original_client = Phake::getClient();1044 $client = Phake::mock('Phake_Client_IClient');1045 Phake::setClient($client);1046 $this->assertSame($client, Phake::getClient());1047 Phake::setClient($original_client);1048 }1049 public function testSettingDefaultClientByString()1050 {1051 $original_client = Phake::getClient();1052 Phake::setClient(Phake::CLIENT_DEFAULT);1053 $this->assertInstanceOf('Phake_Client_Default', Phake::getClient());1054 Phake::setClient($original_client);1055 }1056 public function testSettingPHPUnitClientByString()1057 {1058 $original_client = Phake::getClient();1059 Phake::setClient(Phake::CLIENT_PHPUNIT);1060 $this->assertInstanceOf('Phake_Client_PHPUnit', Phake::getClient());1061 Phake::setClient($original_client);1062 }1063 public function testVerifyNoFurtherInteractionPassesStrict()1064 {1065 Phake::setClient(Phake::CLIENT_PHPUNIT);1066 $mock = Phake::mock('stdClass');1067 $assertionCount = self::getCount();1068 Phake::verifyNoFurtherInteraction($mock);1069 $newAssertionCount = self::getCount();1070 $this->assertGreaterThan($assertionCount, $newAssertionCount);1071 }1072 public function testVerifyNoInteractionPassesStrict()1073 {1074 Phake::setClient(Phake::CLIENT_PHPUNIT);1075 $mock = Phake::mock('stdClass');1076 $assertionCount = self::getCount();1077 Phake::verifyNoInteraction($mock);1078 $newAssertionCount = self::getCount();1079 $this->assertGreaterThan($assertionCount, $newAssertionCount);1080 }1081 public function testMockingStaticClass()1082 {1083 $mock = Phake::mock('PhakeTest_StaticClass');1084 Phake::whenStatic($mock)->staticMethod()->thenReturn('bar');1085 $this->assertEquals('bar', $mock->staticMethod());1086 Phake::verifyStatic($mock)->staticMethod();1087 }1088 public function testMockingStaticInterface()1089 {1090 $mock = Phake::mock('PhakeTest_StaticInterface');1091 $this->assertInstanceOf('Phake_IMock', $mock);1092 }1093 public function testCallingMockStaticMethod()1094 {1095 $mock = Phake::mock('PhakeTest_StaticInterface');1096 $this->assertNull($mock::staticMethod());1097 }1098 public function testVerifyingMockStaticMethod()1099 {1100 $mock = Phake::mock('PhakeTest_StaticInterface');1101 $mock::staticMethod();1102 Phake::verifyStatic($mock)->staticMethod();1103 }1104 public function testMockingAbstractClass()1105 {1106 $mock = Phake::partialMock('PhakeTest_AbstractClass');1107 $this->assertNull($mock->referenceDefault());1108 }1109 public function testStubbingMemcacheSetMethod()1110 {1111 if (!extension_loaded('memcache'))1112 {1113 $this->markTestSkipped('memcache extension not loaded');1114 }1115 $memcache = Phake::mock('Memcache');1116 Phake::when($memcache)->set('key', 'value')->thenReturn(true);1117 $this->assertTrue($memcache->set('key', 'value'));1118 }1119 public function testMockingMethodReturnByReference()1120 {1121 $something = array();1122 $referenceMethodClass = Phake::mock('PhakeTest_ReturnByReferenceMethodClass');1123 Phake::when($referenceMethodClass)->getSomething()->thenReturn($something);1124 $something[] = 'foo';1125 $returnSomething = $referenceMethodClass->getSomething();1126 $this->assertNotContains('foo', $returnSomething);1127 }1128 public function testGetOnMockedClass()1129 {1130 $mock = Phake::mock('PhakeTest_MagicClass');1131 Phake::when($mock)->__get('myId')->thenReturn(500)->thenReturn(501);1132 $this->assertEquals(500, $mock->myId);1133 $this->assertEquals(501, $mock->myId);1134 Phake::verify($mock, Phake::times(2))->__get('myId');1135 }1136 public function testCallOrderInObjectFailsWithPHPUnit()1137 {1138 Phake::setClient(Phake::CLIENT_PHPUNIT);1139 $mock = Phake::mock('PhakeTest_MockedClass');1140 $mock->foo();1141 $mock->callInnerFunc();1142 $mock->fooWithReturnValue();1143 $this->setExpectedException('PHPUnit_Framework_ExpectationFailedException');1144 Phake::inOrder(1145 Phake::verify($mock)->foo(),1146 Phake::verify($mock)->fooWithReturnValue(),1147 Phake::verify($mock)->callInnerFunc()1148 );1149 }1150 public function testGetMockedClassAnythingMatcher()1151 {1152 $mock = Phake::mock('PhakeTest_MagicClass');1153 Phake::when($mock)->__get($this->anything())->thenReturn(500);1154 $this->assertEquals(500, $mock->myId);1155 Phake::verify($mock)->__get($this->anything());1156 }1157 public function testConstructorInterfaceCanBeMocked()1158 {1159 if (defined('HHVM_VERSION')) {1160 $this->markTestSkipped('This test causes a fatal error under HHVM.');1161 }1162 // Generated a fatal error before fixed1163 $this->assertInstanceOf('Phake_IMock', Phake::mock('PhakeTest_ConstructorInterface'));1164 }1165 public function testClassWithWakeupWorks()1166 {1167 $this->assertInstanceOf('Phake_IMock', Phake::mock('PhakeTest_WakeupClass'));1168 }1169 public function testMockPDOStatement()1170 {1171 $this->assertInstanceOf('PDOStatement', Phake::mock('PDOStatement'));1172 }1173 public function testMocksNotEqual()1174 {1175 $chocolateCookie = Phake::mock('PhakeTest_A');1176 $berryCookie = Phake::mock('PhakeTest_A');1177 $this->assertNotEquals($chocolateCookie, $berryCookie);1178 }1179 public function testStaticClassesReset()1180 {1181 $mock1 = Phake::mock('PhakeTest_StaticInterface');1182 $mock1::staticMethod();1183 Phake::verifyStatic($mock1)->staticMethod();1184 Phake::resetStaticInfo();1185 $mock2 = Phake::mock('PhakeTest_StaticInterface');1186 $mock2::staticMethod();1187 Phake::verifyStatic($mock2)->staticMethod();1188 }1189 public function testMockPDO()1190 {1191 $this->assertInstanceOf('PDO', Phake::mock('PDO'));1192 }1193 public function testMockPDOExtendingStatementClass()1194 {1195 $this->assertInstanceOf(1196 'PhakeTest_PDOStatementExtendingClass',1197 Phake::mock('PhakeTest_PDOStatementExtendingClass')1198 );1199 }1200 public function testMockPDOExtendingClass()1201 {1202 $this->assertInstanceOf(1203 'PhakeTest_PDOExtendingClass',1204 Phake::mock('PhakeTest_PDOExtendingClass')1205 );1206 }1207 public function testMockRedis()1208 {1209 if (!extension_loaded('redis'))1210 {1211 $this->markTestSkipped('Cannot run this test without mock redis');1212 }1213 $mock = Phake::mock('Redis');1214 $this->assertInstanceOf('Redis', $mock);1215 }1216 public function testFinallyBlockFiresVerifications()1217 {1218 if (version_compare(PHP_VERSION, '5.5.0', '<')) {1219 $this->markTestSkipped('The finally keyword only exists in php 5.5 and above');1220 }1221 eval('1222 $this->setExpectedException("InvalidArgumentException");1223 $mock = Phake::mock("PhakeTest_MockedClass");1224 try1225 {1226 $mock->foo();1227 throw new InvalidArgumentException();1228 }1229 finally1230 {1231 Phake::verify($mock)->foo();1232 }1233 ');1234 }1235 public function testVerifyNoOtherInteractions()1236 {1237 $mock = Phake::mock('PhakeTest_MockedClass');1238 $mock->foo('a');1239 $mock->foo('b');1240 Phake::verify($mock)->foo('a');1241 $this->setExpectedException('Phake_Exception_VerificationException');1242 Phake::verifyNoOtherInteractions($mock);1243 }1244 public function testVerifyNoOtherInteractionsWorks()1245 {1246 $mock = Phake::mock('PhakeTest_MockedClass');1247 $mock->foo('a');1248 $mock->foo('b');1249 Phake::verify($mock)->foo('a');1250 Phake::verify($mock)->foo('b');1251 Phake::verifyNoOtherInteractions($mock);1252 }1253 public function testCallingProtectedMethods()1254 {1255 $mock = Phake::mock('PhakeTest_MockedClass');1256 Phake::when($mock)->innerFunc()->thenCallParent();1257 $returned = Phake::makeVisible($mock)->innerFunc();1258 Phake::verify($mock)->innerFunc();1259 $this->assertSame('test', $returned);1260 }1261 public function testCallingPrivateMethods()1262 {1263 if (defined('HHVM_VERSION'))1264 {1265 $this->markTestSkipped("Can't call private methods with hhvm");1266 }1267 $mock = Phake::mock('PhakeTest_MockedClass');1268 Phake::when($mock)->privateFunc()->thenCallParent();1269 $returned = Phake::makeVisible($mock)->privateFunc();1270 Phake::verify($mock)->privateFunc();1271 $this->assertSame('blah', $returned);1272 }1273 public function testCallingProtectedStaticMethods()1274 {1275 $mock = Phake::mock('PhakeTest_StaticClass');1276 Phake::whenStatic($mock)->protectedStaticMethod()->thenCallParent();1277 $returned = Phake::makeStaticsVisible($mock)->protectedStaticMethod();1278 Phake::verifyStatic($mock)->protectedStaticMethod();1279 $this->assertSame('foo', $returned);1280 }1281 public function testThenReturnCallback()1282 {1283 $mock = Phake::mock('PhakeTest_MockedClass');1284 Phake::when($mock)->foo->thenReturnCallback(function () {1285 return true;1286 });1287 $this->assertTrue($mock->foo());1288 }1289 public function testMockingMultipleInterfaces()1290 {1291 $mock = Phake::mock(array('PhakeTest_MockedInterface', 'PhakeTest_MockedClass'));1292 $this->assertInstanceOf('PhakeTest_MockedInterface', $mock);1293 $this->assertInstanceOf('PhakeTest_MockedClass', $mock);1294 Phake::when($mock)->foo->thenReturn('bar');1295 Phake::when($mock)->reference->thenReturn('foo');1296 Phake::when($mock)->fooWithArgument->thenReturn(42);1297 $this->assertEquals('bar', $mock->foo());1298 $this->assertEquals('foo', $mock->reference($test));1299 $this->assertEquals(42, $mock->fooWithArgument('blah'));1300 Phake::verify($mock)->foo();1301 Phake::verify($mock)->reference(null);1302 Phake::verify($mock)->fooWithArgument('blah');1303 }1304 public function testReturningSelf()1305 {1306 $mock = Phake::mock('PhakeTest_MockedClass');1307 Phake::when($mock)->foo->thenReturnSelf();1308 $this->assertSame($mock, $mock->foo());1309 }1310 public function testResetStaticPostCall() {1311 $obj = new PhakeTest_StaticMethod;1312 $obj->className = Phake::mock('PhakeTest_ClassWithStaticMethod');1313 Phake::whenStatic($obj->className)->ask()->thenReturn('ASKED');1314 $val = $obj->askSomething();1315 Phake::verifyStatic($obj->className)->ask();1316 $this->assertEquals('ASKED', $val);...

Full Screen

Full Screen

fooWithArgument

Using AI Code Generation

copy

Full Screen

1$mockedClass = Phake::mock('PhakeTest_MockedClass');2Phake::when($mockedClass)->fooWithArgument(Phake::anyParameters())->thenReturn('bar');3$this->assertEquals('bar', $mockedClass->fooWithArgument('foo'));4$this->assertEquals('bar', $mockedClass->fooWithArgument('bar'));5$this->assertEquals('bar', $mockedClass->fooWithArgument('baz'));6$mockedClass = Phake::mock('PhakeTest_MockedClass');7Phake::when($mockedClass)->fooWithArgument(Phake::anyParameters())->thenReturn('bar');8Phake::when($mockedClass)->fooWithArgument('foo')->thenReturn('baz');9$this->assertEquals('baz', $mockedClass->fooWithArgument('foo'));10$this->assertEquals('bar', $mockedClass->fooWithArgument('bar'));11$this->assertEquals('bar', $mockedClass->fooWithArgument('baz'));12$mockedClass = Phake::mock('PhakeTest_MockedClass');13Phake::when($mockedClass)->fooWithArgument(Phake::anyParameters())->thenReturn('bar');14Phake::when($mockedClass)->fooWithArgument('foo')->thenReturn('baz');15Phake::when($mockedClass)->fooWithArgument('bar')->thenReturn('baz');16$this->assertEquals('baz', $mockedClass->fooWithArgument('foo'));17$this->assertEquals('baz', $mockedClass->fooWithArgument('bar'));18$this->assertEquals('bar', $mockedClass->fooWithArgument('baz'));19$mockedClass = Phake::mock('PhakeTest_MockedClass');20Phake::when($mockedClass)->fooWithArgument(Phake::anyParameters())->thenReturn('bar');21Phake::when($mockedClass)->fooWithArgument('foo')->thenReturn('baz');22Phake::when($mockedClass)->fooWithArgument('bar')->thenReturn('baz');23Phake::when($mockedClass)->fooWithArgument('baz')->thenReturn('baz

Full Screen

Full Screen

fooWithArgument

Using AI Code Generation

copy

Full Screen

1$mockedClass->fooWithArgument('argument');2$mockedClass->fooWithArgument('argument');3$mockedClass->fooWithArgument('argument');4$mockedClass->fooWithArgument('argument');5$mockedClass->fooWithArgument('argument');6$mockedClass->fooWithArgument('argument');7$mockedClass->fooWithArgument('argument');8$mockedClass->fooWithArgument('argument');9$mockedClass->fooWithArgument('argument');10$mockedClass->fooWithArgument('argument');11$mockedClass->fooWithArgument('argument');12$mockedClass->fooWithArgument('argument');13$mockedClass->fooWithArgument('argument');14$mockedClass->fooWithArgument('argument');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger fooWithArgument code on LambdaTest Cloud Grid

Execute automation tests with fooWithArgument on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful