Skip to content

Commit

Permalink
tests: Otimiza memória nos testes
Browse files Browse the repository at this point in the history
  • Loading branch information
mazinsw committed Apr 5, 2022
1 parent 3796d9f commit 4d9daa6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
11 changes: 10 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" colors="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="false"
>
<coverage>
<include>
<directory suffix=".php">src/NFe</directory>
Expand All @@ -15,6 +23,7 @@
</testsuite>
</testsuites>
<php>
<ini name="memory_limit" value="-1" />
<ini name="date.timezone" value="UTC"/>
<env name="APP_ENV" value="testing"/>
<env name="TEST_MODE" value="_override"/>
Expand Down
4 changes: 2 additions & 2 deletions src/NFe/Common/Ajuste.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public function __construct($ajuste = [])
$this->setTempoLimite(30);
$root_path = dirname(dirname(dirname(__DIR__)));
$cert_dir = $root_path . '/storage/certs';
$this->setArquivoChavePublica($cert_dir . '/public.pem');
$this->setArquivoChavePrivada($cert_dir . '/private.pem');
$this->getCertificado()->setArquivoChavePublica($cert_dir . '/public.pem');
$this->getCertificado()->setArquivoChavePrivada($cert_dir . '/private.pem');

$this->setPastaXmlBase($root_path . '/storage/xml');
$this->setPastaXmlInutilizado('{ambiente}/inutilizado');
Expand Down
2 changes: 0 additions & 2 deletions src/NFe/Database/IBPT.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ private function load($uf)
return false;
}
$data = json_decode($content, true);
unset($this->tabela);
gc_collect_cycles();
$this->tabela = [$uf => $data];
return $data;
}
Expand Down
14 changes: 8 additions & 6 deletions tests/NFe/Common/ConfiguracaoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class ConfiguracaoTest extends \PHPUnit\Framework\TestCase
{
/** @var Configuracao */
private $config;

protected function setUp(): void
Expand Down Expand Up @@ -51,11 +52,12 @@ public function testFields()
public function testDataExpiracao()
{
$this->config
->setArquivoChavePublica(dirname(dirname(__DIR__)) . '/resources/certs/public.pem')
->setArquivoChavePrivada(dirname(dirname(__DIR__)) . '/resources/certs/private.pem');
$this->config
->setChavePublica($this->config->getChavePublica())
->setChavePrivada($this->config->getChavePrivada());
$this->assertEquals('2010-10-02', date('Y-m-d', $this->config->getExpiracao()));
->getCertificado()
->setArquivoChavePublica(dirname(dirname(__DIR__)) . '/resources/certs/public.pem')
->setArquivoChavePrivada(dirname(dirname(__DIR__)) . '/resources/certs/private.pem');
$this->config->getCertificado()
->setChavePublica($this->config->getCertificado()->getChavePublica())
->setChavePrivada($this->config->getCertificado()->getChavePrivada());
$this->assertEquals('2010-10-02', date('Y-m-d', $this->config->getCertificado()->getExpiracao()));
}
}
15 changes: 13 additions & 2 deletions tests/NFe/Core/SEFAZTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace NFe\Core;

use NFe\Database\Estatico;
use NFe\Logger\Log;
use NFe\Task\Inutilizacao;
use NFe\Task\Tarefa;
Expand All @@ -23,11 +24,21 @@ protected function tearDown(): void
*/
public static function createSEFAZ()
{
$banco = SEFAZ::getInstance()->getConfiguracao()->getBanco();
if ($banco instanceof Estatico) {
$banco->setIBPT(null);
}
SEFAZ::getInstance()->getConfiguracao()->setBanco(null);
SEFAZ::getInstance()->getConfiguracao()->setCertificado(null);
SEFAZ::getInstance()->setConfiguracao(null);
gc_collect_cycles();
$emitente = \NFe\Entity\EmitenteTest::createEmitente();
$sefaz = SEFAZ::getInstance(true);
$sefaz->getConfiguracao()
->setArquivoChavePublica(dirname(dirname(__DIR__)) . '/resources/certs/public.pem')
->setArquivoChavePrivada(dirname(dirname(__DIR__)) . '/resources/certs/private.pem')
->getCertificado()
->setArquivoChavePublica(dirname(dirname(__DIR__)) . '/resources/certs/public.pem')
->setArquivoChavePrivada(dirname(dirname(__DIR__)) . '/resources/certs/private.pem');
$sefaz->getConfiguracao()
->setEmitente($emitente);
return $sefaz;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/NFe/Database/BancoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ public function onlineTestWSDL()
global $app;

$sefaz = \NFe\Core\SEFAZTest::createSEFAZ();
$sefaz->getConfiguracao()
$sefaz->getConfiguracao()->getCertificado()
->setArquivoChavePublica(dirname(dirname(dirname(__DIR__))) . '/docs/certs/public.pem')
->setArquivoChavePrivada(dirname(dirname(dirname(__DIR__))) . '/docs/certs/private.pem');
$banco = $sefaz->getConfiguracao()->getBanco();
$chave_publica = $sefaz->getConfiguracao()->getArquivoChavePublica();
$chave_privada = $sefaz->getConfiguracao()->getArquivoChavePrivada();
$chave_publica = $sefaz->getConfiguracao()->getCertificado()->getArquivoChavePublica();
$chave_privada = $sefaz->getConfiguracao()->getCertificado()->getArquivoChavePrivada();
$soap = new \Curl\Curl();
$soap->setOpt(CURLOPT_SSLCERT, $chave_publica);
$soap->setOpt(CURLOPT_SSLKEY, $chave_privada);
Expand Down
15 changes: 11 additions & 4 deletions tests/NFe/Task/InutilizacaoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class InutilizacaoTest extends \PHPUnit\Framework\TestCase
{
public static function criaInutilizacao()
{
\NFe\Core\SEFAZ::getInstance()
->getConfiguracao()->getEmitente()->getEndereco()
->getMunicipio()->getEstado()->setUF('PR');
\NFe\Core\SEFAZ::getInstance()
->getConfiguracao()->getEmitente()->setCNPJ('08380787000176');
$inutilizacao = new \NFe\Task\Inutilizacao();
$inutilizacao->setUF(\NFe\Core\SEFAZ::getInstance()
->getConfiguracao()->getEmitente()->getEndereco()
Expand Down Expand Up @@ -57,7 +62,7 @@ public function testInutilizaInutilizado()
$inutilizacao->fromArray($inutilizacao);
$inutilizacao->fromArray($inutilizacao->toArray());
$inutilizacao->fromArray(null);
} catch (Exception $e) {
} catch (\Exception $e) {
\NFe\Common\CurlSoap::setPostFunction(null);
throw $e;
}
Expand All @@ -84,14 +89,16 @@ public function testInutilizaRejeitado()
$inutilizacao = self::criaInutilizacao();
$dom = $inutilizacao->getNode()->ownerDocument;
$dom = $inutilizacao->assinar();
$this->expectException('\Exception');
try {
$this->expectException('\Exception');
$inutilizacao->envia($dom);
} catch (Exception $e) {
} catch (\Exception $e) {
\NFe\Common\CurlSoap::setPostFunction(null);
$this->assertEquals('241', $inutilizacao->getStatus());
throw $e;
} finally {
\NFe\Common\CurlSoap::setPostFunction(null);
}
\NFe\Common\CurlSoap::setPostFunction(null);
}

public function testNormalization()
Expand Down

0 comments on commit 4d9daa6

Please sign in to comment.