Skip to content

Commit

Permalink
Merge pull request #6 from tecnospeed/hotfix/types
Browse files Browse the repository at this point in the history
Hotfix/types
  • Loading branch information
ferfabricio authored Mar 20, 2019
2 parents 4e2daab + 122cb31 commit dae6a64
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
Alterações na biblioteca

## [1.4.1] - 20/03/2019
### Corrigido

Correção nos tipos float e boolean que não estavam fazendo o cast adequadamente.
Também corrigido campos nulos que deveriam ser tratados antes de enviar para a API.

## [1.4.0] - 14/03/2019
### Adicionado

Expand Down
2 changes: 1 addition & 1 deletion src/Abstracts/BuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

abstract class BuilderAbstract implements IBuilder
{
public function toArray($excludeNull = false)
public function toArray($excludeNull = true)
{
return Extract::toArray($this, $excludeNull);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Nfse/Servico/Iss.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setAliquota($aliquota)
'É necessário informar um valor numérico para aliquota.'
);
}
$this->aliquota = $aliquota;
$this->aliquota = (float)$aliquota;
}

public function getAliquota()
Expand Down Expand Up @@ -63,7 +63,7 @@ public function setRetido($retido)
'Retido deve ser um valor booleano.'
);
}
$this->retido = $retido;
$this->retido = (bool)$retido;
}

public function getRetido()
Expand Down Expand Up @@ -93,7 +93,7 @@ public function setValor($valor)
'É necessário informar um valor numérico para o campo valor.'
);
}
$this->valor = $valor;
$this->valor = (float)$valor;
}

public function getValor()
Expand All @@ -108,7 +108,7 @@ public function setValorRetido($valorRetido)
'É necessário informar um valor numérico para o campo valorRetido.'
);
}
$this->valorRetido = $valorRetido;
$this->valorRetido = (float)$valorRetido;
}

public function getValorRetido()
Expand Down
12 changes: 6 additions & 6 deletions src/Nfse/Servico/Valor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function setBaseCalculo($baseCalculo)
'Base de cálculo deve ser um valor numérico.'
);
}
$this->baseCalculo = $baseCalculo;
$this->baseCalculo = (float)$baseCalculo;
}

public function getBaseCalculo()
Expand All @@ -37,7 +37,7 @@ public function setDeducoes($deducoes)
'Deduções deve ser um valor numérico.'
);
}
$this->deducoes = $deducoes;
$this->deducoes = (float)$deducoes;
}

public function getDeducoes()
Expand All @@ -52,7 +52,7 @@ public function setDescontoCondicionado($descontoCondicionado)
'Desconto condicional deve ser um valor numérico.'
);
}
$this->descontoCondicionado = $descontoCondicionado;
$this->descontoCondicionado = (float)$descontoCondicionado;
}

public function getDescontoCondicionado()
Expand All @@ -67,7 +67,7 @@ public function setDescontoIncondicionado($descontoIncondicionado)
'Desconto incondicional deve ser um valor numérico.'
);
}
$this->descontoIncondicionado = $descontoIncondicionado;
$this->descontoIncondicionado = (float)$descontoIncondicionado;
}

public function getDescontoIncondicionado()
Expand All @@ -82,7 +82,7 @@ public function setLiquido($liquido)
'Valor líquido deve ser um valor numérico.'
);
}
$this->liquido = $liquido;
$this->liquido = (float)$liquido;
}

public function getLiquido()
Expand All @@ -97,7 +97,7 @@ public function setServico($servico)
'O valor do serviço deve ser um valor numérico.'
);
}
$this->servico = $servico;
$this->servico = (float)$servico;
}

public function getServico()
Expand Down
2 changes: 2 additions & 0 deletions tests/Nfse/PrestadorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public function testValidateWithValidObject()
'cpfCnpj' => '00.000.000/0001-91',
'inscricaoMunicipal' => '123456',
'razaoSocial' => 'Razao Social do Prestador',
'simplesNacional' => false,
'endereco' => [
'logradouro' => 'Rua de Teste',
'numero' => '1234',
Expand Down Expand Up @@ -298,6 +299,7 @@ public function testSend()
$prestador->setInscricaoMunicipal('123456');
$prestador->setRazaoSocial('Razao Social do Prestador');
$prestador->setEndereco($endereco);
$prestador->setSimplesNacional(false);
$response = $prestador->send($configuration);

$this->assertEquals(200, $response->statusCode);
Expand Down
15 changes: 15 additions & 0 deletions tests/Nfse/Servico/IssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ public function testInvalidValorRetido()
$iss->setValorRetido('teste');
}

public function testTypeConversion()
{
$iss = new Iss();
$iss->setAliquota('0.03');
$iss->setRetido('');
$iss->setValor('0.01');
$iss->setValorRetido('0.01');
$this->assertInternalType('double', $iss->getAliquota());
$this->assertInternalType('double', $iss->getAliquota());
$this->assertInternalType('bool', $iss->getRetido());
$this->assertFalse($iss->getRetido());
$this->assertInternalType('double', $iss->getValor());
$this->assertInternalType('double', $iss->getValorRetido());
}

public function testValidCreation()
{
$iss = new Iss();
Expand Down
18 changes: 18 additions & 0 deletions tests/Nfse/Servico/ValorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ public function testServicoWithInvalidValue()
$valor->setServico('teste');
}

public function testTypeConversion()
{
$valor = new Valor();
$valor->setBaseCalculo('0.01');
$valor->setDeducoes('0.02');
$valor->setDescontoCondicionado('0.03');
$valor->setDescontoIncondicionado('0.04');
$valor->setLiquido('0.05');
$valor->setServico('0.06');

$this->assertInternalType('double', $valor->getBaseCalculo());
$this->assertInternalType('double', $valor->getDeducoes());
$this->assertInternalType('double', $valor->getDescontoCondicionado());
$this->assertInternalType('double', $valor->getDescontoIncondicionado());
$this->assertInternalType('double', $valor->getLiquido());
$this->assertInternalType('double', $valor->getServico());
}

public function testWithValidData()
{
$valor = new Valor();
Expand Down

0 comments on commit dae6a64

Please sign in to comment.