/**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->object = new TituloEleitoral();
     for ($i = 0; $i < $this->object->getLength(); $i++) {
         $number .= '' . \Sped\Commons\Math::random(0, 9);
     }
     $this->object->setValue($number);
 }
Example #2
0
 /**
  * Gera o código número aleatório com base nas informações do XML.<br>
  * Este código deve ser de 8 dígitos.
  * @param \Sped\Schemas\V200\DocumentNFe $domNFe Objeto do XML.
  * @return string Código Númerico gerado aleatoriamente.
  */
 public function gerarCodigoNumerico(\Sped\Schemas\V200\DocumentNFe $domNFe)
 {
     $codigoNumerico = 0;
     $hasIndex = 0;
     $nfeHash = sha1($domNFe->getNFe()->C14N(FALSE, FALSE, NULL, NULL));
     $coeficientes = new \Sped\Commons\Collections\ArrayCollection(array(3, 2, 2, 2, 2, 2, 3));
     $iterator = $coeficientes->getIterator();
     foreach ($iterator as $index => $element) {
         $algarismoBytes = substr($nfeHash, $hasIndex, $hasIndex + $element);
         $somaBytes = self::somaBytes($algarismoBytes);
         $algarismo = self::somaInteiro($somaBytes);
         $codigoNumerico = $codigoNumerico + $algarismo * Math::pow(10.0, $index);
         $hasIndex += $element;
     }
     $codigoNumerico = new \Sped\Commons\StringHelper($codigoNumerico);
     return $codigoNumerico->padLeft('0', 8)->toString();
 }