public function testMockInjectedSuccessfully() { $class = 'FakeSingleton'; $stub = $this->getMockBuilder($class)->getMock(); $stub->expects($this->any())->method('returnTrue')->will($this->returnValue(false)); $original = \FakeSingleton::getInstance(); SingletonMock::inject($stub, $class); $shouldBeStub = \FakeSingleton::getInstance(); $this->assertInstanceOf('FakeSingleton', $original); $this->assertInstanceOf('PHPUnit_Framework_MockObject_MockObject', $shouldBeStub); $this->assertTrue($original->returnTrue()); $this->assertFalse($shouldBeStub->returnTrue()); }
public function testMocking() { /** * Creates our stub and sets up the return values we expect */ $stub = $this->getMockBuilder('Flint\\Config')->getMock(); $stub->expects($this->any())->method('load')->will($this->returnValue('hello')); $orig = Config::getInstance(); /** * Inject the stub into the singleton */ SingletonMock::inject($stub, 'Flint\\Config'); $this->assertFalse(Config::getInstance() === $orig); $this->assertTrue('hello' === Config::getInstance()->load('test')); }
public function testSharedServiceWithArgLoadedCorrectly() { \Flint\App::getInstance(['options' => ['debug' => true], 'core' => ['configDir' => __DIR__ . '/../data']]); $serviceConfig = ['Fake' => ['class' => 'SharedServiceWithArgs', 'arguments' => ['Josh'], 'share' => true]]; // Stub out the loadServices method so we isolate the parsing $stub = $this->getMockBuilder('Flint\\ServiceParser')->setConstructorArgs(['fakefile.php'])->setMethods(['loadServices'])->getMock(); $stub->expects($this->any())->method('loadServices')->will($this->returnValue($stub)); SingletonMock::inject($stub, 'Flint\\ServiceParser'); $stub->loadServices()->setServices($serviceConfig); $result = $stub->parse(); $this->assertArrayHasKey('Fake', $result); $time = $result['Fake']->getTime(); $this->assertEquals('Josh', $result['Fake']->getName()); $this->assertEquals($time, $result['Fake']->getTime()); SingletonMock::cleanUp('Flint\\ServiceParser'); }