Nelmio\Alice\ObjectBag::get PHP Method

get() public method

public get ( Nelmio\Alice\FixtureIdInterface $fixture ) : Nelmio\Alice\ObjectInterface
$fixture Nelmio\Alice\FixtureIdInterface
return Nelmio\Alice\ObjectInterface
    public function get(FixtureIdInterface $fixture) : ObjectInterface
    {
        if ($this->has($fixture)) {
            return $this->objects[$fixture->getId()];
        }
        throw ObjectNotFoundExceptionFactory::create($fixture->getId(), $fixture instanceof FixtureInterface ? $fixture->getClassName() : 'no class given');
    }

Usage Example

Example #1
0
 /**
  * @expectedException \Nelmio\Alice\Throwable\Exception\ObjectNotFoundException
  * @expectedExceptionMessage Could not find the object "foo" of the class "Dummy".
  */
 public function testThrowsExceptionWhenTryingToGetInexistingObject()
 {
     $bag = new ObjectBag();
     $bag->get($this->createFixture('foo', 'Dummy'));
 }