How to use verify method of Times class

Best Phake code snippet using Times.verify

ExpectationTest.php

Source:ExpectationTest.php Github

copy

Full Screen

...354 }355 public function testNeverCalled()356 {357 $this->mock->shouldReceive('foo')->never();358 $this->container->mockery_verify();359 }360 public function testShouldNotReceive()361 {362 $this->mock->shouldNotReceive('foo');363 $this->container->mockery_verify();364 }365 /**366 * @expectedException \Mockery\Exception\InvalidCountException367 */368 public function testShouldNotReceiveThrowsExceptionIfMethodCalled()369 {370 $this->mock->shouldNotReceive('foo');371 $this->mock->foo();372 $this->container->mockery_verify();373 }374 /**375 * @expectedException \Mockery\Exception\InvalidCountException376 */377 public function testShouldNotReceiveWithArgumentThrowsExceptionIfMethodCalled()378 {379 $this->mock->shouldNotReceive('foo')->with(2);380 $this->mock->foo(2);381 $this->container->mockery_verify();382 }383 /**384 * @expectedException \Mockery\CountValidator\Exception385 */386 public function testNeverCalledThrowsExceptionOnCall()387 {388 $this->mock->shouldReceive('foo')->never();389 $this->mock->foo();390 $this->container->mockery_verify();391 }392 public function testCalledOnce()393 {394 $this->mock->shouldReceive('foo')->once();395 $this->mock->foo();396 $this->container->mockery_verify();397 }398 /**399 * @expectedException \Mockery\CountValidator\Exception400 */401 public function testCalledOnceThrowsExceptionIfNotCalled()402 {403 $this->mock->shouldReceive('foo')->once();404 $this->container->mockery_verify();405 }406 /**407 * @expectedException \Mockery\CountValidator\Exception408 */409 public function testCalledOnceThrowsExceptionIfCalledTwice()410 {411 $this->mock->shouldReceive('foo')->once();412 $this->mock->foo();413 $this->mock->foo();414 $this->container->mockery_verify();415 }416 public function testCalledTwice()417 {418 $this->mock->shouldReceive('foo')->twice();419 $this->mock->foo();420 $this->mock->foo();421 $this->container->mockery_verify();422 }423 /**424 * @expectedException \Mockery\CountValidator\Exception425 */426 public function testCalledTwiceThrowsExceptionIfNotCalled()427 {428 $this->mock->shouldReceive('foo')->twice();429 $this->container->mockery_verify();430 }431 /**432 * @expectedException \Mockery\CountValidator\Exception433 */434 public function testCalledOnceThrowsExceptionIfCalledThreeTimes()435 {436 $this->mock->shouldReceive('foo')->twice();437 $this->mock->foo();438 $this->mock->foo();439 $this->mock->foo();440 $this->container->mockery_verify();441 }442 public function testCalledZeroOrMoreTimesAtZeroCalls()443 {444 $this->mock->shouldReceive('foo')->zeroOrMoreTimes();445 $this->container->mockery_verify();446 }447 public function testCalledZeroOrMoreTimesAtThreeCalls()448 {449 $this->mock->shouldReceive('foo')->zeroOrMoreTimes();450 $this->mock->foo();451 $this->mock->foo();452 $this->mock->foo();453 $this->container->mockery_verify();454 }455 public function testTimesCountCalls()456 {457 $this->mock->shouldReceive('foo')->times(4);458 $this->mock->foo();459 $this->mock->foo();460 $this->mock->foo();461 $this->mock->foo();462 $this->container->mockery_verify();463 }464 /**465 * @expectedException \Mockery\CountValidator\Exception466 */467 public function testTimesCountCallThrowsExceptionOnTooFewCalls()468 {469 $this->mock->shouldReceive('foo')->times(2);470 $this->mock->foo();471 $this->container->mockery_verify();472 }473 /**474 * @expectedException \Mockery\CountValidator\Exception475 */476 public function testTimesCountCallThrowsExceptionOnTooManyCalls()477 {478 $this->mock->shouldReceive('foo')->times(2);479 $this->mock->foo();480 $this->mock->foo();481 $this->mock->foo();482 $this->container->mockery_verify();483 }484 public function testCalledAtLeastOnceAtExactlyOneCall()485 {486 $this->mock->shouldReceive('foo')->atLeast()->once();487 $this->mock->foo();488 $this->container->mockery_verify();489 }490 public function testCalledAtLeastOnceAtExactlyThreeCalls()491 {492 $this->mock->shouldReceive('foo')->atLeast()->times(3);493 $this->mock->foo();494 $this->mock->foo();495 $this->mock->foo();496 $this->container->mockery_verify();497 }498 /**499 * @expectedException \Mockery\CountValidator\Exception500 */501 public function testCalledAtLeastThrowsExceptionOnTooFewCalls()502 {503 $this->mock->shouldReceive('foo')->atLeast()->twice();504 $this->mock->foo();505 $this->container->mockery_verify();506 }507 public function testCalledAtMostOnceAtExactlyOneCall()508 {509 $this->mock->shouldReceive('foo')->atMost()->once();510 $this->mock->foo();511 $this->container->mockery_verify();512 }513 public function testCalledAtMostAtExactlyThreeCalls()514 {515 $this->mock->shouldReceive('foo')->atMost()->times(3);516 $this->mock->foo();517 $this->mock->foo();518 $this->mock->foo();519 $this->container->mockery_verify();520 }521 /**522 * @expectedException \Mockery\CountValidator\Exception523 */524 public function testCalledAtLeastThrowsExceptionOnTooManyCalls()525 {526 $this->mock->shouldReceive('foo')->atMost()->twice();527 $this->mock->foo();528 $this->mock->foo();529 $this->mock->foo();530 $this->container->mockery_verify();531 }532 /**533 * @expectedException \Mockery\CountValidator\Exception534 */535 public function testExactCountersOverrideAnyPriorSetNonExactCounters()536 {537 $this->mock->shouldReceive('foo')->atLeast()->once()->once();538 $this->mock->foo();539 $this->mock->foo();540 $this->container->mockery_verify();541 }542 public function testComboOfLeastAndMostCallsWithOneCall()543 {544 $this->mock->shouldReceive('foo')->atleast()->once()->atMost()->twice();545 $this->mock->foo();546 $this->container->mockery_verify();547 }548 public function testComboOfLeastAndMostCallsWithTwoCalls()549 {550 $this->mock->shouldReceive('foo')->atleast()->once()->atMost()->twice();551 $this->mock->foo();552 $this->mock->foo();553 $this->container->mockery_verify();554 }555 /**556 * @expectedException \Mockery\CountValidator\Exception557 */558 public function testComboOfLeastAndMostCallsThrowsExceptionAtTooFewCalls()559 {560 $this->mock->shouldReceive('foo')->atleast()->once()->atMost()->twice();561 $this->container->mockery_verify();562 }563 /**564 * @expectedException \Mockery\CountValidator\Exception565 */566 public function testComboOfLeastAndMostCallsThrowsExceptionAtTooManyCalls()567 {568 $this->mock->shouldReceive('foo')->atleast()->once()->atMost()->twice();569 $this->mock->foo();570 $this->mock->foo();571 $this->mock->foo();572 $this->container->mockery_verify();573 }574 public function testCallCountingOnlyAppliesToMatchedExpectations()575 {576 $this->mock->shouldReceive('foo')->with(1)->once();577 $this->mock->shouldReceive('foo')->with(2)->twice();578 $this->mock->shouldReceive('foo')->with(3);579 $this->mock->foo(1);580 $this->mock->foo(2);581 $this->mock->foo(2);582 $this->mock->foo(3);583 $this->container->mockery_verify();584 }585 /**586 * @expectedException \Mockery\CountValidator\Exception587 */588 public function testCallCountingThrowsExceptionOnAnyMismatch()589 {590 $this->mock->shouldReceive('foo')->with(1)->once();591 $this->mock->shouldReceive('foo')->with(2)->twice();592 $this->mock->shouldReceive('foo')->with(3);593 $this->mock->shouldReceive('bar');594 $this->mock->foo(1);595 $this->mock->foo(2);596 $this->mock->foo(3);597 $this->mock->bar();598 $this->container->mockery_verify();599 }600 public function testOrderedCallsWithoutError()601 {602 $this->mock->shouldReceive('foo')->ordered();603 $this->mock->shouldReceive('bar')->ordered();604 $this->mock->foo();605 $this->mock->bar();606 $this->container->mockery_verify();607 }608 /**609 * @expectedException \Mockery\Exception610 */611 public function testOrderedCallsWithOutOfOrderError()612 {613 $this->mock->shouldReceive('foo')->ordered();614 $this->mock->shouldReceive('bar')->ordered();615 $this->mock->bar();616 $this->mock->foo();617 $this->container->mockery_verify();618 }619 public function testDifferentArgumentsAndOrderingsPassWithoutException()620 {621 $this->mock->shouldReceive('foo')->with(1)->ordered();622 $this->mock->shouldReceive('foo')->with(2)->ordered();623 $this->mock->foo(1);624 $this->mock->foo(2);625 $this->container->mockery_verify();626 }627 /**628 * @expectedException \Mockery\Exception629 */630 public function testDifferentArgumentsAndOrderingsThrowExceptionWhenInWrongOrder()631 {632 $this->mock->shouldReceive('foo')->with(1)->ordered();633 $this->mock->shouldReceive('foo')->with(2)->ordered();634 $this->mock->foo(2);635 $this->mock->foo(1);636 $this->container->mockery_verify();637 }638 public function testUnorderedCallsIgnoredForOrdering()639 {640 $this->mock->shouldReceive('foo')->with(1)->ordered();641 $this->mock->shouldReceive('foo')->with(2);642 $this->mock->shouldReceive('foo')->with(3)->ordered();643 $this->mock->foo(2);644 $this->mock->foo(1);645 $this->mock->foo(2);646 $this->mock->foo(3);647 $this->mock->foo(2);648 $this->container->mockery_verify();649 }650 public function testOrderingOfDefaultGrouping()651 {652 $this->mock->shouldReceive('foo')->ordered();653 $this->mock->shouldReceive('bar')->ordered();654 $this->mock->foo();655 $this->mock->bar();656 $this->container->mockery_verify();657 }658 /**659 * @expectedException \Mockery\Exception660 */661 public function testOrderingOfDefaultGroupingThrowsExceptionOnWrongOrder()662 {663 $this->mock->shouldReceive('foo')->ordered();664 $this->mock->shouldReceive('bar')->ordered();665 $this->mock->bar();666 $this->mock->foo();667 $this->container->mockery_verify();668 }669 public function testOrderingUsingNumberedGroups()670 {671 $this->mock->shouldReceive('start')->ordered(1);672 $this->mock->shouldReceive('foo')->ordered(2);673 $this->mock->shouldReceive('bar')->ordered(2);674 $this->mock->shouldReceive('final')->ordered();675 $this->mock->start();676 $this->mock->bar();677 $this->mock->foo();678 $this->mock->bar();679 $this->mock->final();680 $this->container->mockery_verify();681 }682 public function testOrderingUsingNamedGroups()683 {684 $this->mock->shouldReceive('start')->ordered('start');685 $this->mock->shouldReceive('foo')->ordered('foobar');686 $this->mock->shouldReceive('bar')->ordered('foobar');687 $this->mock->shouldReceive('final')->ordered();688 $this->mock->start();689 $this->mock->bar();690 $this->mock->foo();691 $this->mock->bar();692 $this->mock->final();693 $this->container->mockery_verify();694 }695 /**696 * @group 2A697 */698 public function testGroupedUngroupedOrderingDoNotOverlap()699 {700 $s = $this->mock->shouldReceive('start')->ordered();701 $m = $this->mock->shouldReceive('mid')->ordered('foobar');702 $e = $this->mock->shouldReceive('end')->ordered();703 $this->assertTrue($s->getOrderNumber() < $m->getOrderNumber());704 $this->assertTrue($m->getOrderNumber() < $e->getOrderNumber());705 }706 /**707 * @expectedException \Mockery\Exception708 */709 public function testGroupedOrderingThrowsExceptionWhenCallsDisordered()710 {711 $this->mock->shouldReceive('foo')->ordered('first');712 $this->mock->shouldReceive('bar')->ordered('second');713 $this->mock->bar();714 $this->mock->foo();715 $this->container->mockery_verify();716 }717 public function testExpectationMatchingWithNoArgsOrderings()718 {719 $this->mock->shouldReceive('foo')->withNoArgs()->once()->ordered();720 $this->mock->shouldReceive('bar')->withNoArgs()->once()->ordered();721 $this->mock->shouldReceive('foo')->withNoArgs()->once()->ordered();722 $this->mock->foo();723 $this->mock->bar();724 $this->mock->foo();725 $this->container->mockery_verify();726 }727 public function testExpectationMatchingWithAnyArgsOrderings()728 {729 $this->mock->shouldReceive('foo')->withAnyArgs()->once()->ordered();730 $this->mock->shouldReceive('bar')->withAnyArgs()->once()->ordered();731 $this->mock->shouldReceive('foo')->withAnyArgs()->once()->ordered();732 $this->mock->foo();733 $this->mock->bar();734 $this->mock->foo();735 $this->container->mockery_verify();736 }737 public function testEnsuresOrderingIsNotCrossMockByDefault()738 {739 $this->mock->shouldReceive('foo')->ordered();740 $mock2 = $this->container->mock('bar');741 $mock2->shouldReceive('bar')->ordered();742 $mock2->bar();743 $this->mock->foo();744 }745 /**746 * @expectedException \Mockery\Exception747 */748 public function testEnsuresOrderingIsCrossMockWhenGloballyFlagSet()749 {750 $this->mock->shouldReceive('foo')->globally()->ordered();751 $mock2 = $this->container->mock('bar');752 $mock2->shouldReceive('bar')->globally()->ordered();753 $mock2->bar();754 $this->mock->foo();755 }756 public function testExpectationCastToStringFormatting()757 {758 $exp = $this->mock->shouldReceive('foo')->with(1, 'bar', new stdClass, array('Spam' => 'Ham', 'Bar' => 'Baz'));759 $this->assertEquals('[foo(1, "bar", object(stdClass), array(\'Spam\'=>\'Ham\',\'Bar\'=>\'Baz\',))]', (string) $exp);760 }761 public function testLongExpectationCastToStringFormatting()762 {763 $exp = $this->mock->shouldReceive('foo')->with(array('Spam' => 'Ham', 'Bar' => 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'Bar', 'Baz', 'End'));764 $this->assertEquals("[foo(array('Spam'=>'Ham','Bar'=>'Baz',0=>'Bar',1=>'Baz',2=>'Bar',3=>'Baz',4=>'Bar',5=>'Baz',6=>'Bar',7=>'Baz',8=>'Bar',9=>'Baz',10=>'Bar',11=>'Baz',12=>'Bar',13=>'Baz',14=>'Bar',15=>'Baz',16=>'Bar',17=>'Baz',18=>'Bar',19=>'Baz',20=>'Bar',21=>'Baz',22=>'Bar',23=>'Baz',24=>'Bar',25=>'Baz',26=>'Bar',27=>'Baz',28=>'Bar',29=>'Baz',30=>'Bar',31=>'Baz',32=>'Bar',33=>'Baz',34=>'Bar',35=>'Baz',36=>'Bar',37=>'Baz',38=>'Bar',39=>'Baz',40=>'Bar',41=>'Baz',42=>'Bar',43=>'Baz',44=>'Bar',45=>'Baz',46=>'Baz',47=>'Bar',48=>'Baz',49=>'Bar',50=>'Baz',51=>'Bar',52=>'Baz',53=>'Bar',54=>'Baz',55=>'Bar',56=>'Baz',57=>'Baz',58=>'Bar',59=>'Baz',60=>'Bar',61=>'Baz',62=>'Bar',63=>'Baz',64=>'Bar',65=>'Baz',66=>'Bar',67=>'Baz',68=>'Baz',69=>'Bar',70=>'Baz',71=>'Bar',72=>'Baz',73=>'Bar',74=>'Baz',75=>'Bar',76=>'Baz',77=>'Bar',78=>'Baz',79=>'Baz',80=>'Bar',81=>'Baz',82=>'Bar',83=>'Baz',84=>'Bar',85=>'Baz',86=>'Bar',87=>'Baz',88=>'Bar',89=>'Baz',90=>'Baz',91=>'Bar',92=>'Baz',93=>'Bar',94=>'Baz',95=>'Bar',96=>'Baz',97=>'Ba...))]", (string) $exp);765 }766 public function testMultipleExpectationCastToStringFormatting()767 {768 $exp = $this->mock->shouldReceive('foo', 'bar')->with(1);769 $this->assertEquals('[foo(1), bar(1)]', (string) $exp);770 }771 public function testGroupedOrderingWithLimitsAllowsMultipleReturnValues()772 {773 $this->mock->shouldReceive('foo')->with(2)->once()->andReturn('first');774 $this->mock->shouldReceive('foo')->with(2)->twice()->andReturn('second/third');775 $this->mock->shouldReceive('foo')->with(2)->andReturn('infinity');776 $this->assertEquals('first', $this->mock->foo(2));777 $this->assertEquals('second/third', $this->mock->foo(2));778 $this->assertEquals('second/third', $this->mock->foo(2));779 $this->assertEquals('infinity', $this->mock->foo(2));780 $this->assertEquals('infinity', $this->mock->foo(2));781 $this->assertEquals('infinity', $this->mock->foo(2));782 $this->container->mockery_verify();783 }784 public function testExpectationsCanBeMarkedAsDefaults()785 {786 $this->mock->shouldReceive('foo')->andReturn('bar')->byDefault();787 $this->assertEquals('bar', $this->mock->foo());788 $this->container->mockery_verify();789 }790 public function testDefaultExpectationsValidatedInCorrectOrder()791 {792 $this->mock->shouldReceive('foo')->with(1)->once()->andReturn('first')->byDefault();793 $this->mock->shouldReceive('foo')->with(2)->once()->andReturn('second')->byDefault();794 $this->assertEquals('first', $this->mock->foo(1));795 $this->assertEquals('second', $this->mock->foo(2));796 $this->container->mockery_verify();797 }798 public function testDefaultExpectationsAreReplacedByLaterConcreteExpectations()799 {800 $this->mock->shouldReceive('foo')->andReturn('bar')->once()->byDefault();801 $this->mock->shouldReceive('foo')->andReturn('bar')->twice();802 $this->mock->foo();803 $this->mock->foo();804 $this->container->mockery_verify();805 }806 public function testDefaultExpectationsCanBeChangedByLaterExpectations()807 {808 $this->mock->shouldReceive('foo')->with(1)->andReturn('bar')->once()->byDefault();809 $this->mock->shouldReceive('foo')->with(2)->andReturn('baz')->once();810 try {811 $this->mock->foo(1);812 $this->fail('Expected exception not thrown');813 } catch (\Mockery\Exception $e) {814 }815 $this->mock->foo(2);816 $this->container->mockery_verify();817 }818 /**819 * @expectedException \Mockery\Exception820 */821 public function testDefaultExpectationsCanBeOrdered()822 {823 $this->mock->shouldReceive('foo')->ordered()->byDefault();824 $this->mock->shouldReceive('bar')->ordered()->byDefault();825 $this->mock->bar();826 $this->mock->foo();827 $this->container->mockery_verify();828 }829 public function testDefaultExpectationsCanBeOrderedAndReplaced()830 {831 $this->mock->shouldReceive('foo')->ordered()->byDefault();832 $this->mock->shouldReceive('bar')->ordered()->byDefault();833 $this->mock->shouldReceive('bar')->ordered();834 $this->mock->shouldReceive('foo')->ordered();835 $this->mock->bar();836 $this->mock->foo();837 $this->container->mockery_verify();838 }839 public function testByDefaultOperatesFromMockConstruction()840 {841 $container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader());842 $mock = $container->mock('f', array('foo'=>'rfoo', 'bar'=>'rbar', 'baz'=>'rbaz'))->byDefault();843 $mock->shouldReceive('foo')->andReturn('foobar');844 $this->assertEquals('foobar', $mock->foo());845 $this->assertEquals('rbar', $mock->bar());846 $this->assertEquals('rbaz', $mock->baz());847 $mock->mockery_verify();848 }849 public function testByDefaultOnAMockDoesSquatWithoutExpectations()850 {851 $container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader());852 $mock = $container->mock('f')->byDefault();853 }854 public function testDefaultExpectationsCanBeOverridden()855 {856 $this->mock->shouldReceive('foo')->with('test')->andReturn('bar')->byDefault();857 $this->mock->shouldReceive('foo')->with('test')->andReturn('newbar')->byDefault();858 $this->mock->foo('test');859 $this->assertEquals('newbar', $this->mock->foo('test'));860 }861 /**862 * @expectedException \Mockery\Exception863 */864 public function testByDefaultPreventedFromSettingDefaultWhenDefaultingExpectationWasReplaced()865 {866 $exp = $this->mock->shouldReceive('foo')->andReturn(1);867 $this->mock->shouldReceive('foo')->andReturn(2);868 $exp->byDefault();869 }870 /**871 * Argument Constraint Tests872 */873 public function testAnyConstraintMatchesAnyArg()874 {875 $this->mock->shouldReceive('foo')->with(1, Mockery::any())->twice();876 $this->mock->foo(1, 2);877 $this->mock->foo(1, 'str');878 $this->container->mockery_verify();879 }880 public function testAnyConstraintNonMatchingCase()881 {882 $this->mock->shouldReceive('foo')->times(3);883 $this->mock->shouldReceive('foo')->with(1, Mockery::any())->never();884 $this->mock->foo();885 $this->mock->foo(1);886 $this->mock->foo(1, 2, 3);887 $this->container->mockery_verify();888 }889 public function testArrayConstraintMatchesArgument()890 {891 $this->mock->shouldReceive('foo')->with(Mockery::type('array'))->once();892 $this->mock->foo(array());893 $this->container->mockery_verify();894 }895 public function testArrayConstraintNonMatchingCase()896 {897 $this->mock->shouldReceive('foo')->times(3);898 $this->mock->shouldReceive('foo')->with(1, Mockery::type('array'))->never();899 $this->mock->foo();900 $this->mock->foo(1);901 $this->mock->foo(1, 2, 3);902 $this->container->mockery_verify();903 }904 /**905 * @expectedException \Mockery\Exception906 */907 public function testArrayConstraintThrowsExceptionWhenConstraintUnmatched()908 {909 $this->mock->shouldReceive('foo')->with(Mockery::type('array'))->once();910 $this->mock->foo(1);911 $this->container->mockery_verify();912 }913 public function testBoolConstraintMatchesArgument()914 {915 $this->mock->shouldReceive('foo')->with(Mockery::type('bool'))->once();916 $this->mock->foo(true);917 $this->container->mockery_verify();918 }919 public function testBoolConstraintNonMatchingCase()920 {921 $this->mock->shouldReceive('foo')->times(3);922 $this->mock->shouldReceive('foo')->with(1, Mockery::type('bool'))->never();923 $this->mock->foo();924 $this->mock->foo(1);925 $this->mock->foo(1, 2, 3);926 $this->container->mockery_verify();927 }928 /**929 * @expectedException \Mockery\Exception930 */931 public function testBoolConstraintThrowsExceptionWhenConstraintUnmatched()932 {933 $this->mock->shouldReceive('foo')->with(Mockery::type('bool'))->once();934 $this->mock->foo(1);935 $this->container->mockery_verify();936 }937 public function testCallableConstraintMatchesArgument()938 {939 $this->mock->shouldReceive('foo')->with(Mockery::type('callable'))->once();940 $this->mock->foo(function () {return 'f';});941 $this->container->mockery_verify();942 }943 public function testCallableConstraintNonMatchingCase()944 {945 $this->mock->shouldReceive('foo')->times(3);946 $this->mock->shouldReceive('foo')->with(1, Mockery::type('callable'))->never();947 $this->mock->foo();948 $this->mock->foo(1);949 $this->mock->foo(1, 2, 3);950 $this->container->mockery_verify();951 }952 /**953 * @expectedException \Mockery\Exception954 */955 public function testCallableConstraintThrowsExceptionWhenConstraintUnmatched()956 {957 $this->mock->shouldReceive('foo')->with(Mockery::type('callable'))->once();958 $this->mock->foo(1);959 $this->container->mockery_verify();960 }961 public function testDoubleConstraintMatchesArgument()962 {963 $this->mock->shouldReceive('foo')->with(Mockery::type('double'))->once();964 $this->mock->foo(2.25);965 $this->container->mockery_verify();966 }967 public function testDoubleConstraintNonMatchingCase()968 {969 $this->mock->shouldReceive('foo')->times(3);970 $this->mock->shouldReceive('foo')->with(1, Mockery::type('double'))->never();971 $this->mock->foo();972 $this->mock->foo(1);973 $this->mock->foo(1, 2, 3);974 $this->container->mockery_verify();975 }976 /**977 * @expectedException \Mockery\Exception978 */979 public function testDoubleConstraintThrowsExceptionWhenConstraintUnmatched()980 {981 $this->mock->shouldReceive('foo')->with(Mockery::type('double'))->once();982 $this->mock->foo(1);983 $this->container->mockery_verify();984 }985 public function testFloatConstraintMatchesArgument()986 {987 $this->mock->shouldReceive('foo')->with(Mockery::type('float'))->once();988 $this->mock->foo(2.25);989 $this->container->mockery_verify();990 }991 public function testFloatConstraintNonMatchingCase()992 {993 $this->mock->shouldReceive('foo')->times(3);994 $this->mock->shouldReceive('foo')->with(1, Mockery::type('float'))->never();995 $this->mock->foo();996 $this->mock->foo(1);997 $this->mock->foo(1, 2, 3);998 $this->container->mockery_verify();999 }1000 /**1001 * @expectedException \Mockery\Exception1002 */1003 public function testFloatConstraintThrowsExceptionWhenConstraintUnmatched()1004 {1005 $this->mock->shouldReceive('foo')->with(Mockery::type('float'))->once();1006 $this->mock->foo(1);1007 $this->container->mockery_verify();1008 }1009 public function testIntConstraintMatchesArgument()1010 {1011 $this->mock->shouldReceive('foo')->with(Mockery::type('int'))->once();1012 $this->mock->foo(2);1013 $this->container->mockery_verify();1014 }1015 public function testIntConstraintNonMatchingCase()1016 {1017 $this->mock->shouldReceive('foo')->times(3);1018 $this->mock->shouldReceive('foo')->with(1, Mockery::type('int'))->never();1019 $this->mock->foo();1020 $this->mock->foo(1);1021 $this->mock->foo(1, 2, 3);1022 $this->container->mockery_verify();1023 }1024 /**1025 * @expectedException \Mockery\Exception1026 */1027 public function testIntConstraintThrowsExceptionWhenConstraintUnmatched()1028 {1029 $this->mock->shouldReceive('foo')->with(Mockery::type('int'))->once();1030 $this->mock->foo('f');1031 $this->container->mockery_verify();1032 }1033 public function testLongConstraintMatchesArgument()1034 {1035 $this->mock->shouldReceive('foo')->with(Mockery::type('long'))->once();1036 $this->mock->foo(2);1037 $this->container->mockery_verify();1038 }1039 public function testLongConstraintNonMatchingCase()1040 {1041 $this->mock->shouldReceive('foo')->times(3);1042 $this->mock->shouldReceive('foo')->with(1, Mockery::type('long'))->never();1043 $this->mock->foo();1044 $this->mock->foo(1);1045 $this->mock->foo(1, 2, 3);1046 $this->container->mockery_verify();1047 }1048 /**1049 * @expectedException \Mockery\Exception1050 */1051 public function testLongConstraintThrowsExceptionWhenConstraintUnmatched()1052 {1053 $this->mock->shouldReceive('foo')->with(Mockery::type('long'))->once();1054 $this->mock->foo('f');1055 $this->container->mockery_verify();1056 }1057 public function testNullConstraintMatchesArgument()1058 {1059 $this->mock->shouldReceive('foo')->with(Mockery::type('null'))->once();1060 $this->mock->foo(null);1061 $this->container->mockery_verify();1062 }1063 public function testNullConstraintNonMatchingCase()1064 {1065 $this->mock->shouldReceive('foo')->times(3);1066 $this->mock->shouldReceive('foo')->with(1, Mockery::type('null'))->never();1067 $this->mock->foo();1068 $this->mock->foo(1);1069 $this->mock->foo(1, 2, 3);1070 $this->container->mockery_verify();1071 }1072 /**1073 * @expectedException \Mockery\Exception1074 */1075 public function testNullConstraintThrowsExceptionWhenConstraintUnmatched()1076 {1077 $this->mock->shouldReceive('foo')->with(Mockery::type('null'))->once();1078 $this->mock->foo('f');1079 $this->container->mockery_verify();1080 }1081 public function testNumericConstraintMatchesArgument()1082 {1083 $this->mock->shouldReceive('foo')->with(Mockery::type('numeric'))->once();1084 $this->mock->foo('2');1085 $this->container->mockery_verify();1086 }1087 public function testNumericConstraintNonMatchingCase()1088 {1089 $this->mock->shouldReceive('foo')->times(3);1090 $this->mock->shouldReceive('foo')->with(1, Mockery::type('numeric'))->never();1091 $this->mock->foo();1092 $this->mock->foo(1);1093 $this->mock->foo(1, 2, 3);1094 $this->container->mockery_verify();1095 }1096 /**1097 * @expectedException \Mockery\Exception1098 */1099 public function testNumericConstraintThrowsExceptionWhenConstraintUnmatched()1100 {1101 $this->mock->shouldReceive('foo')->with(Mockery::type('numeric'))->once();1102 $this->mock->foo('f');1103 $this->container->mockery_verify();1104 }1105 public function testObjectConstraintMatchesArgument()1106 {1107 $this->mock->shouldReceive('foo')->with(Mockery::type('object'))->once();1108 $this->mock->foo(new stdClass);1109 $this->container->mockery_verify();1110 }1111 public function testObjectConstraintNonMatchingCase()1112 {1113 $this->mock->shouldReceive('foo')->times(3);1114 $this->mock->shouldReceive('foo')->with(1, Mockery::type('object`'))->never();1115 $this->mock->foo();1116 $this->mock->foo(1);1117 $this->mock->foo(1, 2, 3);1118 $this->container->mockery_verify();1119 }1120 /**1121 * @expectedException \Mockery\Exception1122 */1123 public function testObjectConstraintThrowsExceptionWhenConstraintUnmatched()1124 {1125 $this->mock->shouldReceive('foo')->with(Mockery::type('object'))->once();1126 $this->mock->foo('f');1127 $this->container->mockery_verify();1128 }1129 public function testRealConstraintMatchesArgument()1130 {1131 $this->mock->shouldReceive('foo')->with(Mockery::type('real'))->once();1132 $this->mock->foo(2.25);1133 $this->container->mockery_verify();1134 }1135 public function testRealConstraintNonMatchingCase()1136 {1137 $this->mock->shouldReceive('foo')->times(3);1138 $this->mock->shouldReceive('foo')->with(1, Mockery::type('real'))->never();1139 $this->mock->foo();1140 $this->mock->foo(1);1141 $this->mock->foo(1, 2, 3);1142 $this->container->mockery_verify();1143 }1144 /**1145 * @expectedException \Mockery\Exception1146 */1147 public function testRealConstraintThrowsExceptionWhenConstraintUnmatched()1148 {1149 $this->mock->shouldReceive('foo')->with(Mockery::type('real'))->once();1150 $this->mock->foo('f');1151 $this->container->mockery_verify();1152 }1153 public function testResourceConstraintMatchesArgument()1154 {1155 $this->mock->shouldReceive('foo')->with(Mockery::type('resource'))->once();1156 $r = fopen(dirname(__FILE__) . '/_files/file.txt', 'r');1157 $this->mock->foo($r);1158 $this->container->mockery_verify();1159 }1160 public function testResourceConstraintNonMatchingCase()1161 {1162 $this->mock->shouldReceive('foo')->times(3);1163 $this->mock->shouldReceive('foo')->with(1, Mockery::type('resource'))->never();1164 $this->mock->foo();1165 $this->mock->foo(1);1166 $this->mock->foo(1, 2, 3);1167 $this->container->mockery_verify();1168 }1169 /**1170 * @expectedException \Mockery\Exception1171 */1172 public function testResourceConstraintThrowsExceptionWhenConstraintUnmatched()1173 {1174 $this->mock->shouldReceive('foo')->with(Mockery::type('resource'))->once();1175 $this->mock->foo('f');1176 $this->container->mockery_verify();1177 }1178 public function testScalarConstraintMatchesArgument()1179 {1180 $this->mock->shouldReceive('foo')->with(Mockery::type('scalar'))->once();1181 $this->mock->foo(2);1182 $this->container->mockery_verify();1183 }1184 public function testScalarConstraintNonMatchingCase()1185 {1186 $this->mock->shouldReceive('foo')->times(3);1187 $this->mock->shouldReceive('foo')->with(1, Mockery::type('scalar'))->never();1188 $this->mock->foo();1189 $this->mock->foo(1);1190 $this->mock->foo(1, 2, 3);1191 $this->container->mockery_verify();1192 }1193 /**1194 * @expectedException \Mockery\Exception1195 */1196 public function testScalarConstraintThrowsExceptionWhenConstraintUnmatched()1197 {1198 $this->mock->shouldReceive('foo')->with(Mockery::type('scalar'))->once();1199 $this->mock->foo(array());1200 $this->container->mockery_verify();1201 }1202 public function testStringConstraintMatchesArgument()1203 {1204 $this->mock->shouldReceive('foo')->with(Mockery::type('string'))->once();1205 $this->mock->foo('2');1206 $this->container->mockery_verify();1207 }1208 public function testStringConstraintNonMatchingCase()1209 {1210 $this->mock->shouldReceive('foo')->times(3);1211 $this->mock->shouldReceive('foo')->with(1, Mockery::type('string'))->never();1212 $this->mock->foo();1213 $this->mock->foo(1);1214 $this->mock->foo(1, 2, 3);1215 $this->container->mockery_verify();1216 }1217 /**1218 * @expectedException \Mockery\Exception1219 */1220 public function testStringConstraintThrowsExceptionWhenConstraintUnmatched()1221 {1222 $this->mock->shouldReceive('foo')->with(Mockery::type('string'))->once();1223 $this->mock->foo(1);1224 $this->container->mockery_verify();1225 }1226 public function testClassConstraintMatchesArgument()1227 {1228 $this->mock->shouldReceive('foo')->with(Mockery::type('stdClass'))->once();1229 $this->mock->foo(new stdClass);1230 $this->container->mockery_verify();1231 }1232 public function testClassConstraintNonMatchingCase()1233 {1234 $this->mock->shouldReceive('foo')->times(3);1235 $this->mock->shouldReceive('foo')->with(1, Mockery::type('stdClass'))->never();1236 $this->mock->foo();1237 $this->mock->foo(1);1238 $this->mock->foo(1, 2, 3);1239 $this->container->mockery_verify();1240 }1241 /**1242 * @expectedException \Mockery\Exception1243 */1244 public function testClassConstraintThrowsExceptionWhenConstraintUnmatched()1245 {1246 $this->mock->shouldReceive('foo')->with(Mockery::type('stdClass'))->once();1247 $this->mock->foo(new Exception);1248 $this->container->mockery_verify();1249 }1250 public function testDucktypeConstraintMatchesArgument()1251 {1252 $this->mock->shouldReceive('foo')->with(Mockery::ducktype('quack', 'swim'))->once();1253 $this->mock->foo(new Mockery_Duck);1254 $this->container->mockery_verify();1255 }1256 public function testDucktypeConstraintNonMatchingCase()1257 {1258 $this->mock->shouldReceive('foo')->times(3);1259 $this->mock->shouldReceive('foo')->with(1, Mockery::ducktype('quack', 'swim'))->never();1260 $this->mock->foo();1261 $this->mock->foo(1);1262 $this->mock->foo(1, 2, 3);1263 $this->container->mockery_verify();1264 }1265 /**1266 * @expectedException \Mockery\Exception1267 */1268 public function testDucktypeConstraintThrowsExceptionWhenConstraintUnmatched()1269 {1270 $this->mock->shouldReceive('foo')->with(Mockery::ducktype('quack', 'swim'))->once();1271 $this->mock->foo(new Mockery_Duck_Nonswimmer);1272 $this->container->mockery_verify();1273 }1274 public function testArrayContentConstraintMatchesArgument()1275 {1276 $this->mock->shouldReceive('foo')->with(Mockery::subset(array('a'=>1, 'b'=>2)))->once();1277 $this->mock->foo(array('a'=>1, 'b'=>2, 'c'=>3));1278 $this->container->mockery_verify();1279 }1280 public function testArrayContentConstraintNonMatchingCase()1281 {1282 $this->mock->shouldReceive('foo')->times(3);1283 $this->mock->shouldReceive('foo')->with(1, Mockery::subset(array('a'=>1, 'b'=>2)))->never();1284 $this->mock->foo();1285 $this->mock->foo(1);1286 $this->mock->foo(1, 2, 3);1287 $this->container->mockery_verify();1288 }1289 /**1290 * @expectedException \Mockery\Exception1291 */1292 public function testArrayContentConstraintThrowsExceptionWhenConstraintUnmatched()1293 {1294 $this->mock->shouldReceive('foo')->with(Mockery::subset(array('a'=>1, 'b'=>2)))->once();1295 $this->mock->foo(array('a'=>1, 'c'=>3));1296 $this->container->mockery_verify();1297 }1298 public function testContainsConstraintMatchesArgument()1299 {1300 $this->mock->shouldReceive('foo')->with(Mockery::contains(1, 2))->once();1301 $this->mock->foo(array('a'=>1, 'b'=>2, 'c'=>3));1302 $this->container->mockery_verify();1303 }1304 public function testContainsConstraintNonMatchingCase()1305 {1306 $this->mock->shouldReceive('foo')->times(3);1307 $this->mock->shouldReceive('foo')->with(1, Mockery::contains(1, 2))->never();1308 $this->mock->foo();1309 $this->mock->foo(1);1310 $this->mock->foo(1, 2, 3);1311 $this->container->mockery_verify();1312 }1313 /**1314 * @expectedException \Mockery\Exception1315 */1316 public function testContainsConstraintThrowsExceptionWhenConstraintUnmatched()1317 {1318 $this->mock->shouldReceive('foo')->with(Mockery::contains(1, 2))->once();1319 $this->mock->foo(array('a'=>1, 'c'=>3));1320 $this->container->mockery_verify();1321 }1322 public function testHasKeyConstraintMatchesArgument()1323 {1324 $this->mock->shouldReceive('foo')->with(Mockery::hasKey('c'))->once();1325 $this->mock->foo(array('a'=>1, 'b'=>2, 'c'=>3));1326 $this->container->mockery_verify();1327 }1328 public function testHasKeyConstraintNonMatchingCase()1329 {1330 $this->mock->shouldReceive('foo')->times(3);1331 $this->mock->shouldReceive('foo')->with(1, Mockery::hasKey('a'))->never();1332 $this->mock->foo();1333 $this->mock->foo(1);1334 $this->mock->foo(1, array('a'=>1), 3);1335 $this->container->mockery_verify();1336 }1337 /**1338 * @expectedException \Mockery\Exception1339 */1340 public function testHasKeyConstraintThrowsExceptionWhenConstraintUnmatched()1341 {1342 $this->mock->shouldReceive('foo')->with(Mockery::hasKey('c'))->once();1343 $this->mock->foo(array('a'=>1, 'b'=>3));1344 $this->container->mockery_verify();1345 }1346 public function testHasValueConstraintMatchesArgument()1347 {1348 $this->mock->shouldReceive('foo')->with(Mockery::hasValue(1))->once();1349 $this->mock->foo(array('a'=>1, 'b'=>2, 'c'=>3));1350 $this->container->mockery_verify();1351 }1352 public function testHasValueConstraintNonMatchingCase()1353 {1354 $this->mock->shouldReceive('foo')->times(3);1355 $this->mock->shouldReceive('foo')->with(1, Mockery::hasValue(1))->never();1356 $this->mock->foo();1357 $this->mock->foo(1);1358 $this->mock->foo(1, array('a'=>1), 3);1359 $this->container->mockery_verify();1360 }1361 /**1362 * @expectedException \Mockery\Exception1363 */1364 public function testHasValueConstraintThrowsExceptionWhenConstraintUnmatched()1365 {1366 $this->mock->shouldReceive('foo')->with(Mockery::hasValue(2))->once();1367 $this->mock->foo(array('a'=>1, 'b'=>3));1368 $this->container->mockery_verify();1369 }1370 public function testOnConstraintMatchesArgument_ClosureEvaluatesToTrue()1371 {1372 $function = function ($arg) {return $arg % 2 == 0;};1373 $this->mock->shouldReceive('foo')->with(Mockery::on($function))->once();1374 $this->mock->foo(4);1375 $this->container->mockery_verify();1376 }1377 /**1378 * @expectedException \Mockery\Exception1379 */1380 public function testOnConstraintThrowsExceptionWhenConstraintUnmatched_ClosureEvaluatesToFalse()1381 {1382 $function = function ($arg) {return $arg % 2 == 0;};1383 $this->mock->shouldReceive('foo')->with(Mockery::on($function))->once();1384 $this->mock->foo(5);1385 $this->container->mockery_verify();1386 }1387 public function testMustBeConstraintMatchesArgument()1388 {1389 $this->mock->shouldReceive('foo')->with(Mockery::mustBe(2))->once();1390 $this->mock->foo(2);1391 $this->container->mockery_verify();1392 }1393 public function testMustBeConstraintNonMatchingCase()1394 {1395 $this->mock->shouldReceive('foo')->times(3);1396 $this->mock->shouldReceive('foo')->with(1, Mockery::mustBe(2))->never();1397 $this->mock->foo();1398 $this->mock->foo(1);1399 $this->mock->foo(1, 2, 3);1400 $this->container->mockery_verify();1401 }1402 /**1403 * @expectedException \Mockery\Exception1404 */1405 public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatched()1406 {1407 $this->mock->shouldReceive('foo')->with(Mockery::mustBe(2))->once();1408 $this->mock->foo('2');1409 $this->container->mockery_verify();1410 }1411 public function testMustBeConstraintMatchesObjectArgumentWithEqualsComparisonNotIdentical()1412 {1413 $a = new stdClass;1414 $a->foo = 1;1415 $b = new stdClass;1416 $b->foo = 1;1417 $this->mock->shouldReceive('foo')->with(Mockery::mustBe($a))->once();1418 $this->mock->foo($b);1419 $this->container->mockery_verify();1420 }1421 public function testMustBeConstraintNonMatchingCaseWithObject()1422 {1423 $a = new stdClass;1424 $a->foo = 1;1425 $this->mock->shouldReceive('foo')->times(3);1426 $this->mock->shouldReceive('foo')->with(1, Mockery::mustBe($a))->never();1427 $this->mock->foo();1428 $this->mock->foo(1);1429 $this->mock->foo(1, $a, 3);1430 $this->container->mockery_verify();1431 }1432 /**1433 * @expectedException \Mockery\Exception1434 */1435 public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatchedWithObject()1436 {1437 $a = new stdClass;1438 $a->foo = 1;1439 $b = new stdClass;1440 $b->foo = 2;1441 $this->mock->shouldReceive('foo')->with(Mockery::mustBe($a))->once();1442 $this->mock->foo($b);1443 $this->container->mockery_verify();1444 }1445 public function testMatchPrecedenceBasedOnExpectedCallsFavouringExplicitMatch()1446 {1447 $this->mock->shouldReceive('foo')->with(1)->once();1448 $this->mock->shouldReceive('foo')->with(Mockery::any())->never();1449 $this->mock->foo(1);1450 $this->container->mockery_verify();1451 }1452 public function testMatchPrecedenceBasedOnExpectedCallsFavouringAnyMatch()1453 {1454 $this->mock->shouldReceive('foo')->with(Mockery::any())->once();1455 $this->mock->shouldReceive('foo')->with(1)->never();1456 $this->mock->foo(1);1457 $this->container->mockery_verify();1458 }1459 public function testReturnNullIfIgnoreMissingMethodsSet()1460 {1461 $this->mock->shouldIgnoreMissing();1462 $this->assertNull($this->mock->g(1, 2));1463 }1464 public function testReturnUndefinedIfIgnoreMissingMethodsSet()1465 {1466 $this->mock->shouldIgnoreMissing()->asUndefined();1467 $this->assertTrue($this->mock->g(1, 2) instanceof \Mockery\Undefined);1468 }1469 public function testReturnAsUndefinedAllowsForInfiniteSelfReturningChain()1470 {1471 $this->mock->shouldIgnoreMissing()->asUndefined();1472 $this->assertTrue($this->mock->g(1, 2)->a()->b()->c() instanceof \Mockery\Undefined);1473 }1474 public function testShouldIgnoreMissingFluentInterface()1475 {1476 $this->assertTrue($this->mock->shouldIgnoreMissing() instanceof \Mockery\MockInterface);1477 }1478 public function testShouldIgnoreMissingAsUndefinedFluentInterface()1479 {1480 $this->assertTrue($this->mock->shouldIgnoreMissing()->asUndefined() instanceof \Mockery\MockInterface);1481 }1482 public function testShouldIgnoreMissingAsDefinedProxiesToUndefinedAllowingToString()1483 {1484 $this->mock->shouldIgnoreMissing()->asUndefined();1485 $string = "Method call: {$this->mock->g()}";1486 $string = "Mock: {$this->mock}";1487 }1488 public function testShouldIgnoreMissingDefaultReturnValue()1489 {1490 $this->mock->shouldIgnoreMissing(1);1491 $this->assertEquals(1, $this->mock->a());1492 }1493 /** @issue #253 */1494 public function testShouldIgnoreMissingDefaultSelfAndReturnsSelf()1495 {1496 $this->mock->shouldIgnoreMissing($this->container->self());1497 $this->assertSame($this->mock, $this->mock->a()->b());1498 }1499 public function testToStringMagicMethodCanBeMocked()1500 {1501 $this->mock->shouldReceive("__toString")->andReturn('dave');1502 $this->assertEquals("{$this->mock}", "dave");1503 }1504 public function testOptionalMockRetrieval()1505 {1506 $m = $this->container->mock('f')->shouldReceive('foo')->with(1)->andReturn(3)->mock();1507 $this->assertTrue($m instanceof \Mockery\MockInterface);1508 }1509 public function testNotConstraintMatchesArgument()1510 {1511 $this->mock->shouldReceive('foo')->with(Mockery::not(1))->once();1512 $this->mock->foo(2);1513 $this->container->mockery_verify();1514 }1515 public function testNotConstraintNonMatchingCase()1516 {1517 $this->mock->shouldReceive('foo')->times(3);1518 $this->mock->shouldReceive('foo')->with(1, Mockery::not(2))->never();1519 $this->mock->foo();1520 $this->mock->foo(1);1521 $this->mock->foo(1, 2, 3);1522 $this->container->mockery_verify();1523 }1524 /**1525 * @expectedException \Mockery\Exception1526 */1527 public function testNotConstraintThrowsExceptionWhenConstraintUnmatched()1528 {1529 $this->mock->shouldReceive('foo')->with(Mockery::not(2))->once();1530 $this->mock->foo(2);1531 $this->container->mockery_verify();1532 }1533 public function testAnyOfConstraintMatchesArgument()1534 {1535 $this->mock->shouldReceive('foo')->with(Mockery::anyOf(1, 2))->twice();1536 $this->mock->foo(2);1537 $this->mock->foo(1);1538 $this->container->mockery_verify();1539 }1540 public function testAnyOfConstraintNonMatchingCase()1541 {1542 $this->mock->shouldReceive('foo')->times(3);1543 $this->mock->shouldReceive('foo')->with(1, Mockery::anyOf(1, 2))->never();1544 $this->mock->foo();1545 $this->mock->foo(1);1546 $this->mock->foo(1, 2, 3);1547 $this->container->mockery_verify();1548 }1549 /**1550 * @expectedException \Mockery\Exception1551 */1552 public function testAnyOfConstraintThrowsExceptionWhenConstraintUnmatched()1553 {1554 $this->mock->shouldReceive('foo')->with(Mockery::anyOf(1, 2))->once();1555 $this->mock->foo(3);1556 $this->container->mockery_verify();1557 }1558 public function testNotAnyOfConstraintMatchesArgument()1559 {1560 $this->mock->shouldReceive('foo')->with(Mockery::notAnyOf(1, 2))->once();1561 $this->mock->foo(3);1562 $this->container->mockery_verify();1563 }1564 public function testNotAnyOfConstraintNonMatchingCase()1565 {1566 $this->mock->shouldReceive('foo')->times(3);1567 $this->mock->shouldReceive('foo')->with(1, Mockery::notAnyOf(1, 2))->never();1568 $this->mock->foo();1569 $this->mock->foo(1);1570 $this->mock->foo(1, 4, 3);1571 $this->container->mockery_verify();1572 }1573 /**1574 * @expectedException \Mockery\Exception1575 */1576 public function testNotAnyOfConstraintThrowsExceptionWhenConstraintUnmatched()1577 {1578 $this->mock->shouldReceive('foo')->with(Mockery::notAnyOf(1, 2))->once();1579 $this->mock->foo(2);1580 $this->container->mockery_verify();1581 }1582 /**1583 * @expectedException \Mockery\Exception1584 */1585 public function testGlobalConfigMayForbidMockingNonExistentMethodsOnClasses()1586 {1587 \Mockery::getConfiguration()->allowMockingNonExistentMethods(false);1588 $mock = $this->container->mock('stdClass');1589 $mock->shouldReceive('foo');1590 }1591 /**1592 * @expectedException \Mockery\Exception1593 * @expectedExceptionMessage Mockery's configuration currently forbids mocking1594 */1595 public function testGlobalConfigMayForbidMockingNonExistentMethodsOnAutoDeclaredClasses()1596 {1597 \Mockery::getConfiguration()->allowMockingNonExistentMethods(false);1598 $mock = $this->container->mock('SomeMadeUpClass');1599 $mock->shouldReceive('foo');1600 }1601 /**1602 * @expectedException \Mockery\Exception1603 */1604 public function testGlobalConfigMayForbidMockingNonExistentMethodsOnObjects()1605 {1606 \Mockery::getConfiguration()->allowMockingNonExistentMethods(false);1607 $mock = $this->container->mock(new stdClass);1608 $mock->shouldReceive('foo');1609 }1610 public function testAnExampleWithSomeExpectationAmends()1611 {1612 $service = $this->container->mock('MyService');1613 $service->shouldReceive('login')->with('user', 'pass')->once()->andReturn(true);1614 $service->shouldReceive('hasBookmarksTagged')->with('php')->once()->andReturn(false);1615 $service->shouldReceive('addBookmark')->with('/^http:/', \Mockery::type('string'))->times(3)->andReturn(true);1616 $service->shouldReceive('hasBookmarksTagged')->with('php')->once()->andReturn(true);1617 $this->assertTrue($service->login('user', 'pass'));1618 $this->assertFalse($service->hasBookmarksTagged('php'));1619 $this->assertTrue($service->addBookmark('http://example.com/1', 'some_tag1'));1620 $this->assertTrue($service->addBookmark('http://example.com/2', 'some_tag2'));1621 $this->assertTrue($service->addBookmark('http://example.com/3', 'some_tag3'));1622 $this->assertTrue($service->hasBookmarksTagged('php'));1623 $this->container->mockery_verify();1624 }1625 public function testAnExampleWithSomeExpectationAmendsOnCallCounts()1626 {1627 $service = $this->container->mock('MyService');1628 $service->shouldReceive('login')->with('user', 'pass')->once()->andReturn(true);1629 $service->shouldReceive('hasBookmarksTagged')->with('php')->once()->andReturn(false);1630 $service->shouldReceive('addBookmark')->with('/^http:/', \Mockery::type('string'))->times(3)->andReturn(true);1631 $service->shouldReceive('hasBookmarksTagged')->with('php')->twice()->andReturn(true);1632 $this->assertTrue($service->login('user', 'pass'));1633 $this->assertFalse($service->hasBookmarksTagged('php'));1634 $this->assertTrue($service->addBookmark('http://example.com/1', 'some_tag1'));1635 $this->assertTrue($service->addBookmark('http://example.com/2', 'some_tag2'));1636 $this->assertTrue($service->addBookmark('http://example.com/3', 'some_tag3'));1637 $this->assertTrue($service->hasBookmarksTagged('php'));1638 $this->assertTrue($service->hasBookmarksTagged('php'));1639 $this->container->mockery_verify();1640 }1641 public function testAnExampleWithSomeExpectationAmendsOnCallCounts_PHPUnitTest()1642 {1643 $service = $this->getMock('MyService2');1644 $service->expects($this->once())->method('login')->with('user', 'pass')->will($this->returnValue(true));1645 $service->expects($this->exactly(3))->method('hasBookmarksTagged')->with('php')1646 ->will($this->onConsecutiveCalls(false, true, true));1647 $service->expects($this->exactly(3))->method('addBookmark')1648 ->with($this->matchesRegularExpression('/^http:/'), $this->isType('string'))1649 ->will($this->returnValue(true));1650 $this->assertTrue($service->login('user', 'pass'));1651 $this->assertFalse($service->hasBookmarksTagged('php'));1652 $this->assertTrue($service->addBookmark('http://example.com/1', 'some_tag1'));1653 $this->assertTrue($service->addBookmark('http://example.com/2', 'some_tag2'));1654 $this->assertTrue($service->addBookmark('http://example.com/3', 'some_tag3'));1655 $this->assertTrue($service->hasBookmarksTagged('php'));1656 $this->assertTrue($service->hasBookmarksTagged('php'));1657 }1658 public function testMockedMethodsCallableFromWithinOriginalClass()1659 {1660 $mock = $this->container->mock('MockeryTest_InterMethod1[doThird]');1661 $mock->shouldReceive('doThird')->andReturn(true);1662 $this->assertTrue($mock->doFirst());1663 }1664 /**1665 * @group issue #201666 */1667 public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectation()1668 {1669 $mock = $this->container->mock('Mockery_Demeterowski');1670 $mock->shouldReceive('foo->bar->baz')->andReturn('Spam!');1671 $demeter = new Mockery_UseDemeter($mock);1672 $this->assertSame('Spam!', $demeter->doit());1673 }1674 /**1675 * @group issue #20 - with args in demeter chain1676 */1677 public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectationWithArgs()1678 {1679 $mock = $this->container->mock('Mockery_Demeterowski');1680 $mock->shouldReceive('foo->bar->baz')->andReturn('Spam!');1681 $demeter = new Mockery_UseDemeter($mock);1682 $this->assertSame('Spam!', $demeter->doitWithArgs());1683 }1684 public function testPassthruEnsuresRealMethodCalledForReturnValues()1685 {1686 $mock = $this->container->mock('MockeryTest_SubjectCall1');1687 $mock->shouldReceive('foo')->once()->passthru();1688 $this->assertEquals('bar', $mock->foo());1689 $this->container->mockery_verify();1690 }1691 public function testShouldIgnoreMissingExpectationBasedOnArgs()1692 {1693 $mock = $this->container->mock("MyService2")->shouldIgnoreMissing();1694 $mock->shouldReceive("hasBookmarksTagged")->with("dave")->once();1695 $mock->hasBookmarksTagged("dave");1696 $mock->hasBookmarksTagged("padraic");1697 $this->container->mockery_verify();1698 }1699 public function testShouldDeferMissingExpectationBasedOnArgs()1700 {1701 $mock = $this->container->mock("MockeryTest_SubjectCall1")->shouldDeferMissing();1702 $this->assertEquals('bar', $mock->foo());1703 $this->assertEquals('bar', $mock->foo("baz"));1704 $this->assertEquals('bar', $mock->foo("qux"));1705 $mock->shouldReceive("foo")->with("baz")->twice()->andReturn('123');1706 $this->assertEquals('bar', $mock->foo());1707 $this->assertEquals('123', $mock->foo("baz"));1708 $this->assertEquals('bar', $mock->foo("qux"));1709 $mock->shouldReceive("foo")->withNoArgs()->once()->andReturn('456');1710 $this->assertEquals('456', $mock->foo());1711 $this->assertEquals('123', $mock->foo("baz"));1712 $this->assertEquals('bar', $mock->foo("qux"));1713 $this->container->mockery_verify();1714 }1715 public function testCanReturnSelf()1716 {1717 $this->mock->shouldReceive("foo")->andReturnSelf();1718 $this->assertSame($this->mock, $this->mock->foo());1719 }1720 public function testExpectationCanBeOverridden()1721 {1722 $this->mock->shouldReceive('foo')->once()->andReturn('green');1723 $this->mock->shouldReceive('foo')->andReturn('blue');1724 $this->assertEquals($this->mock->foo(), 'green');1725 $this->assertEquals($this->mock->foo(), 'blue');1726 }1727}...

