Esempio n. 1
0
 protected function getModel()
 {
     // Dependências
     $form = new Form();
     $inputFilter = new InputFilter();
     $formSearch = new Form();
     $inputFilterSearch = new InputFilter();
     $persistence = $this->getMock('Balance\\Model\\Persistence\\PersistenceInterface');
     // Parâmetro
     $form->add(new Text('id'));
     $inputFilter->add(new Input('id'));
     // Parâmetro
     $form->add(new Text('foo'));
     $inputFilter->add(new Input('foo'));
     // Pesquisa: Palavras Chave
     $formSearch->add(new Text('keywords'));
     $inputFilterSearch->add(new Input('keywords'));
     // Configurações
     $form->setInputFilter($inputFilter);
     $formSearch->setInputFilter($inputFilterSearch);
     // Inicialização
     $model = new Model($persistence);
     // Formulários
     $model->setForm($form)->setFormSearch($formSearch);
     // Apresentação
     return $model;
 }
 public function testCreateService()
 {
     // Inicializar Localizador de Serviço
     $serviceLocator = new ServiceManager();
     $controllerLocator = (new ControllerManager())->setServiceLocator($serviceLocator);
     // Inicialização
     $form = new Form();
     $formSearch = new Form();
     $persistence = $this->getMock('Balance\\Model\\Persistence\\PersistenceInterface');
     $model = new Model($persistence);
     // Configurações
     $model->setForm($form)->setFormSearch($formSearch);
     // Camada de Modelo
     $serviceLocator->setService('Balance\\Model\\Model', $model);
     // Configurar Elemento
     $serviceLocator->setService('Config', ['balance_manager' => ['factories' => ['BalanceTest\\Mvc\\Controller\\Controller' => ['factory' => 'Balance\\Mvc\\Controller\\AbstractControllerFactory', 'params' => ['model' => 'Balance\\Model\\Model', 'redirect_route_name' => 'controller']]]]]);
     // Fábrica de Componentes
     $factory = new AbstractControllerFactory();
     $result = $factory->canCreateServiceWithName($controllerLocator, 'controller', 'BalanceTest\\Mvc\\Controller\\Controller');
     // Verificações
     $this->assertTrue($result);
     // Construir Elemento
     $element = $factory->createServiceWithName($controllerLocator, 'controller', 'BalanceTest\\Mvc\\Controller\\Controller');
     // Verificações
     $this->assertInstanceOf('BalanceTest\\Mvc\\Controller\\Controller', $element);
     $this->assertSame($model, $element->getModel());
     $this->assertEquals('controller', $element->getRedirectRouteName());
 }
 /**
  * {@inheritdoc}
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     // Captura de Configuração
     $config = $serviceLocator->get('Config')['balance_manager']['factories'][$requestedName];
     // Inicialização
     $form = $serviceLocator->get('FormElementManager')->get($config['params']['form']);
     $inputFilter = $serviceLocator->get('InputFilterManager')->get($config['params']['input_filter']);
     $formSearch = $serviceLocator->get('FormElementManager')->get($config['params']['form_search']);
     $inputFilterSearch = $serviceLocator->get('InputFilterManager')->get($config['params']['input_filter_search']);
     $persistence = $serviceLocator->get($config['params']['persistence']);
     // Filtros de Dados
     $form->setInputFilter($inputFilter);
     $formSearch->setInputFilter($inputFilterSearch);
     // Camada de Modelo
     $model = new Model($persistence);
     // Gerenciador de Eventos
     $model->setEventManager($serviceLocator->get('EventManager'));
     // Formulários
     $model->setForm($form);
     $model->setFormSearch($formSearch);
     // Apresentação
     return $model;
 }