public function get(LocatorInterface $locator) { if (!$this->isCalled) { $this->result = parent::get($locator); $this->isCalled = true; } return $this->result; }
public function testGet() { $factory = new Factory(function () { return new \stdClass(); }); /** @var LocatorInterface $locator */ $locator = $this->getMockBuilder(LocatorInterface::class)->getMock(); $result = $factory->get($locator); $this->assertEquals($result, $factory->get($locator)); $this->assertNotSame($result, $factory->get($locator)); $factory = new Factory(function (LocatorInterface $locator) { return $locator; }); $this->assertSame($locator, $factory->get($locator)); }