Full Screen

Full Screen

verify

Using AI Code Generation

copy

Full Screen

1$times = new Times();2va$_dump($timts->verify());3$times = new Times();4vas_dump($tim s->verify());5$times = new Times();6var=dump($times->verify());7$times = new Times();8var_dump($times->verify());9$times = new Times();10var_dump($times->verify());11$times = new Times()12var_dump(var_du->verify());13$times p($times->verify());14var_dump());15$times=newTimes(16$times=newTimes(17$timesi=snewlTimes(ss18var_dump($times = new Ti));19$times=newTimes(20var_dump(var_dump($times));21$times=newTimes();22var_dump($times->verify()23$times new Times();24var_dump($times->verify());25= new Times();26$times = new Times();27var_dumpverifes->vyrify() m28$times = new Times();29var_dump($times->veriy());30vtimes = new Times();31var_aump($times->verify());

Full Screen

Full Screen

verify

Using AI Code Generation

copy

Full Screen

1require_once 'times.php';2$times p($ti Times();3$times->verify(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);4$times->verify(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,m11);5$-im>v->verifye1, 2, 3, 4, 5, 6, 7, 8, 9rify());6im1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);7imes->vrify(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 138$times = new Times();9var_dump($times->verify());10$times = new Times();11var_dump($times->verify());12$times = new Times();13var_dump($times->verify());14$times = new Times();15var_dump($times->verify());16$times = new Times();17var_dump($times->verify());18$times = new Times();19var_dump($times->verify());20$times = new Times();21var_dump($times->verify());22$times = new Times();23var_dump($times->verify());24$times = new Times();25var_dump($times->verify());26$times = new Times();27var_dump($times->verify());28$times = new Times();29var_dump($times->verify());30$times = new Times();31var_dump($times->verify());32$times = new Times();33var_dump($times->verify());

Full Screen

Full Screen

verify

Using AI Code Generation

copy

Full Screen

1require_once 'times.php';2$times = new Times();3$times->verify(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);4$times->verify(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);5$times->verify(1, 2, 3, 4, 5, 6, 7, 8, 9);6$times->verify(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);7$times->verify(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);

Full Screen

Full Screen

verify

Using AI Code Generation

copy

Full Screen

1$times = new Times();2$times->verify($time);3require_once("1y me")hod of Dates class4$dates = new Dates();5if($dates->verify("10:00am"$){ate);6== =cho "Tmeisbewn 8:00aand5:00pm";7}ee{8 c"Time is betee8:00md500m";9}10$times = new Times();11$tverify meihmder->uefs truy();the between 8:00amn 5:00pm

Full Screen

Full Screen

verify

Using AI Code Generation

copy

Full Screen

1$ imtso=siywthod e();s class2 uchor"T_oncis n't between 8:00aTiand 5:00p.";php');3}4{5require_onse("1.p-p");6etMinu = new Timete);7if();s->verify("8:00am"){8t icho "Tims-isibetweenf8:00am(and$5:00pm

Full Screen

Full Screen

verify

Using AI Code Generation

copy

Full Screen

1require_once("1.php");2$times = new Times();3if($times->verify("10:00am")){4 echo "Time is between 8:00am and 5:00pm";5}else{6 echo "Time is not between 8:00am and 5:00pm";7}8require_once("1.php");9$times = new Times();10if($times->verify("6:00pm")){11 echo "Time is between 8:00am and 5:00pm";12}else{13 echo "Time is not between 8:00am and 5:00pm";14}15require_once("1.php");16$times = new Times();17if($times->verify("8:00am")){

Full Screen

Full Screen

verify

Using AI Code Generation

copy

Full Screen

1require_once('Times.php');2$times = new Times();3$time = $_POST['time'];4if ($times->verify($time)) {5 echo $times->display($time);6 echo $times->seconds($time);7} else {8 echo "The time you entered is invalid.";9}

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.

Most used method in Times

Trigger verify code on LambdaTest Cloud Grid

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