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; }
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; }
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); }
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; }