Exemplo n.º 1
0
 public function testConcat()
 {
     $this->coll->add(1)->add(2)->add(4);
     $coll2 = new ArrayList([3]);
     $this->coll->concat($coll2);
     $this->assertEquals([1, 2, 4, 3], $this->coll->toArray());
     $coll3 = new Dictionary(['key1' => 'value1', 'key2' => 'wrongValue']);
     $coll4 = new Dictionary(['key2' => 'value2']);
     $coll3->concat($coll4);
     $this->assertEquals(['key1' => 'value1', 'key2' => 'value2'], $coll3->toArray());
 }
Exemplo n.º 2
0
 /**
  * Adiciona uma validação.
  * @param mixed $item
  * @return $this|\Collections\VectorInterface|void
  */
 public function add($item)
 {
     if (is_callable($item)) {
         $validation = new Validation();
         $item($validation);
         parent::add($validation);
     }
 }
 private function deserializeConditions(MapInterface $conditions)
 {
     $deserialized = new ArrayList();
     foreach ($conditions as $condition) {
         $deserialized->add($this->operatorConditionSerializer->deserialize($condition));
     }
     return $deserialized;
 }
Exemplo n.º 4
0
 public function testFilter()
 {
     $this->coll->add(1);
     $this->coll->add("foo");
     $this->coll->add(3);
     $res = $this->coll->filter(function ($e) {
         return is_numeric($e);
     });
     $this->assertEquals(array(0 => 1, 1 => 3), $res->toArray());
 }
 public function testRenderTableWithStaticData()
 {
     $columns = new ArrayList();
     $columns->add((new Column())->setName('testHeader')->setTitle('Header'));
     $this->config->setServerSideEnabled(false)->setColumns($columns);
     $datatable = new Datatable($this->config);
     $table = '<table cellspacing="0" class="display" id="datatable"><thead><tr><th>Header</th></tr></thead><tbody><tr><td>test 1</td></tr><tr><td>test 2</td></tr></tbody></table><!-- Built with italolelis/datatables -->';
     $data = [['testHeader' => 'test 1'], ['testHeader' => 'test 2']];
     $this->assertEquals($table, $datatable->getRenderer()->render($data));
 }
 /**
  * Testa a validação de um valor por lista branca.
  */
 public function testValidation()
 {
     // Lista de nomes permitidos
     $allowedNames = new ArrayList();
     $allowedNames->add('Lucas Andrade de Araújo');
     $allowedNames->add('Matheus Andrade de Araújo');
     $validator = new Validator();
     // Valida o nome "Lucas Andrade de Araújo" na lista branca.
     $validator->getValidations()->add(function (Validation $v) use($allowedNames) {
         $v->setField(new Field('nome', 'Lucas Andrade de Araújo'));
         $v->getRules()->add(new WhiteList($allowedNames));
     });
     // Valida o nome "Milena Nascimento Cabreira" na lista branca.
     $validator->getValidations()->add(function (Validation $v) use($allowedNames) {
         $v->setField(new Field('nome', 'Milena Nascimento Cabreira'));
         $v->getRules()->add(new WhiteList($allowedNames));
     });
     // Executa a validação das regras
     $validator->execute();
     // Verifica se o nome invalido é o nome que não está
     // presente na lista de nomes permitidos.
     $invalidName = $validator->getErrors()->first()->getField()->getValue();
     $this->assertEquals('Milena Nascimento Cabreira', $invalidName);
 }
