From 8ef0905c1e2ed98e9a4e8152cd92e497d1b9e893 Mon Sep 17 00:00:00 2001 From: Dave Marshall Date: Sat, 13 May 2017 20:15:15 +0100 Subject: [PATCH] Fixes all risky tests Kinda --- library/Mockery.php | 6 +- .../Phpunit/MockeryPHPUnitIntegration.php | 2 +- tests/Mockery/ContainerTest.php | 367 ++++++++---------- tests/Mockery/ExpectationTest.php | 329 ++++++---------- tests/Mockery/HamcrestExpectationTest.php | 12 +- .../MockClassWithMethodOverloadingTest.php | 16 +- .../MockClassWithUnknownTypeHintTest.php | 15 +- tests/Mockery/MockTest.php | 42 +- ...ockingMethodsWithIterableTypeHintsTest.php | 12 +- ...ckingMethodsWithNullableParametersTest.php | 14 +- tests/Mockery/MockingNullableMethodsTest.php | 33 +- .../MockingParameterAndReturnTypesTest.php | 30 +- tests/Mockery/MockingProtectedMethodsTest.php | 24 +- .../Mockery/MockingVariadicArgumentsTest.php | 12 +- tests/Mockery/MockingVoidMethodsTest.php | 10 +- tests/Mockery/SpyTest.php | 14 +- 16 files changed, 356 insertions(+), 582 deletions(-) diff --git a/library/Mockery.php b/library/Mockery.php index 3bb385eea..3d3011ca6 100644 --- a/library/Mockery.php +++ b/library/Mockery.php @@ -159,9 +159,11 @@ public static function close() return; } - self::$_container->mockery_teardown(); - self::$_container->mockery_close(); + $container = self::$_container; self::$_container = null; + + $container->mockery_teardown(); + $container->mockery_close(); } /** diff --git a/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php b/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php index 25721d917..6f8f38013 100644 --- a/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php +++ b/library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php @@ -70,7 +70,7 @@ protected function purgeMockeryContainer() { if ($this->mockeryOpen) { // post conditions wasn't called, so test probably failed - Mockery::getContainer()->mockery_teardown(); + Mockery::close(); } } } diff --git a/tests/Mockery/ContainerTest.php b/tests/Mockery/ContainerTest.php index 422f72afe..280b26a95 100644 --- a/tests/Mockery/ContainerTest.php +++ b/tests/Mockery/ContainerTest.php @@ -21,55 +21,43 @@ use Mockery\Generator\MockConfigurationBuilder; use Mockery\Adapter\Phpunit\MockeryTestCase; +use Mockery\MockInterface; class ContainerTest extends MockeryTestCase { - /** @var Mockery\Container */ - private $container; - - public function setup() - { - $this->container = new Mockery\Container(Mockery::getDefaultGenerator(), new Mockery\Loader\EvalLoader()); - } - - public function teardown() - { - $this->container->mockery_close(); - } - public function testSimplestMockCreation() { - $m = $this->container->mock(); + $m = mock(); $m->shouldReceive('foo')->andReturn('bar'); $this->assertEquals('bar', $m->foo()); } public function testGetKeyOfDemeterMockShouldReturnKeyWhenMatchingMock() { - $m = $this->container->mock(); + $m = mock(); $m->shouldReceive('foo->bar'); $this->assertRegExp( '/Mockery_(\d+)__demeter_foo/', - $this->container->getKeyOfDemeterMockFor('foo') + Mockery::getContainer()->getKeyOfDemeterMockFor('foo') ); } public function testGetKeyOfDemeterMockShouldReturnNullWhenNoMatchingMock() { $method = 'unknownMethod'; - $this->assertNull($this->container->getKeyOfDemeterMockFor($method)); + $this->assertNull(Mockery::getContainer()->getKeyOfDemeterMockFor($method)); - $m = $this->container->mock(); + $m = mock(); $m->shouldReceive('method'); - $this->assertNull($this->container->getKeyOfDemeterMockFor($method)); + $this->assertNull(Mockery::getContainer()->getKeyOfDemeterMockFor($method)); $m->shouldReceive('foo->bar'); - $this->assertNull($this->container->getKeyOfDemeterMockFor($method)); + $this->assertNull(Mockery::getContainer()->getKeyOfDemeterMockFor($method)); } public function testNamedMocksAddNameToExceptions() { - $m = $this->container->mock('Foo'); + $m = mock('Foo'); $m->shouldReceive('foo')->with(1)->andReturn('bar'); try { $m->foo(); @@ -80,7 +68,7 @@ public function testNamedMocksAddNameToExceptions() public function testSimpleMockWithArrayDefs() { - $m = $this->container->mock(array('foo'=>1, 'bar'=>2)); + $m = mock(array('foo'=>1, 'bar'=>2)); $this->assertEquals(1, $m->foo()); $this->assertEquals(2, $m->bar()); } @@ -88,7 +76,7 @@ public function testSimpleMockWithArrayDefs() public function testSimpleMockWithArrayDefsCanBeOverridden() { // eg. In shared test setup - $m = $this->container->mock(array('foo' => 1, 'bar' => 2)); + $m = mock(array('foo' => 1, 'bar' => 2)); // and then overridden in one test $m->shouldReceive('foo')->with('baz')->once()->andReturn(2); @@ -100,7 +88,7 @@ public function testSimpleMockWithArrayDefsCanBeOverridden() public function testNamedMockWithArrayDefs() { - $m = $this->container->mock('Foo', array('foo'=>1, 'bar'=>2)); + $m = mock('Foo', array('foo'=>1, 'bar'=>2)); $this->assertEquals(1, $m->foo()); $this->assertEquals(2, $m->bar()); try { @@ -113,7 +101,7 @@ public function testNamedMockWithArrayDefs() public function testNamedMockWithArrayDefsCanBeOverridden() { // eg. In shared test setup - $m = $this->container->mock('Foo', array('foo' => 1)); + $m = mock('Foo', array('foo' => 1)); // and then overridden in one test $m->shouldReceive('foo')->with('bar')->once()->andReturn(2); @@ -129,7 +117,7 @@ public function testNamedMockWithArrayDefsCanBeOverridden() public function testNamedMockMultipleInterfaces() { - $m = $this->container->mock('stdClass, ArrayAccess, Countable', array('foo'=>1, 'bar'=>2)); + $m = mock('stdClass, ArrayAccess, Countable', array('foo'=>1, 'bar'=>2)); $this->assertEquals(1, $m->foo()); $this->assertEquals(2, $m->bar()); try { @@ -143,7 +131,7 @@ public function testNamedMockMultipleInterfaces() public function testNamedMockWithConstructorArgs() { - $m = $this->container->mock("MockeryTest_ClassConstructor2[foo]", array($param1 = new stdClass())); + $m = mock("MockeryTest_ClassConstructor2[foo]", array($param1 = new stdClass())); $m->shouldReceive("foo")->andReturn(123); $this->assertEquals(123, $m->foo()); $this->assertEquals($param1, $m->getParam1()); @@ -151,7 +139,7 @@ public function testNamedMockWithConstructorArgs() public function testNamedMockWithConstructorArgsAndArrayDefs() { - $m = $this->container->mock( + $m = mock( "MockeryTest_ClassConstructor2[foo]", array($param1 = new stdClass()), array("foo" => 123) @@ -162,21 +150,21 @@ public function testNamedMockWithConstructorArgsAndArrayDefs() public function testNamedMockWithConstructorArgsWithInternalCallToMockedMethod() { - $m = $this->container->mock("MockeryTest_ClassConstructor2[foo]", array($param1 = new stdClass())); + $m = mock("MockeryTest_ClassConstructor2[foo]", array($param1 = new stdClass())); $m->shouldReceive("foo")->andReturn(123); $this->assertEquals(123, $m->bar()); } public function testNamedMockWithConstructorArgsButNoQuickDefsShouldLeaveConstructorIntact() { - $m = $this->container->mock("MockeryTest_ClassConstructor2", array($param1 = new stdClass())); + $m = mock("MockeryTest_ClassConstructor2", array($param1 = new stdClass())); $m->shouldDeferMissing(); $this->assertEquals($param1, $m->getParam1()); } public function testNamedMockWithShouldDeferMissing() { - $m = $this->container->mock("MockeryTest_ClassConstructor2", array($param1 = new stdClass())); + $m = mock("MockeryTest_ClassConstructor2", array($param1 = new stdClass())); $m->shouldDeferMissing(); $this->assertEquals('foo', $m->bar()); $m->shouldReceive("bar")->andReturn(123); @@ -188,14 +176,14 @@ public function testNamedMockWithShouldDeferMissing() */ public function testNamedMockWithShouldDeferMissingThrowsIfNotAvailable() { - $m = $this->container->mock("MockeryTest_ClassConstructor2", array($param1 = new stdClass())); + $m = mock("MockeryTest_ClassConstructor2", array($param1 = new stdClass())); $m->shouldDeferMissing(); $m->foorbar123(); } public function testMockingAKnownConcreteClassSoMockInheritsClassType() { - $m = $this->container->mock('stdClass'); + $m = mock('stdClass'); $m->shouldReceive('foo')->andReturn('bar'); $this->assertEquals('bar', $m->foo()); $this->assertTrue($m instanceof stdClass); @@ -203,13 +191,13 @@ public function testMockingAKnownConcreteClassSoMockInheritsClassType() public function testMockingAKnownUserClassSoMockInheritsClassType() { - $m = $this->container->mock('MockeryTest_TestInheritedType'); + $m = mock('MockeryTest_TestInheritedType'); $this->assertTrue($m instanceof MockeryTest_TestInheritedType); } public function testMockingAConcreteObjectCreatesAPartialWithoutError() { - $m = $this->container->mock(new stdClass); + $m = mock(new stdClass); $m->shouldReceive('foo')->andReturn('bar'); $this->assertEquals('bar', $m->foo()); $this->assertTrue($m instanceof stdClass); @@ -217,7 +205,7 @@ public function testMockingAConcreteObjectCreatesAPartialWithoutError() public function testCreatingAPartialAllowsDynamicExpectationsAndPassesThroughUnexpectedMethods() { - $m = $this->container->mock(new MockeryTestFoo); + $m = mock(new MockeryTestFoo); $m->shouldReceive('bar')->andReturn('bar'); $this->assertEquals('bar', $m->bar()); $this->assertEquals('foo', $m->foo()); @@ -226,7 +214,7 @@ public function testCreatingAPartialAllowsDynamicExpectationsAndPassesThroughUne public function testCreatingAPartialAllowsExpectationsToInterceptCallsToImplementedMethods() { - $m = $this->container->mock(new MockeryTestFoo2); + $m = mock(new MockeryTestFoo2); $m->shouldReceive('bar')->andReturn('baz'); $this->assertEquals('baz', $m->bar()); $this->assertEquals('foo', $m->foo()); @@ -235,19 +223,19 @@ public function testCreatingAPartialAllowsExpectationsToInterceptCallsToImplemen public function testBlockForwardingToPartialObject() { - $m = $this->container->mock(new MockeryTestBar1, array('foo'=>1, Mockery\Container::BLOCKS => array('method1'))); + $m = mock(new MockeryTestBar1, array('foo'=>1, Mockery\Container::BLOCKS => array('method1'))); $this->assertSame($m, $m->method1()); } public function testPartialWithArrayDefs() { - $m = $this->container->mock(new MockeryTestBar1, array('foo'=>1, Mockery\Container::BLOCKS => array('method1'))); + $m = mock(new MockeryTestBar1, array('foo'=>1, Mockery\Container::BLOCKS => array('method1'))); $this->assertEquals(1, $m->foo()); } public function testPassingClosureAsFinalParameterUsedToDefineExpectations() { - $m = $this->container->mock('foo', function ($m) { + $m = mock('foo', function ($m) { $m->shouldReceive('foo')->once()->andReturn('bar'); }); $this->assertEquals('bar', $m->foo()); @@ -258,12 +246,12 @@ public function testPassingClosureAsFinalParameterUsedToDefineExpectations() */ public function testMockingAKnownConcreteFinalClassThrowsErrors_OnlyPartialMocksCanMockFinalElements() { - $m = $this->container->mock('MockeryFoo3'); + $m = mock('MockeryFoo3'); } public function testMockingAKnownConcreteClassWithFinalMethodsThrowsNoException() { - $m = $this->container->mock('MockeryFoo4'); + $this->assertInstanceOf(MockInterface::class, mock('MockeryFoo4')); } /** @@ -271,7 +259,7 @@ public function testMockingAKnownConcreteClassWithFinalMethodsThrowsNoException( */ public function testFinalClassesCanBePartialMocks() { - $m = $this->container->mock(new MockeryFoo3); + $m = mock(new MockeryFoo3); $m->shouldReceive('foo')->andReturn('baz'); $this->assertEquals('baz', $m->foo()); $this->assertFalse($m instanceof MockeryFoo3); @@ -279,7 +267,7 @@ public function testFinalClassesCanBePartialMocks() public function testSplClassWithFinalMethodsCanBeMocked() { - $m = $this->container->mock('SplFileInfo'); + $m = mock('SplFileInfo'); $m->shouldReceive('foo')->andReturn('baz'); $this->assertEquals('baz', $m->foo()); $this->assertTrue($m instanceof SplFileInfo); @@ -287,8 +275,8 @@ public function testSplClassWithFinalMethodsCanBeMocked() public function testSplClassWithFinalMethodsCanBeMockedMultipleTimes() { - $this->container->mock('SplFileInfo'); - $m = $this->container->mock('SplFileInfo'); + mock('SplFileInfo'); + $m = mock('SplFileInfo'); $m->shouldReceive('foo')->andReturn('baz'); $this->assertEquals('baz', $m->foo()); $this->assertTrue($m instanceof SplFileInfo); @@ -296,7 +284,7 @@ public function testSplClassWithFinalMethodsCanBeMockedMultipleTimes() public function testClassesWithFinalMethodsCanBeProxyPartialMocks() { - $m = $this->container->mock(new MockeryFoo4); + $m = mock(new MockeryFoo4); $m->shouldReceive('foo')->andReturn('baz'); $this->assertEquals('baz', $m->foo()); $this->assertEquals('bar', $m->bar()); @@ -305,7 +293,7 @@ public function testClassesWithFinalMethodsCanBeProxyPartialMocks() public function testClassesWithFinalMethodsCanBeProperPartialMocks() { - $m = $this->container->mock('MockeryFoo4[bar]'); + $m = mock('MockeryFoo4[bar]'); $m->shouldReceive('bar')->andReturn('baz'); $this->assertEquals('baz', $m->foo()); $this->assertEquals('baz', $m->bar()); @@ -314,7 +302,7 @@ public function testClassesWithFinalMethodsCanBeProperPartialMocks() public function testClassesWithFinalMethodsCanBeProperPartialMocksButFinalMethodsNotPartialed() { - $m = $this->container->mock('MockeryFoo4[foo]'); + $m = mock('MockeryFoo4[foo]'); $m->shouldReceive('foo')->andReturn('foo'); $this->assertEquals('baz', $m->foo()); // partial expectation ignored - will fail callcount assertion $this->assertTrue($m instanceof MockeryFoo4); @@ -322,28 +310,35 @@ public function testClassesWithFinalMethodsCanBeProperPartialMocksButFinalMethod public function testSplfileinfoClassMockPassesUserExpectations() { - $file = $this->container->mock('SplFileInfo[getFilename,getPathname,getExtension,getMTime]', array(__FILE__)); + $file = mock('SplFileInfo[getFilename,getPathname,getExtension,getMTime]', array(__FILE__)); $file->shouldReceive('getFilename')->once()->andReturn('foo'); $file->shouldReceive('getPathname')->once()->andReturn('path/to/foo'); $file->shouldReceive('getExtension')->once()->andReturn('css'); $file->shouldReceive('getMTime')->once()->andReturn(time()); + + // not sure what this test is for, maybe something special about + // SplFileInfo + $this->assertEquals('foo', $file->getFilename()); + $this->assertEquals('path/to/foo', $file->getPathname()); + $this->assertEquals('css', $file->getExtension()); + $this->assertInternalType('int', $file->getMTime()); } public function testCanMockInterface() { - $m = $this->container->mock('MockeryTest_Interface'); + $m = mock('MockeryTest_Interface'); $this->assertTrue($m instanceof MockeryTest_Interface); } public function testCanMockSpl() { - $m = $this->container->mock('\\SplFixedArray'); + $m = mock('\\SplFixedArray'); $this->assertTrue($m instanceof SplFixedArray); } public function testCanMockInterfaceWithAbstractMethod() { - $m = $this->container->mock('MockeryTest_InterfaceWithAbstractMethod'); + $m = mock('MockeryTest_InterfaceWithAbstractMethod'); $this->assertTrue($m instanceof MockeryTest_InterfaceWithAbstractMethod); $m->shouldReceive('foo')->andReturn(1); $this->assertEquals(1, $m->foo()); @@ -351,25 +346,25 @@ public function testCanMockInterfaceWithAbstractMethod() public function testCanMockAbstractWithAbstractProtectedMethod() { - $m = $this->container->mock('MockeryTest_AbstractWithAbstractMethod'); + $m = mock('MockeryTest_AbstractWithAbstractMethod'); $this->assertTrue($m instanceof MockeryTest_AbstractWithAbstractMethod); } public function testCanMockInterfaceWithPublicStaticMethod() { - $m = $this->container->mock('MockeryTest_InterfaceWithPublicStaticMethod'); + $m = mock('MockeryTest_InterfaceWithPublicStaticMethod'); $this->assertTrue($m instanceof MockeryTest_InterfaceWithPublicStaticMethod); } public function testCanMockClassWithConstructor() { - $m = $this->container->mock('MockeryTest_ClassConstructor'); + $m = mock('MockeryTest_ClassConstructor'); $this->assertTrue($m instanceof MockeryTest_ClassConstructor); } public function testCanMockClassWithConstructorNeedingClassArgs() { - $m = $this->container->mock('MockeryTest_ClassConstructor2'); + $m = mock('MockeryTest_ClassConstructor2'); $this->assertTrue($m instanceof MockeryTest_ClassConstructor2); } @@ -378,7 +373,7 @@ public function testCanMockClassWithConstructorNeedingClassArgs() */ public function testCanPartiallyMockANormalClass() { - $m = $this->container->mock('MockeryTest_PartialNormalClass[foo]'); + $m = mock('MockeryTest_PartialNormalClass[foo]'); $this->assertTrue($m instanceof MockeryTest_PartialNormalClass); $m->shouldReceive('foo')->andReturn('cba'); $this->assertEquals('abc', $m->bar()); @@ -390,7 +385,7 @@ public function testCanPartiallyMockANormalClass() */ public function testCanPartiallyMockAnAbstractClass() { - $m = $this->container->mock('MockeryTest_PartialAbstractClass[foo]'); + $m = mock('MockeryTest_PartialAbstractClass[foo]'); $this->assertTrue($m instanceof MockeryTest_PartialAbstractClass); $m->shouldReceive('foo')->andReturn('cba'); $this->assertEquals('abc', $m->bar()); @@ -402,7 +397,7 @@ public function testCanPartiallyMockAnAbstractClass() */ public function testCanPartiallyMockANormalClassWith2Methods() { - $m = $this->container->mock('MockeryTest_PartialNormalClass2[foo, baz]'); + $m = mock('MockeryTest_PartialNormalClass2[foo, baz]'); $this->assertTrue($m instanceof MockeryTest_PartialNormalClass2); $m->shouldReceive('foo')->andReturn('cba'); $m->shouldReceive('baz')->andReturn('cba'); @@ -416,7 +411,7 @@ public function testCanPartiallyMockANormalClassWith2Methods() */ public function testCanPartiallyMockAnAbstractClassWith2Methods() { - $m = $this->container->mock('MockeryTest_PartialAbstractClass2[foo,baz]'); + $m = mock('MockeryTest_PartialAbstractClass2[foo,baz]'); $this->assertTrue($m instanceof MockeryTest_PartialAbstractClass2); $m->shouldReceive('foo')->andReturn('cba'); $m->shouldReceive('baz')->andReturn('cba'); @@ -432,7 +427,7 @@ public function testCanPartiallyMockAnAbstractClassWith2Methods() public function testThrowsExceptionIfSettingExpectationForNonMockedMethodOfPartialMock() { $this->markTestSkipped('For now...'); - $m = $this->container->mock('MockeryTest_PartialNormalClass[foo]'); + $m = mock('MockeryTest_PartialNormalClass[foo]'); $this->assertTrue($m instanceof MockeryTest_PartialNormalClass); $m->shouldReceive('bar')->andReturn('cba'); } @@ -443,7 +438,7 @@ public function testThrowsExceptionIfSettingExpectationForNonMockedMethodOfParti */ public function testThrowsExceptionIfClassOrInterfaceForPartialMockDoesNotExist() { - $m = $this->container->mock('MockeryTest_PartialNormalClassXYZ[foo]'); + $m = mock('MockeryTest_PartialNormalClassXYZ[foo]'); } /** @@ -451,7 +446,7 @@ public function testThrowsExceptionIfClassOrInterfaceForPartialMockDoesNotExist( */ public function testCanMockClassContainingMagicCallMethod() { - $m = $this->container->mock('MockeryTest_Call1'); + $m = mock('MockeryTest_Call1'); $this->assertTrue($m instanceof MockeryTest_Call1); } @@ -460,7 +455,7 @@ public function testCanMockClassContainingMagicCallMethod() */ public function testCanMockClassContainingMagicCallMethodWithoutTypeHinting() { - $m = $this->container->mock('MockeryTest_Call2'); + $m = mock('MockeryTest_Call2'); $this->assertTrue($m instanceof MockeryTest_Call2); } @@ -469,7 +464,7 @@ public function testCanMockClassContainingMagicCallMethodWithoutTypeHinting() */ public function testCanMockClassContainingAPublicWakeupMethod() { - $m = $this->container->mock('MockeryTest_Wakeup1'); + $m = mock('MockeryTest_Wakeup1'); $this->assertTrue($m instanceof MockeryTest_Wakeup1); } @@ -498,7 +493,7 @@ public function testCanPartialMockObjectUsingMagicCallMethodsInPlaceOfNormalMeth */ public function testCanMockClassWhereMethodHasReferencedParameter() { - $m = Mockery::mock(new MockeryTest_MethodParamRef); + $this->assertInstanceOf(MockInterface::class, Mockery::mock(new MockeryTest_MethodParamRef)); } /** @@ -506,7 +501,7 @@ public function testCanMockClassWhereMethodHasReferencedParameter() */ public function testCanPartiallyMockObjectWhereMethodHasReferencedParameter() { - $m = Mockery::mock(new MockeryTest_MethodParamRef2); + $this->assertInstanceOf(MockInterface::class, Mockery::mock(new MockeryTest_MethodParamRef2)); } /** @@ -514,7 +509,7 @@ public function testCanPartiallyMockObjectWhereMethodHasReferencedParameter() */ public function testMockingAKnownConcreteClassCanBeGrantedAnArbitraryClassType() { - $m = $this->container->mock('alias:MyNamespace\MyClass'); + $m = mock('alias:MyNamespace\MyClass'); $m->shouldReceive('foo')->andReturn('bar'); $this->assertEquals('bar', $m->foo()); $this->assertTrue($m instanceof MyNamespace\MyClass); @@ -525,7 +520,7 @@ public function testMockingAKnownConcreteClassCanBeGrantedAnArbitraryClassType() */ public function testCanMockMultipleInterfaces() { - $m = $this->container->mock('MockeryTest_Interface1, MockeryTest_Interface2'); + $m = mock('MockeryTest_Interface1, MockeryTest_Interface2'); $this->assertTrue($m instanceof MockeryTest_Interface1); $this->assertTrue($m instanceof MockeryTest_Interface2); } @@ -534,7 +529,7 @@ public function testCanMockMultipleInterfaces() */ public function testCanMockMultipleInterfacesThatMayNotExist() { - $m = $this->container->mock('NonExistingClass, MockeryTest_Interface1, MockeryTest_Interface2, \Some\Thing\That\Doesnt\Exist'); + $m = mock('NonExistingClass, MockeryTest_Interface1, MockeryTest_Interface2, \Some\Thing\That\Doesnt\Exist'); $this->assertTrue($m instanceof MockeryTest_Interface1); $this->assertTrue($m instanceof MockeryTest_Interface2); $this->assertTrue($m instanceof \Some\Thing\That\Doesnt\Exist); @@ -545,7 +540,7 @@ public function testCanMockMultipleInterfacesThatMayNotExist() */ public function testCanMockClassAndApplyMultipleInterfaces() { - $m = $this->container->mock('MockeryTestFoo, MockeryTest_Interface1, MockeryTest_Interface2'); + $m = mock('MockeryTestFoo, MockeryTest_Interface1, MockeryTest_Interface2'); $this->assertTrue($m instanceof MockeryTestFoo); $this->assertTrue($m instanceof MockeryTest_Interface1); $this->assertTrue($m instanceof MockeryTest_Interface2); @@ -560,11 +555,9 @@ public function testCanMockClassAndApplyMultipleInterfaces() */ public function testCanMockStaticMethods() { - Mockery::setContainer($this->container); - $m = $this->container->mock('alias:MyNamespace\MyClass2'); + $m = mock('alias:MyNamespace\MyClass2'); $m->shouldReceive('staticFoo')->andReturn('bar'); $this->assertEquals('bar', \MyNameSpace\MyClass2::staticFoo()); - Mockery::resetContainer(); } /** @@ -573,11 +566,9 @@ public function testCanMockStaticMethods() */ public function testMockedStaticMethodsObeyMethodCounting() { - Mockery::setContainer($this->container); - $m = $this->container->mock('alias:MyNamespace\MyClass3'); + $m = mock('alias:MyNamespace\MyClass3'); $m->shouldReceive('staticFoo')->once()->andReturn('bar'); - $this->container->mockery_verify(); - Mockery::resetContainer(); + Mockery::close(); } /** @@ -585,10 +576,8 @@ public function testMockedStaticMethodsObeyMethodCounting() */ public function testMockedStaticThrowsExceptionWhenMethodDoesNotExist() { - Mockery::setContainer($this->container); - $m = $this->container->mock('alias:MyNamespace\StaticNoMethod'); + $m = mock('alias:MyNamespace\StaticNoMethod'); $this->assertEquals('bar', MyNameSpace\StaticNoMethod::staticFoo()); - Mockery::resetContainer(); } /** @@ -596,7 +585,7 @@ public function testMockedStaticThrowsExceptionWhenMethodDoesNotExist() */ public function testMockingAllowsPublicPropertyStubbingOnRealClass() { - $m = $this->container->mock('MockeryTestFoo'); + $m = mock('MockeryTestFoo'); $m->foo = 'bar'; $this->assertEquals('bar', $m->foo); //$this->assertTrue(array_key_exists('foo', $m->mockery_getMockableProperties())); @@ -607,7 +596,7 @@ public function testMockingAllowsPublicPropertyStubbingOnRealClass() */ public function testMockingAllowsPublicPropertyStubbingOnNamedMock() { - $m = $this->container->mock('Foo'); + $m = mock('Foo'); $m->foo = 'bar'; $this->assertEquals('bar', $m->foo); //$this->assertTrue(array_key_exists('foo', $m->mockery_getMockableProperties())); @@ -618,7 +607,7 @@ public function testMockingAllowsPublicPropertyStubbingOnNamedMock() */ public function testMockingAllowsPublicPropertyStubbingOnPartials() { - $m = $this->container->mock(new stdClass); + $m = mock(new stdClass); $m->foo = 'bar'; $this->assertEquals('bar', $m->foo); //$this->assertTrue(array_key_exists('foo', $m->mockery_getMockableProperties())); @@ -629,52 +618,45 @@ public function testMockingAllowsPublicPropertyStubbingOnPartials() */ public function testMockingDoesNotStubNonStubbedPropertiesOnPartials() { - $m = $this->container->mock(new MockeryTest_ExistingProperty); + $m = mock(new MockeryTest_ExistingProperty); $this->assertEquals('bar', $m->foo); $this->assertFalse(array_key_exists('foo', $m->mockery_getMockableProperties())); } public function testCreationOfInstanceMock() { - $m = $this->container->mock('overload:MyNamespace\MyClass4'); + $m = mock('overload:MyNamespace\MyClass4'); $this->assertTrue($m instanceof MyNamespace\MyClass4); } public function testInstantiationOfInstanceMock() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass5'); + $m = mock('overload:MyNamespace\MyClass5'); $instance = new MyNamespace\MyClass5; $this->assertTrue($instance instanceof MyNamespace\MyClass5); - Mockery::resetContainer(); } public function testInstantiationOfInstanceMockImportsExpectations() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass6'); + $m = mock('overload:MyNamespace\MyClass6'); $m->shouldReceive('foo')->andReturn('bar'); $instance = new MyNamespace\MyClass6; $this->assertEquals('bar', $instance->foo()); - Mockery::resetContainer(); } public function testInstantiationOfInstanceMockImportsDefaultExpectations() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass6'); + $m = mock('overload:MyNamespace\MyClass6'); $m->shouldReceive('foo')->andReturn('bar')->byDefault(); $instance = new MyNamespace\MyClass6; $this->assertEquals('bar', $instance->foo()); - Mockery::resetContainer(); } public function testInstantiationOfInstanceMockImportsDefaultExpectationsInTheCorrectOrder() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass6'); + $m = mock('overload:MyNamespace\MyClass6'); $m->shouldReceive('foo')->andReturn(1)->byDefault(); $m->shouldReceive('foo')->andReturn(2)->byDefault(); $m->shouldReceive('foo')->andReturn(3)->byDefault(); @@ -682,16 +664,12 @@ public function testInstantiationOfInstanceMockImportsDefaultExpectationsInTheCo $this->assertEquals(3, $instance->foo()); - Mockery::resetContainer(); } public function testInstantiationOfInstanceMocksIgnoresVerificationOfOriginMock() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass7'); + $m = mock('overload:MyNamespace\MyClass7'); $m->shouldReceive('foo')->once()->andReturn('bar'); - $this->container->mockery_verify(); - Mockery::resetContainer(); //should not throw an exception } /** @@ -699,25 +677,20 @@ public function testInstantiationOfInstanceMocksIgnoresVerificationOfOriginMock( */ public function testInstantiationOfInstanceMocksAddsThemToContainerForVerification() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass8'); + $m = mock('overload:MyNamespace\MyClass8'); $m->shouldReceive('foo')->once(); $instance = new MyNamespace\MyClass8; - $this->container->mockery_verify(); - Mockery::resetContainer(); + Mockery::close(); } public function testInstantiationOfInstanceMocksDoesNotHaveCountValidatorCrossover() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass9'); + $m = mock('overload:MyNamespace\MyClass9'); $m->shouldReceive('foo')->once(); $instance1 = new MyNamespace\MyClass9; $instance2 = new MyNamespace\MyClass9; $instance1->foo(); $instance2->foo(); - $this->container->mockery_verify(); - Mockery::resetContainer(); } /** @@ -725,32 +698,27 @@ public function testInstantiationOfInstanceMocksDoesNotHaveCountValidatorCrossov */ public function testInstantiationOfInstanceMocksDoesNotHaveCountValidatorCrossover2() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass10'); + $m = mock('overload:MyNamespace\MyClass10'); $m->shouldReceive('foo')->once(); $instance1 = new MyNamespace\MyClass10; $instance2 = new MyNamespace\MyClass10; $instance1->foo(); - $this->container->mockery_verify(); - Mockery::resetContainer(); + Mockery::close(); } public function testCreationOfInstanceMockWithFullyQualifiedName() { - $m = $this->container->mock('overload:\MyNamespace\MyClass11'); + $m = mock('overload:\MyNamespace\MyClass11'); $this->assertTrue($m instanceof MyNamespace\MyClass11); } public function testInstanceMocksShouldIgnoreMissing() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass12'); + $m = mock('overload:MyNamespace\MyClass12'); $m->shouldIgnoreMissing(); $instance = new MyNamespace\MyClass12(); - $instance->foo(); - - Mockery::resetContainer(); + $this->assertNull($instance->foo()); } /** @@ -758,19 +726,17 @@ public function testInstanceMocksShouldIgnoreMissing() */ public function testSettingPropertyOnInstanceMockWillSetItOnActualInstance() { - Mockery::setContainer($this->container); - $m = $this->container->mock('overload:MyNamespace\MyClass13'); + $m = mock('overload:MyNamespace\MyClass13'); $m->shouldReceive('foo')->andSet('bar', 'baz'); $instance = new MyNamespace\MyClass13; $instance->foo(); $this->assertEquals('baz', $m->bar); $this->assertEquals('baz', $instance->bar); - Mockery::resetContainer(); } public function testMethodParamsPassedByReferenceHaveReferencePreserved() { - $m = $this->container->mock('MockeryTestRef1'); + $m = mock('MockeryTestRef1'); $m->shouldReceive('foo')->with( Mockery::on(function (&$a) { $a += 1; @@ -787,7 +753,7 @@ public function testMethodParamsPassedByReferenceHaveReferencePreserved() public function testMethodParamsPassedByReferenceThroughWithArgsHaveReferencePreserved() { - $m = $this->container->mock('MockeryTestRef1'); + $m = mock('MockeryTestRef1'); $m->shouldReceive('foo')->withArgs(function (&$a, $b) { $a += 1; $b += 1; @@ -813,7 +779,7 @@ public function testCanOverrideExpectedParametersOfInternalPHPClassesToPreserveR 'DateTime', 'modify', array('&$string') ); // @ used to avoid E_STRICT for incompatible signature - @$m = $this->container->mock('DateTime'); + @$m = mock('DateTime'); $this->assertInstanceOf("Mockery\MockInterface", $m, "Mocking failed, remove @ error suppresion to debug"); $m->shouldReceive('modify')->with( Mockery::on(function (&$string) { @@ -824,8 +790,6 @@ public function testCanOverrideExpectedParametersOfInternalPHPClassesToPreserveR $data ='bar'; $m->modify($data); $this->assertEquals('foo', $data); - $this->container->mockery_verify(); - Mockery::resetContainer(); Mockery::getConfiguration()->resetInternalClassMethodParamMaps(); } @@ -842,7 +806,7 @@ public function testCanOverrideExpectedParametersOfExtensionPHPClassesToPreserve 'MongoCollection', 'insert', array('&$data', '$options') ); // @ used to avoid E_STRICT for incompatible signature - @$m = $this->container->mock('MongoCollection'); + @$m = mock('MongoCollection'); $this->assertInstanceOf("Mockery\MockInterface", $m, "Mocking failed, remove @ error suppresion to debug"); $m->shouldReceive('insert')->with( Mockery::on(function (&$data) { @@ -855,8 +819,6 @@ public function testCanOverrideExpectedParametersOfExtensionPHPClassesToPreserve $m->insert($data, array()); $this->assertTrue(isset($data['_id'])); $this->assertEquals(123, $data['_id']); - $this->container->mockery_verify(); - Mockery::resetContainer(); Mockery::getConfiguration()->resetInternalClassMethodParamMaps(); } @@ -866,7 +828,7 @@ public function testCanCreateNonOverridenInstanceOfPreviouslyOverridenInternalCl 'DateTime', 'modify', array('&$string') ); // @ used to avoid E_STRICT for incompatible signature - @$m = $this->container->mock('DateTime'); + @$m = mock('DateTime'); $this->assertInstanceOf("Mockery\MockInterface", $m, "Mocking failed, remove @ error suppresion to debug"); $rc = new ReflectionClass($m); $rm = $rc->getMethod('modify'); @@ -875,14 +837,13 @@ public function testCanCreateNonOverridenInstanceOfPreviouslyOverridenInternalCl Mockery::getConfiguration()->resetInternalClassMethodParamMaps(); - $m = $this->container->mock('DateTime'); + $m = mock('DateTime'); $this->assertInstanceOf("Mockery\MockInterface", $m, "Mocking failed"); $rc = new ReflectionClass($m); $rm = $rc->getMethod('modify'); $params = $rm->getParameters(); $this->assertFalse($params[0]->isPassedByReference()); - Mockery::resetContainer(); Mockery::getConfiguration()->resetInternalClassMethodParamMaps(); } @@ -891,7 +852,7 @@ public function testCanCreateNonOverridenInstanceOfPreviouslyOverridenInternalCl */ public function testCanMockAbstractClassWithAbstractPublicMethod() { - $m = $this->container->mock('MockeryTest_AbstractWithAbstractPublicMethod'); + $m = mock('MockeryTest_AbstractWithAbstractPublicMethod'); $this->assertTrue($m instanceof MockeryTest_AbstractWithAbstractPublicMethod); } @@ -900,10 +861,7 @@ public function testCanMockAbstractClassWithAbstractPublicMethod() */ public function testClassDeclaringIssetDoesNotThrowException() { - Mockery::setContainer($this->container); - $m = $this->container->mock('MockeryTest_IssetMethod'); - $this->container->mockery_verify(); - Mockery::resetContainer(); + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_IssetMethod')); } /** @@ -911,10 +869,7 @@ public function testClassDeclaringIssetDoesNotThrowException() */ public function testClassDeclaringUnsetDoesNotThrowException() { - Mockery::setContainer($this->container); - $m = $this->container->mock('MockeryTest_UnsetMethod'); - $this->container->mockery_verify(); - Mockery::resetContainer(); + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_UnsetMethod')); } /** @@ -922,15 +877,13 @@ public function testClassDeclaringUnsetDoesNotThrowException() */ public function testCallingSelfOnlyReturnsLastMockCreatedOrCurrentMockBeingProgrammedSinceTheyAreOneAndTheSame() { - Mockery::setContainer($this->container); - $m = $this->container->mock('MockeryTestFoo'); - $this->assertFalse($this->container->self() instanceof MockeryTestFoo2); - //$m = $this->container->mock('MockeryTestFoo2'); - //$this->assertTrue($this->container->self() instanceof MockeryTestFoo2); - //$m = $this->container->mock('MockeryTestFoo'); + $m = mock('MockeryTestFoo'); + $this->assertFalse(Mockery::self() instanceof MockeryTestFoo2); + //$m = mock('MockeryTestFoo2'); + //$this->assertTrue(self() instanceof MockeryTestFoo2); + //$m = mock('MockeryTestFoo'); //$this->assertFalse(Mockery::self() instanceof MockeryTestFoo2); //$this->assertTrue(Mockery::self() instanceof MockeryTestFoo); - Mockery::resetContainer(); } /** @@ -938,37 +891,35 @@ public function testCallingSelfOnlyReturnsLastMockCreatedOrCurrentMockBeingProgr */ public function testCreatingMockOfClassWithExistingToStringMethodDoesntCreateClassWithTwoToStringMethods() { - Mockery::setContainer($this->container); - $m = $this->container->mock('MockeryTest_WithToString'); // this would fatal + $m = mock('MockeryTest_WithToString'); // this would fatal $m->shouldReceive("__toString")->andReturn('dave'); $this->assertEquals("dave", "$m"); } public function testGetExpectationCount_freshContainer() { - $this->assertEquals(0, $this->container->mockery_getExpectationCount()); + $this->assertEquals(0, Mockery::getContainer()->mockery_getExpectationCount()); } public function testGetExpectationCount_simplestMock() { - $m = $this->container->mock(); + $m = mock(); $m->shouldReceive('foo')->andReturn('bar'); - $this->assertEquals(1, $this->container->mockery_getExpectationCount()); + $this->assertEquals(1, Mockery::getContainer()->mockery_getExpectationCount()); } public function testMethodsReturningParamsByReferenceDoesNotErrorOut() { - $this->container->mock('MockeryTest_ReturnByRef'); - $mock = $this->container->mock('MockeryTest_ReturnByRef'); + mock('MockeryTest_ReturnByRef'); + $mock = mock('MockeryTest_ReturnByRef'); $mock->shouldReceive("get")->andReturn($var = 123); $this->assertSame($var, $mock->get()); } + public function testMockCallableTypeHint() { - if (PHP_VERSION_ID >= 50400) { - $this->container->mock('MockeryTest_MockCallableTypeHint'); - } + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_MockCallableTypeHint')); } public function testCanMockClassWithReservedWordMethod() @@ -977,27 +928,27 @@ public function testCanMockClassWithReservedWordMethod() $this->markTestSkipped("phpredis not installed"); } - $this->container->mock("Redis"); + mock("Redis"); } public function testUndeclaredClassIsDeclared() { $this->assertFalse(class_exists("BlahBlah")); - $mock = $this->container->mock("BlahBlah"); + $mock = mock("BlahBlah"); $this->assertInstanceOf("BlahBlah", $mock); } public function testUndeclaredClassWithNamespaceIsDeclared() { $this->assertFalse(class_exists("MyClasses\Blah\BlahBlah")); - $mock = $this->container->mock("MyClasses\Blah\BlahBlah"); + $mock = mock("MyClasses\Blah\BlahBlah"); $this->assertInstanceOf("MyClasses\Blah\BlahBlah", $mock); } public function testUndeclaredClassWithNamespaceIncludingLeadingOperatorIsDeclared() { $this->assertFalse(class_exists("\MyClasses\DaveBlah\BlahBlah")); - $mock = $this->container->mock("\MyClasses\DaveBlah\BlahBlah"); + $mock = mock("\MyClasses\DaveBlah\BlahBlah"); $this->assertInstanceOf("\MyClasses\DaveBlah\BlahBlah", $mock); } @@ -1006,16 +957,18 @@ public function testMockingPhpredisExtensionClassWorks() if (!class_exists('Redis')) { $this->markTestSkipped('PHPRedis extension required for this test'); } - $m = $this->container->mock('Redis'); + $m = mock('Redis'); } public function testIssetMappingUsingProxiedPartials_CheckNoExceptionThrown() { - $var = $this->container->mock(new MockeryTestIsset_Bar()); - $mock = $this->container->mock(new MockeryTestIsset_Foo($var)); + $var = mock(new MockeryTestIsset_Bar()); + $mock = mock(new MockeryTestIsset_Foo($var)); $mock->shouldReceive('bar')->once(); $mock->bar(); - $this->container->mockery_teardown(); // closed by teardown() + Mockery::close(); + + $this->assertTrue(true); } /** @@ -1023,7 +976,7 @@ public function testIssetMappingUsingProxiedPartials_CheckNoExceptionThrown() */ public function testCanMockInterfacesExtendingTraversable() { - $mock = $this->container->mock('MockeryTest_InterfaceWithTraversable'); + $mock = mock('MockeryTest_InterfaceWithTraversable'); $this->assertInstanceOf('MockeryTest_InterfaceWithTraversable', $mock); $this->assertInstanceOf('ArrayAccess', $mock); $this->assertInstanceOf('Countable', $mock); @@ -1035,7 +988,7 @@ public function testCanMockInterfacesExtendingTraversable() */ public function testCanMockInterfacesAlongsideTraversable() { - $mock = $this->container->mock('stdClass, ArrayAccess, Countable, Traversable'); + $mock = mock('stdClass, ArrayAccess, Countable, Traversable'); $this->assertInstanceOf('stdClass', $mock); $this->assertInstanceOf('ArrayAccess', $mock); $this->assertInstanceOf('Countable', $mock); @@ -1044,17 +997,14 @@ public function testCanMockInterfacesAlongsideTraversable() public function testInterfacesCanHaveAssertions() { - Mockery::setContainer($this->container); - $m = $this->container->mock('stdClass, ArrayAccess, Countable, Traversable'); + $m = mock('stdClass, ArrayAccess, Countable, Traversable'); $m->shouldReceive('foo')->once(); $m->foo(); - $this->container->mockery_verify(); - Mockery::resetContainer(); } public function testMockingIteratorAggregateDoesNotImplementIterator() { - $mock = $this->container->mock('MockeryTest_ImplementsIteratorAggregate'); + $mock = mock('MockeryTest_ImplementsIteratorAggregate'); $this->assertInstanceOf('IteratorAggregate', $mock); $this->assertInstanceOf('Traversable', $mock); $this->assertNotInstanceOf('Iterator', $mock); @@ -1062,14 +1012,14 @@ public function testMockingIteratorAggregateDoesNotImplementIterator() public function testMockingInterfaceThatExtendsIteratorDoesNotImplementIterator() { - $mock = $this->container->mock('MockeryTest_InterfaceThatExtendsIterator'); + $mock = mock('MockeryTest_InterfaceThatExtendsIterator'); $this->assertInstanceOf('Iterator', $mock); $this->assertInstanceOf('Traversable', $mock); } public function testMockingInterfaceThatExtendsIteratorAggregateDoesNotImplementIterator() { - $mock = $this->container->mock('MockeryTest_InterfaceThatExtendsIteratorAggregate'); + $mock = mock('MockeryTest_InterfaceThatExtendsIteratorAggregate'); $this->assertInstanceOf('IteratorAggregate', $mock); $this->assertInstanceOf('Traversable', $mock); $this->assertNotInstanceOf('Iterator', $mock); @@ -1077,7 +1027,7 @@ public function testMockingInterfaceThatExtendsIteratorAggregateDoesNotImplement public function testMockingIteratorAggregateDoesNotImplementIteratorAlongside() { - $mock = $this->container->mock('IteratorAggregate'); + $mock = mock('IteratorAggregate'); $this->assertInstanceOf('IteratorAggregate', $mock); $this->assertInstanceOf('Traversable', $mock); $this->assertNotInstanceOf('Iterator', $mock); @@ -1085,14 +1035,14 @@ public function testMockingIteratorAggregateDoesNotImplementIteratorAlongside() public function testMockingIteratorDoesNotImplementIteratorAlongside() { - $mock = $this->container->mock('Iterator'); + $mock = mock('Iterator'); $this->assertInstanceOf('Iterator', $mock); $this->assertInstanceOf('Traversable', $mock); } public function testMockingIteratorDoesNotImplementIterator() { - $mock = $this->container->mock('MockeryTest_ImplementsIterator'); + $mock = mock('MockeryTest_ImplementsIterator'); $this->assertInstanceOf('Iterator', $mock); $this->assertInstanceOf('Traversable', $mock); } @@ -1105,19 +1055,23 @@ public function testMockeryCloseForIllegalIssetFileInclude() ->getMock(); $m->get(); Mockery::close(); + + // no idea what this test does, adding this as an assertion... + $this->assertTrue(true); } public function testMockeryShouldDistinguishBetweenConstructorParamsAndClosures() { $obj = new MockeryTestFoo(); - $mock = $this->container->mock('MockeryTest_ClassMultipleConstructorParams[dave]', - array( &$obj, 'foo' )); + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_ClassMultipleConstructorParams[dave]', [ + &$obj, 'foo' + ])); } /** @group nette */ public function testMockeryShouldNotMockCallstaticMagicMethod() { - $mock = $this->container->mock('MockeryTest_CallStatic'); + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_CallStatic')); } /** @@ -1125,40 +1079,39 @@ public function testMockeryShouldNotMockCallstaticMagicMethod() */ public function testCanMockClassWithOldStyleConstructorAndArguments() { - $mock = $this->container->mock('MockeryTest_OldStyleConstructor'); + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_OldStyleConstructor')); } /** @group issue/144 */ public function testMockeryShouldInterpretEmptyArrayAsConstructorArgs() { - $mock = $this->container->mock("EmptyConstructorTest", array()); + $mock = mock("EmptyConstructorTest", array()); $this->assertSame(0, $mock->numberOfConstructorArgs); } /** @group issue/144 */ public function testMockeryShouldCallConstructorByDefaultWhenRequestingPartials() { - $mock = $this->container->mock("EmptyConstructorTest[foo]"); + $mock = mock("EmptyConstructorTest[foo]"); $this->assertSame(0, $mock->numberOfConstructorArgs); } /** @group issue/158 */ public function testMockeryShouldRespectInterfaceWithMethodParamSelf() { - $this->container->mock('MockeryTest_InterfaceWithMethodParamSelf'); + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_InterfaceWithMethodParamSelf')); } /** @group issue/162 */ public function testMockeryDoesntTryAndMockLowercaseToString() { - $this->container->mock('MockeryTest_Lowercase_ToString'); + $this->assertInstanceOf(MockInterface::class, mock('MockeryTest_Lowercase_ToString')); } /** @group issue/175 */ public function testExistingStaticMethodMocking() { - Mockery::setContainer($this->container); - $mock = $this->container->mock('MockeryTest_PartialStatic[mockMe]'); + $mock = mock('MockeryTest_PartialStatic[mockMe]'); $mock->shouldReceive('mockMe')->with(5)->andReturn(10); @@ -1173,7 +1126,7 @@ public function testExistingStaticMethodMocking() */ public function testShouldThrowIfAttemptingToStubProtectedMethod() { - $mock = $this->container->mock('MockeryTest_WithProtectedAndPrivate'); + $mock = mock('MockeryTest_WithProtectedAndPrivate'); $mock->shouldReceive("protectedMethod"); } @@ -1184,13 +1137,13 @@ public function testShouldThrowIfAttemptingToStubProtectedMethod() */ public function testShouldThrowIfAttemptingToStubPrivateMethod() { - $mock = $this->container->mock('MockeryTest_WithProtectedAndPrivate'); + $mock = mock('MockeryTest_WithProtectedAndPrivate'); $mock->shouldReceive("privateMethod"); } public function testWakeupMagicIsNotMockedToAllowSerialisationInstanceHack() { - $mock = $this->container->mock('DateTime'); + $this->assertInstanceOf(\DateTime::class, mock('DateTime')); } /** @@ -1198,9 +1151,9 @@ public function testWakeupMagicIsNotMockedToAllowSerialisationInstanceHack() */ public function testCanMockMethodsWithRequiredParamsThatHaveDefaultValues() { - $mock = $this->container->mock('MockeryTest_MethodWithRequiredParamWithDefaultValue'); + $mock = mock('MockeryTest_MethodWithRequiredParamWithDefaultValue'); $mock->shouldIgnoreMissing(); - $mock->foo(null, 123); + $this->assertNull($mock->foo(null, 123)); } /** @@ -1213,7 +1166,7 @@ public function testThrowsWhenNamedMockClassExistsAndIsNotMockery() { $builder = new MockConfigurationBuilder(); $builder->setName("DateTime"); - $mock = $this->container->mock($builder); + $mock = mock($builder); } /** @@ -1222,7 +1175,7 @@ public function testThrowsWhenNamedMockClassExistsAndIsNotMockery() */ public function testHandlesMethodWithArgumentExpectationWhenCalledWithResource() { - $mock = $this->container->mock('MyTestClass'); + $mock = mock('MyTestClass'); $mock->shouldReceive('foo')->with(array('yourself' => 21)); $mock->foo(fopen('php://memory', 'r')); @@ -1237,7 +1190,7 @@ public function testHandlesMethodWithArgumentExpectationWhenCalledWithCircularAr $testArray = array(); $testArray['myself'] =& $testArray; - $mock = $this->container->mock('MyTestClass'); + $mock = mock('MyTestClass'); $mock->shouldReceive('foo')->with(array('yourself' => 21)); $mock->foo($testArray); @@ -1253,7 +1206,7 @@ public function testHandlesMethodWithArgumentExpectationWhenCalledWithNestedArra $testArray['a_scalar'] = 2; $testArray['an_array'] = array(1, 2, 3); - $mock = $this->container->mock('MyTestClass'); + $mock = mock('MyTestClass'); $mock->shouldReceive('foo')->with(array('yourself' => 21)); $mock->foo($testArray); @@ -1269,7 +1222,7 @@ public function testHandlesMethodWithArgumentExpectationWhenCalledWithNestedObje $testArray['a_scalar'] = 2; $testArray['an_object'] = new stdClass(); - $mock = $this->container->mock('MyTestClass'); + $mock = mock('MyTestClass'); $mock->shouldReceive('foo')->with(array('yourself' => 21)); $mock->foo($testArray); @@ -1286,7 +1239,7 @@ public function testHandlesMethodWithArgumentExpectationWhenCalledWithNestedClos $testArray['a_closure'] = function () { }; - $mock = $this->container->mock('MyTestClass'); + $mock = mock('MyTestClass'); $mock->shouldReceive('foo')->with(array('yourself' => 21)); $mock->foo($testArray); @@ -1302,7 +1255,7 @@ public function testHandlesMethodWithArgumentExpectationWhenCalledWithNestedReso $testArray['a_scalar'] = 2; $testArray['a_resource'] = fopen('php://memory', 'r'); - $mock = $this->container->mock('MyTestClass'); + $mock = mock('MyTestClass'); $mock->shouldReceive('foo')->with(array('yourself' => 21)); $mock->foo($testArray); @@ -1310,7 +1263,7 @@ public function testHandlesMethodWithArgumentExpectationWhenCalledWithNestedReso public function testExceptionOutputMakesBooleansLookLikeBooleans() { - $mock = $this->container->mock('MyTestClass'); + $mock = mock('MyTestClass'); $mock->shouldReceive("foo")->with(123); $this->expectException( @@ -1327,7 +1280,7 @@ public function testExceptionOutputMakesBooleansLookLikeBooleans() */ public function canMockClassesThatDescendFromInternalClasses() { - $mock = $this->container->mock("MockeryTest_ClassThatDescendsFromInternalClass"); + $mock = mock("MockeryTest_ClassThatDescendsFromInternalClass"); $this->assertInstanceOf("DateTime", $mock); } @@ -1337,7 +1290,7 @@ public function canMockClassesThatDescendFromInternalClasses() */ public function canMockClassesThatImplementSerializable() { - $mock = $this->container->mock("MockeryTest_ClassThatImplementsSerializable"); + $mock = mock("MockeryTest_ClassThatImplementsSerializable"); $this->assertInstanceOf("Serializable", $mock); } @@ -1347,7 +1300,7 @@ public function canMockClassesThatImplementSerializable() */ public function canMockInternalClassesThatImplementSerializable() { - $mock = $this->container->mock("ArrayObject"); + $mock = mock("ArrayObject"); $this->assertInstanceOf("Serializable", $mock); } diff --git a/tests/Mockery/ExpectationTest.php b/tests/Mockery/ExpectationTest.php index de855358b..8b966f27d 100644 --- a/tests/Mockery/ExpectationTest.php +++ b/tests/Mockery/ExpectationTest.php @@ -21,19 +21,20 @@ use Mockery\Adapter\Phpunit\MockeryTestCase; use Mockery\Exception\InvalidCountException; +use Mockery\MockInterface; class ExpectationTest extends MockeryTestCase { public function setup() { - $this->container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader()); - $this->mock = $this->container->mock('foo'); + parent::setUp(); + $this->mock = mock(); } public function teardown() { + parent::tearDown(); \Mockery::getConfiguration()->allowMockingNonExistentMethods(true); - $this->container->mockery_close(); } public function testReturnsNullWhenNoArgs() @@ -62,14 +63,14 @@ public function testReturnsNullIfNullIsReturnValue() public function testReturnsNullForMockedExistingClassIfAndreturnnullCalled() { - $mock = $this->container->mock('MockeryTest_Foo'); + $mock = mock('MockeryTest_Foo'); $mock->shouldReceive('foo')->andReturn(null); $this->assertNull($mock->foo()); } public function testReturnsNullForMockedExistingClassIfNullIsReturnValue() { - $mock = $this->container->mock('MockeryTest_Foo'); + $mock = mock('MockeryTest_Foo'); $mock->shouldReceive('foo')->andReturnNull(); $this->assertNull($mock->foo()); } @@ -238,6 +239,7 @@ public function testThrowsException() { $this->mock->shouldReceive('foo')->andThrow(new OutOfBoundsException); $this->mock->foo(); + Mockery::close(); } /** @@ -258,6 +260,7 @@ public function testThrowsExceptionBasedOnArgs() { $this->mock->shouldReceive('foo')->andThrow('OutOfBoundsException'); $this->mock->foo(); + Mockery::close(); } public function testThrowsExceptionBasedOnArgsWithMessage() @@ -281,6 +284,7 @@ public function testThrowsExceptionSequentially() } catch (Exception $e) { } $this->mock->foo(); + Mockery::close(); } public function testAndThrowExceptions() @@ -314,6 +318,7 @@ public function testAndThrowExceptionsCatchNonExceptionArgument() $this->mock ->shouldReceive('foo') ->andThrowExceptions(array('NotAnException')); + Mockery::close(); } public function testMultipleExpectationsWithReturns() @@ -337,6 +342,7 @@ public function testExpectsNoArgumentsThrowsExceptionIfAnyPassed() { $this->mock->shouldReceive('foo')->withNoArgs(); $this->mock->foo(1); + Mockery::close(); } public function testExpectsArgumentsArray() @@ -352,6 +358,7 @@ public function testExpectsArgumentsArrayThrowsExceptionIfPassedEmptyArray() { $this->mock->shouldReceive('foo')->withArgs(array()); $this->mock->foo(1, 2); + Mockery::close(); } /** @@ -361,6 +368,7 @@ public function testExpectsArgumentsArrayThrowsExceptionIfNoArgumentsPassed() { $this->mock->shouldReceive('foo')->with(); $this->mock->foo(1); + Mockery::close(); } /** @@ -370,6 +378,7 @@ public function testExpectsArgumentsArrayThrowsExceptionIfPassedWrongArguments() { $this->mock->shouldReceive('foo')->withArgs(array(1, 2)); $this->mock->foo(3, 4); + Mockery::close(); } /** @@ -380,6 +389,7 @@ public function testExpectsStringArgumentExceptionMessageDifferentiatesBetweenNu { $this->mock->shouldReceive('foo')->withArgs(array('a string')); $this->mock->foo(null); + Mockery::close(); } /** @@ -389,6 +399,7 @@ public function testExpectsStringArgumentExceptionMessageDifferentiatesBetweenNu public function testExpectsArgumentsArrayThrowsExceptionIfPassedWrongArgumentType() { $this->mock->shouldReceive('foo')->withArgs(5); + Mockery::close(); } public function testExpectsArgumentsArrayAcceptAClosureThatValidatesPassedArguments() @@ -398,7 +409,6 @@ public function testExpectsArgumentsArrayAcceptAClosureThatValidatesPassedArgume }; $this->mock->shouldReceive('foo')->withArgs($closure); $this->mock->foo(1, 2); - $this->container->mockery_verify(); } /** @@ -411,7 +421,7 @@ public function testExpectsArgumentsArrayThrowsExceptionWhenClosureEvaluatesToFa }; $this->mock->shouldReceive('foo')->withArgs($closure); $this->mock->foo(4, 2); - $this->container->mockery_verify(); + Mockery::close(); } public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalArgumentsAreMissing() @@ -425,7 +435,6 @@ public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalA }; $this->mock->shouldReceive('foo')->withArgs($closure); $this->mock->foo(1, 4); - $this->container->mockery_verify(); } public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalArgumentsMathTheExpectation() @@ -439,7 +448,6 @@ public function testExpectsArgumentsArrayClosureDoesNotThrowExceptionIfOptionalA }; $this->mock->shouldReceive('foo')->withArgs($closure); $this->mock->foo(1, 4, 5); - $this->container->mockery_verify(); } /** @@ -456,7 +464,7 @@ public function testExpectsArgumentsArrayClosureThrowsExceptionIfOptionalArgumen }; $this->mock->shouldReceive('foo')->withArgs($closure); $this->mock->foo(1, 4, 2); - $this->container->mockery_verify(); + Mockery::close(); } public function testExpectsAnyArguments() @@ -480,18 +488,17 @@ public function testThrowsExceptionOnNoArgumentMatch() { $this->mock->shouldReceive('foo')->with(1); $this->mock->foo(2); + Mockery::close(); } public function testNeverCalled() { $this->mock->shouldReceive('foo')->never(); - $this->container->mockery_verify(); } public function testShouldNotReceive() { $this->mock->shouldNotReceive('foo'); - $this->container->mockery_verify(); } /** @@ -501,7 +508,7 @@ public function testShouldNotReceiveThrowsExceptionIfMethodCalled() { $this->mock->shouldNotReceive('foo'); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -511,7 +518,7 @@ public function testShouldNotReceiveWithArgumentThrowsExceptionIfMethodCalled() { $this->mock->shouldNotReceive('foo')->with(2); $this->mock->foo(2); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -521,14 +528,13 @@ public function testNeverCalledThrowsExceptionOnCall() { $this->mock->shouldReceive('foo')->never(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testCalledOnce() { $this->mock->shouldReceive('foo')->once(); $this->mock->foo(); - $this->container->mockery_verify(); } /** @@ -537,7 +543,7 @@ public function testCalledOnce() public function testCalledOnceThrowsExceptionIfNotCalled() { $this->mock->shouldReceive('foo')->once(); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -548,7 +554,7 @@ public function testCalledOnceThrowsExceptionIfCalledTwice() $this->mock->shouldReceive('foo')->once(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testCalledTwice() @@ -556,7 +562,6 @@ public function testCalledTwice() $this->mock->shouldReceive('foo')->twice(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); } /** @@ -565,7 +570,7 @@ public function testCalledTwice() public function testCalledTwiceThrowsExceptionIfNotCalled() { $this->mock->shouldReceive('foo')->twice(); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -577,13 +582,12 @@ public function testCalledOnceThrowsExceptionIfCalledThreeTimes() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testCalledZeroOrMoreTimesAtZeroCalls() { $this->mock->shouldReceive('foo')->zeroOrMoreTimes(); - $this->container->mockery_verify(); } public function testCalledZeroOrMoreTimesAtThreeCalls() @@ -592,7 +596,6 @@ public function testCalledZeroOrMoreTimesAtThreeCalls() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); } public function testTimesCountCalls() @@ -602,7 +605,6 @@ public function testTimesCountCalls() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); } /** @@ -612,7 +614,7 @@ public function testTimesCountCallThrowsExceptionOnTooFewCalls() { $this->mock->shouldReceive('foo')->times(2); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -624,14 +626,13 @@ public function testTimesCountCallThrowsExceptionOnTooManyCalls() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testCalledAtLeastOnceAtExactlyOneCall() { $this->mock->shouldReceive('foo')->atLeast()->once(); $this->mock->foo(); - $this->container->mockery_verify(); } public function testCalledAtLeastOnceAtExactlyThreeCalls() @@ -640,7 +641,6 @@ public function testCalledAtLeastOnceAtExactlyThreeCalls() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); } /** @@ -650,14 +650,13 @@ public function testCalledAtLeastThrowsExceptionOnTooFewCalls() { $this->mock->shouldReceive('foo')->atLeast()->twice(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testCalledAtMostOnceAtExactlyOneCall() { $this->mock->shouldReceive('foo')->atMost()->once(); $this->mock->foo(); - $this->container->mockery_verify(); } public function testCalledAtMostAtExactlyThreeCalls() @@ -666,7 +665,6 @@ public function testCalledAtMostAtExactlyThreeCalls() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); } /** @@ -678,7 +676,7 @@ public function testCalledAtLeastThrowsExceptionOnTooManyCalls() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -689,14 +687,13 @@ public function testExactCountersOverrideAnyPriorSetNonExactCounters() $this->mock->shouldReceive('foo')->atLeast()->once()->once(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testComboOfLeastAndMostCallsWithOneCall() { $this->mock->shouldReceive('foo')->atleast()->once()->atMost()->twice(); $this->mock->foo(); - $this->container->mockery_verify(); } public function testComboOfLeastAndMostCallsWithTwoCalls() @@ -704,7 +701,6 @@ public function testComboOfLeastAndMostCallsWithTwoCalls() $this->mock->shouldReceive('foo')->atleast()->once()->atMost()->twice(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); } /** @@ -713,7 +709,7 @@ public function testComboOfLeastAndMostCallsWithTwoCalls() public function testComboOfLeastAndMostCallsThrowsExceptionAtTooFewCalls() { $this->mock->shouldReceive('foo')->atleast()->once()->atMost()->twice(); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -725,7 +721,7 @@ public function testComboOfLeastAndMostCallsThrowsExceptionAtTooManyCalls() $this->mock->foo(); $this->mock->foo(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testCallCountingOnlyAppliesToMatchedExpectations() @@ -737,7 +733,6 @@ public function testCallCountingOnlyAppliesToMatchedExpectations() $this->mock->foo(2); $this->mock->foo(2); $this->mock->foo(3); - $this->container->mockery_verify(); } /** @@ -753,7 +748,7 @@ public function testCallCountingThrowsExceptionOnAnyMismatch() $this->mock->foo(2); $this->mock->foo(3); $this->mock->bar(); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -772,7 +767,7 @@ public function testCallCountingThrowsExceptionFirst() $this->mock->foo(1); $this->mock->foo(1); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testOrderedCallsWithoutError() @@ -781,7 +776,6 @@ public function testOrderedCallsWithoutError() $this->mock->shouldReceive('bar')->ordered(); $this->mock->foo(); $this->mock->bar(); - $this->container->mockery_verify(); } /** @@ -793,7 +787,7 @@ public function testOrderedCallsWithOutOfOrderError() $this->mock->shouldReceive('bar')->ordered(); $this->mock->bar(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testDifferentArgumentsAndOrderingsPassWithoutException() @@ -802,7 +796,6 @@ public function testDifferentArgumentsAndOrderingsPassWithoutException() $this->mock->shouldReceive('foo')->with(2)->ordered(); $this->mock->foo(1); $this->mock->foo(2); - $this->container->mockery_verify(); } /** @@ -814,7 +807,7 @@ public function testDifferentArgumentsAndOrderingsThrowExceptionWhenInWrongOrder $this->mock->shouldReceive('foo')->with(2)->ordered(); $this->mock->foo(2); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testUnorderedCallsIgnoredForOrdering() @@ -827,7 +820,6 @@ public function testUnorderedCallsIgnoredForOrdering() $this->mock->foo(2); $this->mock->foo(3); $this->mock->foo(2); - $this->container->mockery_verify(); } public function testOrderingOfDefaultGrouping() @@ -836,7 +828,6 @@ public function testOrderingOfDefaultGrouping() $this->mock->shouldReceive('bar')->ordered(); $this->mock->foo(); $this->mock->bar(); - $this->container->mockery_verify(); } /** @@ -848,7 +839,7 @@ public function testOrderingOfDefaultGroupingThrowsExceptionOnWrongOrder() $this->mock->shouldReceive('bar')->ordered(); $this->mock->bar(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testOrderingUsingNumberedGroups() @@ -862,7 +853,6 @@ public function testOrderingUsingNumberedGroups() $this->mock->foo(); $this->mock->bar(); $this->mock->final(); - $this->container->mockery_verify(); } public function testOrderingUsingNamedGroups() @@ -876,7 +866,6 @@ public function testOrderingUsingNamedGroups() $this->mock->foo(); $this->mock->bar(); $this->mock->final(); - $this->container->mockery_verify(); } /** @@ -900,7 +889,7 @@ public function testGroupedOrderingThrowsExceptionWhenCallsDisordered() $this->mock->shouldReceive('bar')->ordered('second'); $this->mock->bar(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testExpectationMatchingWithNoArgsOrderings() @@ -911,7 +900,6 @@ public function testExpectationMatchingWithNoArgsOrderings() $this->mock->foo(); $this->mock->bar(); $this->mock->foo(); - $this->container->mockery_verify(); } public function testExpectationMatchingWithAnyArgsOrderings() @@ -922,13 +910,12 @@ public function testExpectationMatchingWithAnyArgsOrderings() $this->mock->foo(); $this->mock->bar(); $this->mock->foo(); - $this->container->mockery_verify(); } public function testEnsuresOrderingIsNotCrossMockByDefault() { $this->mock->shouldReceive('foo')->ordered(); - $mock2 = $this->container->mock('bar'); + $mock2 = mock('bar'); $mock2->shouldReceive('bar')->ordered(); $mock2->bar(); $this->mock->foo(); @@ -940,10 +927,11 @@ public function testEnsuresOrderingIsNotCrossMockByDefault() public function testEnsuresOrderingIsCrossMockWhenGloballyFlagSet() { $this->mock->shouldReceive('foo')->globally()->ordered(); - $mock2 = $this->container->mock('bar'); + $mock2 = mock('bar'); $mock2->shouldReceive('bar')->globally()->ordered(); $mock2->bar(); $this->mock->foo(); + Mockery::close(); } public function testExpectationCastToStringFormatting() @@ -975,14 +963,12 @@ public function testGroupedOrderingWithLimitsAllowsMultipleReturnValues() $this->assertEquals('infinity', $this->mock->foo(2)); $this->assertEquals('infinity', $this->mock->foo(2)); $this->assertEquals('infinity', $this->mock->foo(2)); - $this->container->mockery_verify(); } public function testExpectationsCanBeMarkedAsDefaults() { $this->mock->shouldReceive('foo')->andReturn('bar')->byDefault(); $this->assertEquals('bar', $this->mock->foo()); - $this->container->mockery_verify(); } public function testDefaultExpectationsValidatedInCorrectOrder() @@ -991,7 +977,6 @@ public function testDefaultExpectationsValidatedInCorrectOrder() $this->mock->shouldReceive('foo')->with(2)->once()->andReturn('second')->byDefault(); $this->assertEquals('first', $this->mock->foo(1)); $this->assertEquals('second', $this->mock->foo(2)); - $this->container->mockery_verify(); } public function testDefaultExpectationsAreReplacedByLaterConcreteExpectations() @@ -1000,7 +985,6 @@ public function testDefaultExpectationsAreReplacedByLaterConcreteExpectations() $this->mock->shouldReceive('foo')->andReturn('baz')->twice(); $this->assertEquals('baz', $this->mock->foo()); $this->assertEquals('baz', $this->mock->foo()); - $this->container->mockery_verify(); } public function testExpectationFallsBackToDefaultExpectationWhenConcreteExpectationsAreUsedUp() @@ -1009,7 +993,6 @@ public function testExpectationFallsBackToDefaultExpectationWhenConcreteExpectat $this->mock->shouldReceive('foo')->with(2)->andReturn('baz')->once(); $this->assertEquals('baz', $this->mock->foo(2)); $this->assertEquals('bar', $this->mock->foo(1)); - $this->container->mockery_verify(); } /** @@ -1021,7 +1004,7 @@ public function testDefaultExpectationsCanBeOrdered() $this->mock->shouldReceive('bar')->ordered()->byDefault(); $this->mock->bar(); $this->mock->foo(); - $this->container->mockery_verify(); + Mockery::close(); } public function testDefaultExpectationsCanBeOrderedAndReplaced() @@ -1032,7 +1015,6 @@ public function testDefaultExpectationsCanBeOrderedAndReplaced() $this->mock->shouldReceive('foo')->ordered(); $this->mock->bar(); $this->mock->foo(); - $this->container->mockery_verify(); } public function testByDefaultOperatesFromMockConstruction() @@ -1043,13 +1025,11 @@ public function testByDefaultOperatesFromMockConstruction() $this->assertEquals('foobar', $mock->foo()); $this->assertEquals('rbar', $mock->bar()); $this->assertEquals('rbaz', $mock->baz()); - $mock->mockery_verify(); } public function testByDefaultOnAMockDoesSquatWithoutExpectations() { - $container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader()); - $mock = $container->mock('f')->byDefault(); + $this->assertInstanceOf(MockInterface::class, mock('f')->byDefault()); } public function testDefaultExpectationsCanBeOverridden() @@ -1068,6 +1048,7 @@ public function testByDefaultPreventedFromSettingDefaultWhenDefaultingExpectatio $exp = $this->mock->shouldReceive('foo')->andReturn(1); $this->mock->shouldReceive('foo')->andReturn(2); $exp->byDefault(); + Mockery::close(); } /** @@ -1079,7 +1060,6 @@ public function testAnyConstraintMatchesAnyArg() $this->mock->shouldReceive('foo')->with(1, Mockery::any())->twice(); $this->mock->foo(1, 2); $this->mock->foo(1, 'str'); - $this->container->mockery_verify(); } public function testAnyConstraintNonMatchingCase() @@ -1089,14 +1069,12 @@ public function testAnyConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } public function testArrayConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('array'))->once(); $this->mock->foo(array()); - $this->container->mockery_verify(); } public function testArrayConstraintNonMatchingCase() @@ -1106,7 +1084,6 @@ public function testArrayConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1114,16 +1091,15 @@ public function testArrayConstraintNonMatchingCase() */ public function testArrayConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('array'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('array')); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testBoolConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('bool'))->once(); $this->mock->foo(true); - $this->container->mockery_verify(); } public function testBoolConstraintNonMatchingCase() @@ -1133,7 +1109,6 @@ public function testBoolConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1141,9 +1116,9 @@ public function testBoolConstraintNonMatchingCase() */ public function testBoolConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('bool'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('bool')); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testCallableConstraintMatchesArgument() @@ -1152,7 +1127,6 @@ public function testCallableConstraintMatchesArgument() $this->mock->foo(function () { return 'f'; }); - $this->container->mockery_verify(); } public function testCallableConstraintNonMatchingCase() @@ -1162,7 +1136,6 @@ public function testCallableConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1170,16 +1143,15 @@ public function testCallableConstraintNonMatchingCase() */ public function testCallableConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('callable'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('callable')); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testDoubleConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('double'))->once(); $this->mock->foo(2.25); - $this->container->mockery_verify(); } public function testDoubleConstraintNonMatchingCase() @@ -1189,7 +1161,6 @@ public function testDoubleConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1197,16 +1168,15 @@ public function testDoubleConstraintNonMatchingCase() */ public function testDoubleConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('double'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('double')); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testFloatConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('float'))->once(); $this->mock->foo(2.25); - $this->container->mockery_verify(); } public function testFloatConstraintNonMatchingCase() @@ -1216,7 +1186,6 @@ public function testFloatConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1224,16 +1193,15 @@ public function testFloatConstraintNonMatchingCase() */ public function testFloatConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('float'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('float')); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testIntConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('int'))->once(); $this->mock->foo(2); - $this->container->mockery_verify(); } public function testIntConstraintNonMatchingCase() @@ -1243,7 +1211,6 @@ public function testIntConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1251,16 +1218,15 @@ public function testIntConstraintNonMatchingCase() */ public function testIntConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('int'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('int')); $this->mock->foo('f'); - $this->container->mockery_verify(); + Mockery::close(); } public function testLongConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('long'))->once(); $this->mock->foo(2); - $this->container->mockery_verify(); } public function testLongConstraintNonMatchingCase() @@ -1270,7 +1236,6 @@ public function testLongConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1278,16 +1243,15 @@ public function testLongConstraintNonMatchingCase() */ public function testLongConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('long'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('long')); $this->mock->foo('f'); - $this->container->mockery_verify(); + Mockery::close(); } public function testNullConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('null'))->once(); $this->mock->foo(null); - $this->container->mockery_verify(); } public function testNullConstraintNonMatchingCase() @@ -1297,7 +1261,6 @@ public function testNullConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1305,16 +1268,15 @@ public function testNullConstraintNonMatchingCase() */ public function testNullConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('null'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('null')); $this->mock->foo('f'); - $this->container->mockery_verify(); + Mockery::close(); } public function testNumericConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('numeric'))->once(); $this->mock->foo('2'); - $this->container->mockery_verify(); } public function testNumericConstraintNonMatchingCase() @@ -1324,7 +1286,6 @@ public function testNumericConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1332,16 +1293,15 @@ public function testNumericConstraintNonMatchingCase() */ public function testNumericConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('numeric'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('numeric')); $this->mock->foo('f'); - $this->container->mockery_verify(); + Mockery::close(); } public function testObjectConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('object'))->once(); $this->mock->foo(new stdClass); - $this->container->mockery_verify(); } public function testObjectConstraintNonMatchingCase() @@ -1351,7 +1311,6 @@ public function testObjectConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1359,16 +1318,15 @@ public function testObjectConstraintNonMatchingCase() */ public function testObjectConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('object'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('object')); $this->mock->foo('f'); - $this->container->mockery_verify(); + Mockery::close(); } public function testRealConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('real'))->once(); $this->mock->foo(2.25); - $this->container->mockery_verify(); } public function testRealConstraintNonMatchingCase() @@ -1378,7 +1336,6 @@ public function testRealConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1386,9 +1343,9 @@ public function testRealConstraintNonMatchingCase() */ public function testRealConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('real'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('real')); $this->mock->foo('f'); - $this->container->mockery_verify(); + Mockery::close(); } public function testResourceConstraintMatchesArgument() @@ -1396,7 +1353,6 @@ public function testResourceConstraintMatchesArgument() $this->mock->shouldReceive('foo')->with(Mockery::type('resource'))->once(); $r = fopen(dirname(__FILE__) . '/_files/file.txt', 'r'); $this->mock->foo($r); - $this->container->mockery_verify(); } public function testResourceConstraintNonMatchingCase() @@ -1406,7 +1362,6 @@ public function testResourceConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1414,16 +1369,15 @@ public function testResourceConstraintNonMatchingCase() */ public function testResourceConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('resource'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('resource')); $this->mock->foo('f'); - $this->container->mockery_verify(); + Mockery::close(); } public function testScalarConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('scalar'))->once(); $this->mock->foo(2); - $this->container->mockery_verify(); } public function testScalarConstraintNonMatchingCase() @@ -1433,7 +1387,6 @@ public function testScalarConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1441,16 +1394,15 @@ public function testScalarConstraintNonMatchingCase() */ public function testScalarConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('scalar'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('scalar')); $this->mock->foo(array()); - $this->container->mockery_verify(); + Mockery::close(); } public function testStringConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('string'))->once(); $this->mock->foo('2'); - $this->container->mockery_verify(); } public function testStringConstraintNonMatchingCase() @@ -1460,7 +1412,6 @@ public function testStringConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1468,16 +1419,15 @@ public function testStringConstraintNonMatchingCase() */ public function testStringConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('string'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('string')); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } public function testClassConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::type('stdClass'))->once(); $this->mock->foo(new stdClass); - $this->container->mockery_verify(); } public function testClassConstraintNonMatchingCase() @@ -1487,7 +1437,6 @@ public function testClassConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1495,16 +1444,15 @@ public function testClassConstraintNonMatchingCase() */ public function testClassConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::type('stdClass'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::type('stdClass')); $this->mock->foo(new Exception); - $this->container->mockery_verify(); + Mockery::close(); } public function testDucktypeConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::ducktype('quack', 'swim'))->once(); $this->mock->foo(new Mockery_Duck); - $this->container->mockery_verify(); } public function testDucktypeConstraintNonMatchingCase() @@ -1514,7 +1462,6 @@ public function testDucktypeConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1522,16 +1469,15 @@ public function testDucktypeConstraintNonMatchingCase() */ public function testDucktypeConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::ducktype('quack', 'swim'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::ducktype('quack', 'swim')); $this->mock->foo(new Mockery_Duck_Nonswimmer); - $this->container->mockery_verify(); + 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)); - $this->container->mockery_verify(); } public function testArrayContentConstraintNonMatchingCase() @@ -1541,7 +1487,6 @@ public function testArrayContentConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1549,16 +1494,15 @@ public function testArrayContentConstraintNonMatchingCase() */ public function testArrayContentConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::subset(array('a'=>1, 'b'=>2)))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::subset(array('a'=>1, 'b'=>2))); $this->mock->foo(array('a'=>1, 'c'=>3)); - $this->container->mockery_verify(); + 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)); - $this->container->mockery_verify(); } public function testContainsConstraintNonMatchingCase() @@ -1568,7 +1512,6 @@ public function testContainsConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1576,16 +1519,15 @@ public function testContainsConstraintNonMatchingCase() */ public function testContainsConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::contains(1, 2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::contains(1, 2)); $this->mock->foo(array('a'=>1, 'c'=>3)); - $this->container->mockery_verify(); + Mockery::close(); } public function testHasKeyConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::hasKey('c'))->once(); $this->mock->foo(array('a'=>1, 'b'=>2, 'c'=>3)); - $this->container->mockery_verify(); } public function testHasKeyConstraintNonMatchingCase() @@ -1595,7 +1537,6 @@ public function testHasKeyConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, array('a'=>1), 3); - $this->container->mockery_verify(); } /** @@ -1603,16 +1544,15 @@ public function testHasKeyConstraintNonMatchingCase() */ public function testHasKeyConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::hasKey('c'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::hasKey('c')); $this->mock->foo(array('a'=>1, 'b'=>3)); - $this->container->mockery_verify(); + Mockery::close(); } public function testHasValueConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::hasValue(1))->once(); $this->mock->foo(array('a'=>1, 'b'=>2, 'c'=>3)); - $this->container->mockery_verify(); } public function testHasValueConstraintNonMatchingCase() @@ -1622,7 +1562,6 @@ public function testHasValueConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, array('a'=>1), 3); - $this->container->mockery_verify(); } /** @@ -1630,9 +1569,9 @@ public function testHasValueConstraintNonMatchingCase() */ public function testHasValueConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::hasValue(2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::hasValue(2)); $this->mock->foo(array('a'=>1, 'b'=>3)); - $this->container->mockery_verify(); + Mockery::close(); } public function testOnConstraintMatchesArgument_ClosureEvaluatesToTrue() @@ -1642,7 +1581,6 @@ public function testOnConstraintMatchesArgument_ClosureEvaluatesToTrue() }; $this->mock->shouldReceive('foo')->with(Mockery::on($function))->once(); $this->mock->foo(4); - $this->container->mockery_verify(); } public function testOnConstraintMatchesArgumentOfTypeArray_ClosureEvaluatesToTrue() @@ -1652,7 +1590,6 @@ public function testOnConstraintMatchesArgumentOfTypeArray_ClosureEvaluatesToTru }; $this->mock->shouldReceive('foo')->with(Mockery::on($function))->once(); $this->mock->foo([4, 5]); - $this->container->mockery_verify(); } /** @@ -1663,16 +1600,15 @@ public function testOnConstraintThrowsExceptionWhenConstraintUnmatched_ClosureEv $function = function ($arg) { return $arg % 2 == 0; }; - $this->mock->shouldReceive('foo')->with(Mockery::on($function))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::on($function)); $this->mock->foo(5); - $this->container->mockery_verify(); + Mockery::close(); } public function testMustBeConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::mustBe(2))->once(); $this->mock->foo(2); - $this->container->mockery_verify(); } public function testMustBeConstraintNonMatchingCase() @@ -1682,7 +1618,6 @@ public function testMustBeConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1690,9 +1625,9 @@ public function testMustBeConstraintNonMatchingCase() */ public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::mustBe(2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::mustBe(2)); $this->mock->foo('2'); - $this->container->mockery_verify(); + Mockery::close(); } public function testMustBeConstraintMatchesObjectArgumentWithEqualsComparisonNotIdentical() @@ -1703,7 +1638,6 @@ public function testMustBeConstraintMatchesObjectArgumentWithEqualsComparisonNot $b->foo = 1; $this->mock->shouldReceive('foo')->with(Mockery::mustBe($a))->once(); $this->mock->foo($b); - $this->container->mockery_verify(); } public function testMustBeConstraintNonMatchingCaseWithObject() @@ -1715,7 +1649,6 @@ public function testMustBeConstraintNonMatchingCaseWithObject() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, $a, 3); - $this->container->mockery_verify(); } /** @@ -1727,9 +1660,9 @@ public function testMustBeConstraintThrowsExceptionWhenConstraintUnmatchedWithOb $a->foo = 1; $b = new stdClass; $b->foo = 2; - $this->mock->shouldReceive('foo')->with(Mockery::mustBe($a))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::mustBe($a)); $this->mock->foo($b); - $this->container->mockery_verify(); + Mockery::close(); } public function testMatchPrecedenceBasedOnExpectedCallsFavouringExplicitMatch() @@ -1737,7 +1670,6 @@ public function testMatchPrecedenceBasedOnExpectedCallsFavouringExplicitMatch() $this->mock->shouldReceive('foo')->with(1)->once(); $this->mock->shouldReceive('foo')->with(Mockery::any())->never(); $this->mock->foo(1); - $this->container->mockery_verify(); } public function testMatchPrecedenceBasedOnExpectedCallsFavouringAnyMatch() @@ -1745,7 +1677,6 @@ public function testMatchPrecedenceBasedOnExpectedCallsFavouringAnyMatch() $this->mock->shouldReceive('foo')->with(Mockery::any())->once(); $this->mock->shouldReceive('foo')->with(1)->never(); $this->mock->foo(1); - $this->container->mockery_verify(); } public function testReturnNullIfIgnoreMissingMethodsSet() @@ -1779,8 +1710,8 @@ public function testShouldIgnoreMissingAsUndefinedFluentInterface() public function testShouldIgnoreMissingAsDefinedProxiesToUndefinedAllowingToString() { $this->mock->shouldIgnoreMissing()->asUndefined(); - $string = "Method call: {$this->mock->g()}"; - $string = "Mock: {$this->mock}"; + $this->assertInternalType('string', "{$this->mock->g()}"); + $this->assertInternalType('string', "{$this->mock}"); } public function testShouldIgnoreMissingDefaultReturnValue() @@ -1792,7 +1723,7 @@ public function testShouldIgnoreMissingDefaultReturnValue() /** @issue #253 */ public function testShouldIgnoreMissingDefaultSelfAndReturnsSelf() { - $this->mock->shouldIgnoreMissing($this->container->self()); + $this->mock->shouldIgnoreMissing(\Mockery::self()); $this->assertSame($this->mock, $this->mock->a()->b()); } @@ -1804,7 +1735,7 @@ public function testToStringMagicMethodCanBeMocked() public function testOptionalMockRetrieval() { - $m = $this->container->mock('f')->shouldReceive('foo')->with(1)->andReturn(3)->mock(); + $m = mock('f')->shouldReceive('foo')->with(1)->andReturn(3)->mock(); $this->assertTrue($m instanceof \Mockery\MockInterface); } @@ -1812,7 +1743,6 @@ public function testNotConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::not(1))->once(); $this->mock->foo(2); - $this->container->mockery_verify(); } public function testNotConstraintNonMatchingCase() @@ -1822,7 +1752,6 @@ public function testNotConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1830,9 +1759,9 @@ public function testNotConstraintNonMatchingCase() */ public function testNotConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::not(2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::not(2)); $this->mock->foo(2); - $this->container->mockery_verify(); + Mockery::close(); } public function testAnyOfConstraintMatchesArgument() @@ -1840,7 +1769,6 @@ public function testAnyOfConstraintMatchesArgument() $this->mock->shouldReceive('foo')->with(Mockery::anyOf(1, 2))->twice(); $this->mock->foo(2); $this->mock->foo(1); - $this->container->mockery_verify(); } public function testAnyOfConstraintNonMatchingCase() @@ -1850,7 +1778,6 @@ public function testAnyOfConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 2, 3); - $this->container->mockery_verify(); } /** @@ -1858,9 +1785,9 @@ public function testAnyOfConstraintNonMatchingCase() */ public function testAnyOfConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::anyOf(1, 2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::anyOf(1, 2)); $this->mock->foo(3); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -1868,9 +1795,8 @@ public function testAnyOfConstraintThrowsExceptionWhenConstraintUnmatched() */ public function testAnyOfConstraintThrowsExceptionWhenTrueIsNotAnExpectedArgument() { - $this->mock->shouldReceive('foo')->with(Mockery::anyOf(1, 2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::anyOf(1, 2)); $this->mock->foo(true); - $this->container->mockery_verify(); } /** @@ -1878,16 +1804,14 @@ public function testAnyOfConstraintThrowsExceptionWhenTrueIsNotAnExpectedArgumen */ public function testAnyOfConstraintThrowsExceptionWhenFalseIsNotAnExpectedArgument() { - $this->mock->shouldReceive('foo')->with(Mockery::anyOf(0, 1, 2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::anyOf(0, 1, 2)); $this->mock->foo(false); - $this->container->mockery_verify(); } public function testNotAnyOfConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::notAnyOf(1, 2))->once(); $this->mock->foo(3); - $this->container->mockery_verify(); } public function testNotAnyOfConstraintNonMatchingCase() @@ -1897,7 +1821,6 @@ public function testNotAnyOfConstraintNonMatchingCase() $this->mock->foo(); $this->mock->foo(1); $this->mock->foo(1, 4, 3); - $this->container->mockery_verify(); } /** @@ -1905,16 +1828,15 @@ public function testNotAnyOfConstraintNonMatchingCase() */ public function testNotAnyOfConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::notAnyOf(1, 2))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::notAnyOf(1, 2)); $this->mock->foo(2); - $this->container->mockery_verify(); + Mockery::close(); } public function testPatternConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(Mockery::pattern('/foo.*/'))->once(); $this->mock->foo('foobar'); - $this->container->mockery_verify(); } public function testPatternConstraintNonMatchingCase() @@ -1922,7 +1844,6 @@ public function testPatternConstraintNonMatchingCase() $this->mock->shouldReceive('foo')->once(); $this->mock->shouldReceive('foo')->with(Mockery::pattern('/foo.*/'))->never(); $this->mock->foo('bar'); - $this->container->mockery_verify(); } /** @@ -1930,9 +1851,9 @@ public function testPatternConstraintNonMatchingCase() */ public function testPatternConstraintThrowsExceptionWhenConstraintUnmatched() { - $this->mock->shouldReceive('foo')->with(Mockery::pattern('/foo.*/'))->once(); + $this->mock->shouldReceive('foo')->with(Mockery::pattern('/foo.*/')); $this->mock->foo('bar'); - $this->container->mockery_verify(); + Mockery::close(); } /** @@ -1941,8 +1862,9 @@ public function testPatternConstraintThrowsExceptionWhenConstraintUnmatched() public function testGlobalConfigMayForbidMockingNonExistentMethodsOnClasses() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $mock = $this->container->mock('stdClass'); + $mock = mock('stdClass'); $mock->shouldReceive('foo'); + Mockery::close(); } /** @@ -1952,8 +1874,9 @@ public function testGlobalConfigMayForbidMockingNonExistentMethodsOnClasses() public function testGlobalConfigMayForbidMockingNonExistentMethodsOnAutoDeclaredClasses() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $mock = $this->container->mock('SomeMadeUpClass'); + $mock = mock('SomeMadeUpClass'); $mock->shouldReceive('foo'); + Mockery::close(); } /** @@ -1962,13 +1885,14 @@ public function testGlobalConfigMayForbidMockingNonExistentMethodsOnAutoDeclared public function testGlobalConfigMayForbidMockingNonExistentMethodsOnObjects() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $mock = $this->container->mock(new stdClass); + $mock = mock(new stdClass); $mock->shouldReceive('foo'); + Mockery::close(); } public function testAnExampleWithSomeExpectationAmends() { - $service = $this->container->mock('MyService'); + $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); @@ -1980,13 +1904,11 @@ public function testAnExampleWithSomeExpectationAmends() $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->container->mockery_verify(); } public function testAnExampleWithSomeExpectationAmendsOnCallCounts() { - $service = $this->container->mock('MyService'); + $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); @@ -2000,7 +1922,6 @@ public function testAnExampleWithSomeExpectationAmendsOnCallCounts() $this->assertTrue($service->hasBookmarksTagged('php')); $this->assertTrue($service->hasBookmarksTagged('php')); - $this->container->mockery_verify(); } public function testAnExampleWithSomeExpectationAmendsOnCallCounts_PHPUnitTest() @@ -2024,7 +1945,7 @@ public function testAnExampleWithSomeExpectationAmendsOnCallCounts_PHPUnitTest() public function testMockedMethodsCallableFromWithinOriginalClass() { - $mock = $this->container->mock('MockeryTest_InterMethod1[doThird]'); + $mock = mock('MockeryTest_InterMethod1[doThird]'); $mock->shouldReceive('doThird')->andReturn(true); $this->assertTrue($mock->doFirst()); } @@ -2034,7 +1955,7 @@ public function testMockedMethodsCallableFromWithinOriginalClass() */ public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectation() { - $mock = $this->container->mock('Mockery_Demeterowski'); + $mock = mock('Mockery_Demeterowski'); $mock->shouldReceive('foo->bar->baz')->andReturn('Spam!'); $demeter = new Mockery_UseDemeter($mock); $this->assertSame('Spam!', $demeter->doit()); @@ -2045,7 +1966,7 @@ public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpec */ public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpectationWithArgs() { - $mock = $this->container->mock('Mockery_Demeterowski'); + $mock = mock('Mockery_Demeterowski'); $mock->shouldReceive('foo->bar->baz')->andReturn('Spam!'); $demeter = new Mockery_UseDemeter($mock); $this->assertSame('Spam!', $demeter->doitWithArgs()); @@ -2053,24 +1974,22 @@ public function testMockingDemeterChainsPassesMockeryExpectationToCompositeExpec public function testPassthruEnsuresRealMethodCalledForReturnValues() { - $mock = $this->container->mock('MockeryTest_SubjectCall1'); + $mock = mock('MockeryTest_SubjectCall1'); $mock->shouldReceive('foo')->once()->passthru(); $this->assertEquals('bar', $mock->foo()); - $this->container->mockery_verify(); } public function testShouldIgnoreMissingExpectationBasedOnArgs() { - $mock = $this->container->mock("MyService2")->shouldIgnoreMissing(); + $mock = mock("MyService2")->shouldIgnoreMissing(); $mock->shouldReceive("hasBookmarksTagged")->with("dave")->once(); $mock->hasBookmarksTagged("dave"); $mock->hasBookmarksTagged("padraic"); - $this->container->mockery_verify(); } public function testShouldDeferMissingExpectationBasedOnArgs() { - $mock = $this->container->mock("MockeryTest_SubjectCall1")->shouldDeferMissing(); + $mock = mock("MockeryTest_SubjectCall1")->shouldDeferMissing(); $this->assertEquals('bar', $mock->foo()); $this->assertEquals('bar', $mock->foo("baz")); @@ -2086,7 +2005,6 @@ public function testShouldDeferMissingExpectationBasedOnArgs() $this->assertEquals('123', $mock->foo("baz")); $this->assertEquals('bar', $mock->foo("qux")); - $this->container->mockery_verify(); } public function testCanReturnSelf() @@ -2121,11 +2039,12 @@ public function testExpectationCanBeOverridden() public function testTimesExpectationForbidsFloatNumbers() { $this->mock->shouldReceive('foo')->times(1.3); + Mockery::close(); } public function testIfExceptionIndicatesAbsenceOfMethodAndExpectationsOnMock() { - $mock = $this->container->mock('Mockery_Duck'); + $mock = mock('Mockery_Duck'); $this->expectException( '\BadMethodCallException', @@ -2134,11 +2053,12 @@ public function testIfExceptionIndicatesAbsenceOfMethodAndExpectationsOnMock() ); $mock->nonExistent(); + Mockery::close(); } public function testIfCallingMethodWithNoExpectationsHasSpecificExceptionMessage() { - $mock = $this->container->mock('Mockery_Duck'); + $mock = mock('Mockery_Duck'); $this->expectException( '\BadMethodCallException', @@ -2147,11 +2067,12 @@ public function testIfCallingMethodWithNoExpectationsHasSpecificExceptionMessage ); $mock->quack(); + Mockery::close(); } public function testMockShouldNotBeAnonymousWhenImplementingSpecificInterface() { - $waterMock = $this->container->mock('IWater'); + $waterMock = mock('IWater'); $this->assertFalse($waterMock->mockery_isAnonymous()); } diff --git a/tests/Mockery/HamcrestExpectationTest.php b/tests/Mockery/HamcrestExpectationTest.php index 25f150ad5..659397c0f 100644 --- a/tests/Mockery/HamcrestExpectationTest.php +++ b/tests/Mockery/HamcrestExpectationTest.php @@ -25,15 +25,15 @@ class HamcrestExpectationTest extends MockeryTestCase { public function setUp() { - $this->container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader()); - $this->mock = $this->container->mock('foo'); + parent::setUp(); + $this->mock = mock('foo'); } public function tearDown() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(true); - $this->container->mockery_close(); + parent::tearDown(); } /** Just a quickie roundup of a few Hamcrest matchers to check nothing obvious out of place **/ @@ -42,14 +42,12 @@ public function testAnythingConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(anything())->once(); $this->mock->foo(2); - $this->container->mockery_verify(); } public function testGreaterThanConstraintMatchesArgument() { $this->mock->shouldReceive('foo')->with(greaterThan(1))->once(); $this->mock->foo(2); - $this->container->mockery_verify(); } /** @@ -57,8 +55,8 @@ public function testGreaterThanConstraintMatchesArgument() */ public function testGreaterThanConstraintNotMatchesArgument() { - $this->mock->shouldReceive('foo')->with(greaterThan(1))->once(); + $this->mock->shouldReceive('foo')->with(greaterThan(1)); $this->mock->foo(1); - $this->container->mockery_verify(); + Mockery::close(); } } diff --git a/tests/Mockery/MockClassWithMethodOverloadingTest.php b/tests/Mockery/MockClassWithMethodOverloadingTest.php index 941e9c069..b0284dc0c 100644 --- a/tests/Mockery/MockClassWithMethodOverloadingTest.php +++ b/tests/Mockery/MockClassWithMethodOverloadingTest.php @@ -6,24 +6,12 @@ class MockClassWithMethodOverloadingTest extends MockeryTestCase { - private $container; - - protected function setUp() - { - $this->container = new \Mockery\Container; - } - - protected function tearDown() - { - $this->container->mockery_close(); - } - /** * @expectedException BadMethodCallException */ public function testCreateMockForClassWithMethodOverloading() { - $mock = $this->container->mock('test\Mockery\TestWithMethodOverloading') + $mock = mock('test\Mockery\TestWithMethodOverloading') ->makePartial(); $this->assertInstanceOf('test\Mockery\TestWithMethodOverloading', $mock); @@ -33,7 +21,7 @@ public function testCreateMockForClassWithMethodOverloading() public function testCreateMockForClassWithMethodOverloadingWithExistingMethod() { - $mock = $this->container->mock('test\Mockery\TestWithMethodOverloading') + $mock = mock('test\Mockery\TestWithMethodOverloading') ->makePartial(); $this->assertInstanceOf('test\Mockery\TestWithMethodOverloading', $mock); diff --git a/tests/Mockery/MockClassWithUnknownTypeHintTest.php b/tests/Mockery/MockClassWithUnknownTypeHintTest.php index 9d7121253..8706f8d79 100644 --- a/tests/Mockery/MockClassWithUnknownTypeHintTest.php +++ b/tests/Mockery/MockClassWithUnknownTypeHintTest.php @@ -21,24 +21,17 @@ namespace test\Mockery; +use Mockery\MockInterface; use Mockery\Adapter\Phpunit\MockeryTestCase; class MockClassWithUnknownTypeHintTest extends MockeryTestCase { - protected function setUp() - { - $this->container = new \Mockery\Container; - } - - protected function tearDown() - { - $this->container->mockery_close(); - } - /** @test */ public function itShouldSuccessfullyBuildTheMock() { - $this->container->mock("test\Mockery\HasUnknownClassAsTypeHintOnMethod"); + $mock = mock("test\Mockery\HasUnknownClassAsTypeHintOnMethod"); + + $this->assertInstanceOf(MockInterface::class, $mock); } } diff --git a/tests/Mockery/MockTest.php b/tests/Mockery/MockTest.php index 8f4eed23b..c05624c23 100644 --- a/tests/Mockery/MockTest.php +++ b/tests/Mockery/MockTest.php @@ -23,20 +23,10 @@ class Mockery_MockTest extends MockeryTestCase { - public function setup() - { - $this->container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader()); - } - - public function teardown() - { - $this->container->mockery_close(); - } - public function testAnonymousMockWorksWithNotAllowingMockingOfNonExistentMethods() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $m = $this->container->mock(); + $m = mock(); $m->shouldReceive("test123")->andReturn(true); assertThat($m->test123(), equalTo(true)); \Mockery::getConfiguration()->allowMockingNonExistentMethods(true); @@ -45,7 +35,7 @@ public function testAnonymousMockWorksWithNotAllowingMockingOfNonExistentMethods public function testMockWithNotAllowingMockingOfNonExistentMethodsCanBeGivenAdditionalMethodsToMockEvenIfTheyDontExistOnClass() { \Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $m = $this->container->mock('ExampleClassForTestingNonExistentMethod'); + $m = mock('ExampleClassForTestingNonExistentMethod'); $m->shouldAllowMockingMethod('testSomeNonExistentMethod'); $m->shouldReceive("testSomeNonExistentMethod")->andReturn(true); assertThat($m->testSomeNonExistentMethod(), equalTo(true)); @@ -66,29 +56,29 @@ public function testShouldAllowMockingProtectedMethodReturnsMockInstance() public function testMockAddsToString() { - $mock = $this->container->mock('ClassWithNoToString'); - assertThat(hasToString($mock)); + $mock = mock('ClassWithNoToString'); + $this->assertTrue(method_exists($mock, '__toString')); } public function testMockToStringMayBeDeferred() { - $mock = $this->container->mock('ClassWithToString')->shouldDeferMissing(); - assertThat((string)$mock, equalTo("foo")); + $mock = mock('ClassWithToString')->shouldDeferMissing(); + $this->assertEquals("foo", (string)$mock); } public function testMockToStringShouldIgnoreMissingAlwaysReturnsString() { - $mock = $this->container->mock('ClassWithNoToString')->shouldIgnoreMissing(); - assertThat(isNonEmptyString((string)$mock)); + $mock = mock('ClassWithNoToString')->shouldIgnoreMissing(); + $this->assertNotEquals('', (string)$mock); $mock->asUndefined(); - assertThat(isNonEmptyString((string)$mock)); + $this->assertNotEquals('', (string)$mock); } public function testShouldIgnoreMissing() { - $mock = $this->container->mock('ClassWithNoToString')->shouldIgnoreMissing(); - assertThat(nullValue($mock->nonExistingMethod())); + $mock = mock('ClassWithNoToString')->shouldIgnoreMissing(); + $this->assertNull($mock->nonExistingMethod()); } /** @@ -97,7 +87,7 @@ public function testShouldIgnoreMissing() public function testShouldIgnoreMissingDisallowMockingNonExistentMethodsUsingGlobalConfiguration() { Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $mock = $this->container->mock('ClassWithMethods')->shouldIgnoreMissing(); + $mock = mock('ClassWithMethods')->shouldIgnoreMissing(); $mock->shouldReceive('nonExistentMethod'); } @@ -107,14 +97,14 @@ public function testShouldIgnoreMissingDisallowMockingNonExistentMethodsUsingGlo public function testShouldIgnoreMissingCallingNonExistentMethodsUsingGlobalConfiguration() { Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $mock = $this->container->mock('ClassWithMethods')->shouldIgnoreMissing(); + $mock = mock('ClassWithMethods')->shouldIgnoreMissing(); $mock->nonExistentMethod(); } public function testShouldIgnoreMissingCallingExistentMethods() { Mockery::getConfiguration()->allowMockingNonExistentMethods(false); - $mock = $this->container->mock('ClassWithMethods')->shouldIgnoreMissing(); + $mock = mock('ClassWithMethods')->shouldIgnoreMissing(); assertThat(nullValue($mock->foo())); $mock->shouldReceive('bar')->passthru(); assertThat($mock->bar(), equalTo('bar')); @@ -123,7 +113,7 @@ public function testShouldIgnoreMissingCallingExistentMethods() public function testShouldIgnoreMissingCallingNonExistentMethods() { Mockery::getConfiguration()->allowMockingNonExistentMethods(true); - $mock = $this->container->mock('ClassWithMethods')->shouldIgnoreMissing(); + $mock = mock('ClassWithMethods')->shouldIgnoreMissing(); assertThat(nullValue($mock->foo())); assertThat(nullValue($mock->bar())); assertThat(nullValue($mock->nonExistentMethod())); @@ -161,7 +151,7 @@ public function testCallingShouldReceiveWithoutAValidMethodName() */ public function testShouldThrowExceptionWithInvalidClassName() { - $this->container->mock('ClassName.CannotContainDot'); + mock('ClassName.CannotContainDot'); } } diff --git a/tests/Mockery/MockingMethodsWithIterableTypeHintsTest.php b/tests/Mockery/MockingMethodsWithIterableTypeHintsTest.php index 9ee9e4a0d..e1b5e5740 100644 --- a/tests/Mockery/MockingMethodsWithIterableTypeHintsTest.php +++ b/tests/Mockery/MockingMethodsWithIterableTypeHintsTest.php @@ -28,21 +28,11 @@ */ class MockingMethodsWithIterableTypeHintsTest extends MockeryTestCase { - protected function setUp() - { - $this->container = new \Mockery\Container; - } - - protected function tearDown() - { - $this->container->mockery_close(); - } - /** @test */ public function itShouldSuccessfullyBuildTheMock() { require __DIR__."/Fixtures/MethodWithIterableTypeHints.php"; - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithIterableTypeHints"); + $mock = mock("test\Mockery\Fixtures\MethodWithIterableTypeHints"); $this->assertTrue($mock instanceof \test\Mockery\Fixtures\MethodWithIterableTypeHints); } diff --git a/tests/Mockery/MockingMethodsWithNullableParametersTest.php b/tests/Mockery/MockingMethodsWithNullableParametersTest.php index 9c787789f..2f3b6d47f 100644 --- a/tests/Mockery/MockingMethodsWithNullableParametersTest.php +++ b/tests/Mockery/MockingMethodsWithNullableParametersTest.php @@ -27,16 +27,6 @@ */ class MockingMethodsWithNullableParametersTest extends MockeryTestCase { - protected function setUp() - { - $this->container = new \Mockery\Container; - } - - protected function tearDown() - { - $this->container->mockery_close(); - } - /** * @test * @requires PHP 7.1.0RC3 @@ -44,7 +34,7 @@ protected function tearDown() public function it_can_handle_nullable_typed_parameters() { require __DIR__."/Fixtures/MethodWithNullableTypedParameter.php"; - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableTypedParameter"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableTypedParameter"); $this->assertTrue($mock instanceof \test\Mockery\Fixtures\MethodWithNullableTypedParameter); } @@ -55,7 +45,7 @@ public function it_can_handle_nullable_typed_parameters() public function it_can_handle_default_parameters() { require __DIR__."/Fixtures/MethodWithParametersWithDefaultValues.php"; - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithParametersWithDefaultValues"); + $mock = mock("test\Mockery\Fixtures\MethodWithParametersWithDefaultValues"); $this->assertTrue($mock instanceof \test\Mockery\Fixtures\MethodWithParametersWithDefaultValues); } diff --git a/tests/Mockery/MockingNullableMethodsTest.php b/tests/Mockery/MockingNullableMethodsTest.php index 7d420c024..f29c53ae6 100644 --- a/tests/Mockery/MockingNullableMethodsTest.php +++ b/tests/Mockery/MockingNullableMethodsTest.php @@ -37,14 +37,9 @@ class MockingNullableMethodsTest extends MockeryTestCase protected function setUp() { - require_once __DIR__."/Fixtures/MethodWithNullableReturnType.php"; - - $this->container = new \Mockery\Container; - } + parent::setUp(); - protected function tearDown() - { - $this->container->mockery_close(); + require_once __DIR__."/Fixtures/MethodWithNullableReturnType.php"; } /** @@ -52,7 +47,7 @@ protected function tearDown() */ public function itShouldAllowNonNullableTypeToBeSet() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nonNullablePrimitive')->andReturn('a string'); $mock->nonNullablePrimitive(); @@ -64,7 +59,7 @@ public function itShouldAllowNonNullableTypeToBeSet() */ public function itShouldNotAllowNonNullToBeNull() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nonNullablePrimitive')->andReturn(null); $mock->nonNullablePrimitive(); @@ -75,7 +70,7 @@ public function itShouldNotAllowNonNullToBeNull() */ public function itShouldAllowPrimitiveNullableToBeNull() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nullablePrimitive')->andReturn(null); $mock->nullablePrimitive(); @@ -86,7 +81,7 @@ public function itShouldAllowPrimitiveNullableToBeNull() */ public function itShouldAllowPrimitiveNullabeToBeSet() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nullablePrimitive')->andReturn('a string'); $mock->nullablePrimitive(); @@ -97,7 +92,7 @@ public function itShouldAllowPrimitiveNullabeToBeSet() */ public function itShouldAllowSelfToBeSet() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nonNullableSelf')->andReturn(new MethodWithNullableReturnType()); $mock->nonNullableSelf(); @@ -109,7 +104,7 @@ public function itShouldAllowSelfToBeSet() */ public function itShouldNotAllowSelfToBeNull() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nonNullableSelf')->andReturn(null); $mock->nonNullableSelf(); @@ -120,7 +115,7 @@ public function itShouldNotAllowSelfToBeNull() */ public function itShouldAllowNullableSelfToBeSet() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nullableSelf')->andReturn(new MethodWithNullableReturnType()); $mock->nullableSelf(); @@ -131,7 +126,7 @@ public function itShouldAllowNullableSelfToBeSet() */ public function itShouldAllowNullableSelfToBeNull() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nullableSelf')->andReturn(null); $mock->nullableSelf(); @@ -142,7 +137,7 @@ public function itShouldAllowNullableSelfToBeNull() */ public function itShouldAllowClassToBeSet() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nonNullableClass')->andReturn(new MethodWithNullableReturnType()); $mock->nonNullableClass(); @@ -154,7 +149,7 @@ public function itShouldAllowClassToBeSet() */ public function itShouldNotAllowClassToBeNull() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nonNullableClass')->andReturn(null); $mock->nonNullableClass(); @@ -165,7 +160,7 @@ public function itShouldNotAllowClassToBeNull() */ public function itShouldAllowNullalbeClassToBeSet() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nullableClass')->andReturn(new MethodWithNullableReturnType()); $mock->nullableClass(); @@ -176,7 +171,7 @@ public function itShouldAllowNullalbeClassToBeSet() */ public function itShouldAllowNullableClassToBeNull() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithNullableReturnType"); $mock->shouldReceive('nullableClass')->andReturn(null); $mock->nullableClass(); diff --git a/tests/Mockery/MockingParameterAndReturnTypesTest.php b/tests/Mockery/MockingParameterAndReturnTypesTest.php index fbeeb28db..3613707a5 100644 --- a/tests/Mockery/MockingParameterAndReturnTypesTest.php +++ b/tests/Mockery/MockingParameterAndReturnTypesTest.php @@ -27,19 +27,9 @@ class MockingParameterAndReturnTypesTest extends MockeryTestCase { - public function setup() - { - $this->container = new \Mockery\Container; - } - - public function teardown() - { - $this->container->mockery_close(); - } - public function testMockingStringReturnType() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("returnString"); $this->assertSame("", $mock->returnString()); @@ -47,7 +37,7 @@ public function testMockingStringReturnType() public function testMockingIntegerReturnType() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("returnInteger"); $this->assertSame(0, $mock->returnInteger()); @@ -55,7 +45,7 @@ public function testMockingIntegerReturnType() public function testMockingFloatReturnType() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("returnFloat"); $this->assertSame(0.0, $mock->returnFloat()); @@ -63,7 +53,7 @@ public function testMockingFloatReturnType() public function testMockingBooleanReturnType() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("returnBoolean"); $this->assertSame(false, $mock->returnBoolean()); @@ -71,7 +61,7 @@ public function testMockingBooleanReturnType() public function testMockingArrayReturnType() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("returnArray"); $this->assertSame([], $mock->returnArray()); @@ -79,7 +69,7 @@ public function testMockingArrayReturnType() public function testMockingGeneratorReturnTyps() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("returnGenerator"); $this->assertInstanceOf("\Generator", $mock->returnGenerator()); @@ -87,7 +77,7 @@ public function testMockingGeneratorReturnTyps() public function testMockingCallableReturnType() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("returnCallable"); $this->assertTrue(is_callable($mock->returnCallable())); @@ -95,7 +85,7 @@ public function testMockingCallableReturnType() public function testMockingClassReturnTypes() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("withClassReturnType"); $this->assertInstanceOf("test\Mockery\TestWithParameterAndReturnType", $mock->withClassReturnType()); @@ -103,7 +93,7 @@ public function testMockingClassReturnTypes() public function testMockingParameterTypes() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldReceive("withScalarParameters"); $mock->withScalarParameters(1, 1.0, true, 'string'); @@ -111,7 +101,7 @@ public function testMockingParameterTypes() public function testIgnoringMissingReturnsType() { - $mock = $this->container->mock("test\Mockery\TestWithParameterAndReturnType"); + $mock = mock("test\Mockery\TestWithParameterAndReturnType"); $mock->shouldIgnoreMissing(); diff --git a/tests/Mockery/MockingProtectedMethodsTest.php b/tests/Mockery/MockingProtectedMethodsTest.php index 6cc3c4805..4041516dc 100644 --- a/tests/Mockery/MockingProtectedMethodsTest.php +++ b/tests/Mockery/MockingProtectedMethodsTest.php @@ -25,16 +25,6 @@ class MockingProtectedMethodsTest extends MockeryTestCase { - public function setup() - { - $this->container = new \Mockery\Container; - } - - public function teardown() - { - $this->container->mockery_close(); - } - /** * @test * @@ -43,7 +33,7 @@ public function teardown() */ public function shouldAutomaticallyDeferCallsToProtectedMethodsForPartials() { - $mock = $this->container->mock("test\Mockery\TestWithProtectedMethods[foo]"); + $mock = mock("test\Mockery\TestWithProtectedMethods[foo]"); $this->assertEquals("bar", $mock->bar()); } @@ -55,21 +45,21 @@ public function shouldAutomaticallyDeferCallsToProtectedMethodsForPartials() */ public function shouldAutomaticallyDeferCallsToProtectedMethodsForRuntimePartials() { - $mock = $this->container->mock("test\Mockery\TestWithProtectedMethods")->shouldDeferMissing(); + $mock = mock("test\Mockery\TestWithProtectedMethods")->shouldDeferMissing(); $this->assertEquals("bar", $mock->bar()); } /** @test */ public function shouldAutomaticallyIgnoreAbstractProtectedMethods() { - $mock = $this->container->mock("test\Mockery\TestWithProtectedMethods")->shouldDeferMissing(); + $mock = mock("test\Mockery\TestWithProtectedMethods")->shouldDeferMissing(); $this->assertEquals(null, $mock->foo()); } /** @test */ public function shouldAllowMockingProtectedMethods() { - $mock = $this->container->mock("test\Mockery\TestWithProtectedMethods") + $mock = mock("test\Mockery\TestWithProtectedMethods") ->shouldDeferMissing() ->shouldAllowMockingProtectedMethods(); @@ -80,7 +70,7 @@ public function shouldAllowMockingProtectedMethods() /** @test */ public function shouldAllowMockingProtectedMethodOnDefinitionTimePartial() { - $mock = $this->container->mock("test\Mockery\TestWithProtectedMethods[protectedBar]") + $mock = mock("test\Mockery\TestWithProtectedMethods[protectedBar]") ->shouldAllowMockingProtectedMethods(); $mock->shouldReceive("protectedBar")->andReturn("notbar"); @@ -90,7 +80,7 @@ public function shouldAllowMockingProtectedMethodOnDefinitionTimePartial() /** @test */ public function shouldAllowMockingAbstractProtectedMethods() { - $mock = $this->container->mock("test\Mockery\TestWithProtectedMethods") + $mock = mock("test\Mockery\TestWithProtectedMethods") ->shouldDeferMissing() ->shouldAllowMockingProtectedMethods(); @@ -101,7 +91,7 @@ public function shouldAllowMockingAbstractProtectedMethods() /** @test */ public function shouldAllowMockingIncreasedVisabilityMethods() { - $mock = $this->container->mock("test\Mockery\TestIncreasedVisibilityChild"); + $mock = mock("test\Mockery\TestIncreasedVisibilityChild"); $mock->shouldReceive('foobar')->andReturn("foobar"); $this->assertEquals('foobar', $mock->foobar()); } diff --git a/tests/Mockery/MockingVariadicArgumentsTest.php b/tests/Mockery/MockingVariadicArgumentsTest.php index 27ae25677..a940f63ad 100644 --- a/tests/Mockery/MockingVariadicArgumentsTest.php +++ b/tests/Mockery/MockingVariadicArgumentsTest.php @@ -25,20 +25,10 @@ class MockingVariadicArgumentsTest extends MockeryTestCase { - public function setup() - { - $this->container = new \Mockery\Container; - } - - public function teardown() - { - $this->container->mockery_close(); - } - /** @test */ public function shouldAllowMockingVariadicArguments() { - $mock = $this->container->mock("test\Mockery\TestWithVariadicArguments"); + $mock = mock("test\Mockery\TestWithVariadicArguments"); $mock->shouldReceive("foo")->andReturn("notbar"); $this->assertEquals("notbar", $mock->foo()); diff --git a/tests/Mockery/MockingVoidMethodsTest.php b/tests/Mockery/MockingVoidMethodsTest.php index b923dcf16..a9fb3d7b6 100644 --- a/tests/Mockery/MockingVoidMethodsTest.php +++ b/tests/Mockery/MockingVoidMethodsTest.php @@ -31,19 +31,13 @@ class MockingVoidMethodsTest extends MockeryTestCase protected function setUp() { require_once __DIR__."/Fixtures/MethodWithVoidReturnType.php"; - - $this->container = new \Mockery\Container; } - protected function tearDown() - { - $this->container->mockery_close(); - } /** @test */ public function itShouldSuccessfullyBuildTheMock() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithVoidReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithVoidReturnType"); $this->assertTrue($mock instanceof \test\Mockery\Fixtures\MethodWithVoidReturnType); } @@ -51,7 +45,7 @@ public function itShouldSuccessfullyBuildTheMock() /** @test */ public function it_can_stub_and_mock_void_methods() { - $mock = $this->container->mock("test\Mockery\Fixtures\MethodWithVoidReturnType"); + $mock = mock("test\Mockery\Fixtures\MethodWithVoidReturnType"); $mock->shouldReceive("foo"); $mock->foo(); diff --git a/tests/Mockery/SpyTest.php b/tests/Mockery/SpyTest.php index cafb47517..78be2a7d9 100644 --- a/tests/Mockery/SpyTest.php +++ b/tests/Mockery/SpyTest.php @@ -23,20 +23,10 @@ use Mockery as m; use Mockery\Spy; -use PHPUnit\Framework\TestCase; +use Mockery\Adapter\Phpunit\MockeryTestCase; -class SpyTest extends TestCase +class SpyTest extends MockeryTestCase { - public function setup() - { - $this->container = new \Mockery\Container; - } - - public function teardown() - { - $this->container->mockery_close(); - } - /** @test */ public function itVerifiesAMethodWasCalled() {