-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from tecnospeed/MAN-187
Adicionando suporte a rota Empresa; Adicionando IE para o Prestador.
- Loading branch information
Showing
6 changed files
with
147 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace TecnoSpeed\Plugnotas\Common; | ||
|
||
use TecnoSpeed\Plugnotas\Abstracts\BuilderAbstract; | ||
use TecnoSpeed\Plugnotas\Error\ValidationError; | ||
use Respect\Validation\Validator as v; | ||
|
||
class Nfse extends BuilderAbstract | ||
{ | ||
private $ativo; | ||
private $tipoContrato; | ||
|
||
public function setAtivo($ativo) | ||
{ | ||
if ( | ||
is_null($ativo) || | ||
!v::boolVal()->validate($ativo) | ||
) { | ||
throw new ValidationError( | ||
'Ativo é requerido para o cadastro de NFS-e.' | ||
); | ||
} | ||
|
||
$this->ativo = $ativo; | ||
} | ||
|
||
public function getAtivo() | ||
{ | ||
return $this->ativo; | ||
} | ||
|
||
public function setTipoContrato($tipoContrato) | ||
{ | ||
if ( | ||
!is_null($tipoContrato) && | ||
!($tipoContrato === 0 || | ||
$tipoContrato === 1) | ||
){ | ||
throw new ValidationError( | ||
'Valor inválido para o TipoContrato. Valores aceitos: null, 0, 1' | ||
); | ||
} | ||
|
||
$this->tipoContrato = $tipoContrato; | ||
} | ||
|
||
public function getTipoContrato() | ||
{ | ||
return $this->tipoContrato; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
use PHPUnit\Framework\TestCase; | ||
use TecnoSpeed\Plugnotas\Common\Endereco; | ||
use TecnoSpeed\Plugnotas\Common\Telefone; | ||
use TecnoSpeed\Plugnotas\Common\Nfse; | ||
use TecnoSpeed\Plugnotas\Communication\CallApi; | ||
use TecnoSpeed\Plugnotas\Configuration; | ||
use TecnoSpeed\Plugnotas\Error\InvalidTypeError; | ||
|
@@ -85,17 +86,6 @@ public function testWithNullRazaoSocial() | |
$prestador->setRazaoSocial(null); | ||
} | ||
|
||
/** | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setInscricaoMunicipal | ||
*/ | ||
public function testWithNullIncricaoMunicipal() | ||
{ | ||
$this->expectException(ValidationError::class); | ||
$this->expectExceptionMessage('Inscrição municipal é requerida para NFSe.'); | ||
$prestador = new Prestador(); | ||
$prestador->setInscricaoMunicipal(null); | ||
} | ||
|
||
/** | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setEmail | ||
*/ | ||
|
@@ -121,6 +111,7 @@ public function testWithInvalidEmail() | |
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getRegimeTributarioEspecial | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getSimplesNacional | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getTelefone | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getNfse | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setCertificado | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setCpfCnpj | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setEmail | ||
|
@@ -134,6 +125,7 @@ public function testWithInvalidEmail() | |
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setRegimeTributarioEspecial | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setSimplesNacional | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setTelefone | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setNfse | ||
*/ | ||
public function testValidPrestadorCreation() | ||
{ | ||
|
@@ -151,6 +143,10 @@ public function testValidPrestadorCreation() | |
|
||
$telefone = new Telefone('44', '1234-1234'); | ||
|
||
$nfse = new Nfse(); | ||
$nfse->setAtivo(true); | ||
$nfse->setTipoContrato(1); | ||
|
||
$prestador = new Prestador(); | ||
$prestador->setCertificado('5b855b0926ddb251e0f0ef42'); | ||
$prestador->setCpfCnpj('00.000.000/0001-91'); | ||
|
@@ -165,7 +161,8 @@ public function testValidPrestadorCreation() | |
$prestador->setRegimeTributarioEspecial(0); | ||
$prestador->setSimplesNacional(0); | ||
$prestador->setTelefone($telefone); | ||
|
||
$prestador->setNfse($nfse); | ||
|
||
$this->assertSame($prestador->getCertificado(), '5b855b0926ddb251e0f0ef42'); | ||
$this->assertSame($prestador->getCpfCnpj(), '00000000000191'); | ||
$this->assertSame($prestador->getEmail(), '[email protected]'); | ||
|
@@ -179,7 +176,9 @@ public function testValidPrestadorCreation() | |
$this->assertSame($prestador->getRegimeTributarioEspecial(), 0); | ||
$this->assertSame($prestador->getSimplesNacional(), 0); | ||
$this->assertSame($prestador->getTelefone()->getDdd(), '44'); | ||
$this->assertSame($prestador->getTelefone()->getNumero(), '12341234'); | ||
$this->assertSame($prestador->getTelefone()->getNumero(), '12341234'); | ||
$this->assertSame($prestador->getNfse()->getAtivo(), true); | ||
$this->assertSame($prestador->getNfse()->getTipoContrato(), 1); | ||
} | ||
|
||
/** | ||
|
@@ -193,6 +192,44 @@ public function testBuildFromArray() | |
$this->assertSame($prestador->getCertificado(), '5b855b0926ddb251e0f0ef42'); | ||
} | ||
|
||
/** | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray | ||
*/ | ||
public function testBuildFromArrayWithNfse() | ||
{ | ||
$data = [ | ||
'certificado' => '5b855b0926ddb251e0f0ef42', | ||
'nfse' => [ | ||
'ativo' => true, | ||
'tipoContrato' => 1 | ||
] | ||
]; | ||
$prestador = Prestador::fromArray($data); | ||
$this->assertInstanceOf(Prestador::class, $prestador); | ||
$this->assertSame($prestador->getCertificado(), '5b855b0926ddb251e0f0ef42'); | ||
$this->assertInstanceOf(Nfse::class, $prestador->getNfse()); | ||
} | ||
|
||
/** | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray | ||
*/ | ||
public function testBuildFromArrayWithNfseInvalid() | ||
{ | ||
$this->expectExceptionMessage( | ||
'Valor inválido para o TipoContrato. Valores aceitos: null, 0, 1' | ||
); | ||
|
||
$data = [ | ||
'certificado' => '5b855b0926ddb251e0f0ef42', | ||
'nfse' => [ | ||
'ativo' => true, | ||
'tipoContrato' => 3 | ||
] | ||
]; | ||
$prestador = Prestador::fromArray($data); | ||
$prestador->validate(); | ||
} | ||
|
||
/** | ||
* @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray | ||
*/ | ||
|
@@ -248,7 +285,6 @@ public function testValidateWithValidObject() | |
{ | ||
$data = [ | ||
'cpfCnpj' => '00.000.000/0001-91', | ||
'inscricaoMunicipal' => '123456', | ||
'razaoSocial' => 'Razao Social do Prestador', | ||
'simplesNacional' => false, | ||
'endereco' => [ | ||
|
@@ -295,10 +331,15 @@ public function testSend() | |
'codigoCidade' => '4115200', | ||
'cep' => '87.050-800' | ||
]); | ||
$nfse = Nfse::fromArray([ | ||
'ativo' => true, | ||
'tipoContrato' => 1 | ||
]); | ||
$prestador->setCpfCnpj('00.000.000/0001-91'); | ||
$prestador->setInscricaoMunicipal('123456'); | ||
$prestador->setRazaoSocial('Razao Social do Prestador'); | ||
$prestador->setEndereco($endereco); | ||
$prestador->setNfse($nfse); | ||
$prestador->setSimplesNacional(false); | ||
$response = $prestador->send($configuration); | ||
|
||
|