How to use callInnerFunc method of PhakeTest_MockedClass class

Best Phake code snippet using PhakeTest_MockedClass.callInnerFunc

PhakeTest.php

Source:PhakeTest.php Github

copy

Full Screen

...438 */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 }...

Full Screen

Full Screen

callInnerFunc

Using AI Code Generation

copy

Full Screen

1$obj = new PhakeTest_MockedClass();2$obj->callInnerFunc();3$obj = new PhakeTest_MockedClass();4$obj->callInnerFunc();5If you run the test you will see that the call to the innerFunc() method will be executed 3 times, which is not what we want. We want the call to the innerFunc() method to be executed only once. To do this we need to mock the innerFunc() method of the PhakeTest_MockedClass class. The following code shows how we can do it:6Phake::when($obj)->innerFunc()->thenReturn('mocked value');7$obj = new PhakeTest_MockedClass();8$obj->callInnerFunc();9$obj = new PhakeTest_MockedClass();10$obj->callInnerFunc();

Full Screen

Full Screen

callInnerFunc

Using AI Code Generation

copy

Full Screen

1$mockedClass = new PhakeTest_MockedClass();2$mockedClass->callInnerFunc();3$mockedClass = new PhakeTest_MockedClass();4$mockedClass->callInnerFunc();5$mockedClass = new PhakeTest_MockedClass();6$mockedClass->callInnerFunc();7$mockedClass = new PhakeTest_MockedClass();8$mockedClass->callInnerFunc();9$mockedClass = new PhakeTest_MockedClass();10$mockedClass->callInnerFunc();11$mockedClass = new PhakeTest_MockedClass();12$mockedClass->callInnerFunc();13$mockedClass = new PhakeTest_MockedClass();14$mockedClass->callInnerFunc();15$mockedClass = new PhakeTest_MockedClass();16$mockedClass->callInnerFunc();17$mockedClass = new PhakeTest_MockedClass();18$mockedClass->callInnerFunc();19$mockedClass = new PhakeTest_MockedClass();20$mockedClass->callInnerFunc();21$mockedClass = new PhakeTest_MockedClass();22$mockedClass->callInnerFunc();

Full Screen

Full Screen

callInnerFunc

Using AI Code Generation

copy

Full Screen

1$obj = new PhakeTest_MockedClass();2$obj->callInnerFunc();3$obj = new PhakeTest_MockedClass();4$obj->callInnerFunc();5$obj = new PhakeTest_MockedClass();6$obj->callInnerFunc();7$obj = new PhakeTest_MockedClass();8$obj->callInnerFunc();9$obj = new PhakeTest_MockedClass();10$obj->callInnerFunc();11$obj = new PhakeTest_MockedClass();12$obj->callInnerFunc();13$obj = new PhakeTest_MockedClass();14$obj->callInnerFunc();15$obj = new PhakeTest_MockedClass();16$obj->callInnerFunc();17$obj = new PhakeTest_MockedClass();18$obj->callInnerFunc();19$obj = new PhakeTest_MockedClass();20$obj->callInnerFunc();21$obj = new PhakeTest_MockedClass();22$obj->callInnerFunc();23$obj = new PhakeTest_MockedClass();24$obj->callInnerFunc();25$obj = new PhakeTest_MockedClass();26$obj->callInnerFunc();

Full Screen

Full Screen

callInnerFunc

Using AI Code Generation

copy

Full Screen

1$mock->callInnerFunc();2$mock->callInnerFunc();3$mock->callInnerFunc();4$mock->callInnerFunc();5$mock->callInnerFunc();6$mock->callInnerFunc();7$mock->callInnerFunc();8$mock->callInnerFunc();9$mock->callInnerFunc();10$mock->callInnerFunc();11$mock->callInnerFunc();12$mock->callInnerFunc();13$mock->callInnerFunc();14$mock->callInnerFunc();15$mock->callInnerFunc();16$mock->callInnerFunc();

Full Screen

Full Screen

callInnerFunc

Using AI Code Generation

copy

Full Screen

1$mockedObj = new PhakeTest_MockedClass();2$mockedObj->callInnerFunc();3$mockedObj = new PhakeTest_MockedClass();4$mockedObj->callInnerFunc();5$mockedObj = new PhakeTest_MockedClass();6$mockedObj->callInnerFunc();7$mockedObj = new PhakeTest_MockedClass();8$mockedObj->callInnerFunc();9$mockedObj = new PhakeTest_MockedClass();10$mockedObj->callInnerFunc();11$mockedObj = new PhakeTest_MockedClass();12$mockedObj->callInnerFunc();13$mockedObj = new PhakeTest_MockedClass();14$mockedObj->callInnerFunc();15$mockedObj = new PhakeTest_MockedClass();16$mockedObj->callInnerFunc();

Full Screen

Full Screen

callInnerFunc

Using AI Code Generation

copy

Full Screen

1$mockedClass = new PhakeTest_MockedClass();2$mockedClass->callInnerFunc();3echo $mockedClass->innerFunc();4echo $mockedClass->innerFunc();5$mockedClass = new PhakeTest_MockedClass();6$mockedClass->callInnerFunc();7echo $mockedClass->innerFunc();8echo $mockedClass->innerFunc();9Phake::mock('PhakeTest_MockedClass')->innerFunc();10$mockedClass = new PhakeTest_MockedClass();11$mockedClass->callInnerFunc();12echo $mockedClass->innerFunc();13echo $mockedClass->innerFunc();14Phake::mock('PhakeTest_MockedClass')->innerFunc();15$mockedClass = new PhakeTest_MockedClass();16$mockedClass->callInnerFunc();17echo $mockedClass->innerFunc();18echo $mockedClass->innerFunc();

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 callInnerFunc code on LambdaTest Cloud Grid

Execute automation tests with callInnerFunc 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