Example #1
0
 /**
  * @dataProvider getProvider
  *
  * @covers ::get
  * @covers ::has
  *
  * @param array     $contents           An array of items to store, indexed by id
  * @param string    $id                 The id to pass to ::get
  * @param mixed     $expected           The expected result of ::get($id)
  * @param string    $expectedException  If set, the expected exception
  */
 public function testGet(array $contents, $id, $expected, $expectedException = '')
 {
     $container = new Container();
     foreach ($contents as $itemId => $item) {
         $container->set($itemId, $item);
     }
     if ($expectedException) {
         $this->setExpectedException($expectedException);
     }
     $this->assertEquals($expected, $container->get($id));
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function has($id)
 {
     $getter = $this->getGetter($id);
     if (parent::has($id) || \method_exists($this, $getter)) {
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function get($id, $default = self::NO_DEFAULT)
 {
     if (!$this->has($id)) {
         if ($default !== self::NO_DEFAULT) {
             return $default;
         }
         throw new NotFoundException("Parameter \"{$id}\" not found");
     }
     return parent::get($id);
 }