Ejemplo n.º 1
0
 protected function getPersistence()
 {
     // Inicialização
     $persistence = new Balance();
     // Localizador de Serviço
     $serviceLocator = new ServiceManager();
     // Configurações
     $persistence->setServiceLocator($serviceLocator);
     // Banco de Dados
     $db = Application::getApplication()->getServiceManager()->get('db');
     // Configurações
     $serviceLocator->setService('db', $db);
     // Limpeza de Lançamentos
     $delete = (new Sql($db))->delete()->from('postings');
     // Execução
     $db->query($delete->getSqlString($db->getPlatform()))->execute();
     // Limpeza de Contas
     $delete = (new Sql($db))->delete()->from('accounts');
     // Execução
     $db->query($delete->getSqlString($db->getPlatform()))->execute();
     // Inicializar Banco de Dados
     $this->initDatabase();
     // Apresentação
     return $persistence;
 }
Ejemplo n.º 2
0
 public function testSimpleSavePosting()
 {
     // Localizador de Serviços
     $serviceLocator = Application::getApplication()->getServiceManager();
     // Camada de Modelo
     $mAccounts = $serviceLocator->get('Balance\\Model\\Persistence\\Accounts');
     // Conta A
     $accountA = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'Issue 151 A', 'description' => 'Account A', 'accumulate' => BooleanType::NO]);
     // Salvar
     $mAccounts->save($accountA);
     // Conta B
     $accountB = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'Issue 151 B', 'description' => 'Account B', 'accumulate' => BooleanType::NO]);
     // Salvar
     $mAccounts->save($accountB);
     // Camada de Modelo
     $mPostings = $serviceLocator->get('Balance\\Model\\Postings');
     // Lançamento
     $posting = new Parameters(['id' => '', 'datetime' => '10/10/2010 10:10:10', 'description' => 'Issue 151 Posting A', 'entries' => [['account_id' => (string) $accountA['id'], 'type' => EntryType::CREDIT, 'value' => '100,00'], ['account_id' => (string) $accountB['id'], 'type' => EntryType::DEBIT, 'value' => '100,00']]]);
     try {
         // Salvar
         $mPostings->save($posting);
     } catch (ModelException $e) {
         // Capturar Formulário
         $form = $mPostings->getForm();
         // Formulário Válido?
         if ($form->isValid()) {
             // Erro em outro lugar!
             throw $e;
         }
         // Capturar Mensagens do Formulário
         $messages = $form->getMessages();
         // Erro Encontrado
         $this->fail('Invalid Form ' . json_encode($messages));
     }
 }
Ejemplo n.º 3
0
 protected function setUp()
 {
     // Inicialização
     $persistence = new Accounts();
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configurações
     $persistence->setServiceLocator($serviceLocator);
     // Banco de Dados
     $db = Application::getApplication()->getServiceManager()->get('db');
     // Configurações
     $serviceLocator->setService('db', $db);
     // Tabela de Contas
     $tbAccounts = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Accounts');
     // Configurações
     $serviceLocator->setService('Balance\\Db\\TableGateway\\Accounts', $tbAccounts);
     // Tabela de Lançamentos
     $tbPostings = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Postings');
     // Não Precisamos Informar os Lançamentos
     // Remover Todos os Lançamentos
     $tbPostings->delete(function () {
         // Remover Todos Elementos
     });
     // Remover Todas as Contas
     $tbAccounts->delete(function () {
         // Remover Todos Elementos
     });
     // Configuração
     $this->persistence = $persistence;
 }
