/**
  * Registers services on th' given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Container $barnacle An Container instance
  */
 public function register(Container $barnacle)
 {
     $barnacle['param'] = 'value';
     $barnacle['service'] = function () {
         return new Service();
     };
     $barnacle['factory'] = $barnacle->factory(function () {
         return new Service();
     });
 }
 public function testProviderWithRegisterMethod()
 {
     $barnacle = new Container();
     $barnacle->register(new Fixtures\BarnacleServiceProvider(), array('anotherParameter' => 'anotherValue'));
     $this->assertEquals('value', $barnacle['param']);
     $this->assertEquals('anotherValue', $barnacle['anotherParameter']);
     $this->assertInstanceOf('Barnacle\\Tests\\Fixtures\\Service', $barnacle['service']);
     $serviceOne = $barnacle['factory'];
     $this->assertInstanceOf('Barnacle\\Tests\\Fixtures\\Service', $serviceOne);
     $serviceTwo = $barnacle['factory'];
     $this->assertInstanceOf('Barnacle\\Tests\\Fixtures\\Service', $serviceTwo);
     $this->assertNotSame($serviceOne, $serviceTwo);
 }
Esempio n. 3
0
 public function testExtendingServiceAfterOtherServiceFreeze()
 {
     $barnacle = new Container();
     $barnacle['foo'] = function () {
         return 'foo';
     };
     $barnacle['bar'] = function () {
         return 'bar';
     };
     $foo = $barnacle['foo'];
     $barnacle['bar'] = $barnacle->extend('bar', function ($bar, $app) {
         return "{$bar}.baz";
     });
     $this->assertSame('bar.baz', $barnacle['bar']);
 }