public function testClone() { $mockClass = new ClassMock(); $instance = $mockClass->newInstance(); $this->assertSame(null, $instance->foo()); $instance->mockMethod('foo')->set(function () { return 'foo'; }); $clonedInstance = clone $instance; $this->assertSame('foo', $instance->foo()); $this->assertSame('foo', $clonedInstance->foo()); $clonedInstance->mockMethod('foo')->set(function () { return 'bar'; }); $this->assertSame('foo', $instance->foo()); $this->assertSame('bar', $clonedInstance->foo()); $instance->mockMethod('bar')->set(function () { return 'bar'; }); $this->assertSame('bar', $instance->bar()); $this->assertSame(null, $clonedInstance->bar()); }
public function testNewInstanceWithoutConstructor() { $classMock = new ClassMock(); $constructorRun = false; $classMock->mockMethod('__construct')->set(function () use(&$constructorRun) { $constructorRun = true; }); $classMock->newInstanceWithoutConstructor(); $this->assertFalse($constructorRun); $classMock->newInstance(); $this->assertTrue($constructorRun); }