Ejemplo n.º 4
0
 public function testEntryValueFormat()
 {
     // Gerenciador de Serviços
     $serviceLocator = Application::getApplication()->getServiceManager();
     // Camada de Modelo
     $mAccounts = $serviceLocator->get('Balance\\Model\\Persistence\\Accounts');
     // Conta A
     $accountA = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'A', 'description' => 'Issue 152 Account', 'accumulate' => BooleanType::NO]);
     // Salvar
     $mAccounts->save($accountA);
     // Conta B
     $accountB = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'B', 'description' => 'Issue 152 Account', 'accumulate' => BooleanType::NO]);
     // Salvar
     $mAccounts->save($accountB);
     // Camada de Modelo
     $mPostings = $serviceLocator->get('Balance\\Model\\Persistence\\Postings');
     // Lançamento
     $posting = new Parameters(['datetime' => '10/10/2010 10:10:10', 'description' => 'Issue 152 Posting', 'entries' => [['type' => EntryType::CREDIT, 'account_id' => $accountA['id'], 'value' => '100,00'], ['type' => EntryType::DEBIT, 'account_id' => $accountB['id'], 'value' => '100,00']]]);
     // Salvar
     $mPostings->save($posting);
     // Carregar Informações
     $result = $mPostings->find(new Parameters(['id' => $posting['id']]));
     // Capturar Primeira Entrada
     $element = current($result['entries']);
     // Verificações
     $this->assertEquals('100,00', $element['value']);
     // Capturar Segunda Entrada
     $element = next($result['entries']);
     // Verificações
     $this->assertEquals('100,00', $element['value']);
 }
Ejemplo n.º 5
0
 protected function getPersistence()
 {
     // Inicialização
     $persistence = new Postings();
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configuração
     $persistence->setServiceLocator($serviceLocator);
     // Banco de Dados
     $db = Application::getApplication()->getServiceManager()->get('db');
     // Configuração
     $serviceLocator->setService('db', $db);
     // Tabelas
     $tbAccounts = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Accounts');
     $tbPostings = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Postings');
     $tbEntries = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Entries');
     // Formatador de Datas
     $formatter = new IntlDateFormatter(null, IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM);
     // Configuração
     $serviceLocator->setService('Balance\\Db\\TableGateway\\Accounts', $tbAccounts)->setService('Balance\\Db\\TableGateway\\Postings', $tbPostings)->setService('Balance\\Db\\TableGateway\\Entries', $tbEntries);
     // Limpeza
     $tbPostings->delete(function () {
         // Remover Todos
     });
     $tbAccounts->delete(function () {
         // Remover Todos
     });
     // Chaves Primárias
     $primaries = ['postings' => [], 'accounts' => []];
     // Inserir Conta 1
     $tbAccounts->insert(['name' => 'Account AA', 'type' => AccountType::ACTIVE, 'description' => 'Account AA Description', 'position' => 0, 'accumulate' => 0]);
     // Captura de Chave Primária
     $primaries['accounts']['aa'] = (int) $tbAccounts->getLastInsertValue();
     // Inserir Conta 2
     $tbAccounts->insert(['name' => 'Account BB', 'type' => AccountType::ACTIVE, 'description' => 'Account BB Description', 'position' => 1, 'accumulate' => 0]);
     // Captura de Chave Primária
     $primaries['accounts']['bb'] = (int) $tbAccounts->getLastInsertValue();
     // Inserir Lançamento 1
     $tbPostings->insert(['datetime' => date('c', $formatter->parse('10/10/2010 09:10:10')), 'description' => 'Posting XX']);
     // Captura de Chave Primária
     $primaries['postings']['xx'] = (int) $tbPostings->getLastInsertValue();
     // Inserir Lançamento 2
     $tbPostings->insert(['datetime' => date('c', $formatter->parse('10/10/2010 10:10:10')), 'description' => 'Posting YY']);
     // Captura de Chave Primária
     $primaries['postings']['yy'] = (int) $tbPostings->getLastInsertValue();
     // Relacionamento 0-0
     $tbEntries->insert(['posting_id' => $primaries['postings']['xx'], 'account_id' => $primaries['accounts']['aa'], 'type' => EntryType::CREDIT, 'value' => 100, 'position' => 0]);
     // Relacionamento 0-1
     $tbEntries->insert(['posting_id' => $primaries['postings']['xx'], 'account_id' => $primaries['accounts']['bb'], 'type' => EntryType::DEBIT, 'value' => 100, 'position' => 1]);
     // Relacionamento 1-0
     $tbEntries->insert(['posting_id' => $primaries['postings']['yy'], 'account_id' => $primaries['accounts']['aa'], 'type' => EntryType::CREDIT, 'value' => 200, 'position' => 0]);
     // Relacionamento 1-1
     $tbEntries->insert(['posting_id' => $primaries['postings']['yy'], 'account_id' => $primaries['accounts']['bb'], 'type' => EntryType::DEBIT, 'value' => 200, 'position' => 1]);
     // Configuração
     $this->primaries = $primaries;
     // Apresentação
     return $persistence;
 }