Exemplo n.º 7
0
 /**
  * Seleciona uma coleção de objetos do tipo do objeto que fora
  * chamado. O método irá identificar qual a classe filho dessa
  * classe atual, e instanciar um objeto do tipo da classe filho
  * e em seguida popular ele e adicioná-lo na lista de dados.
  *
  * @param $where
  * @return ArrayList
  * @throws NoDataFoundException
  */
 public static function select($where)
 {
     $table = new TableGateway(self::getInstance());
     $resultSet = $table->select($where);
     if ($resultSet->count() == 0) {
         throw new NoDataFoundException();
     }
     $list = new ArrayList();
     foreach ($resultSet->toArray() as $array) {
         $obj = self::getInstance();
         Populator::populate($obj, $array);
         $list->add($obj);
     }
     return $list;
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function createWorksheet() : WorksheetInterface
 {
     $worksheet = new Worksheet($this->documentAdapter->createSheet());
     $this->worksheets->add($worksheet);
     return $worksheet;
 }
Exemplo n.º 9
0
 /**
  * Build the array for the 'aaSorting' option
  *
  * @return ArrayList
  */
 protected function renderDefaultSortColumns()
 {
     $columns = new ArrayList();
     foreach ($this->config->getColumns() as $id => $column) {
         if ($column->isDefaultSort()) {
             $columns->add([$id, $column->getDefaultSortDirection()]);
         }
     }
     return $columns;
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public static function fromArray(array $arr)
 {
     $map = new ArrayList();
     foreach ($arr as $v) {
         if (is_array($v)) {
             $map->add(new ArrayList($v));
         } else {
             $map->add($v);
         }
     }
     return $map;
 }
Exemplo n.º 11
-1
 /**
  * Obtém a lista de medicamentos do sistema da Anvisa e retorna um array
  * com os resultados.
  *
  * @param string $medicamento Nome de medicamento
  * @param string $empresa     Nome da fabricante do medicamento
  * @param string $expediente  Número do expediente da bula
  *
  * @throws \Exception Caso não for possível trazer os resultados
  *
  * @return \Collections\ArrayList Todas as bulas encontradas
  */
 public static function buscarMedicamentos($medicamento = '', $empresa = '', $expediente = '')
 {
     if (empty($medicamento) && empty($empresa) && empty($expediente)) {
         throw new \InvalidArgumentException('Informe pelo menos um parâmetro para o método!');
     }
     $Client = new Client();
     $crawler = $Client->request('POST', 'http://www.anvisa.gov.br/datavisa/fila_bula/frmResultado.asp', ['hddLetra' => '', 'txtMedicamento' => $medicamento, 'txtEmpresa' => $empresa, 'txtNuExpediente' => $expediente, 'txtDataPublicacaoI' => '', 'txtDataPublicacaoF' => '', 'txtPageSize' => '1000', 'btnPesquisar' => '']);
     $Medicamentos = new ArrayList();
     try {
         $trs = $crawler->filter('#tblResultado > tbody > tr');
         if ($trs->first()->filter('td')->count() > 1) {
             $trs->each(function ($node) use(&$Medicamentos) {
                 if (trim($node->filter('td')->eq(0)->text()) != 'Nenhuma bula na fila de análise') {
                     $nomeMedicamento = trim($node->filter('td')->eq(0)->text());
                     $nomeEmpresa = trim($node->filter('td')->eq(1)->text());
                     $exp = trim($node->filter('td')->eq(2)->text());
                     $dataPub = trim($node->filter('td')->eq(3)->text());
                     $dadosBulaPaciente = self::stripJsFunction($node->filter('td')->eq(4)->filter('a')->attr('onclick'));
                     $dadosBulaProfissional = self::stripJsFunction($node->filter('td')->eq(5)->filter('a')->attr('onclick'));
                     $Bula = new Bula();
                     $Bula->setMedicamento($nomeMedicamento);
                     $Bula->setEmpresa($nomeEmpresa);
                     $Bula->setExpediente($exp);
                     $Bula->setDataPublicacao($dataPub);
                     $Bula->setBulaPaciente(new DadosBula($dadosBulaPaciente['transacao'], $dadosBulaPaciente['anexo']));
                     $Bula->setBulaProfissional(new DadosBula($dadosBulaProfissional['transacao'], $dadosBulaProfissional['anexo']));
                     $Medicamentos->add($Bula);
                 }
             });
         }
     } catch (\Exception $ex) {
         throw new Exception('Houve um erro ao obter os medicamentos do sistema da Anvisa!');
     }
     return $Medicamentos;
 }