/**
  *
  */
 public function testApiFactory_ThrowsException_WhenModelThrowsException()
 {
     $this->setExpectedException(WriteException::class);
     $container = $this->createContainer();
     $alias = 'alias';
     $callback = function () {
     };
     $this->container->add($alias, $callback)->willThrow(new Exception())->shouldBeCalledTimes(1);
     $container->factory($alias, $callback);
 }
Exemple #2
0
 /**
  * @override
  * @inheritDoc
  */
 public function factory($aliasOrClass, callable $factoryMethod, $args = [])
 {
     $object = null;
     $ex = null;
     try {
         $object = $this->container->add($aliasOrClass, $factoryMethod);
     } catch (Error $ex) {
     } catch (Exception $ex) {
     }
     if ($object === null || $ex !== null) {
         throw new WriteException("Binding factory of [{$aliasOrClass}] to Container failed.", $ex);
     }
     $object->withArguments($args);
 }