Ejemplo n.º 6
0
 protected function getPersistence()
 {
     // Inicialização
     $persistence = new Accounts();
     // Conta ZZ
     $elementZZ = ['name' => 'ZZ Account Test', 'type' => AccountType::ACTIVE, 'description' => 'Description', 'position' => 1, 'accumulate' => 0];
     // Conta AA
     $elementAA = ['name' => 'AA Account Test', 'type' => AccountType::ACTIVE, 'description' => 'Description', 'position' => 0, 'accumulate' => 0];
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configurações
     $persistence->setServiceLocator($serviceLocator);
     // Banco de Dados
     $db = Application::getApplication()->getServiceManager()->get('db');
     // Configurações
     $serviceLocator->setService('db', $db);
     // Tabela de Contas
     $tbAccounts = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Accounts');
     // Configurações
     $serviceLocator->setService('Balance\\Db\\TableGateway\\Accounts', $tbAccounts);
     // Remover Todos os Lançamentos
     $delete = (new Sql($db))->delete()->from('postings');
     // Execução
     $db->query($delete->getSqlString($db->getPlatform()))->execute();
     // Remover Todas as Contas
     $delete = (new Sql($db))->delete()->from('accounts');
     // Execução
     $db->query($delete->getSqlString($db->getPlatform()))->execute();
     // Preparar Inserção
     $insert = (new Sql($db))->insert()->into('accounts')->columns(['name', 'type', 'description', 'position', 'accumulate']);
     // Adicionar Conta ZZ
     $insert->values($elementZZ);
     // Execução
     $db->query($insert->getSqlString($db->getPlatform()))->execute();
     // Adicionar Conta AA
     $insert->values($elementAA);
     // Execução
     $db->query($insert->getSqlString($db->getPlatform()))->execute();
     // Consultar as Duas Chaves Primárias
     $select = (new Sql($db))->select()->from('accounts')->columns(['id', 'name']);
     $rowset = $db->query($select->getSqlString($db->getPlatform()))->execute();
     // Consulta
     foreach ($rowset as $row) {
         switch ($row['name']) {
             case $elementAA['name']:
                 $elementAA['id'] = (int) $row['id'];
                 break;
             case $elementZZ['name']:
                 $elementZZ['id'] = (int) $row['id'];
                 break;
         }
     }
     // Configurar Elementos
     $this->data = [$elementAA, $elementZZ];
     // Apresentação
     return $persistence;
 }
Ejemplo n.º 7
0
 protected function renderTitle($template)
 {
     // Gerenciador de Serviços
     $serviceManager = Application::getApplication()->getServiceManager();
     // Resolução de Scripts
     $resolver = new TemplateMapResolver(['error/404' => './module/Balance/view/error/404.phtml', 'error/500' => './module/Balance/view/error/500.phtml', 'layout/page-header' => './module/Balance/view/layout/page-header.phtml']);
     // Renderização
     $renderer = (new PhpRenderer())->setResolver($resolver);
     // Configurar Serviço
     $renderer->getHelperPluginManager()->setServiceLocator($serviceManager);
     // Camada de Visualização
     $view = (new ViewModel())->setTemplate($template);
     // Renderização
     $renderer->render($view);
     // Capturar Título
     return $renderer->headTitle()->toString();
 }
