Ejemplo n.º 1
0
 public function test1()
 {
     $container = new Container();
     $container->set('scalar', 42);
     $this->assertEquals(42, $container->get('scalar'));
     $this->assertTrue($container->has('scalar'));
     $this->assertFalse($container->has('scalaR'));
 }
Ejemplo n.º 2
0
 /**
  * @param mixed $definition
  *
  * @dataProvider providerDefinitions
  */
 public function testHasAndRemove($definition)
 {
     $di = new Container();
     $di->set('test', $definition);
     $this->assertTrue($di->has('test'));
     $di->remove('test');
     $this->assertFalse($di->has('test'));
 }
Ejemplo n.º 3
0
 /**
  * @todo Implement testHas().
  */
 public function testHasGet()
 {
     $expect = new \StdClass();
     $this->container->set('foo', $expect);
     $this->assertTrue($this->container->has('foo'));
     $this->assertFalse($this->container->has('bar'));
     $actual = $this->container->get('foo');
     $this->assertSame($expect, $actual);
 }
Ejemplo n.º 4
0
 /**
  * Returns true if key exists in langs array
  *
  * @param string $name
  * @return boolean
  */
 function lang_exists($name)
 {
     if (is_null($name)) {
         return false;
     } else {
         return $this->langs->has($name);
     }
 }
Ejemplo n.º 5
0
 /**
  * Constructor
  *
  * Instantiate the service locator object.
  *
  * @param  array $services
  */
 public function __construct(array $services = null)
 {
     if (null !== $services) {
         $this->setServices($services);
     }
     if (!Container::has('default')) {
         Container::set('default', $this);
     }
 }
Ejemplo n.º 6
0
 /**
  * @covers ::__construct
  * @covers ::initContainer
  * @covers ::register
  * @covers ::has
  * @covers ::get
  * @covers Nora\Core\DI\Exception\InstanceNotFound::__construct
  * @expectedException Nora\Core\DI\Exception\InstanceNotFound
  */
 public function testCreate()
 {
     $c = new Container();
     $c->register(['hOge' => function () {
         return new \StdClass();
     }]);
     $this->assertTrue($c->has('Hoge'));
     $this->assertInstanceOf('StdClass', $c->get('hogE'));
     $c->get('Hoge')->cnt = 0;
     $c->get('hoGe')->cnt++;
     $c->on('di.container.pre_get', function ($e) {
         if (strtolower($e->name) === 'phpunit') {
             $e->instance = $this;
         }
     });
     $this->assertEquals($this, $c->get('phpUnit'));
     $c->get('InvalidName');
 }
Ejemplo n.º 7
0
 /**
  * Returns true if the given service is defined.
  *
  * @param  string  $id      The service identifier
  *
  * @return Boolean true if the service is defined, false otherwise
  */
 public function has($id)
 {
     return isset($this->definitions[$id]) || isset($this->aliases[$id]) || parent::has($id);
 }
Ejemplo n.º 8
0
 /**
  * @param Container $container
  * @depends testMakeContainer
  */
 public function testRemove(Container $container)
 {
     $this->assertEquals('H', $container->remove('h'));
     $this->assertFalse($container->has('h'));
 }