public function testOverrideServiceWhenUsingADumpedContainer() { require_once self::$fixturesPath . '/php/services9.php'; require_once self::$fixturesPath . '/includes/foo.php'; $container = new \ProjectServiceContainer(); $container->setService('bar', $bar = new \stdClass()); $container->setParameter('foo_bar', 'foo_bar'); $this->assertEquals($bar, $container->getBarService(), '->setService() overrides an already defined service'); $this->assertEquals($bar, $container->getService('bar'), '->setService() overrides an already defined service'); }
} protected function getBarService() { return $this->__bar; } protected function getFooBarService() { return $this->__foo_bar; } protected function getFoo_BazService() { return $this->__foo_baz; } } $sc = new ProjectServiceContainer(); $t->is(spl_object_hash($sc->getService('bar')), spl_object_hash($sc->__bar), '->getService() looks for a getXXXService() method'); $t->ok($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method'); $sc->setService('bar', $bar = new stdClass()); $t->isnt(spl_object_hash($sc->getService('bar')), spl_object_hash($bar), '->getService() prefers to return a service defined with a getXXXService() method than one defined with setService()'); try { $sc->getService('baba'); $t->fail('->getService() thrown an \\InvalidArgumentException if the service does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->getService() thrown an \\InvalidArgumentException if the service does not exist'); } try { $sc->baba; $t->fail('->__get() thrown an \\InvalidArgumentException if the service does not exist'); } catch (\InvalidArgumentException $e) { $t->pass('->__get() thrown an \\InvalidArgumentException if the service does not exist'); }