Ejemplo n.º 8
0
 protected function getPersistence()
 {
     // Inicialização
     $persistence = new Postings();
     // Gerenciador de Serviços
     $serviceManager = Application::getApplication()->getServiceManager();
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configurações
     $persistence->setServiceLocator($serviceLocator);
     // Tabelas
     $tbPostings = $serviceManager->get('Balance\\Db\\TableGateway\\Postings');
     $tbAccounts = $serviceManager->get('Balance\\Db\\TableGateway\\Accounts');
     $tbEntries = $serviceManager->get('Balance\\Db\\TableGateway\\Entries');
     // Configurações
     $serviceLocator->setService('db', $serviceManager->get('db'))->setService('Balance\\Db\\TableGateway\\Postings', $tbPostings)->setService('Balance\\Db\\TableGateway\\Accounts', $tbAccounts)->setService('Balance\\Db\\TableGateway\\Entries', $tbEntries);
     // Limpeza
     $tbPostings->delete(function () {
         // Remover Todos
     });
     $tbAccounts->delete(function () {
         // Remover Todos
     });
     // Criar um Lançamento
     $tbPostings->insert(['datetime' => '2010-10-10 10:10:10', 'description' => 'Posting Description']);
     // Chave Primária
     $this->primary = (int) $tbPostings->getLastInsertValue();
     // Inserir Conta A
     $tbAccounts->insert(['name' => 'Account A', 'type' => AccountType::ACTIVE, 'description' => 'Account A Description', 'position' => 0, 'accumulate' => 0]);
     // Chave Primária
     $accountA = (int) $tbAccounts->getLastInsertValue();
     // Inserir Conta B
     $tbAccounts->insert(['name' => 'Account B', 'type' => AccountType::ACTIVE, 'description' => 'Account B Description', 'position' => 1, 'accumulate' => 0]);
     // Chave Primária
     $accountB = (int) $tbAccounts->getLastInsertValue();
     // Entrada 0
     $tbEntries->insert(['posting_id' => $this->primary, 'account_id' => $accountA, 'type' => EntryType::CREDIT, 'value' => 9999999.99, 'position' => 0]);
     // Entrada 1
     $tbEntries->insert(['posting_id' => $this->primary, 'account_id' => $accountB, 'type' => EntryType::DEBIT, 'value' => 9999999.99, 'position' => 1]);
     // Apresentação
     return $persistence;
 }
Ejemplo n.º 9
0
 protected function getPersistence()
 {
     // Inicialização
     $persistence = new Accounts();
     // Gerenciador de Serviços
     $serviceManager = Application::getApplication()->getServiceManager();
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configurações
     $persistence->setServiceLocator($serviceLocator);
     // Banco de Dados
     $db = $serviceManager->get('db');
     $tbAccounts = $serviceManager->get('Balance\\Db\\TableGateway\\Accounts');
     $tbPostings = $serviceManager->get('Balance\\Db\\TableGateway\\Postings');
     // Configurações
     $serviceLocator->setService('db', $db)->setService('Balance\\Db\\TableGateway\\Accounts', $tbAccounts);
     // Limpeza
     $tbPostings->delete(function () {
         // Remover Todos
     });
     $tbAccounts->delete(function () {
         // Remover Todos
     });
     // Conta A
     $accountA = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'A', 'description' => '', 'accumulate' => BooleanType::NO]);
     // Salvar
     $persistence->save($accountA);
     // Conta B
     $accountB = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'B', 'description' => '', 'accumulate' => BooleanType::NO]);
     // Salvar
     $persistence->save($accountB);
     // Conta C
     $accountC = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'C', 'description' => '', 'accumulate' => BooleanType::NO]);
     // Salvar
     $persistence->save($accountC);
     // Salvamento
     $this->data = ['A' => $accountA, 'B' => $accountB, 'C' => $accountC];
     // Apresentação
     return $persistence;
 }
