Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php use Mockery\Adapter\Phpunit\MockeryTestCase; use Mockery\Exception\InvalidCountExce..

Decoded Output download

<?php
 use Mockery\Adapter\Phpunit\MockeryTestCase; use Mockery\Exception\InvalidCountException; use Mockery\MockInterface; use test\Mockery\RegExpCompatability; goto eOzaD; ow8Bm: class MockeryTest_Foo { public function foo() { } } goto RhNI3; cpZLp: class Mockery_UseDemeter { protected $demeter; public function __construct($demeter) { $this->demeter = $demeter; } public function doit() { return $this->demeter->foo()->bar()->baz(); } public function doitWithArgs() { return $this->demeter->foo("foo")->bar("bar")->baz("baz"); } } goto ow8Bm; rnUd9: class Mockery_Duck_Nonswimmer { public function quack() { } } goto OT9oS; BXyUC: interface IWater { public function dry(); } goto GyXmO; FmoT9: class MyService2 { public function login($user, $pass) { } public function hasBookmarksTagged($tag) { } public function addBookmark($uri, $tag) { } } goto tKY2R; GyXmO: class MockeryTest_SubjectCall1 { public function foo() { return "bar"; } } goto a7FzE; OT9oS: class Mockery_Demeterowski { public function foo() { return $this; } public function bar() { return $this; } public function baz() { return "Ham!"; } } goto cpZLp; tKY2R: class Mockery_Duck { public function quack() { } public function swim() { } } goto rnUd9; a7FzE: class MockeryTest_InterMethod1 { public function doFirst() { return $this->doSecond(); } private function doSecond() { return $this->doThird(); } public function doThird() { return false; } } goto FmoT9; eOzaD: class ExpectationTest extends MockeryTestCase { use RegExpCompatability; protected $mock; public function mockeryTestSetUp() { parent::mockeryTestSetUp(); $this->mock = mock("Foo"); } public function mockeryTestTearDown() { parent::mockeryTestTearDown(); \Mockery::getConfiguration()->allowMockingNonExistentMethods(true); } public function testReturnsNullWhenNoArgs() { $this->mock->shouldReceive("foo"); $this->assertNull($this->mock->foo()); } public function testReturnsNullWhenSingleArg() { $this->mock->shouldReceive("foo"); $this->assertNull($this->mock->foo(1)); } public function testReturnsNullWhenManyArgs() { $this->mock->shouldReceive("foo"); $this->assertNull($this->mock->foo("foo", array(), new stdClass())); } public function testReturnsNullIfNullIsReturnValue() { $this->mock->shouldReceive("foo")->andReturn(null); $this->assertNull($this->mock->foo()); } public function testReturnsNullForMockedExistingClassIfAndreturnnullCalled() { $mock = mock("MockeryTest_Foo"); $mock->shouldReceive("foo")->andReturn(null); $this->assertNull($mock->foo()); } public function testReturnsNullForMockedExistingClassIfNullIsReturnValue() { $mock = mock("MockeryTest_Foo"); $mock->shouldReceive("foo")->andReturnNull(); $this->assertNull($mock->foo()); } public function testReturnsSameValueForAllIfNoArgsExpectationAndNoneGiven() { $this->mock->shouldReceive("foo")->andReturn(1); $this->assertEquals(1, $this->mock->foo()); } public function testSetsPublicPropertyWhenRequested() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->andSet("bar", "baz"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); } public function testSetsPublicPropertyWhenRequestedUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->set("bar", "baz"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequested() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->andSet("bar", "baz", "bazz", "bazzz"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazzz", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->set("bar", "baz", "bazz", "bazzz"); $this->assertTrue(empty($this->mock->bar)); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazzz", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValues() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->andSet("bar", "baz", "bazz"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValuesUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->andSet("bar", "baz", "bazz"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValuesWithDirectSet() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->andSet("bar", "baz", "bazz"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); $this->mock->bar = null; $this->mock->foo(); $this->assertNull($this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValuesWithDirectSetUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("foo")->set("bar", "baz", "bazz"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("baz", $this->mock->bar); $this->mock->foo(); $this->assertEquals("bazz", $this->mock->bar); $this->mock->bar = null; $this->mock->foo(); $this->assertNull($this->mock->bar); } public function testSetsPublicPropertiesCorrectlyForDifferentInstancesOfSameClass() { $mockInstanceOne = mock("MockeryTest_Foo"); $mockInstanceTwo = mock("MockeryTest_Foo"); $mockInstanceOne->shouldReceive("foo")->andSet("bar", "baz"); $mockInstanceTwo->shouldReceive("foo")->andSet("bar", "bazz"); $mockInstanceOne->foo(); $mockInstanceTwo->foo(); $this->assertEquals("baz", $mockInstanceOne->bar); $this->assertEquals("bazz", $mockInstanceTwo->bar); } public function testReturnsSameValueForAllIfNoArgsExpectationAndSomeGiven() { $this->mock->shouldReceive("foo")->andReturn(1); $this->assertEquals(1, $this->mock->foo("foo")); } public function testReturnsValueFromSequenceSequentially() { $this->mock->shouldReceive("foo")->andReturn(1, 2, 3); $this->mock->foo("foo"); $this->assertEquals(2, $this->mock->foo("foo")); } public function testReturnsValueFromSequenceSequentiallyAndRepeatedlyReturnsFinalValueOnExtraCalls() { $this->mock->shouldReceive("foo")->andReturn(1, 2, 3); $this->mock->foo("foo"); $this->mock->foo("foo"); $this->assertEquals(3, $this->mock->foo("foo")); $this->assertEquals(3, $this->mock->foo("foo")); } public function testReturnsValueFromSequenceSequentiallyAndRepeatedlyReturnsFinalValueOnExtraCallsWithManyAndReturnCalls() { $this->mock->shouldReceive("foo")->andReturn(1)->andReturn(2, 3); $this->mock->foo("foo"); $this->mock->foo("foo"); $this->assertEquals(3, $this->mock->foo("foo")); $this->assertEquals(3, $this->mock->foo("foo")); } public function testReturnsValueOfClosure() { $this->mock->shouldReceive("foo")->with(5)->andReturnUsing(function ($v) { return $v + 1; }); $this->assertEquals(6, $this->mock->foo(5)); } public function testReturnsValueOfArgument() { $args = array(1, 2, 3, 4, 5); $index = 2; $this->mock->shouldReceive("foo")->withArgs($args)->andReturnArg($index); $this->assertEquals($args[$index], $this->mock->foo(...$args)); } public function testReturnsNullArgument() { $args = array(1, null, 3); $index = 1; $this->mock->shouldReceive("foo")->withArgs($args)->andReturnArg($index); $this->assertNull($this->mock->foo(...$args)); } public function testExceptionOnInvalidArgumentIndexValue() { $this->expectException(\InvalidArgumentException::class); $this->mock->shouldReceive("foo")->andReturnArg("invalid"); } public function testExceptionOnArgumentIndexOutOfRange() { $this->expectException(\OutOfBoundsException::class); $this->mock->shouldReceive("foo")->andReturnArg(2); $this->mock->foo(0, 1); } public function testReturnsUndefined() { $this->mock->shouldReceive("foo")->andReturnUndefined(); $this->assertInstanceOf(\Mockery\Undefined::class, $this->mock->foo()); } public function testReturnsValuesSetAsArray() { $this->mock->shouldReceive("foo")->andReturnValues(array(1, 2, 3)); $this->assertEquals(1, $this->mock->foo()); $this->assertEquals(2, $this->mock->foo()); $this->assertEquals(3, $this->mock->foo()); } public function testAndYield() : void { $this->mock->shouldReceive("foo")->andYield(1, 2, 3); self::assertSame(array(1, 2, 3), iterator_to_array($this->mock->foo())); } public function testThrowsException() { $this->mock->shouldReceive("foo")->andThrow(new OutOfBoundsException()); $this->expectException(OutOfBoundsException::class); $this->mock->foo(); Mockery::close(); } public function and_throws_is_an_alias_to_and_throw() { $this->mock->shouldReceive("foo")->andThrows(new OutOfBoundsException()); $this->expectException(OutOfBoundsException::class); $this->mock->foo(); } public function it_can_throw_a_throwable() { $this->expectException(\Error::class); $this->mock->shouldReceive("foo")->andThrow(new \Error()); $this->mock->foo(); } public function testThrowsExceptionBasedOnArgs() { $this->mock->shouldReceive("foo")->andThrow("OutOfBoundsException"); $this->expectException(OutOfBoundsException::class); $this->mock->foo(); Mockery::close(); } public function testThrowsExceptionBasedOnArgsWithMessage() { $this->mock->shouldReceive("foo")->andThrow("OutOfBoundsException", "foo"); try { $this->mock->foo(); } catch (OutOfBoundsException $e) { $this->assertEquals("foo", $e->getMessage()); } } public function testThrowsExceptionSequentially() { $this->mock->shouldReceive("foo")->andThrow(new Exception())->andThrow(new OutOfBoundsException()); try { $this->mock->foo(); } catch (Exception $e) { } $this->expectException(OutOfBoundsException::class); $this->mock->foo(); Mockery::close(); } public function testAndThrowExceptions() { $this->mock->shouldReceive("foo")->andThrowExceptions(array(new OutOfBoundsException(), new InvalidArgumentException())); try { $this->mock->foo(); throw new Exception("Expected OutOfBoundsException, non thrown"); } catch (\Exception $e) { $this->assertInstanceOf("OutOfBoundsException", $e, "Wrong or no exception thrown: {$e->getMessage()}"); } try { $this->mock->foo(); throw new Exception("Expected InvalidArgumentException, non thrown"); } catch (\Exception $e) { $this->assertInstanceOf("InvalidArgumentException", $e, "Wrong or no exception thrown: {$e->getMessage()}"); } } public function testAndThrowExceptionsCatchNonExceptionArgument() { $this->expectException(\Mockery\Exception::class); $this->expectExceptionMessage("You must pass an array of exception objects to andThrowExceptions"); $this->mock->shouldReceive("foo")->andThrowExceptions(array("NotAnException")); Mockery::close(); } public function testMultipleExpectationsWithReturns() { $this->mock->shouldReceive("foo")->with(1)->andReturn(10); $this->mock->shouldReceive("bar")->with(2)->andReturn(20); $this->assertEquals(10, $this->mock->foo(1)); $this->assertEquals(20, $this->mock->bar(2)); } public function testExpectsNoArguments() { $this->mock->shouldReceive("foo")->withNoArgs()->once(); $this->mock->foo(); } public function testExpectsNoArgumentsThrowsExceptionIfAnyPassed() { $this->mock->shouldReceive("foo")->withNoArgs(); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testExpectsArgumentsArray() { $this->mock->shouldReceive("foo")->withArgs(array(1, 2))->once(); $this->mock->foo(1, 2); } public function testExpectsArgumentsArrayThrowsExceptionIfPassedEmptyArray() { $this->mock->shouldReceive("foo")->withArgs(array()); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1, 2); Mockery::close(); } public function testExpectsArgumentsArrayThrowsExceptionIfNoArgumentsPassed() { $this->mock->shouldReceive("foo")->with(); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testExpectsArgumentsArrayThrowsExceptionIfPassedWrongArguments() { $this->mock->shouldReceive("foo")->withArgs(array(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(3, 4); Mockery::close(); } public function testExpectsStringArgumentExceptionMessageDifferentiatesBetweenNullAndEmptyString() { $this->mock->shouldReceive("foo")->withArgs(array("a string")); $this->expectException(\Mockery\Exception::class); $this->expectExceptionMessageRegEx("/foo\(NULL\)/"); $this->mock->foo(null); Mockery::close(); } public function testExpectsArgumentsArrayThrowsExceptionIfPassedWrongArgumentType() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessageRegEx("/invalid argument (.+), only array and closure are allowed/"); $this->mock->shouldReceive("foo")->withArgs(5); Mockery::close(); } public function testExpectsArgumentsArrayAcceptAClosureThatValidatesPassedArguments() { $closure = function ($odd, $even) { return $odd % 2 != 0 && $even % 2 == 0; }; $this->mock->shouldReceive("foo")->withArgs($closure)->once(); $this->mock->foo(1, 2); } public function testExpectsArgumentsArrayThrowsExceptionWhenClosureEvaluatesToFalse() { $closure = function ($odd, $even) { return $odd % 2 != 0 && $even % 2 == 0; }; $this->mock->shouldReceive("foo")->withArgs($closure); $this->expectException(\Mockery\Exception::class); $this->mock->foo(4, 2); Mockery::close(); } public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalArgumentsAreMissing() { $closure = function ($odd, $even, $sum = null) { $result = $odd % 2 != 0 && $even % 2 == 0; if (!is_null($sum)) { return $result && $odd + $even == $sum; } return $result; }; $this->mock->shouldReceive("foo")->withArgs($closure)->once(); $this->mock->foo(1, 4); } public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalArgumentsMathTheExpectation() { $closure = function ($odd, $even, $sum = null) { $result = $odd % 2 != 0 && $even % 2 == 0; if (!is_null($sum)) { return $result && $odd + $even == $sum; } return $result; }; $this->mock->shouldReceive("foo")->withArgs($closure)->once(); $this->mock->foo(1, 4, 5); } public function testExpectsArgumentsArrayClosureThrowsExceptionIfOptionalArgumentsDontMatchTheExpectation() { $closure = function ($odd, $even, $sum = null) { $result = $odd % 2 != 0 && $even % 2 == 0; if (!is_null($sum)) { return $result && $odd + $even == $sum; } return $result; }; $this->mock->shouldReceive("foo")->withArgs($closure); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1, 4, 2); Mockery::close(); } public function testExpectsSomeOfArgumentsMatchRealArguments() { $this->mock->shouldReceive("foo")->withSomeOfArgs(1, 3, 5)->times(4); $this->mock->foo(1, 2, 3, 4, 5); $this->mock->foo(1, 3, 5, 2, 4); $this->mock->foo(1, "foo", 3, "bar", 5); $this->mock->foo(1, 3, 5); $this->mock->shouldReceive("foo")->withSomeOfArgs("foo")->times(2); $this->mock->foo("foo", "bar"); $this->mock->foo("bar", "foo"); } public function testExpectsSomeOfArgumentsGivenArgsDoNotMatchRealArgsAndThrowNoMatchingException() { $this->mock->shouldReceive("foo")->withSomeOfArgs(1, 3, 5); $this->expectException(\Mockery\Exception\NoMatchingExpectationException::class); $this->mock->foo(1, 2, 4, 5); } public function testExpectsAnyArguments() { $this->mock->shouldReceive("foo")->withAnyArgs()->times(3); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, "k", new stdClass()); } public function testExpectsArgumentMatchingObjectType() { $this->mock->shouldReceive("foo")->with("\stdClass")->once(); $this->mock->foo(new stdClass()); } public function testThrowsExceptionOnNoArgumentMatch() { $this->mock->shouldReceive("foo")->with(1); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); Mockery::close(); } public function testNeverCalled() { $this->mock->shouldReceive("foo")->never(); } public function testShouldNotReceive() { $this->mock->shouldNotReceive("foo"); } public function testShouldNotReceiveThrowsExceptionIfMethodCalled() { $this->mock->shouldNotReceive("foo"); $this->expectException(\Mockery\Exception\InvalidCountException::class); $this->mock->foo(); Mockery::close(); } public function testShouldNotReceiveWithArgumentThrowsExceptionIfMethodCalled() { $this->mock->shouldNotReceive("foo")->with(2); $this->expectException(\Mockery\Exception\InvalidCountException::class); $this->mock->foo(2); Mockery::close(); } public function testNeverCalledThrowsExceptionOnCall() { $this->mock->shouldReceive("foo")->never(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledOnce() { $this->mock->shouldReceive("foo")->once(); $this->mock->foo(); } public function testCalledOnceThrowsExceptionIfNotCalled() { $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->shouldReceive("foo")->once(); Mockery::close(); } public function testCalledOnceThrowsExceptionIfCalledTwice() { $this->mock->shouldReceive("foo")->once(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledTwice() { $this->mock->shouldReceive("foo")->twice(); $this->mock->foo(); $this->mock->foo(); } public function testCalledTwiceThrowsExceptionIfNotCalled() { $this->mock->shouldReceive("foo")->twice(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testCalledOnceThrowsExceptionIfCalledThreeTimes() { $this->mock->shouldReceive("foo")->twice(); $this->mock->foo(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledZeroOrMoreTimesAtZeroCalls() { $this->mock->shouldReceive("foo")->zeroOrMoreTimes(); } public function testCalledZeroOrMoreTimesAtThreeCalls() { $this->mock->shouldReceive("foo")->zeroOrMoreTimes(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testTimesCountCalls() { $this->mock->shouldReceive("foo")->times(4); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testTimesCountCallThrowsExceptionOnTooFewCalls() { $this->mock->shouldReceive("foo")->times(2); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testTimesCountCallThrowsExceptionOnTooManyCalls() { $this->mock->shouldReceive("foo")->times(2); $this->mock->foo(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledAtLeastOnceAtExactlyOneCall() { $this->mock->shouldReceive("foo")->atLeast()->once(); $this->mock->foo(); } public function testCalledAtLeastOnceAtExactlyThreeCalls() { $this->mock->shouldReceive("foo")->atLeast()->times(3); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testExpectsStringArgumentCalledAtLeastOnceOverridingDefaultOnceCall() { $this->mock->expects("foo")->atLeast()->once(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testExpectsNoArgumentCalledAtLeastOnceOverridingDefaultOnceCall() { $this->mock->expects()->foo()->atLeast()->once(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testCalledAtLeastThrowsExceptionOnTooFewCalls() { $this->mock->shouldReceive("foo")->atLeast()->twice(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testCalledAtMostOnceAtExactlyOneCall() { $this->mock->shouldReceive("foo")->atMost()->once(); $this->mock->foo(); } public function testCalledAtMostAtExactlyThreeCalls() { $this->mock->shouldReceive("foo")->atMost()->times(3); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testCalledAtLeastThrowsExceptionOnTooManyCalls() { $this->mock->shouldReceive("foo")->atMost()->twice(); $this->mock->foo(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testExactCountersOverrideAnyPriorSetNonExactCounters() { $this->mock->shouldReceive("foo")->atLeast()->once()->once(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testComboOfLeastAndMostCallsWithOneCall() { $this->mock->shouldReceive("foo")->atleast()->once()->atMost()->twice(); $this->mock->foo(); } public function testComboOfLeastAndMostCallsWithTwoCalls() { $this->mock->shouldReceive("foo")->atleast()->once()->atMost()->twice(); $this->mock->foo(); $this->mock->foo(); } public function testComboOfLeastAndMostCallsThrowsExceptionAtTooFewCalls() { $this->mock->shouldReceive("foo")->atleast()->once()->atMost()->twice(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testComboOfLeastAndMostCallsThrowsExceptionAtTooManyCalls() { $this->mock->shouldReceive("foo")->atleast()->once()->atMost()->twice(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); $this->mock->foo(); Mockery::close(); } public function testCallCountingOnlyAppliesToMatchedExpectations() { $this->mock->shouldReceive("foo")->with(1)->once(); $this->mock->shouldReceive("foo")->with(2)->twice(); $this->mock->shouldReceive("foo")->with(3); $this->mock->foo(1); $this->mock->foo(2); $this->mock->foo(2); $this->mock->foo(3); } public function testCallCountingThrowsExceptionOnAnyMismatch() { $this->mock->shouldReceive("foo")->with(1)->once(); $this->mock->shouldReceive("foo")->with(2)->twice(); $this->mock->shouldReceive("foo")->with(3); $this->mock->shouldReceive("bar"); $this->mock->foo(1); $this->mock->foo(2); $this->mock->foo(3); $this->mock->bar(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testCallCountingThrowsExceptionFirst() { $number_of_calls = 0; $this->mock->shouldReceive("foo")->times(2)->with(\Mockery::on(function ($argument) use(&$number_of_calls) { $number_of_calls++; return $number_of_calls <= 3; })); $this->mock->foo(1); $this->mock->foo(1); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testOrderedCallsWithoutError() { $this->mock->shouldReceive("foo")->ordered()->once(); $this->mock->shouldReceive("bar")->ordered()->once(); $this->mock->foo(); $this->mock->bar(); } public function testOrderedCallsWithOutOfOrderError() { $this->mock->shouldReceive("foo")->ordered(); $this->mock->shouldReceive("bar")->ordered(); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testDifferentArgumentsAndOrderingsPassWithoutException() { $this->mock->shouldReceive("foo")->with(1)->ordered()->once(); $this->mock->shouldReceive("foo")->with(2)->ordered()->once(); $this->mock->foo(1); $this->mock->foo(2); } public function testDifferentArgumentsAndOrderingsThrowExceptionWhenInWrongOrder() { $this->mock->shouldReceive("foo")->with(1)->ordered(); $this->mock->shouldReceive("foo")->with(2)->ordered(); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); $this->mock->foo(1); Mockery::close(); } public function testUnorderedCallsIgnoredForOrdering() { $this->mock->shouldReceive("foo")->with(1)->ordered()->once(); $this->mock->shouldReceive("foo")->with(2)->times(3); $this->mock->shouldReceive("foo")->with(3)->ordered()->once(); $this->mock->foo(2); $this->mock->foo(1); $this->mock->foo(2); $this->mock->foo(3); $this->mock->foo(2); } public function testOrderingOfDefaultGrouping() { $this->mock->shouldReceive("foo")->ordered()->once(); $this->mock->shouldReceive("bar")->ordered()->once(); $this->mock->foo(); $this->mock->bar(); } public function testOrderingOfDefaultGroupingThrowsExceptionOnWrongOrder() { $this->mock->shouldReceive("foo")->ordered(); $this->mock->shouldReceive("bar")->ordered(); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testOrderingUsingNumberedGroups() { $this->mock->shouldReceive("start")->ordered(1)->once(); $this->mock->shouldReceive("foo")->ordered(2)->once(); $this->mock->shouldReceive("bar")->ordered(2)->twice(); $this->mock->shouldReceive("final")->ordered()->once(); $this->mock->start(); $this->mock->bar(); $this->mock->foo(); $this->mock->bar(); $this->mock->final(); } public function testOrderingUsingNamedGroups() { $this->mock->shouldReceive("start")->ordered("start")->once(); $this->mock->shouldReceive("foo")->ordered("foobar")->once(); $this->mock->shouldReceive("bar")->ordered("foobar")->twice(); $this->mock->shouldReceive("final")->ordered()->once(); $this->mock->start(); $this->mock->bar(); $this->mock->foo(); $this->mock->bar(); $this->mock->final(); } public function testGroupedUngroupedOrderingDoNotOverlap() { $s = $this->mock->shouldReceive("start")->ordered(); $m = $this->mock->shouldReceive("mid")->ordered("foobar"); $e = $this->mock->shouldReceive("end")->ordered(); $this->assertLessThan($m->getOrderNumber(), $s->getOrderNumber()); $this->assertLessThan($e->getOrderNumber(), $m->getOrderNumber()); } public function testGroupedOrderingThrowsExceptionWhenCallsDisordered() { $this->mock->shouldReceive("foo")->ordered("first"); $this->mock->shouldReceive("bar")->ordered("second"); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testExpectationMatchingWithNoArgsOrderings() { $this->mock->shouldReceive("foo")->withNoArgs()->once()->ordered(); $this->mock->shouldReceive("bar")->withNoArgs()->once()->ordered(); $this->mock->shouldReceive("foo")->withNoArgs()->once()->ordered(); $this->mock->foo(); $this->mock->bar(); $this->mock->foo(); } public function testExpectationMatchingWithAnyArgsOrderings() { $this->mock->shouldReceive("foo")->withAnyArgs()->once()->ordered(); $this->mock->shouldReceive("bar")->withAnyArgs()->once()->ordered(); $this->mock->shouldReceive("foo")->withAnyArgs()->once()->ordered(); $this->mock->foo(); $this->mock->bar(); $this->mock->foo(); } public function testEnsuresOrderingIsNotCrossMockByDefault() { $this->mock->shouldReceive("foo")->ordered()->once(); $mock2 = mock("bar"); $mock2->shouldReceive("bar")->ordered()->once(); $mock2->bar(); $this->mock->foo(); } public function testEnsuresOrderingIsCrossMockWhenGloballyFlagSet() { $this->mock->shouldReceive("foo")->globally()->ordered(); $mock2 = mock("bar"); $mock2->shouldReceive("bar")->globally()->ordered(); $this->expectException(\Mockery\Exception::class); $mock2->bar(); $this->mock->foo(); Mockery::close(); } public function testExpectationCastToStringFormatting() { $exp = $this->mock->shouldReceive("foo")->with(1, "bar", new stdClass(), array("Spam" => "Ham", "Bar" => "Baz")); $this->assertEquals("[foo(1, 'bar', object(stdClass), ['Spam' => 'Ham', 'Bar' => 'Baz'])]", (string) $exp); } public function testLongExpectationCastToStringFormatting() { $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")); $this->assertEquals("[foo(['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', 7...])]", (string) $exp); } public function testMultipleExpectationCastToStringFormatting() { $exp = $this->mock->shouldReceive("foo", "bar")->with(1); $this->assertEquals("[foo(1), bar(1)]", (string) $exp); } public function testGroupedOrderingWithLimitsAllowsMultipleReturnValues() { $this->mock->shouldReceive("foo")->with(2)->once()->andReturn("first"); $this->mock->shouldReceive("foo")->with(2)->twice()->andReturn("second/third"); $this->mock->shouldReceive("foo")->with(2)->andReturn("infinity"); $this->assertEquals("first", $this->mock->foo(2)); $this->assertEquals("second/third", $this->mock->foo(2)); $this->assertEquals("second/third", $this->mock->foo(2)); $this->assertEquals("infinity", $this->mock->foo(2)); $this->assertEquals("infinity", $this->mock->foo(2)); $this->assertEquals("infinity", $this->mock->foo(2)); } public function testExpectationsCanBeMarkedAsDefaults() { $this->mock->shouldReceive("foo")->andReturn("bar")->byDefault(); $this->assertEquals("bar", $this->mock->foo()); } public function testDefaultExpectationsValidatedInCorrectOrder() { $this->mock->shouldReceive("foo")->with(1)->once()->andReturn("first")->byDefault(); $this->mock->shouldReceive("foo")->with(2)->once()->andReturn("second")->byDefault(); $this->assertEquals("first", $this->mock->foo(1)); $this->assertEquals("second", $this->mock->foo(2)); } public function testDefaultExpectationsAreReplacedByLaterConcreteExpectations() { $this->mock->shouldReceive("foo")->andReturn("bar")->once()->byDefault(); $this->mock->shouldReceive("foo")->andReturn("baz")->twice(); $this->assertEquals("baz", $this->mock->foo()); $this->assertEquals("baz", $this->mock->foo()); } public function testExpectationFallsBackToDefaultExpectationWhenConcreteExpectationsAreUsedUp() { $this->mock->shouldReceive("foo")->with(1)->andReturn("bar")->once()->byDefault(); $this->mock->shouldReceive("foo")->with(2)->andReturn("baz")->once(); $this->assertEquals("baz", $this->mock->foo(2)); $this->assertEquals("bar", $this->mock->foo(1)); } public function testDefaultExpectationsCanBeOrdered() { $this->mock->shouldReceive("foo")->ordered()->byDefault(); $this->mock->shouldReceive("bar")->ordered()->byDefault(); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testDefaultExpectationsCanBeOrderedAndReplaced() { $this->mock->shouldReceive("foo")->ordered()->byDefault(); $this->mock->shouldReceive("bar")->ordered()->byDefault(); $this->mock->shouldReceive("bar")->ordered()->once(); $this->mock->shouldReceive("foo")->ordered()->once(); $this->mock->bar(); $this->mock->foo(); } public function testByDefaultOperatesFromMockConstruction() { $container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader()); $mock = $container->mock("f", array("foo" => "rfoo", "bar" => "rbar", "baz" => "rbaz"))->byDefault(); $mock->shouldReceive("foo")->andReturn("foobar"); $this->assertEquals("foobar", $mock->foo()); $this->assertEquals("rbar", $mock->bar()); $this->assertEquals("rbaz", $mock->baz()); } public function testByDefaultOnAMockDoesSquatWithoutExpectations() { $this->assertInstanceOf(MockInterface::class, mock("f")->byDefault()); } public function testDefaultExpectationsCanBeOverridden() { $this->mock->shouldReceive("foo")->with("test")->andReturn("bar")->byDefault(); $this->mock->shouldReceive("foo")->with("test")->andReturn("newbar")->byDefault(); $this->mock->foo("test"); $this->assertEquals("newbar", $this->mock->foo("test")); } public function testByDefaultPreventedFromSettingDefaultWhenDefaultingExpectationWasReplaced() { $exp = $this->mock->shouldReceive("foo")->andReturn(1); $this->mock->shouldReceive("foo")->andReturn(2); $this->expectException(\Mockery\Exception::class); $exp->byDefault(); Mockery::close(); } public function testAnyConstraintMatchesAnyArg() { $this->mock->shouldReceive("foo")->with(1, Mockery::any())->twice(); $this->mock->foo(1, 2); $this->mock->foo(1, "str"); } public function testAnyConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::any())->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testAndAnyOtherConstraintMatchesTheRestOfTheArguments() { $this->mock->shouldReceive("foo")->with(1, 2, Mockery::andAnyOthers())->twice(); $this->mock->foo(1, 2, 3, 4, 5); $this->mock->foo(1, 2, "str", 3, 4); } public function testAndAnyOtherConstraintDoesNotPreventMatchingOfRegularArguments() { $this->mock->shouldReceive("foo")->with(1, 2, Mockery::andAnyOthers()); $this->expectException(\Mockery\Exception::class); $this->mock->foo(10, 2, 3, 4, 5); Mockery::close(); } public function testAndAnyOtherConstraintMultipleExpectationsButNoOthers() { $this->mock->shouldReceive("foo")->with("a", Mockery::andAnyOthers())->andReturn("a"); $this->mock->shouldReceive("foo")->with("b", Mockery::andAnyOthers())->andReturn("b"); $this->assertEquals("a", $this->mock->foo("a")); $this->assertEquals("b", $this->mock->foo("b")); } public function testArrayConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("array"))->once(); $this->mock->foo(array()); } public function testArrayConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("array"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testArrayConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("array")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testBoolConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("bool"))->once(); $this->mock->foo(true); } public function testBoolConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("bool"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testBoolConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("bool")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testCallableConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("callable"))->once(); $this->mock->foo(function () { return "f"; }); } public function testCallableConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("callable"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testCallableConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("callable")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testDoubleConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("double"))->once(); $this->mock->foo(2.25); } public function testDoubleConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("double"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testDoubleConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("double")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testFloatConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("float"))->once(); $this->mock->foo(2.25); } public function testFloatConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("float"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testFloatConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("float")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testIntConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("int"))->once(); $this->mock->foo(2); } public function testIntConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("int"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testIntConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("int")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("f"); Mockery::close(); } public function testLongConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("long"))->once(); $this->mock->foo(2); } public function testLongConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("long"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testLongConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("long")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("f"); Mockery::close(); } public function testNullConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("null"))->once(); $this->mock->foo(null); } public function testNullConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("null"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testNullConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("null")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("f"); Mockery::close(); } public function testNumericConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("numeric"))->once(); $this->mock->foo("2"); } public function testNumericConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("numeric"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testNumericConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("numeric")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("f"); Mockery::close(); } public function testObjectConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("object"))->once(); $this->mock->foo(new stdClass()); } public function testObjectConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("object`"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testObjectConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("object")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("f"); Mockery::close(); } public function testRealConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("float"))->once(); $this->mock->foo(2.25); } public function testRealConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("float"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testRealConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("float")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("f"); Mockery::close(); } public function testResourceConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("resource"))->once(); $r = fopen(dirname(__FILE__) . "/_files/file.txt", "r"); $this->mock->foo($r); } public function testResourceConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("resource"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testResourceConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("resource")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("f"); Mockery::close(); } public function testScalarConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("scalar"))->once(); $this->mock->foo(2); } public function testScalarConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("scalar"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testScalarConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("scalar")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array()); Mockery::close(); } public function testStringConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("string"))->once(); $this->mock->foo("2"); } public function testStringConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("string"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testStringConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("string")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testClassConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::type("stdClass"))->once(); $this->mock->foo(new stdClass()); } public function testClassConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::type("stdClass"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testClassConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::type("stdClass")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(new Exception()); Mockery::close(); } public function testDucktypeConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::ducktype("quack", "swim"))->once(); $this->mock->foo(new Mockery_Duck()); } public function testDucktypeConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::ducktype("quack", "swim"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testDucktypeConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::ducktype("quack", "swim")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(new Mockery_Duck_Nonswimmer()); Mockery::close(); } public function testArrayContentConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::subset(array("a" => 1, "b" => 2)))->once(); $this->mock->foo(array("a" => 1, "b" => 2, "c" => 3)); } public function testArrayContentConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::subset(array("a" => 1, "b" => 2)))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testArrayContentConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::subset(array("a" => 1, "b" => 2))); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("a" => 1, "c" => 3)); Mockery::close(); } public function testContainsConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::contains(1, 2))->once(); $this->mock->foo(array("a" => 1, "b" => 2, "c" => 3)); } public function testContainsConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::contains(1, 2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testContainsConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::contains(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("a" => 1, "c" => 3)); Mockery::close(); } public function testHasKeyConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::hasKey("c"))->once(); $this->mock->foo(array("a" => 1, "b" => 2, "c" => 3)); } public function testHasKeyConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::hasKey("a"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, array("a" => 1), 3); } public function testHasKeyConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::hasKey("c")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("a" => 1, "b" => 3)); Mockery::close(); } public function testHasValueConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::hasValue(1))->once(); $this->mock->foo(array("a" => 1, "b" => 2, "c" => 3)); } public function testHasValueConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::hasValue(1))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, array("a" => 1), 3); } public function testHasValueConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::hasValue(2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("a" => 1, "b" => 3)); Mockery::close(); } public function testCaptureStoresArgumentOfTypeScalar_ClosureEvaluatesToTrue() { $temp = null; $this->mock->shouldReceive("foo")->with(Mockery::capture($temp))->once(); $this->mock->foo(4); $this->assertSame(4, $temp); } public function testCaptureStoresArgumentOfTypeArgument_ClosureEvaluatesToTrue() { $object = new stdClass(); $temp = null; $this->mock->shouldReceive("foo")->with(Mockery::capture($temp))->once(); $this->mock->foo($object); $this->assertSame($object, $temp); } public function testOnConstraintMatchesArgument_ClosureEvaluatesToTrue() { $function = function ($arg) { return $arg % 2 == 0; }; $this->mock->shouldReceive("foo")->with(Mockery::on($function))->once(); $this->mock->foo(4); } public function testOnConstraintMatchesArgumentOfTypeArray_ClosureEvaluatesToTrue() { $function = function ($arg) { return is_array($arg); }; $this->mock->shouldReceive("foo")->with(Mockery::on($function))->once(); $this->mock->foo(array(4, 5)); } public function testOnConstraintThrowsExceptionWhenConstraintUnmatched_ClosureEvaluatesToFalse() { $function = function ($arg) { return $arg % 2 == 0; }; $this->mock->shouldReceive("foo")->with(Mockery::on($function)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(5); Mockery::close(); } public function testMustBeConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::mustBe(2))->once(); $this->mock->foo(2); } public function testMustBeConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::mustBe(2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::mustBe(2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo("2"); Mockery::close(); } public function testMustBeConstraintMatchesObjectArgumentWithEqualsComparisonNotIdentical() { $a = new stdClass(); $a->foo = 1; $b = new stdClass(); $b->foo = 1; $this->mock->shouldReceive("foo")->with(Mockery::mustBe($a))->once(); $this->mock->foo($b); } public function testMustBeConstraintNonMatchingCaseWithObject() { $a = new stdClass(); $a->foo = 1; $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::mustBe($a))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, $a, 3); } public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatchedWithObject() { $a = new stdClass(); $a->foo = 1; $b = new stdClass(); $b->foo = 2; $this->mock->shouldReceive("foo")->with(Mockery::mustBe($a)); $this->expectException(\Mockery\Exception::class); $this->mock->foo($b); Mockery::close(); } public function testMatchPrecedenceBasedOnExpectedCallsFavouringExplicitMatch() { $this->mock->shouldReceive("foo")->with(1)->once(); $this->mock->shouldReceive("foo")->with(Mockery::any())->never(); $this->mock->foo(1); } public function testMatchPrecedenceBasedOnExpectedCallsFavouringAnyMatch() { $this->mock->shouldReceive("foo")->with(Mockery::any())->once(); $this->mock->shouldReceive("foo")->with(1)->never(); $this->mock->foo(1); } public function testReturnNullIfIgnoreMissingMethodsSet() { $this->mock->shouldIgnoreMissing(); $this->assertNull($this->mock->g(1, 2)); } public function testReturnUndefinedIfIgnoreMissingMethodsSet() { $this->mock->shouldIgnoreMissing()->asUndefined(); $this->assertInstanceOf(\Mockery\Undefined::class, $this->mock->g(1, 2)); } public function testReturnAsUndefinedAllowsForInfiniteSelfReturningChain() { $this->mock->shouldIgnoreMissing()->asUndefined(); $this->assertInstanceOf(\Mockery\Undefined::class, $this->mock->g(1, 2)->a()->b()->c()); } public function testShouldIgnoreMissingFluentInterface() { $this->assertInstanceOf(\Mockery\MockInterface::class, $this->mock->shouldIgnoreMissing()); } public function testShouldIgnoreMissingAsUndefinedFluentInterface() { $this->assertInstanceOf(\Mockery\MockInterface::class, $this->mock->shouldIgnoreMissing()->asUndefined()); } public function testShouldIgnoreMissingAsDefinedProxiesToUndefinedAllowingToString() { $this->mock->shouldIgnoreMissing()->asUndefined(); $this->assertTrue(is_string("{$this->mock->g()}")); $this->assertTrue(is_string("{$this->mock}")); } public function testShouldIgnoreMissingDefaultReturnValue() { $this->mock->shouldIgnoreMissing(1); $this->assertEquals(1, $this->mock->a()); } public function testShouldIgnoreMissingDefaultSelfAndReturnsSelf() { $this->mock->shouldIgnoreMissing(\Mockery::self()); $this->assertSame($this->mock, $this->mock->a()->b()); } public function testToStringMagicMethodCanBeMocked() { $this->mock->shouldReceive("__toString")->andReturn("dave"); $this->assertEquals("{$this->mock}", "dave"); } public function testOptionalMockRetrieval() { $m = mock("f")->shouldReceive("foo")->with(1)->andReturn(3)->mock(); $this->assertInstanceOf(\Mockery\MockInterface::class, $m); } public function testNotConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::not(1))->once(); $this->mock->foo(2); } public function testNotConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::not(2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testNotConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::not(2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); Mockery::close(); } public function testAnyOfConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::anyOf(1, 2))->twice(); $this->mock->foo(2); $this->mock->foo(1); } public function testAnyOfConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::anyOf(1, 2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testAnyOfConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::anyOf(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(3); Mockery::close(); } public function testAnyOfConstraintThrowsExceptionWhenTrueIsNotAnExpectedArgument() { $this->mock->shouldReceive("foo")->with(Mockery::anyOf(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(true); } public function testAnyOfConstraintThrowsExceptionWhenFalseIsNotAnExpectedArgument() { $this->mock->shouldReceive("foo")->with(Mockery::anyOf(0, 1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(false); } public function testNotAnyOfConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::notAnyOf(1, 2))->once(); $this->mock->foo(3); } public function testNotAnyOfConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->times(3); $this->mock->shouldReceive("foo")->with(1, Mockery::notAnyOf(1, 2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 4, 3); } public function testNotAnyOfConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::notAnyOf(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); Mockery::close(); } public function testPatternConstraintMatchesArgument() { $this->mock->shouldReceive("foo")->with(Mockery::pattern("/foo.*/"))->once(); $this->mock->foo("foobar"); } public function testPatternConstraintNonMatchingCase() { $this->mock->shouldReceive("foo")->once(); $this->mock->shouldReceive("foo")->with(Mockery::pattern("/foo.*/"))->never(); $this->mock->foo("bar"); } public function testPatternConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("foo")->with(Mockery::pattern("/foo.*/")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("bar"); Mockery::close(); } public function testGlobalConfigMayForbidMockingNonExistentMethodsOnClasses() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $mock = mock("stdClass"); $this->expectException(\Mockery\Exception::class); $mock->shouldReceive("foo"); Mockery::close(); } public function testGlobalConfigMayForbidMockingNonExistentMethodsOnAutoDeclaredClasses() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $this->expectException(\Mockery\Exception::class); $this->expectExceptionMessage("Mockery can't find 'SomeMadeUpClass' so can't mock it"); $mock = mock("SomeMadeUpClass"); $mock->shouldReceive("foo"); Mockery::close(); } public function testGlobalConfigMayForbidMockingNonExistentMethodsOnObjects() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $mock = mock(new stdClass()); $this->expectException(\Mockery\Exception::class); $mock->shouldReceive("foo"); Mockery::close(); } public function testGlobalConfigQuickDefinitionsConfigurationDefaultExpectation() { \Mockery::getConfiguration()->getQuickDefinitions()->shouldBeCalledAtLeastOnce(false); mock(array("foo" => 1)); $this->expectNotToPerformAssertions(); Mockery::close(); } public function testGlobalConfigQuickDefinitionsConfigurationMockAtLeastOnce() { \Mockery::getConfiguration()->getQuickDefinitions()->shouldBeCalledAtLeastOnce(true); mock(array("foo" => 1)); $this->expectException(\Mockery\Exception\InvalidCountException::class); Mockery::close(); } public function testAnExampleWithSomeExpectationAmends() { $service = mock("MyService"); $service->shouldReceive("login")->with("user", "pass")->once()->andReturn(true); $service->shouldReceive("hasBookmarksTagged")->with("php")->once()->andReturn(false); $service->shouldReceive("addBookmark")->with(Mockery::pattern("/^http:/"), \Mockery::type("string"))->times(3)->andReturn(true); $service->shouldReceive("hasBookmarksTagged")->with("php")->once()->andReturn(true); $this->assertTrue($service->login("user", "pass")); $this->assertFalse($service->hasBookmarksTagged("php")); $this->assertTrue($service->addBookmark("http://example.com/1", "some_tag1")); $this->assertTrue($service->addBookmark("http://example.com/2", "some_tag2")); $this->assertTrue($service->addBookmark("http://example.com/3", "some_tag3")); $this->assertTrue($service->hasBookmarksTagged("php")); } public function testAnExampleWithSomeExpectationAmendsOnCallCounts() { $service = mock("MyService"); $service->shouldReceive("login")->with("user", "pass")->once()->andReturn(true); $service->shouldReceive("hasBookmarksTagged")->with("php")->once()->andReturn(false); $service->shouldReceive("addBookmark")->with(Mockery::pattern("/^http:/"), \Mockery::type("string"))->times(3)->andReturn(true); $service->shouldReceive("hasBookmarksTagged")->with("php")->twice()->andReturn(true); $this->assertTrue($service->login("user", "pass")); $this->assertFalse($service->hasBookmarksTagged("php")); $this->assertTrue($service->addBookmark("http://example.com/1", "some_tag1")); $this->assertTrue($service->addBookmark("http://example.com/2", "some_tag2")); $this->assertTrue($service->addBookmark("http://example.com/3", "some_tag3")); $this->assertTrue($service->hasBookmarksTagged("php")); $this->assertTrue($service->hasBookmarksTagged("php")); } public function testAnExampleWithSomeExpectationAmendsOnCallCounts_PHPUnitTest() { $service = mock("MyService2"); $service->expects("login")->once()->with("user", "pass")->andReturnTrue(); $service->expects("hasBookmarksTagged")->times(3)->with("php")->andReturns(false, true, true); $service->expects("addBookmark")->times(3)->andReturnTrue(); $this->assertTrue($service->login("user", "pass")); $this->assertFalse($service->hasBookmarksTagged("php")); $this->assertTrue($service->addBookmark("http://example.com/1", "some_tag1")); $this->assertTrue($service->addBookmark("http://example.com/2", "some_tag2")); $this->assertTrue($service->addBookmark("http://example.com/3", "some_tag3")); $this->assertTrue($service->hasBookmarksTagged("php")); $this->assertTrue($service->hasBookmarksTagged("php")); } public function testMockedMethodsCallableFromWithinOriginalClass() { $mock = mock("MockeryTest_InterMethod1[doThird]"); $mock->shouldReceive("doThird")->andReturn(true); $this->assertTrue($mock->doFirst()); } public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectation() { $mock = mock("Mockery_Demeterowski"); $mock->shouldReceive("foo->bar->baz")->andReturn("Spam!"); $demeter = new Mockery_UseDemeter($mock); $this->assertSame("Spam!", $demeter->doit()); } public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectationWithArgs() { $mock = mock("Mockery_Demeterowski"); $mock->shouldReceive("foo->bar->baz")->andReturn("Spam!"); $demeter = new Mockery_UseDemeter($mock); $this->assertSame("Spam!", $demeter->doitWithArgs()); } public function testShouldNotReceiveCanBeAddedToCompositeExpectation() { $mock = mock("Foo"); $mock->shouldReceive("a")->once()->andReturn("Spam!")->shouldNotReceive("b"); $mock->a(); } public function testPassthruEnsuresRealMethodCalledForReturnValues() { $mock = mock("MockeryTest_SubjectCall1"); $mock->shouldReceive("foo")->once()->passthru(); $this->assertEquals("bar", $mock->foo()); } public function testPassthruCallMagic() { $mock = mock("Mockery_Magic"); $mock->shouldReceive("theAnswer")->once()->passthru(); $this->assertSame(42, $mock->theAnswer()); } public function testShouldIgnoreMissingExpectationBasedOnArgs() { $mock = mock("MyService2")->shouldIgnoreMissing(); $mock->shouldReceive("hasBookmarksTagged")->with("dave")->once(); $mock->hasBookmarksTagged("dave"); $mock->hasBookmarksTagged("padraic"); } public function testMakePartialExpectationBasedOnArgs() { $mock = mock("MockeryTest_SubjectCall1")->makePartial(); $this->assertEquals("bar", $mock->foo()); $this->assertEquals("bar", $mock->foo("baz")); $this->assertEquals("bar", $mock->foo("qux")); $mock->shouldReceive("foo")->with("baz")->twice()->andReturn("123"); $this->assertEquals("bar", $mock->foo()); $this->assertEquals("123", $mock->foo("baz")); $this->assertEquals("bar", $mock->foo("qux")); $mock->shouldReceive("foo")->withNoArgs()->once()->andReturn("456"); $this->assertEquals("456", $mock->foo()); $this->assertEquals("123", $mock->foo("baz")); $this->assertEquals("bar", $mock->foo("qux")); } public function testCanReturnSelf() { $this->mock->shouldReceive("foo")->andReturnSelf(); $this->assertSame($this->mock, $this->mock->foo()); } public function testReturnsTrueIfTrueIsReturnValue() { $this->mock->shouldReceive("foo")->andReturnTrue(); $this->assertTrue($this->mock->foo()); } public function testReturnsFalseIfFalseIsReturnValue() { $this->mock->shouldReceive("foo")->andReturnFalse(); $this->assertFalse($this->mock->foo()); } public function testExpectationCanBeOverridden() { $this->mock->shouldReceive("foo")->once()->andReturn("green"); $this->mock->shouldReceive("foo")->andReturn("blue"); $this->assertEquals("green", $this->mock->foo()); $this->assertEquals("blue", $this->mock->foo()); } public function testTimesExpectationForbidsFloatNumbers() { $this->expectException(\InvalidArgumentException::class); $this->mock->shouldReceive("foo")->times(1.3); Mockery::close(); } public function testIfExceptionIndicatesAbsenceOfMethodAndExpectationsOnMock() { $mock = mock("Mockery_Duck"); $this->expectException("\BadMethodCallException", "Method " . get_class($mock) . "::nonExistent() does not exist on this mock object"); $mock->nonExistent(); Mockery::close(); } public function testIfCallingMethodWithNoExpectationsHasSpecificExceptionMessage() { $mock = mock("Mockery_Duck"); $this->expectException("\BadMethodCallException", "Received " . get_class($mock) . "::quack(), " . "but no expectations were specified"); $mock->quack(); Mockery::close(); } public function testMockShouldNotBeAnonymousWhenImplementingSpecificInterface() { $waterMock = mock("IWater"); $this->assertFalse($waterMock->mockery_isAnonymous()); } public function testWetherMockWithInterfaceOnlyCanNotImplementNonExistingMethods() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $waterMock = \Mockery::mock("IWater"); $this->expectException(\Mockery\Exception::class); $waterMock->shouldReceive("nonExistentMethod")->once()->andReturnNull(); \Mockery::close(); } public function testCountWithBecauseExceptionMessage() { $this->expectException(InvalidCountException::class); $this->expectExceptionMessageRegex("/Method foo\(<Any Arguments>\) from Mockery_(.*?) should be called" . PHP_EOL . " " . "exactly 1 times but called 0 times. Because We like foo/"); $this->mock->shouldReceive("foo")->once()->because("We like foo"); Mockery::close(); } public function it_uses_a_matchers_to_string_method_in_the_exception_output() { $mock = Mockery::mock(); $mock->expects()->foo(Mockery::hasKey("foo")); $this->expectException(InvalidCountException::class, "Method foo(<HasKey[foo]>)"); Mockery::close(); } public function testNonObjectEqualsExpectation() { $input = array("club_id" => 1, "user_id" => 1, "is_admin" => 1); $foo = Mockery::mock(); $foo->shouldReceive("foo")->with($input)->andReturn("foobar"); ksort($input); self::assertSame("foobar", $foo->foo($input)); } } goto BXyUC; RhNI3: class Mockery_Magic { public function __call($method, $args) { return 42; } } ?>

Did this file decode correctly?

Original Code

<?php
 use Mockery\Adapter\Phpunit\MockeryTestCase; use Mockery\Exception\InvalidCountException; use Mockery\MockInterface; use test\Mockery\RegExpCompatability; goto eOzaD; ow8Bm: class MockeryTest_Foo { public function foo() { } } goto RhNI3; cpZLp: class Mockery_UseDemeter { protected $demeter; public function __construct($demeter) { $this->demeter = $demeter; } public function doit() { return $this->demeter->foo()->bar()->baz(); } public function doitWithArgs() { return $this->demeter->foo("\146\x6f\157")->bar("\142\x61\162")->baz("\142\x61\x7a"); } } goto ow8Bm; rnUd9: class Mockery_Duck_Nonswimmer { public function quack() { } } goto OT9oS; BXyUC: interface IWater { public function dry(); } goto GyXmO; FmoT9: class MyService2 { public function login($user, $pass) { } public function hasBookmarksTagged($tag) { } public function addBookmark($uri, $tag) { } } goto tKY2R; GyXmO: class MockeryTest_SubjectCall1 { public function foo() { return "\142\x61\162"; } } goto a7FzE; OT9oS: class Mockery_Demeterowski { public function foo() { return $this; } public function bar() { return $this; } public function baz() { return "\110\x61\x6d\41"; } } goto cpZLp; tKY2R: class Mockery_Duck { public function quack() { } public function swim() { } } goto rnUd9; a7FzE: class MockeryTest_InterMethod1 { public function doFirst() { return $this->doSecond(); } private function doSecond() { return $this->doThird(); } public function doThird() { return false; } } goto FmoT9; eOzaD: class ExpectationTest extends MockeryTestCase { use RegExpCompatability; protected $mock; public function mockeryTestSetUp() { parent::mockeryTestSetUp(); $this->mock = mock("\106\x6f\157"); } public function mockeryTestTearDown() { parent::mockeryTestTearDown(); \Mockery::getConfiguration()->allowMockingNonExistentMethods(true); } public function testReturnsNullWhenNoArgs() { $this->mock->shouldReceive("\146\x6f\x6f"); $this->assertNull($this->mock->foo()); } public function testReturnsNullWhenSingleArg() { $this->mock->shouldReceive("\146\157\x6f"); $this->assertNull($this->mock->foo(1)); } public function testReturnsNullWhenManyArgs() { $this->mock->shouldReceive("\x66\x6f\157"); $this->assertNull($this->mock->foo("\146\157\x6f", array(), new stdClass())); } public function testReturnsNullIfNullIsReturnValue() { $this->mock->shouldReceive("\146\x6f\x6f")->andReturn(null); $this->assertNull($this->mock->foo()); } public function testReturnsNullForMockedExistingClassIfAndreturnnullCalled() { $mock = mock("\115\x6f\143\x6b\145\162\171\124\145\163\164\137\106\157\x6f"); $mock->shouldReceive("\x66\x6f\157")->andReturn(null); $this->assertNull($mock->foo()); } public function testReturnsNullForMockedExistingClassIfNullIsReturnValue() { $mock = mock("\115\157\143\x6b\x65\162\171\x54\x65\x73\164\137\106\x6f\157"); $mock->shouldReceive("\x66\157\x6f")->andReturnNull(); $this->assertNull($mock->foo()); } public function testReturnsSameValueForAllIfNoArgsExpectationAndNoneGiven() { $this->mock->shouldReceive("\x66\157\157")->andReturn(1); $this->assertEquals(1, $this->mock->foo()); } public function testSetsPublicPropertyWhenRequested() { $this->mock->bar = null; $this->mock->shouldReceive("\146\157\157")->andSet("\142\x61\162", "\x62\141\172"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\141\172", $this->mock->bar); } public function testSetsPublicPropertyWhenRequestedUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("\146\x6f\x6f")->set("\142\141\x72", "\142\141\172"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\141\x7a", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequested() { $this->mock->bar = null; $this->mock->shouldReceive("\146\x6f\157")->andSet("\x62\141\x72", "\142\x61\172", "\142\x61\172\x7a", "\142\141\x7a\x7a\172"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\x61\x7a", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\x61\x7a\x7a", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\x61\172\172\172", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("\x66\157\x6f")->set("\142\141\162", "\x62\141\172", "\142\141\172\172", "\142\x61\x7a\x7a\x7a"); $this->assertTrue(empty($this->mock->bar)); $this->mock->foo(); $this->assertEquals("\x62\141\172", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\x61\x7a\x7a", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\x61\172\172\x7a", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValues() { $this->mock->bar = null; $this->mock->shouldReceive("\x66\157\x6f")->andSet("\142\141\x72", "\x62\x61\x7a", "\x62\141\172\172"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\x61\172", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\x61\x7a\x7a", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\141\172\172", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValuesUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("\x66\157\x6f")->andSet("\x62\x61\x72", "\x62\141\x7a", "\142\141\x7a\172"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\x61\172", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\x61\x7a\x7a", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\141\172\x7a", $this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValuesWithDirectSet() { $this->mock->bar = null; $this->mock->shouldReceive("\146\157\157")->andSet("\142\141\x72", "\142\141\x7a", "\142\141\x7a\x7a"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\x61\172", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\x61\x7a\172", $this->mock->bar); $this->mock->bar = null; $this->mock->foo(); $this->assertNull($this->mock->bar); } public function testSetsPublicPropertiesWhenRequestedMoreTimesThanSetValuesWithDirectSetUsingAlias() { $this->mock->bar = null; $this->mock->shouldReceive("\x66\157\x6f")->set("\142\141\x72", "\x62\x61\172", "\142\x61\172\x7a"); $this->assertNull($this->mock->bar); $this->mock->foo(); $this->assertEquals("\x62\x61\172", $this->mock->bar); $this->mock->foo(); $this->assertEquals("\142\x61\x7a\x7a", $this->mock->bar); $this->mock->bar = null; $this->mock->foo(); $this->assertNull($this->mock->bar); } public function testSetsPublicPropertiesCorrectlyForDifferentInstancesOfSameClass() { $mockInstanceOne = mock("\115\157\x63\153\x65\x72\171\124\145\163\164\137\x46\x6f\157"); $mockInstanceTwo = mock("\x4d\x6f\x63\153\145\x72\x79\124\x65\x73\x74\137\106\157\x6f"); $mockInstanceOne->shouldReceive("\146\157\x6f")->andSet("\x62\141\162", "\142\x61\172"); $mockInstanceTwo->shouldReceive("\146\157\x6f")->andSet("\142\x61\x72", "\x62\x61\172\x7a"); $mockInstanceOne->foo(); $mockInstanceTwo->foo(); $this->assertEquals("\x62\141\172", $mockInstanceOne->bar); $this->assertEquals("\142\141\172\172", $mockInstanceTwo->bar); } public function testReturnsSameValueForAllIfNoArgsExpectationAndSomeGiven() { $this->mock->shouldReceive("\x66\157\x6f")->andReturn(1); $this->assertEquals(1, $this->mock->foo("\146\157\157")); } public function testReturnsValueFromSequenceSequentially() { $this->mock->shouldReceive("\146\x6f\157")->andReturn(1, 2, 3); $this->mock->foo("\x66\157\157"); $this->assertEquals(2, $this->mock->foo("\x66\157\157")); } public function testReturnsValueFromSequenceSequentiallyAndRepeatedlyReturnsFinalValueOnExtraCalls() { $this->mock->shouldReceive("\146\x6f\157")->andReturn(1, 2, 3); $this->mock->foo("\146\157\157"); $this->mock->foo("\x66\x6f\157"); $this->assertEquals(3, $this->mock->foo("\146\x6f\x6f")); $this->assertEquals(3, $this->mock->foo("\x66\157\157")); } public function testReturnsValueFromSequenceSequentiallyAndRepeatedlyReturnsFinalValueOnExtraCallsWithManyAndReturnCalls() { $this->mock->shouldReceive("\146\x6f\157")->andReturn(1)->andReturn(2, 3); $this->mock->foo("\146\x6f\x6f"); $this->mock->foo("\x66\157\157"); $this->assertEquals(3, $this->mock->foo("\146\157\157")); $this->assertEquals(3, $this->mock->foo("\146\157\x6f")); } public function testReturnsValueOfClosure() { $this->mock->shouldReceive("\146\157\157")->with(5)->andReturnUsing(function ($v) { return $v + 1; }); $this->assertEquals(6, $this->mock->foo(5)); } public function testReturnsValueOfArgument() { $args = array(1, 2, 3, 4, 5); $index = 2; $this->mock->shouldReceive("\146\157\157")->withArgs($args)->andReturnArg($index); $this->assertEquals($args[$index], $this->mock->foo(...$args)); } public function testReturnsNullArgument() { $args = array(1, null, 3); $index = 1; $this->mock->shouldReceive("\x66\157\x6f")->withArgs($args)->andReturnArg($index); $this->assertNull($this->mock->foo(...$args)); } public function testExceptionOnInvalidArgumentIndexValue() { $this->expectException(\InvalidArgumentException::class); $this->mock->shouldReceive("\146\157\157")->andReturnArg("\151\156\x76\x61\x6c\151\144"); } public function testExceptionOnArgumentIndexOutOfRange() { $this->expectException(\OutOfBoundsException::class); $this->mock->shouldReceive("\x66\x6f\157")->andReturnArg(2); $this->mock->foo(0, 1); } public function testReturnsUndefined() { $this->mock->shouldReceive("\x66\157\x6f")->andReturnUndefined(); $this->assertInstanceOf(\Mockery\Undefined::class, $this->mock->foo()); } public function testReturnsValuesSetAsArray() { $this->mock->shouldReceive("\x66\157\157")->andReturnValues(array(1, 2, 3)); $this->assertEquals(1, $this->mock->foo()); $this->assertEquals(2, $this->mock->foo()); $this->assertEquals(3, $this->mock->foo()); } public function testAndYield() : void { $this->mock->shouldReceive("\x66\157\157")->andYield(1, 2, 3); self::assertSame(array(1, 2, 3), iterator_to_array($this->mock->foo())); } public function testThrowsException() { $this->mock->shouldReceive("\146\157\157")->andThrow(new OutOfBoundsException()); $this->expectException(OutOfBoundsException::class); $this->mock->foo(); Mockery::close(); } public function and_throws_is_an_alias_to_and_throw() { $this->mock->shouldReceive("\146\x6f\157")->andThrows(new OutOfBoundsException()); $this->expectException(OutOfBoundsException::class); $this->mock->foo(); } public function it_can_throw_a_throwable() { $this->expectException(\Error::class); $this->mock->shouldReceive("\x66\x6f\157")->andThrow(new \Error()); $this->mock->foo(); } public function testThrowsExceptionBasedOnArgs() { $this->mock->shouldReceive("\146\x6f\x6f")->andThrow("\x4f\x75\164\x4f\146\102\x6f\x75\156\x64\x73\105\170\143\x65\160\164\x69\157\156"); $this->expectException(OutOfBoundsException::class); $this->mock->foo(); Mockery::close(); } public function testThrowsExceptionBasedOnArgsWithMessage() { $this->mock->shouldReceive("\x66\157\157")->andThrow("\117\165\164\x4f\146\x42\157\x75\x6e\144\163\105\170\143\x65\x70\x74\151\157\156", "\x66\157\x6f"); try { $this->mock->foo(); } catch (OutOfBoundsException $e) { $this->assertEquals("\146\x6f\157", $e->getMessage()); } } public function testThrowsExceptionSequentially() { $this->mock->shouldReceive("\x66\157\157")->andThrow(new Exception())->andThrow(new OutOfBoundsException()); try { $this->mock->foo(); } catch (Exception $e) { } $this->expectException(OutOfBoundsException::class); $this->mock->foo(); Mockery::close(); } public function testAndThrowExceptions() { $this->mock->shouldReceive("\146\x6f\157")->andThrowExceptions(array(new OutOfBoundsException(), new InvalidArgumentException())); try { $this->mock->foo(); throw new Exception("\x45\x78\160\x65\143\164\145\x64\x20\117\x75\x74\x4f\146\x42\157\165\x6e\144\x73\105\x78\x63\x65\x70\164\151\x6f\x6e\54\40\x6e\157\x6e\x20\x74\x68\162\157\167\x6e"); } catch (\Exception $e) { $this->assertInstanceOf("\x4f\165\x74\x4f\x66\x42\x6f\x75\156\x64\x73\x45\170\x63\145\x70\164\x69\157\x6e", $e, "\x57\162\x6f\x6e\147\x20\157\162\x20\x6e\157\40\145\170\143\x65\160\164\x69\157\156\x20\164\x68\x72\x6f\167\x6e\72\x20{$e->getMessage()}"); } try { $this->mock->foo(); throw new Exception("\105\170\160\145\143\164\145\x64\40\x49\x6e\166\x61\x6c\x69\144\x41\x72\x67\x75\x6d\x65\x6e\164\105\x78\x63\145\x70\164\151\x6f\x6e\x2c\x20\x6e\x6f\156\40\164\x68\x72\x6f\x77\x6e"); } catch (\Exception $e) { $this->assertInstanceOf("\x49\x6e\166\141\154\151\144\x41\162\x67\x75\x6d\145\156\x74\x45\170\x63\x65\x70\x74\151\157\156", $e, "\127\162\x6f\x6e\x67\x20\157\x72\40\156\x6f\x20\x65\170\143\145\160\164\151\x6f\x6e\40\x74\150\x72\x6f\x77\x6e\x3a\40{$e->getMessage()}"); } } public function testAndThrowExceptionsCatchNonExceptionArgument() { $this->expectException(\Mockery\Exception::class); $this->expectExceptionMessage("\x59\x6f\x75\x20\155\x75\x73\x74\x20\x70\x61\x73\x73\40\x61\156\40\141\x72\x72\x61\171\40\x6f\x66\x20\145\170\x63\x65\x70\164\151\157\156\x20\157\x62\152\145\x63\164\163\x20\164\157\40\141\156\x64\124\x68\162\x6f\x77\x45\170\143\145\160\164\x69\x6f\x6e\x73"); $this->mock->shouldReceive("\146\x6f\x6f")->andThrowExceptions(array("\116\x6f\x74\101\x6e\x45\170\x63\145\x70\x74\151\x6f\156")); Mockery::close(); } public function testMultipleExpectationsWithReturns() { $this->mock->shouldReceive("\x66\157\x6f")->with(1)->andReturn(10); $this->mock->shouldReceive("\x62\x61\162")->with(2)->andReturn(20); $this->assertEquals(10, $this->mock->foo(1)); $this->assertEquals(20, $this->mock->bar(2)); } public function testExpectsNoArguments() { $this->mock->shouldReceive("\x66\x6f\x6f")->withNoArgs()->once(); $this->mock->foo(); } public function testExpectsNoArgumentsThrowsExceptionIfAnyPassed() { $this->mock->shouldReceive("\146\x6f\157")->withNoArgs(); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testExpectsArgumentsArray() { $this->mock->shouldReceive("\x66\157\x6f")->withArgs(array(1, 2))->once(); $this->mock->foo(1, 2); } public function testExpectsArgumentsArrayThrowsExceptionIfPassedEmptyArray() { $this->mock->shouldReceive("\x66\157\x6f")->withArgs(array()); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1, 2); Mockery::close(); } public function testExpectsArgumentsArrayThrowsExceptionIfNoArgumentsPassed() { $this->mock->shouldReceive("\146\x6f\157")->with(); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testExpectsArgumentsArrayThrowsExceptionIfPassedWrongArguments() { $this->mock->shouldReceive("\146\157\157")->withArgs(array(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(3, 4); Mockery::close(); } public function testExpectsStringArgumentExceptionMessageDifferentiatesBetweenNullAndEmptyString() { $this->mock->shouldReceive("\146\157\x6f")->withArgs(array("\141\x20\163\x74\162\x69\x6e\147")); $this->expectException(\Mockery\Exception::class); $this->expectExceptionMessageRegEx("\x2f\146\x6f\x6f\134\x28\x4e\125\x4c\114\x5c\x29\x2f"); $this->mock->foo(null); Mockery::close(); } public function testExpectsArgumentsArrayThrowsExceptionIfPassedWrongArgumentType() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessageRegEx("\57\x69\x6e\x76\141\x6c\151\x64\x20\141\x72\x67\165\x6d\x65\x6e\164\x20\50\x2e\53\51\54\x20\157\156\x6c\171\x20\x61\x72\162\x61\171\x20\x61\x6e\x64\40\143\x6c\x6f\x73\165\x72\x65\40\141\x72\x65\x20\141\154\154\x6f\x77\145\x64\x2f"); $this->mock->shouldReceive("\146\x6f\157")->withArgs(5); Mockery::close(); } public function testExpectsArgumentsArrayAcceptAClosureThatValidatesPassedArguments() { $closure = function ($odd, $even) { return $odd % 2 != 0 && $even % 2 == 0; }; $this->mock->shouldReceive("\x66\x6f\157")->withArgs($closure)->once(); $this->mock->foo(1, 2); } public function testExpectsArgumentsArrayThrowsExceptionWhenClosureEvaluatesToFalse() { $closure = function ($odd, $even) { return $odd % 2 != 0 && $even % 2 == 0; }; $this->mock->shouldReceive("\x66\x6f\x6f")->withArgs($closure); $this->expectException(\Mockery\Exception::class); $this->mock->foo(4, 2); Mockery::close(); } public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalArgumentsAreMissing() { $closure = function ($odd, $even, $sum = null) { $result = $odd % 2 != 0 && $even % 2 == 0; if (!is_null($sum)) { return $result && $odd + $even == $sum; } return $result; }; $this->mock->shouldReceive("\x66\x6f\157")->withArgs($closure)->once(); $this->mock->foo(1, 4); } public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalArgumentsMathTheExpectation() { $closure = function ($odd, $even, $sum = null) { $result = $odd % 2 != 0 && $even % 2 == 0; if (!is_null($sum)) { return $result && $odd + $even == $sum; } return $result; }; $this->mock->shouldReceive("\x66\157\157")->withArgs($closure)->once(); $this->mock->foo(1, 4, 5); } public function testExpectsArgumentsArrayClosureThrowsExceptionIfOptionalArgumentsDontMatchTheExpectation() { $closure = function ($odd, $even, $sum = null) { $result = $odd % 2 != 0 && $even % 2 == 0; if (!is_null($sum)) { return $result && $odd + $even == $sum; } return $result; }; $this->mock->shouldReceive("\146\157\x6f")->withArgs($closure); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1, 4, 2); Mockery::close(); } public function testExpectsSomeOfArgumentsMatchRealArguments() { $this->mock->shouldReceive("\x66\x6f\x6f")->withSomeOfArgs(1, 3, 5)->times(4); $this->mock->foo(1, 2, 3, 4, 5); $this->mock->foo(1, 3, 5, 2, 4); $this->mock->foo(1, "\146\157\x6f", 3, "\x62\x61\x72", 5); $this->mock->foo(1, 3, 5); $this->mock->shouldReceive("\x66\x6f\x6f")->withSomeOfArgs("\146\157\157")->times(2); $this->mock->foo("\x66\x6f\x6f", "\142\141\x72"); $this->mock->foo("\x62\x61\x72", "\146\157\157"); } public function testExpectsSomeOfArgumentsGivenArgsDoNotMatchRealArgsAndThrowNoMatchingException() { $this->mock->shouldReceive("\x66\x6f\x6f")->withSomeOfArgs(1, 3, 5); $this->expectException(\Mockery\Exception\NoMatchingExpectationException::class); $this->mock->foo(1, 2, 4, 5); } public function testExpectsAnyArguments() { $this->mock->shouldReceive("\146\x6f\157")->withAnyArgs()->times(3); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, "\x6b", new stdClass()); } public function testExpectsArgumentMatchingObjectType() { $this->mock->shouldReceive("\x66\157\x6f")->with("\134\x73\x74\144\103\154\141\x73\x73")->once(); $this->mock->foo(new stdClass()); } public function testThrowsExceptionOnNoArgumentMatch() { $this->mock->shouldReceive("\x66\157\157")->with(1); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); Mockery::close(); } public function testNeverCalled() { $this->mock->shouldReceive("\x66\157\x6f")->never(); } public function testShouldNotReceive() { $this->mock->shouldNotReceive("\x66\x6f\x6f"); } public function testShouldNotReceiveThrowsExceptionIfMethodCalled() { $this->mock->shouldNotReceive("\146\x6f\157"); $this->expectException(\Mockery\Exception\InvalidCountException::class); $this->mock->foo(); Mockery::close(); } public function testShouldNotReceiveWithArgumentThrowsExceptionIfMethodCalled() { $this->mock->shouldNotReceive("\x66\x6f\x6f")->with(2); $this->expectException(\Mockery\Exception\InvalidCountException::class); $this->mock->foo(2); Mockery::close(); } public function testNeverCalledThrowsExceptionOnCall() { $this->mock->shouldReceive("\x66\x6f\x6f")->never(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledOnce() { $this->mock->shouldReceive("\x66\157\157")->once(); $this->mock->foo(); } public function testCalledOnceThrowsExceptionIfNotCalled() { $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->shouldReceive("\x66\157\157")->once(); Mockery::close(); } public function testCalledOnceThrowsExceptionIfCalledTwice() { $this->mock->shouldReceive("\146\157\157")->once(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledTwice() { $this->mock->shouldReceive("\146\157\157")->twice(); $this->mock->foo(); $this->mock->foo(); } public function testCalledTwiceThrowsExceptionIfNotCalled() { $this->mock->shouldReceive("\x66\x6f\157")->twice(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testCalledOnceThrowsExceptionIfCalledThreeTimes() { $this->mock->shouldReceive("\x66\157\157")->twice(); $this->mock->foo(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledZeroOrMoreTimesAtZeroCalls() { $this->mock->shouldReceive("\146\157\x6f")->zeroOrMoreTimes(); } public function testCalledZeroOrMoreTimesAtThreeCalls() { $this->mock->shouldReceive("\146\157\x6f")->zeroOrMoreTimes(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testTimesCountCalls() { $this->mock->shouldReceive("\x66\x6f\x6f")->times(4); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testTimesCountCallThrowsExceptionOnTooFewCalls() { $this->mock->shouldReceive("\x66\157\157")->times(2); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testTimesCountCallThrowsExceptionOnTooManyCalls() { $this->mock->shouldReceive("\x66\157\x6f")->times(2); $this->mock->foo(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testCalledAtLeastOnceAtExactlyOneCall() { $this->mock->shouldReceive("\146\157\x6f")->atLeast()->once(); $this->mock->foo(); } public function testCalledAtLeastOnceAtExactlyThreeCalls() { $this->mock->shouldReceive("\x66\x6f\x6f")->atLeast()->times(3); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testExpectsStringArgumentCalledAtLeastOnceOverridingDefaultOnceCall() { $this->mock->expects("\x66\157\157")->atLeast()->once(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testExpectsNoArgumentCalledAtLeastOnceOverridingDefaultOnceCall() { $this->mock->expects()->foo()->atLeast()->once(); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testCalledAtLeastThrowsExceptionOnTooFewCalls() { $this->mock->shouldReceive("\146\157\x6f")->atLeast()->twice(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testCalledAtMostOnceAtExactlyOneCall() { $this->mock->shouldReceive("\146\157\x6f")->atMost()->once(); $this->mock->foo(); } public function testCalledAtMostAtExactlyThreeCalls() { $this->mock->shouldReceive("\146\x6f\x6f")->atMost()->times(3); $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); } public function testCalledAtLeastThrowsExceptionOnTooManyCalls() { $this->mock->shouldReceive("\146\x6f\x6f")->atMost()->twice(); $this->mock->foo(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testExactCountersOverrideAnyPriorSetNonExactCounters() { $this->mock->shouldReceive("\x66\157\x6f")->atLeast()->once()->once(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); Mockery::close(); } public function testComboOfLeastAndMostCallsWithOneCall() { $this->mock->shouldReceive("\x66\x6f\157")->atleast()->once()->atMost()->twice(); $this->mock->foo(); } public function testComboOfLeastAndMostCallsWithTwoCalls() { $this->mock->shouldReceive("\x66\x6f\157")->atleast()->once()->atMost()->twice(); $this->mock->foo(); $this->mock->foo(); } public function testComboOfLeastAndMostCallsThrowsExceptionAtTooFewCalls() { $this->mock->shouldReceive("\x66\x6f\x6f")->atleast()->once()->atMost()->twice(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testComboOfLeastAndMostCallsThrowsExceptionAtTooManyCalls() { $this->mock->shouldReceive("\x66\157\157")->atleast()->once()->atMost()->twice(); $this->mock->foo(); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(); $this->mock->foo(); Mockery::close(); } public function testCallCountingOnlyAppliesToMatchedExpectations() { $this->mock->shouldReceive("\x66\157\x6f")->with(1)->once(); $this->mock->shouldReceive("\x66\x6f\157")->with(2)->twice(); $this->mock->shouldReceive("\x66\157\157")->with(3); $this->mock->foo(1); $this->mock->foo(2); $this->mock->foo(2); $this->mock->foo(3); } public function testCallCountingThrowsExceptionOnAnyMismatch() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(1)->once(); $this->mock->shouldReceive("\146\157\157")->with(2)->twice(); $this->mock->shouldReceive("\146\x6f\x6f")->with(3); $this->mock->shouldReceive("\142\x61\162"); $this->mock->foo(1); $this->mock->foo(2); $this->mock->foo(3); $this->mock->bar(); $this->expectException(\Mockery\CountValidator\Exception::class); Mockery::close(); } public function testCallCountingThrowsExceptionFirst() { $number_of_calls = 0; $this->mock->shouldReceive("\146\x6f\x6f")->times(2)->with(\Mockery::on(function ($argument) use(&$number_of_calls) { $number_of_calls++; return $number_of_calls <= 3; })); $this->mock->foo(1); $this->mock->foo(1); $this->expectException(\Mockery\CountValidator\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testOrderedCallsWithoutError() { $this->mock->shouldReceive("\x66\x6f\x6f")->ordered()->once(); $this->mock->shouldReceive("\x62\x61\x72")->ordered()->once(); $this->mock->foo(); $this->mock->bar(); } public function testOrderedCallsWithOutOfOrderError() { $this->mock->shouldReceive("\x66\x6f\157")->ordered(); $this->mock->shouldReceive("\142\141\162")->ordered(); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testDifferentArgumentsAndOrderingsPassWithoutException() { $this->mock->shouldReceive("\146\x6f\x6f")->with(1)->ordered()->once(); $this->mock->shouldReceive("\x66\157\157")->with(2)->ordered()->once(); $this->mock->foo(1); $this->mock->foo(2); } public function testDifferentArgumentsAndOrderingsThrowExceptionWhenInWrongOrder() { $this->mock->shouldReceive("\146\157\157")->with(1)->ordered(); $this->mock->shouldReceive("\x66\157\x6f")->with(2)->ordered(); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); $this->mock->foo(1); Mockery::close(); } public function testUnorderedCallsIgnoredForOrdering() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(1)->ordered()->once(); $this->mock->shouldReceive("\146\157\x6f")->with(2)->times(3); $this->mock->shouldReceive("\x66\157\x6f")->with(3)->ordered()->once(); $this->mock->foo(2); $this->mock->foo(1); $this->mock->foo(2); $this->mock->foo(3); $this->mock->foo(2); } public function testOrderingOfDefaultGrouping() { $this->mock->shouldReceive("\x66\157\x6f")->ordered()->once(); $this->mock->shouldReceive("\142\x61\162")->ordered()->once(); $this->mock->foo(); $this->mock->bar(); } public function testOrderingOfDefaultGroupingThrowsExceptionOnWrongOrder() { $this->mock->shouldReceive("\146\x6f\157")->ordered(); $this->mock->shouldReceive("\x62\141\162")->ordered(); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testOrderingUsingNumberedGroups() { $this->mock->shouldReceive("\x73\x74\x61\x72\x74")->ordered(1)->once(); $this->mock->shouldReceive("\x66\157\x6f")->ordered(2)->once(); $this->mock->shouldReceive("\142\x61\x72")->ordered(2)->twice(); $this->mock->shouldReceive("\146\x69\156\x61\x6c")->ordered()->once(); $this->mock->start(); $this->mock->bar(); $this->mock->foo(); $this->mock->bar(); $this->mock->final(); } public function testOrderingUsingNamedGroups() { $this->mock->shouldReceive("\x73\x74\141\x72\164")->ordered("\x73\x74\x61\162\164")->once(); $this->mock->shouldReceive("\146\157\x6f")->ordered("\146\157\157\142\x61\x72")->once(); $this->mock->shouldReceive("\142\141\162")->ordered("\146\157\157\142\x61\162")->twice(); $this->mock->shouldReceive("\x66\151\x6e\141\154")->ordered()->once(); $this->mock->start(); $this->mock->bar(); $this->mock->foo(); $this->mock->bar(); $this->mock->final(); } public function testGroupedUngroupedOrderingDoNotOverlap() { $s = $this->mock->shouldReceive("\163\164\x61\162\x74")->ordered(); $m = $this->mock->shouldReceive("\155\151\x64")->ordered("\146\x6f\157\x62\141\x72"); $e = $this->mock->shouldReceive("\x65\x6e\144")->ordered(); $this->assertLessThan($m->getOrderNumber(), $s->getOrderNumber()); $this->assertLessThan($e->getOrderNumber(), $m->getOrderNumber()); } public function testGroupedOrderingThrowsExceptionWhenCallsDisordered() { $this->mock->shouldReceive("\146\157\x6f")->ordered("\x66\x69\162\163\x74"); $this->mock->shouldReceive("\x62\x61\162")->ordered("\163\x65\x63\157\x6e\x64"); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testExpectationMatchingWithNoArgsOrderings() { $this->mock->shouldReceive("\x66\157\157")->withNoArgs()->once()->ordered(); $this->mock->shouldReceive("\142\141\162")->withNoArgs()->once()->ordered(); $this->mock->shouldReceive("\146\157\157")->withNoArgs()->once()->ordered(); $this->mock->foo(); $this->mock->bar(); $this->mock->foo(); } public function testExpectationMatchingWithAnyArgsOrderings() { $this->mock->shouldReceive("\146\x6f\157")->withAnyArgs()->once()->ordered(); $this->mock->shouldReceive("\x62\x61\162")->withAnyArgs()->once()->ordered(); $this->mock->shouldReceive("\146\x6f\x6f")->withAnyArgs()->once()->ordered(); $this->mock->foo(); $this->mock->bar(); $this->mock->foo(); } public function testEnsuresOrderingIsNotCrossMockByDefault() { $this->mock->shouldReceive("\x66\x6f\157")->ordered()->once(); $mock2 = mock("\142\x61\x72"); $mock2->shouldReceive("\142\141\162")->ordered()->once(); $mock2->bar(); $this->mock->foo(); } public function testEnsuresOrderingIsCrossMockWhenGloballyFlagSet() { $this->mock->shouldReceive("\x66\x6f\x6f")->globally()->ordered(); $mock2 = mock("\x62\141\x72"); $mock2->shouldReceive("\x62\x61\162")->globally()->ordered(); $this->expectException(\Mockery\Exception::class); $mock2->bar(); $this->mock->foo(); Mockery::close(); } public function testExpectationCastToStringFormatting() { $exp = $this->mock->shouldReceive("\146\x6f\x6f")->with(1, "\x62\141\162", new stdClass(), array("\123\x70\141\155" => "\110\141\x6d", "\102\141\x72" => "\102\141\172")); $this->assertEquals("\133\146\x6f\157\x28\x31\54\x20\47\x62\x61\162\47\54\x20\157\142\x6a\x65\143\164\50\163\164\144\x43\154\141\163\163\51\54\x20\133\x27\x53\x70\x61\x6d\47\40\x3d\76\40\x27\x48\x61\155\47\54\x20\47\102\x61\x72\47\40\75\76\x20\x27\x42\141\172\47\135\51\x5d", (string) $exp); } public function testLongExpectationCastToStringFormatting() { $exp = $this->mock->shouldReceive("\146\157\157")->with(array("\x53\x70\x61\x6d" => "\110\141\x6d", "\x42\x61\162" => "\x42\141\172", "\102\141\x72", "\102\x61\x7a", "\102\x61\x72", "\102\x61\x7a", "\102\x61\x72", "\102\x61\x7a", "\x42\141\x72", "\x42\x61\x7a", "\x42\x61\162", "\102\141\x7a", "\x42\141\162", "\x42\141\x7a", "\x42\x61\x72", "\102\141\x7a", "\102\141\x72", "\x42\x61\x7a", "\x42\141\x72", "\102\141\172", "\102\141\x72", "\102\141\172", "\x42\x61\x72", "\102\x61\x7a", "\x42\141\x72", "\102\141\x7a", "\x42\x61\162", "\x42\141\172", "\102\x61\x72", "\x42\141\x7a", "\x42\141\162", "\102\141\x7a", "\102\141\x72", "\x42\x61\172", "\102\141\x72", "\102\x61\172", "\x42\141\x72", "\102\141\172", "\102\x61\162", "\x42\x61\x7a", "\102\141\x72", "\102\x61\172", "\x42\141\x72", "\x42\141\172", "\102\x61\x72", "\x42\141\172", "\102\x61\x72", "\x42\x61\172", "\x42\141\x7a", "\102\141\162", "\x42\x61\x7a", "\x42\x61\162", "\102\x61\x7a", "\x42\141\162", "\102\141\x7a", "\x42\141\162", "\x42\141\x7a", "\x42\x61\x72", "\102\141\x7a", "\102\x61\x7a", "\102\x61\x72", "\x42\x61\172", "\x42\x61\162", "\x42\x61\x7a", "\x42\x61\x72", "\x42\141\x7a", "\x42\x61\162", "\102\x61\172", "\x42\141\x72", "\102\x61\x7a", "\102\141\172", "\102\x61\x72", "\x42\x61\x7a", "\102\141\x72", "\102\141\172", "\102\x61\162", "\x42\x61\x7a", "\102\x61\162", "\x42\x61\x7a", "\102\141\162", "\x42\x61\172", "\102\141\172", "\x42\141\x72", "\102\x61\172", "\x42\141\162", "\102\x61\x7a", "\102\x61\x72", "\x42\141\x7a", "\102\x61\x72", "\x42\141\172", "\102\141\162", "\102\x61\172", "\x42\141\172", "\x42\141\x72", "\102\141\172", "\x42\x61\162", "\102\x61\x7a", "\x42\141\162", "\102\141\x7a", "\x42\141\x72", "\x42\x61\172", "\102\x61\x72", "\x42\141\172", "\x42\141\x7a", "\x42\141\162", "\x42\x61\x7a", "\x42\x61\162", "\102\x61\172", "\102\141\x72", "\102\x61\x7a", "\x42\x61\162", "\x42\x61\x7a", "\x42\x61\x72", "\x42\141\x7a", "\x42\141\172", "\x42\x61\x72", "\x42\141\x7a", "\102\x61\x72", "\102\x61\x7a", "\102\141\162", "\102\x61\x7a", "\x42\x61\x72", "\x42\141\x7a", "\x42\x61\162", "\x42\x61\172", "\102\141\172", "\x42\141\162", "\102\x61\172", "\x42\x61\x72", "\x42\x61\172", "\102\x61\x72", "\102\141\172", "\102\x61\162", "\102\x61\172", "\102\141\x72", "\x42\141\x7a", "\x42\141\x7a", "\x42\x61\162", "\102\x61\172", "\x42\x61\x72", "\102\141\172", "\x42\x61\x72", "\102\x61\x7a", "\102\x61\162", "\102\x61\172", "\102\x61\x72", "\102\x61\x7a", "\105\x6e\x64")); $this->assertEquals("\x5b\146\x6f\x6f\x28\133\x27\x53\x70\141\x6d\x27\40\x3d\x3e\x20\47\x48\x61\x6d\47\x2c\x20\x27\102\141\x72\x27\40\75\76\x20\47\x42\x61\x7a\47\54\40\x30\x20\75\x3e\x20\47\102\x61\x72\x27\x2c\x20\x31\x20\75\76\40\x27\x42\x61\x7a\x27\54\40\62\x20\75\x3e\40\x27\x42\x61\x72\47\54\x20\63\x20\x3d\76\x20\x27\102\141\172\x27\x2c\x20\x34\40\x3d\76\40\x27\x42\141\162\x27\x2c\x20\x35\40\x3d\x3e\40\x27\102\x61\172\x27\x2c\x20\x36\40\x3d\76\x20\x27\x42\x61\162\x27\54\x20\x37\40\75\x3e\40\47\102\x61\x7a\47\54\40\x38\x20\x3d\76\x20\x27\x42\x61\x72\x27\x2c\40\71\40\x3d\76\40\47\x42\141\x7a\47\54\40\61\60\40\x3d\76\x20\x27\102\141\x72\x27\x2c\40\61\61\40\x3d\76\x20\47\x42\x61\172\x27\x2c\x20\x31\62\x20\75\x3e\40\47\102\x61\162\47\54\x20\61\x33\40\75\76\40\47\x42\x61\x7a\47\54\40\61\x34\40\75\x3e\x20\x27\102\x61\x72\x27\x2c\40\61\x35\x20\x3d\76\x20\x27\x42\x61\172\47\x2c\40\x31\66\40\75\76\40\x27\x42\x61\x72\47\54\x20\x31\67\x20\75\x3e\40\47\x42\141\172\47\54\x20\61\70\x20\75\76\40\47\x42\x61\162\x27\x2c\x20\61\71\x20\x3d\76\40\x27\102\141\x7a\x27\x2c\40\x32\x30\x20\75\76\x20\47\102\141\x72\x27\54\x20\x32\61\x20\75\x3e\x20\x27\102\x61\172\x27\x2c\x20\x32\x32\40\x3d\76\40\47\x42\x61\x72\47\x2c\40\x32\x33\x20\x3d\x3e\40\x27\x42\x61\172\47\54\40\62\64\40\75\76\40\47\102\x61\x72\x27\x2c\x20\x32\x35\x20\75\76\40\47\x42\141\172\47\x2c\x20\x32\66\x20\x3d\x3e\x20\x27\102\x61\162\47\x2c\40\62\67\40\75\x3e\x20\x27\102\x61\172\47\54\40\x32\70\x20\75\x3e\x20\47\x42\141\x72\x27\54\x20\x32\x39\x20\x3d\76\x20\47\x42\x61\172\47\x2c\x20\63\60\x20\x3d\x3e\x20\47\102\141\x72\x27\54\40\x33\x31\40\x3d\76\x20\47\x42\x61\172\x27\x2c\40\x33\62\x20\x3d\x3e\40\x27\102\x61\162\x27\54\x20\63\63\x20\75\76\40\x27\102\x61\172\x27\54\x20\x33\64\40\75\76\40\47\x42\141\162\x27\54\40\x33\x35\40\x3d\x3e\x20\x27\x42\141\x7a\47\54\x20\x33\x36\x20\75\x3e\x20\x27\x42\x61\162\x27\x2c\40\63\67\40\75\x3e\x20\x27\102\x61\172\47\x2c\x20\63\x38\x20\75\x3e\40\x27\x42\x61\162\47\x2c\40\63\x39\x20\x3d\x3e\40\47\102\x61\x7a\x27\54\x20\x34\60\40\75\x3e\x20\x27\102\141\162\47\54\40\x34\x31\40\x3d\x3e\40\47\x42\x61\x7a\x27\x2c\x20\x34\x32\x20\75\x3e\x20\47\x42\x61\162\47\54\x20\64\x33\x20\75\76\x20\x27\x42\x61\172\x27\x2c\x20\x34\64\40\x3d\76\40\x27\x42\141\162\x27\x2c\40\64\65\40\x3d\x3e\x20\47\102\x61\172\47\54\x20\64\66\40\75\76\40\47\102\141\172\47\54\40\x34\x37\x20\x3d\x3e\40\47\x42\x61\x72\47\x2c\x20\64\x38\x20\x3d\x3e\x20\47\102\141\172\x27\54\40\64\71\x20\x3d\x3e\40\x27\x42\141\x72\x27\54\x20\65\x30\x20\x3d\76\40\47\102\x61\x7a\47\54\x20\x35\x31\x20\75\x3e\40\47\102\x61\162\47\54\40\65\62\40\x3d\x3e\40\x27\102\x61\172\47\x2c\40\x35\63\x20\75\76\40\x27\102\141\x72\47\54\x20\x35\64\x20\75\x3e\40\47\x42\141\172\x27\54\40\x35\x35\40\x3d\x3e\40\x27\102\141\162\x27\x2c\40\65\66\x20\x3d\76\x20\47\x42\x61\172\47\x2c\x20\65\67\40\x3d\76\40\47\102\141\172\47\54\40\x35\70\x20\75\76\x20\x27\102\141\x72\x27\54\40\x35\x39\40\x3d\76\40\x27\x42\141\x7a\47\54\x20\x36\60\40\x3d\x3e\x20\47\102\141\x72\47\54\x20\x36\x31\40\75\x3e\x20\47\102\141\172\x27\x2c\x20\x36\62\x20\x3d\76\x20\47\102\x61\162\x27\54\x20\66\x33\40\x3d\x3e\40\x27\x42\x61\x7a\47\x2c\40\x36\x34\40\x3d\x3e\x20\47\102\141\162\x27\54\x20\x36\65\40\75\x3e\40\47\x42\141\x7a\47\x2c\x20\66\66\x20\x3d\76\x20\47\102\141\x72\47\x2c\40\66\x37\x20\x3d\76\x20\x27\x42\x61\172\47\x2c\40\x36\70\40\75\76\40\x27\102\x61\x7a\47\54\40\x36\71\x20\75\x3e\40\47\102\x61\x72\x27\54\x20\x37\60\x20\75\x3e\x20\47\x42\141\x7a\47\x2c\40\67\x31\x20\x3d\x3e\40\47\102\141\x72\47\54\x20\x37\62\x20\75\76\x20\47\x42\x61\172\x27\x2c\40\x37\63\40\x3d\76\40\x27\x42\141\162\x27\x2c\x20\x37\x34\40\75\x3e\40\47\x42\x61\x7a\47\54\x20\67\56\56\56\135\51\135", (string) $exp); } public function testMultipleExpectationCastToStringFormatting() { $exp = $this->mock->shouldReceive("\146\x6f\x6f", "\x62\x61\162")->with(1); $this->assertEquals("\x5b\146\x6f\157\x28\61\51\54\40\142\141\x72\50\x31\x29\135", (string) $exp); } public function testGroupedOrderingWithLimitsAllowsMultipleReturnValues() { $this->mock->shouldReceive("\146\157\157")->with(2)->once()->andReturn("\146\151\x72\163\164"); $this->mock->shouldReceive("\146\157\157")->with(2)->twice()->andReturn("\x73\145\x63\157\x6e\144\57\164\150\x69\x72\144"); $this->mock->shouldReceive("\146\157\157")->with(2)->andReturn("\x69\x6e\146\x69\156\151\x74\x79"); $this->assertEquals("\x66\151\162\x73\164", $this->mock->foo(2)); $this->assertEquals("\x73\x65\143\x6f\156\144\57\164\x68\x69\x72\x64", $this->mock->foo(2)); $this->assertEquals("\x73\x65\x63\x6f\156\144\x2f\164\x68\x69\162\x64", $this->mock->foo(2)); $this->assertEquals("\x69\156\x66\x69\x6e\x69\x74\x79", $this->mock->foo(2)); $this->assertEquals("\x69\x6e\146\151\x6e\x69\x74\171", $this->mock->foo(2)); $this->assertEquals("\151\156\x66\x69\x6e\151\x74\x79", $this->mock->foo(2)); } public function testExpectationsCanBeMarkedAsDefaults() { $this->mock->shouldReceive("\x66\157\157")->andReturn("\x62\141\x72")->byDefault(); $this->assertEquals("\x62\141\162", $this->mock->foo()); } public function testDefaultExpectationsValidatedInCorrectOrder() { $this->mock->shouldReceive("\x66\x6f\157")->with(1)->once()->andReturn("\146\x69\162\163\164")->byDefault(); $this->mock->shouldReceive("\146\x6f\x6f")->with(2)->once()->andReturn("\x73\145\x63\157\x6e\x64")->byDefault(); $this->assertEquals("\x66\x69\162\x73\x74", $this->mock->foo(1)); $this->assertEquals("\x73\x65\143\x6f\156\x64", $this->mock->foo(2)); } public function testDefaultExpectationsAreReplacedByLaterConcreteExpectations() { $this->mock->shouldReceive("\146\157\157")->andReturn("\x62\141\x72")->once()->byDefault(); $this->mock->shouldReceive("\146\157\x6f")->andReturn("\142\141\x7a")->twice(); $this->assertEquals("\x62\x61\x7a", $this->mock->foo()); $this->assertEquals("\x62\141\x7a", $this->mock->foo()); } public function testExpectationFallsBackToDefaultExpectationWhenConcreteExpectationsAreUsedUp() { $this->mock->shouldReceive("\146\157\x6f")->with(1)->andReturn("\x62\x61\162")->once()->byDefault(); $this->mock->shouldReceive("\x66\157\x6f")->with(2)->andReturn("\142\141\x7a")->once(); $this->assertEquals("\142\141\172", $this->mock->foo(2)); $this->assertEquals("\x62\141\162", $this->mock->foo(1)); } public function testDefaultExpectationsCanBeOrdered() { $this->mock->shouldReceive("\x66\157\157")->ordered()->byDefault(); $this->mock->shouldReceive("\x62\141\x72")->ordered()->byDefault(); $this->expectException(\Mockery\Exception::class); $this->mock->bar(); $this->mock->foo(); Mockery::close(); } public function testDefaultExpectationsCanBeOrderedAndReplaced() { $this->mock->shouldReceive("\x66\x6f\157")->ordered()->byDefault(); $this->mock->shouldReceive("\142\141\x72")->ordered()->byDefault(); $this->mock->shouldReceive("\x62\x61\x72")->ordered()->once(); $this->mock->shouldReceive("\x66\157\x6f")->ordered()->once(); $this->mock->bar(); $this->mock->foo(); } public function testByDefaultOperatesFromMockConstruction() { $container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader()); $mock = $container->mock("\146", array("\x66\157\157" => "\x72\146\x6f\x6f", "\142\x61\162" => "\162\142\x61\x72", "\142\x61\172" => "\162\142\x61\172"))->byDefault(); $mock->shouldReceive("\146\x6f\x6f")->andReturn("\x66\x6f\x6f\x62\x61\162"); $this->assertEquals("\146\157\157\x62\141\x72", $mock->foo()); $this->assertEquals("\x72\x62\141\x72", $mock->bar()); $this->assertEquals("\162\142\141\172", $mock->baz()); } public function testByDefaultOnAMockDoesSquatWithoutExpectations() { $this->assertInstanceOf(MockInterface::class, mock("\x66")->byDefault()); } public function testDefaultExpectationsCanBeOverridden() { $this->mock->shouldReceive("\x66\x6f\157")->with("\x74\x65\x73\164")->andReturn("\142\141\x72")->byDefault(); $this->mock->shouldReceive("\x66\157\x6f")->with("\x74\x65\x73\164")->andReturn("\156\x65\x77\x62\x61\162")->byDefault(); $this->mock->foo("\x74\x65\x73\164"); $this->assertEquals("\x6e\145\167\x62\x61\162", $this->mock->foo("\164\145\x73\164")); } public function testByDefaultPreventedFromSettingDefaultWhenDefaultingExpectationWasReplaced() { $exp = $this->mock->shouldReceive("\x66\x6f\157")->andReturn(1); $this->mock->shouldReceive("\146\x6f\x6f")->andReturn(2); $this->expectException(\Mockery\Exception::class); $exp->byDefault(); Mockery::close(); } public function testAnyConstraintMatchesAnyArg() { $this->mock->shouldReceive("\x66\157\x6f")->with(1, Mockery::any())->twice(); $this->mock->foo(1, 2); $this->mock->foo(1, "\163\x74\162"); } public function testAnyConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\x6f")->times(3); $this->mock->shouldReceive("\146\157\x6f")->with(1, Mockery::any())->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testAndAnyOtherConstraintMatchesTheRestOfTheArguments() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(1, 2, Mockery::andAnyOthers())->twice(); $this->mock->foo(1, 2, 3, 4, 5); $this->mock->foo(1, 2, "\163\x74\x72", 3, 4); } public function testAndAnyOtherConstraintDoesNotPreventMatchingOfRegularArguments() { $this->mock->shouldReceive("\x66\157\157")->with(1, 2, Mockery::andAnyOthers()); $this->expectException(\Mockery\Exception::class); $this->mock->foo(10, 2, 3, 4, 5); Mockery::close(); } public function testAndAnyOtherConstraintMultipleExpectationsButNoOthers() { $this->mock->shouldReceive("\x66\x6f\157")->with("\141", Mockery::andAnyOthers())->andReturn("\141"); $this->mock->shouldReceive("\146\157\x6f")->with("\x62", Mockery::andAnyOthers())->andReturn("\142"); $this->assertEquals("\x61", $this->mock->foo("\141")); $this->assertEquals("\142", $this->mock->foo("\x62")); } public function testArrayConstraintMatchesArgument() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\x61\162\162\141\171"))->once(); $this->mock->foo(array()); } public function testArrayConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\157\157")->times(3); $this->mock->shouldReceive("\146\157\x6f")->with(1, Mockery::type("\141\162\162\x61\171"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testArrayConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(Mockery::type("\x61\162\162\141\x79")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testBoolConstraintMatchesArgument() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::type("\x62\157\x6f\154"))->once(); $this->mock->foo(true); } public function testBoolConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\x6f")->times(3); $this->mock->shouldReceive("\146\x6f\157")->with(1, Mockery::type("\142\157\x6f\154"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testBoolConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::type("\x62\157\157\x6c")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testCallableConstraintMatchesArgument() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\x63\x61\x6c\x6c\141\142\154\x65"))->once(); $this->mock->foo(function () { return "\146"; }); } public function testCallableConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\157")->times(3); $this->mock->shouldReceive("\146\x6f\157")->with(1, Mockery::type("\x63\x61\x6c\x6c\x61\x62\154\145"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testCallableConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\x63\x61\154\154\141\x62\154\x65")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testDoubleConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\157\157")->with(Mockery::type("\x64\x6f\165\142\154\x65"))->once(); $this->mock->foo(2.25); } public function testDoubleConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\157\157")->times(3); $this->mock->shouldReceive("\x66\157\x6f")->with(1, Mockery::type("\x64\x6f\x75\142\x6c\x65"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testDoubleConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\x64\x6f\x75\142\x6c\145")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testFloatConstraintMatchesArgument() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\x66\154\157\x61\164"))->once(); $this->mock->foo(2.25); } public function testFloatConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\x6f")->times(3); $this->mock->shouldReceive("\146\x6f\157")->with(1, Mockery::type("\146\154\x6f\141\x74"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testFloatConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::type("\146\154\x6f\141\164")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testIntConstraintMatchesArgument() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::type("\151\x6e\164"))->once(); $this->mock->foo(2); } public function testIntConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\x6f\x6f")->times(3); $this->mock->shouldReceive("\x66\157\x6f")->with(1, Mockery::type("\x69\x6e\164"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testIntConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\151\156\164")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\146"); Mockery::close(); } public function testLongConstraintMatchesArgument() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::type("\x6c\157\x6e\147"))->once(); $this->mock->foo(2); } public function testLongConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\x6f")->times(3); $this->mock->shouldReceive("\146\x6f\157")->with(1, Mockery::type("\x6c\x6f\x6e\x67"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testLongConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::type("\x6c\x6f\156\x67")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\x66"); Mockery::close(); } public function testNullConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::type("\x6e\165\154\x6c"))->once(); $this->mock->foo(null); } public function testNullConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\157\x6f")->times(3); $this->mock->shouldReceive("\x66\157\157")->with(1, Mockery::type("\156\165\154\x6c"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testNullConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\157")->with(Mockery::type("\x6e\165\154\154")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\146"); Mockery::close(); } public function testNumericConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\x6f\157")->with(Mockery::type("\156\165\155\x65\162\151\x63"))->once(); $this->mock->foo("\x32"); } public function testNumericConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\157\x6f")->times(3); $this->mock->shouldReceive("\146\x6f\157")->with(1, Mockery::type("\x6e\165\155\145\162\151\143"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testNumericConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::type("\x6e\x75\155\145\162\151\143")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\x66"); Mockery::close(); } public function testObjectConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::type("\x6f\142\x6a\145\x63\164"))->once(); $this->mock->foo(new stdClass()); } public function testObjectConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\157\157")->times(3); $this->mock->shouldReceive("\146\157\157")->with(1, Mockery::type("\157\x62\x6a\145\x63\x74\x60"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testObjectConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::type("\157\142\x6a\x65\143\x74")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\146"); Mockery::close(); } public function testRealConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::type("\146\x6c\x6f\141\x74"))->once(); $this->mock->foo(2.25); } public function testRealConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\157\x6f")->times(3); $this->mock->shouldReceive("\x66\157\157")->with(1, Mockery::type("\146\154\157\x61\x74"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testRealConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::type("\x66\x6c\157\x61\x74")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\146"); Mockery::close(); } public function testResourceConstraintMatchesArgument() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::type("\x72\x65\x73\157\x75\162\143\145"))->once(); $r = fopen(dirname(__FILE__) . "\57\x5f\x66\x69\154\x65\163\x2f\146\x69\x6c\145\x2e\x74\x78\x74", "\162"); $this->mock->foo($r); } public function testResourceConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\x6f\157")->times(3); $this->mock->shouldReceive("\x66\157\157")->with(1, Mockery::type("\x72\145\x73\x6f\165\x72\x63\x65"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testResourceConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::type("\x72\145\163\x6f\x75\x72\143\x65")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\x66"); Mockery::close(); } public function testScalarConstraintMatchesArgument() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::type("\x73\x63\141\x6c\141\x72"))->once(); $this->mock->foo(2); } public function testScalarConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\157\157")->times(3); $this->mock->shouldReceive("\146\x6f\x6f")->with(1, Mockery::type("\x73\x63\141\154\141\162"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testScalarConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\157")->with(Mockery::type("\163\143\x61\154\141\x72")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array()); Mockery::close(); } public function testStringConstraintMatchesArgument() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\x73\x74\162\151\x6e\147"))->once(); $this->mock->foo("\62"); } public function testStringConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\157")->times(3); $this->mock->shouldReceive("\x66\157\157")->with(1, Mockery::type("\x73\x74\x72\151\156\x67"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testStringConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::type("\163\164\162\x69\x6e\x67")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(1); Mockery::close(); } public function testClassConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\x6f\157")->with(Mockery::type("\163\x74\144\x43\154\141\x73\x73"))->once(); $this->mock->foo(new stdClass()); } public function testClassConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\157\157")->times(3); $this->mock->shouldReceive("\x66\157\157")->with(1, Mockery::type("\x73\164\144\103\154\141\x73\163"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testClassConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::type("\x73\164\144\103\154\141\x73\x73")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(new Exception()); Mockery::close(); } public function testDucktypeConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::ducktype("\x71\x75\x61\143\x6b", "\x73\x77\x69\155"))->once(); $this->mock->foo(new Mockery_Duck()); } public function testDucktypeConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\x6f\x6f")->times(3); $this->mock->shouldReceive("\x66\x6f\x6f")->with(1, Mockery::ducktype("\x71\x75\x61\143\x6b", "\x73\x77\151\x6d"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testDucktypeConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(Mockery::ducktype("\x71\165\x61\x63\153", "\163\x77\x69\155")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(new Mockery_Duck_Nonswimmer()); Mockery::close(); } public function testArrayContentConstraintMatchesArgument() { $this->mock->shouldReceive("\146\x6f\157")->with(Mockery::subset(array("\x61" => 1, "\142" => 2)))->once(); $this->mock->foo(array("\141" => 1, "\142" => 2, "\143" => 3)); } public function testArrayContentConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\x6f")->times(3); $this->mock->shouldReceive("\146\x6f\x6f")->with(1, Mockery::subset(array("\x61" => 1, "\x62" => 2)))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testArrayContentConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\157")->with(Mockery::subset(array("\x61" => 1, "\142" => 2))); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("\x61" => 1, "\143" => 3)); Mockery::close(); } public function testContainsConstraintMatchesArgument() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::contains(1, 2))->once(); $this->mock->foo(array("\x61" => 1, "\x62" => 2, "\x63" => 3)); } public function testContainsConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\x6f\x6f")->times(3); $this->mock->shouldReceive("\x66\157\157")->with(1, Mockery::contains(1, 2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testContainsConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::contains(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("\x61" => 1, "\x63" => 3)); Mockery::close(); } public function testHasKeyConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::hasKey("\143"))->once(); $this->mock->foo(array("\x61" => 1, "\142" => 2, "\143" => 3)); } public function testHasKeyConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\157\x6f")->times(3); $this->mock->shouldReceive("\x66\157\157")->with(1, Mockery::hasKey("\141"))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, array("\x61" => 1), 3); } public function testHasKeyConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::hasKey("\x63")); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("\141" => 1, "\x62" => 3)); Mockery::close(); } public function testHasValueConstraintMatchesArgument() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::hasValue(1))->once(); $this->mock->foo(array("\141" => 1, "\x62" => 2, "\x63" => 3)); } public function testHasValueConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\157\157")->times(3); $this->mock->shouldReceive("\x66\x6f\x6f")->with(1, Mockery::hasValue(1))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, array("\141" => 1), 3); } public function testHasValueConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\x66\x6f\157")->with(Mockery::hasValue(2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(array("\x61" => 1, "\142" => 3)); Mockery::close(); } public function testCaptureStoresArgumentOfTypeScalar_ClosureEvaluatesToTrue() { $temp = null; $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::capture($temp))->once(); $this->mock->foo(4); $this->assertSame(4, $temp); } public function testCaptureStoresArgumentOfTypeArgument_ClosureEvaluatesToTrue() { $object = new stdClass(); $temp = null; $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::capture($temp))->once(); $this->mock->foo($object); $this->assertSame($object, $temp); } public function testOnConstraintMatchesArgument_ClosureEvaluatesToTrue() { $function = function ($arg) { return $arg % 2 == 0; }; $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::on($function))->once(); $this->mock->foo(4); } public function testOnConstraintMatchesArgumentOfTypeArray_ClosureEvaluatesToTrue() { $function = function ($arg) { return is_array($arg); }; $this->mock->shouldReceive("\x66\x6f\157")->with(Mockery::on($function))->once(); $this->mock->foo(array(4, 5)); } public function testOnConstraintThrowsExceptionWhenConstraintUnmatched_ClosureEvaluatesToFalse() { $function = function ($arg) { return $arg % 2 == 0; }; $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::on($function)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(5); Mockery::close(); } public function testMustBeConstraintMatchesArgument() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::mustBe(2))->once(); $this->mock->foo(2); } public function testMustBeConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\x6f\x6f")->times(3); $this->mock->shouldReceive("\146\x6f\157")->with(1, Mockery::mustBe(2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\x6f\157")->with(Mockery::mustBe(2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\62"); Mockery::close(); } public function testMustBeConstraintMatchesObjectArgumentWithEqualsComparisonNotIdentical() { $a = new stdClass(); $a->foo = 1; $b = new stdClass(); $b->foo = 1; $this->mock->shouldReceive("\x66\157\157")->with(Mockery::mustBe($a))->once(); $this->mock->foo($b); } public function testMustBeConstraintNonMatchingCaseWithObject() { $a = new stdClass(); $a->foo = 1; $this->mock->shouldReceive("\x66\x6f\x6f")->times(3); $this->mock->shouldReceive("\146\157\x6f")->with(1, Mockery::mustBe($a))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, $a, 3); } public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatchedWithObject() { $a = new stdClass(); $a->foo = 1; $b = new stdClass(); $b->foo = 2; $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::mustBe($a)); $this->expectException(\Mockery\Exception::class); $this->mock->foo($b); Mockery::close(); } public function testMatchPrecedenceBasedOnExpectedCallsFavouringExplicitMatch() { $this->mock->shouldReceive("\146\157\x6f")->with(1)->once(); $this->mock->shouldReceive("\146\157\157")->with(Mockery::any())->never(); $this->mock->foo(1); } public function testMatchPrecedenceBasedOnExpectedCallsFavouringAnyMatch() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(Mockery::any())->once(); $this->mock->shouldReceive("\146\x6f\x6f")->with(1)->never(); $this->mock->foo(1); } public function testReturnNullIfIgnoreMissingMethodsSet() { $this->mock->shouldIgnoreMissing(); $this->assertNull($this->mock->g(1, 2)); } public function testReturnUndefinedIfIgnoreMissingMethodsSet() { $this->mock->shouldIgnoreMissing()->asUndefined(); $this->assertInstanceOf(\Mockery\Undefined::class, $this->mock->g(1, 2)); } public function testReturnAsUndefinedAllowsForInfiniteSelfReturningChain() { $this->mock->shouldIgnoreMissing()->asUndefined(); $this->assertInstanceOf(\Mockery\Undefined::class, $this->mock->g(1, 2)->a()->b()->c()); } public function testShouldIgnoreMissingFluentInterface() { $this->assertInstanceOf(\Mockery\MockInterface::class, $this->mock->shouldIgnoreMissing()); } public function testShouldIgnoreMissingAsUndefinedFluentInterface() { $this->assertInstanceOf(\Mockery\MockInterface::class, $this->mock->shouldIgnoreMissing()->asUndefined()); } public function testShouldIgnoreMissingAsDefinedProxiesToUndefinedAllowingToString() { $this->mock->shouldIgnoreMissing()->asUndefined(); $this->assertTrue(is_string("{$this->mock->g()}")); $this->assertTrue(is_string("{$this->mock}")); } public function testShouldIgnoreMissingDefaultReturnValue() { $this->mock->shouldIgnoreMissing(1); $this->assertEquals(1, $this->mock->a()); } public function testShouldIgnoreMissingDefaultSelfAndReturnsSelf() { $this->mock->shouldIgnoreMissing(\Mockery::self()); $this->assertSame($this->mock, $this->mock->a()->b()); } public function testToStringMagicMethodCanBeMocked() { $this->mock->shouldReceive("\x5f\137\164\x6f\x53\x74\162\x69\x6e\147")->andReturn("\x64\141\166\145"); $this->assertEquals("{$this->mock}", "\144\141\166\x65"); } public function testOptionalMockRetrieval() { $m = mock("\x66")->shouldReceive("\x66\157\157")->with(1)->andReturn(3)->mock(); $this->assertInstanceOf(\Mockery\MockInterface::class, $m); } public function testNotConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(Mockery::not(1))->once(); $this->mock->foo(2); } public function testNotConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\x6f\157")->times(3); $this->mock->shouldReceive("\146\x6f\157")->with(1, Mockery::not(2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testNotConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::not(2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); Mockery::close(); } public function testAnyOfConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\x6f\157")->with(Mockery::anyOf(1, 2))->twice(); $this->mock->foo(2); $this->mock->foo(1); } public function testAnyOfConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\157\x6f")->times(3); $this->mock->shouldReceive("\x66\157\x6f")->with(1, Mockery::anyOf(1, 2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); } public function testAnyOfConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(Mockery::anyOf(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(3); Mockery::close(); } public function testAnyOfConstraintThrowsExceptionWhenTrueIsNotAnExpectedArgument() { $this->mock->shouldReceive("\146\x6f\157")->with(Mockery::anyOf(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(true); } public function testAnyOfConstraintThrowsExceptionWhenFalseIsNotAnExpectedArgument() { $this->mock->shouldReceive("\146\x6f\157")->with(Mockery::anyOf(0, 1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(false); } public function testNotAnyOfConstraintMatchesArgument() { $this->mock->shouldReceive("\146\x6f\x6f")->with(Mockery::notAnyOf(1, 2))->once(); $this->mock->foo(3); } public function testNotAnyOfConstraintNonMatchingCase() { $this->mock->shouldReceive("\146\157\x6f")->times(3); $this->mock->shouldReceive("\146\x6f\x6f")->with(1, Mockery::notAnyOf(1, 2))->never(); $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 4, 3); } public function testNotAnyOfConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\146\157\157")->with(Mockery::notAnyOf(1, 2)); $this->expectException(\Mockery\Exception::class); $this->mock->foo(2); Mockery::close(); } public function testPatternConstraintMatchesArgument() { $this->mock->shouldReceive("\x66\x6f\x6f")->with(Mockery::pattern("\57\146\x6f\157\x2e\x2a\57"))->once(); $this->mock->foo("\146\157\x6f\x62\x61\x72"); } public function testPatternConstraintNonMatchingCase() { $this->mock->shouldReceive("\x66\157\157")->once(); $this->mock->shouldReceive("\146\157\x6f")->with(Mockery::pattern("\57\146\157\x6f\x2e\52\57"))->never(); $this->mock->foo("\142\x61\x72"); } public function testPatternConstraintThrowsExceptionWhenConstraintUnmatched() { $this->mock->shouldReceive("\x66\157\x6f")->with(Mockery::pattern("\x2f\x66\157\x6f\x2e\x2a\57")); $this->expectException(\Mockery\Exception::class); $this->mock->foo("\142\x61\162"); Mockery::close(); } public function testGlobalConfigMayForbidMockingNonExistentMethodsOnClasses() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $mock = mock("\x73\164\144\103\154\x61\163\x73"); $this->expectException(\Mockery\Exception::class); $mock->shouldReceive("\x66\x6f\x6f"); Mockery::close(); } public function testGlobalConfigMayForbidMockingNonExistentMethodsOnAutoDeclaredClasses() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $this->expectException(\Mockery\Exception::class); $this->expectExceptionMessage("\x4d\157\143\153\145\162\x79\x20\x63\141\x6e\47\164\40\146\x69\156\x64\x20\x27\123\x6f\x6d\x65\115\141\144\145\x55\x70\x43\x6c\x61\163\x73\47\x20\x73\x6f\40\x63\x61\156\x27\164\40\x6d\157\143\x6b\x20\151\x74"); $mock = mock("\x53\157\x6d\145\x4d\141\x64\145\x55\x70\103\x6c\x61\163\163"); $mock->shouldReceive("\146\157\x6f"); Mockery::close(); } public function testGlobalConfigMayForbidMockingNonExistentMethodsOnObjects() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $mock = mock(new stdClass()); $this->expectException(\Mockery\Exception::class); $mock->shouldReceive("\x66\x6f\x6f"); Mockery::close(); } public function testGlobalConfigQuickDefinitionsConfigurationDefaultExpectation() { \Mockery::getConfiguration()->getQuickDefinitions()->shouldBeCalledAtLeastOnce(false); mock(array("\146\x6f\x6f" => 1)); $this->expectNotToPerformAssertions(); Mockery::close(); } public function testGlobalConfigQuickDefinitionsConfigurationMockAtLeastOnce() { \Mockery::getConfiguration()->getQuickDefinitions()->shouldBeCalledAtLeastOnce(true); mock(array("\x66\x6f\x6f" => 1)); $this->expectException(\Mockery\Exception\InvalidCountException::class); Mockery::close(); } public function testAnExampleWithSomeExpectationAmends() { $service = mock("\115\171\x53\x65\162\x76\151\x63\x65"); $service->shouldReceive("\154\x6f\147\151\x6e")->with("\x75\163\145\162", "\x70\x61\x73\163")->once()->andReturn(true); $service->shouldReceive("\150\141\163\x42\x6f\157\x6b\155\141\162\153\x73\x54\x61\147\147\145\x64")->with("\160\x68\x70")->once()->andReturn(false); $service->shouldReceive("\141\x64\144\x42\157\x6f\x6b\155\x61\162\153")->with(Mockery::pattern("\x2f\x5e\150\x74\x74\x70\x3a\57"), \Mockery::type("\163\x74\162\151\156\147"))->times(3)->andReturn(true); $service->shouldReceive("\150\141\163\x42\157\157\x6b\155\x61\162\x6b\163\124\x61\x67\147\145\x64")->with("\160\x68\160")->once()->andReturn(true); $this->assertTrue($service->login("\165\x73\x65\162", "\x70\x61\x73\163")); $this->assertFalse($service->hasBookmarksTagged("\x70\150\x70")); $this->assertTrue($service->addBookmark("\x68\x74\x74\160\72\x2f\x2f\145\170\141\155\x70\x6c\145\x2e\x63\157\x6d\57\x31", "\163\157\x6d\x65\x5f\x74\x61\x67\x31")); $this->assertTrue($service->addBookmark("\x68\x74\x74\x70\x3a\57\57\x65\170\x61\x6d\x70\x6c\145\56\143\x6f\155\57\62", "\x73\157\155\145\137\x74\141\147\x32")); $this->assertTrue($service->addBookmark("\x68\164\x74\160\x3a\x2f\57\x65\170\141\155\x70\154\x65\56\x63\157\x6d\x2f\x33", "\163\157\x6d\x65\137\164\141\x67\63")); $this->assertTrue($service->hasBookmarksTagged("\160\x68\160")); } public function testAnExampleWithSomeExpectationAmendsOnCallCounts() { $service = mock("\115\x79\x53\x65\x72\166\x69\x63\x65"); $service->shouldReceive("\154\x6f\147\151\x6e")->with("\x75\163\145\162", "\x70\x61\x73\163")->once()->andReturn(true); $service->shouldReceive("\150\141\x73\102\x6f\157\153\155\141\x72\153\163\x54\141\x67\x67\x65\144")->with("\x70\150\x70")->once()->andReturn(false); $service->shouldReceive("\x61\x64\144\x42\157\157\153\155\141\x72\x6b")->with(Mockery::pattern("\x2f\x5e\x68\x74\x74\x70\72\57"), \Mockery::type("\x73\164\162\x69\x6e\147"))->times(3)->andReturn(true); $service->shouldReceive("\x68\x61\163\x42\157\x6f\153\x6d\x61\162\153\x73\x54\x61\x67\147\x65\144")->with("\x70\150\160")->twice()->andReturn(true); $this->assertTrue($service->login("\x75\163\145\x72", "\x70\141\x73\x73")); $this->assertFalse($service->hasBookmarksTagged("\160\150\160")); $this->assertTrue($service->addBookmark("\x68\164\164\x70\72\57\x2f\x65\170\x61\155\x70\154\145\x2e\x63\x6f\x6d\x2f\61", "\x73\x6f\x6d\x65\x5f\164\141\147\61")); $this->assertTrue($service->addBookmark("\150\x74\164\160\72\x2f\57\145\x78\141\x6d\x70\x6c\145\56\143\157\x6d\57\62", "\x73\x6f\155\x65\137\x74\x61\147\x32")); $this->assertTrue($service->addBookmark("\150\164\164\160\72\57\x2f\x65\x78\x61\x6d\160\x6c\x65\x2e\x63\157\155\x2f\x33", "\163\x6f\155\x65\137\164\x61\x67\63")); $this->assertTrue($service->hasBookmarksTagged("\x70\x68\x70")); $this->assertTrue($service->hasBookmarksTagged("\160\x68\160")); } public function testAnExampleWithSomeExpectationAmendsOnCallCounts_PHPUnitTest() { $service = mock("\115\171\x53\145\x72\166\151\143\145\x32"); $service->expects("\x6c\x6f\x67\151\x6e")->once()->with("\x75\163\145\162", "\160\x61\x73\163")->andReturnTrue(); $service->expects("\150\141\163\x42\x6f\157\x6b\x6d\x61\162\x6b\x73\124\x61\147\x67\x65\144")->times(3)->with("\x70\x68\x70")->andReturns(false, true, true); $service->expects("\x61\144\144\x42\x6f\x6f\153\x6d\x61\x72\153")->times(3)->andReturnTrue(); $this->assertTrue($service->login("\x75\163\145\x72", "\160\141\163\x73")); $this->assertFalse($service->hasBookmarksTagged("\x70\150\160")); $this->assertTrue($service->addBookmark("\150\164\164\160\x3a\x2f\x2f\x65\x78\141\155\160\154\x65\56\x63\157\155\57\x31", "\x73\x6f\x6d\145\137\164\x61\x67\61")); $this->assertTrue($service->addBookmark("\x68\x74\164\160\x3a\57\57\145\x78\x61\155\x70\x6c\145\56\143\x6f\155\57\x32", "\163\157\155\x65\x5f\164\x61\147\62")); $this->assertTrue($service->addBookmark("\x68\x74\164\x70\72\x2f\57\145\x78\141\155\x70\x6c\x65\56\x63\x6f\155\x2f\x33", "\x73\x6f\x6d\145\x5f\x74\x61\147\63")); $this->assertTrue($service->hasBookmarksTagged("\x70\150\x70")); $this->assertTrue($service->hasBookmarksTagged("\x70\x68\160")); } public function testMockedMethodsCallableFromWithinOriginalClass() { $mock = mock("\x4d\157\143\x6b\x65\x72\171\124\x65\163\164\137\111\156\164\145\162\x4d\x65\x74\150\157\x64\x31\x5b\144\157\x54\x68\151\x72\144\x5d"); $mock->shouldReceive("\x64\157\124\x68\151\162\x64")->andReturn(true); $this->assertTrue($mock->doFirst()); } public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectation() { $mock = mock("\x4d\157\x63\x6b\x65\x72\171\137\104\145\x6d\x65\164\145\162\x6f\167\163\153\x69"); $mock->shouldReceive("\146\157\157\55\76\x62\141\162\x2d\x3e\x62\141\172")->andReturn("\123\x70\141\x6d\x21"); $demeter = new Mockery_UseDemeter($mock); $this->assertSame("\x53\160\141\155\x21", $demeter->doit()); } public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectationWithArgs() { $mock = mock("\115\157\x63\x6b\145\162\171\137\x44\x65\x6d\x65\x74\145\162\x6f\167\163\x6b\x69"); $mock->shouldReceive("\146\x6f\157\x2d\x3e\x62\141\x72\55\x3e\142\x61\x7a")->andReturn("\123\x70\141\155\41"); $demeter = new Mockery_UseDemeter($mock); $this->assertSame("\x53\x70\x61\x6d\x21", $demeter->doitWithArgs()); } public function testShouldNotReceiveCanBeAddedToCompositeExpectation() { $mock = mock("\x46\157\x6f"); $mock->shouldReceive("\x61")->once()->andReturn("\123\160\141\x6d\x21")->shouldNotReceive("\142"); $mock->a(); } public function testPassthruEnsuresRealMethodCalledForReturnValues() { $mock = mock("\115\157\143\x6b\x65\162\x79\124\145\x73\x74\x5f\x53\165\142\152\145\x63\164\x43\141\154\x6c\x31"); $mock->shouldReceive("\146\x6f\x6f")->once()->passthru(); $this->assertEquals("\142\x61\162", $mock->foo()); } public function testPassthruCallMagic() { $mock = mock("\x4d\x6f\143\x6b\x65\x72\171\137\115\141\x67\x69\143"); $mock->shouldReceive("\164\x68\145\101\x6e\x73\167\145\x72")->once()->passthru(); $this->assertSame(42, $mock->theAnswer()); } public function testShouldIgnoreMissingExpectationBasedOnArgs() { $mock = mock("\115\171\x53\x65\x72\166\151\x63\145\62")->shouldIgnoreMissing(); $mock->shouldReceive("\150\x61\163\x42\x6f\157\x6b\x6d\141\x72\153\163\124\141\x67\x67\145\144")->with("\144\x61\166\x65")->once(); $mock->hasBookmarksTagged("\x64\x61\166\145"); $mock->hasBookmarksTagged("\160\141\x64\x72\141\x69\143"); } public function testMakePartialExpectationBasedOnArgs() { $mock = mock("\x4d\x6f\x63\x6b\x65\x72\x79\124\145\x73\x74\137\123\x75\x62\152\145\x63\164\103\x61\154\154\x31")->makePartial(); $this->assertEquals("\142\141\x72", $mock->foo()); $this->assertEquals("\142\x61\x72", $mock->foo("\142\x61\172")); $this->assertEquals("\x62\x61\162", $mock->foo("\161\165\170")); $mock->shouldReceive("\146\157\x6f")->with("\142\141\172")->twice()->andReturn("\61\x32\63"); $this->assertEquals("\x62\x61\x72", $mock->foo()); $this->assertEquals("\x31\x32\63", $mock->foo("\142\141\172")); $this->assertEquals("\142\141\162", $mock->foo("\161\165\170")); $mock->shouldReceive("\x66\x6f\157")->withNoArgs()->once()->andReturn("\x34\x35\66"); $this->assertEquals("\64\x35\66", $mock->foo()); $this->assertEquals("\61\62\63", $mock->foo("\x62\x61\172")); $this->assertEquals("\x62\x61\x72", $mock->foo("\x71\165\170")); } public function testCanReturnSelf() { $this->mock->shouldReceive("\x66\157\157")->andReturnSelf(); $this->assertSame($this->mock, $this->mock->foo()); } public function testReturnsTrueIfTrueIsReturnValue() { $this->mock->shouldReceive("\146\157\x6f")->andReturnTrue(); $this->assertTrue($this->mock->foo()); } public function testReturnsFalseIfFalseIsReturnValue() { $this->mock->shouldReceive("\x66\157\157")->andReturnFalse(); $this->assertFalse($this->mock->foo()); } public function testExpectationCanBeOverridden() { $this->mock->shouldReceive("\x66\157\157")->once()->andReturn("\147\162\145\x65\156"); $this->mock->shouldReceive("\x66\157\x6f")->andReturn("\x62\154\x75\145"); $this->assertEquals("\147\x72\x65\x65\x6e", $this->mock->foo()); $this->assertEquals("\x62\154\x75\x65", $this->mock->foo()); } public function testTimesExpectationForbidsFloatNumbers() { $this->expectException(\InvalidArgumentException::class); $this->mock->shouldReceive("\x66\157\157")->times(1.3); Mockery::close(); } public function testIfExceptionIndicatesAbsenceOfMethodAndExpectationsOnMock() { $mock = mock("\115\x6f\x63\x6b\145\x72\x79\137\x44\165\143\153"); $this->expectException("\x5c\x42\141\144\115\x65\164\150\157\x64\x43\x61\154\154\105\170\143\145\160\164\x69\x6f\156", "\x4d\145\164\150\x6f\144\x20" . get_class($mock) . "\72\72\156\157\156\105\170\x69\163\164\145\x6e\x74\x28\x29\40\x64\157\145\163\x20\156\157\x74\40\145\x78\151\x73\x74\40\x6f\x6e\40\164\x68\x69\x73\40\x6d\x6f\x63\x6b\x20\157\142\x6a\x65\143\x74"); $mock->nonExistent(); Mockery::close(); } public function testIfCallingMethodWithNoExpectationsHasSpecificExceptionMessage() { $mock = mock("\115\157\143\x6b\145\x72\x79\x5f\x44\165\143\153"); $this->expectException("\x5c\102\x61\x64\115\x65\164\x68\157\x64\103\x61\154\154\x45\170\x63\x65\160\x74\151\157\x6e", "\122\145\x63\x65\151\166\145\144\x20" . get_class($mock) . "\x3a\x3a\x71\165\141\143\153\x28\x29\54\x20" . "\142\165\x74\x20\x6e\157\x20\x65\x78\160\145\x63\164\141\x74\x69\157\x6e\x73\x20\x77\x65\162\145\40\163\x70\145\x63\151\x66\x69\145\x64"); $mock->quack(); Mockery::close(); } public function testMockShouldNotBeAnonymousWhenImplementingSpecificInterface() { $waterMock = mock("\111\127\x61\164\x65\162"); $this->assertFalse($waterMock->mockery_isAnonymous()); } public function testWetherMockWithInterfaceOnlyCanNotImplementNonExistingMethods() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); $waterMock = \Mockery::mock("\111\127\x61\164\145\x72"); $this->expectException(\Mockery\Exception::class); $waterMock->shouldReceive("\x6e\x6f\156\x45\170\x69\163\164\145\x6e\164\115\145\164\150\x6f\144")->once()->andReturnNull(); \Mockery::close(); } public function testCountWithBecauseExceptionMessage() { $this->expectException(InvalidCountException::class); $this->expectExceptionMessageRegex("\x2f\115\x65\x74\x68\157\144\x20\x66\157\x6f\x5c\x28\x3c\x41\x6e\x79\x20\x41\162\x67\x75\x6d\x65\156\x74\163\x3e\134\51\x20\x66\x72\157\155\40\115\x6f\x63\153\145\162\x79\137\x28\56\52\x3f\x29\40\x73\x68\157\165\x6c\x64\x20\x62\x65\40\143\x61\154\154\145\144" . PHP_EOL . "\40" . "\x65\x78\141\143\164\154\x79\x20\x31\x20\164\151\x6d\145\163\40\x62\165\164\40\143\x61\x6c\154\145\x64\40\60\x20\164\151\x6d\145\163\x2e\x20\x42\145\143\x61\165\163\145\x20\127\145\40\x6c\151\x6b\x65\x20\x66\x6f\x6f\x2f"); $this->mock->shouldReceive("\146\157\x6f")->once()->because("\x57\x65\x20\154\151\x6b\x65\40\146\157\157"); Mockery::close(); } public function it_uses_a_matchers_to_string_method_in_the_exception_output() { $mock = Mockery::mock(); $mock->expects()->foo(Mockery::hasKey("\x66\157\157")); $this->expectException(InvalidCountException::class, "\115\145\164\150\157\144\x20\146\157\x6f\x28\74\110\x61\163\113\145\x79\x5b\146\157\x6f\x5d\76\51"); Mockery::close(); } public function testNonObjectEqualsExpectation() { $input = array("\143\x6c\x75\x62\x5f\151\x64" => 1, "\x75\163\145\x72\137\x69\144" => 1, "\151\163\x5f\141\x64\155\x69\156" => 1); $foo = Mockery::mock(); $foo->shouldReceive("\146\157\x6f")->with($input)->andReturn("\146\x6f\x6f\142\x61\x72"); ksort($input); self::assertSame("\x66\x6f\x6f\x62\x61\162", $foo->foo($input)); } } goto BXyUC; RhNI3: class Mockery_Magic { public function __call($method, $args) { return 42; } }

Function Calls

None

Variables

None

Stats

MD5 504f6817ff3b8994cf5f0cd6a326a86b
Eval Count 0
Decode Time 149 ms