Ejemplo n.º 10
0
 protected function setUp()
 {
     $component = new Modules();
     $serviceLocator = new ServiceManager();
     $component->setServiceLocator($serviceLocator);
     $moduleA = $this->getMock('Balance\\Module\\ModuleInterface');
     $moduleA->method('getIdentifier')->will($this->returnValue('ModuleA'));
     $moduleA->method('getName')->will($this->returnValue('Testing Module A'));
     $moduleA->method('getDescription')->will($this->returnValue('Description of Module A'));
     $moduleB = $this->getMock('Balance\\Module\\ModuleInterface');
     $moduleB->method('getIdentifier')->will($this->returnValue('ModuleB'));
     $moduleB->method('getName')->will($this->returnValue('Testing Module B'));
     $moduleB->method('getDescription')->will($this->returnValue('Description of Module B'));
     $moduleC = $this->getMock('Balance\\Module\\ModuleInterface');
     $moduleC->method('getIdentifier')->will($this->returnValue('ModuleC'));
     $moduleC->method('getName')->will($this->returnValue('Testing Module C'));
     $moduleC->method('getDescription')->will($this->returnValue('Description of Module C'));
     $manager = $this->getMockBuilder('FooBar')->setMethods(['getLoadedModules'])->getMock();
     $manager->method('getLoadedModules')->will($this->returnValue(['ModuleA' => $moduleA, 'ModuleB' => $moduleB, 'ModuleC' => $moduleC]));
     $serviceLocator->setService('ModuleManager', $manager);
     // Banco de Dados
     $db = Application::getApplication()->getServiceManager()->get('db');
     $serviceLocator->setService('db', $db);
     // Tabela de Módulos
     $tbModules = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Modules');
     $serviceLocator->setService('Balance\\Db\\TableGateway\\Modules', $tbModules);
     // Limpar Módulos
     $tbModules->delete(function () {
         // Remover Todos
     });
     // Habilitar Módulos no Banco
     $tbModules->insert(['identifier' => 'ModuleA', 'enabled' => 1]);
     $tbModules->insert(['identifier' => 'ModuleC', 'enabled' => 1]);
     // Configurações
     $this->component = $component;
     $this->moduleA = $moduleA;
     $this->moduleB = $moduleB;
     $this->moduleC = $moduleC;
 }
Ejemplo n.º 11
0
 public function testDom()
 {
     // Gerenciador de Serviços
     $serviceManager = Application::getApplication()->getServiceManager();
     // Resolução de Scripts
     $resolver = new TemplateMapResolver(['error/404' => './module/Balance/view/error/404.phtml', 'layout/page-header' => './module/Balance/view/layout/page-header.phtml']);
     // Renderização
     $renderer = (new PhpRenderer())->setResolver($resolver);
     // Configurar Serviço
     $renderer->getHelperPluginManager()->setServiceLocator($serviceManager);
     // Camada de Visualização
     $view = (new ViewModel())->setTemplate('error/404');
     // Configurar Controladora
     $view->setVariable('controller', 'FooController');
     // Renderização
     $content = $renderer->render($view);
     // Apresentar Estrutura
     $document = new Document($content);
     // Capturar DOM
     $document->getDomDocument();
     // Validação
     $this->assertEmpty($document->getErrors(), 'Invalid Document Structure');
 }
Ejemplo n.º 12
0
 public function testAccountUpdateWithException()
 {
     // Erro Esperado
     $this->setExpectedException('Balance\\Model\\ModelException', 'Database Error');
     // Inicialização
     $persistence = new Accounts();
     // Gerenciador de Serviços
     $serviceManager = Application::getApplication()->getServiceManager();
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configurações
     $persistence->setServiceLocator($serviceLocator);
     // Configurações de Serviços
     $serviceLocator->setService('db', $serviceManager->get('db'))->setService('Balance\\Db\\TableGateway\\Accounts', $serviceManager->get('Balance\\Db\\TableGateway\\Accounts'));
     // Conta para Inserção
     $data = new Parameters(['type' => AccountType::ACTIVE, 'name' => 'Account A', 'description' => 'Description', 'accumulate' => BooleanType::NO]);
     // Salvar Dados
     $persistence->save($data);
     // Colocar um Tipo Inválido
     $data['type'] = 'UNKNOWN';
     // Salvar Dados
     $persistence->save($data);
 }