1010use PHPUnit \Framework \TestCase ;
1111use TecnoSpeed \Plugnotas \Common \Endereco ;
1212use TecnoSpeed \Plugnotas \Common \Telefone ;
13+ use TecnoSpeed \Plugnotas \Common \Nfse ;
1314use TecnoSpeed \Plugnotas \Communication \CallApi ;
1415use TecnoSpeed \Plugnotas \Configuration ;
1516use TecnoSpeed \Plugnotas \Error \InvalidTypeError ;
@@ -85,17 +86,6 @@ public function testWithNullRazaoSocial()
8586 $ prestador ->setRazaoSocial (null );
8687 }
8788
88- /**
89- * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setInscricaoMunicipal
90- */
91- public function testWithNullIncricaoMunicipal ()
92- {
93- $ this ->expectException (ValidationError::class);
94- $ this ->expectExceptionMessage ('Inscrição municipal é requerida para NFSe. ' );
95- $ prestador = new Prestador ();
96- $ prestador ->setInscricaoMunicipal (null );
97- }
98-
9989 /**
10090 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setEmail
10191 */
@@ -121,6 +111,7 @@ public function testWithInvalidEmail()
121111 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getRegimeTributarioEspecial
122112 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getSimplesNacional
123113 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getTelefone
114+ * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::getNfse
124115 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setCertificado
125116 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setCpfCnpj
126117 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setEmail
@@ -134,6 +125,7 @@ public function testWithInvalidEmail()
134125 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setRegimeTributarioEspecial
135126 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setSimplesNacional
136127 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setTelefone
128+ * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::setNfse
137129 */
138130 public function testValidPrestadorCreation ()
139131 {
@@ -151,6 +143,10 @@ public function testValidPrestadorCreation()
151143
152144 $ telefone = new Telefone ('44 ' , '1234-1234 ' );
153145
146+ $ nfse = new Nfse ();
147+ $ nfse ->setAtivo (true );
148+ $ nfse ->setTipoContrato (1 );
149+
154150 $ prestador = new Prestador ();
155151 $ prestador ->setCertificado ('5b855b0926ddb251e0f0ef42 ' );
156152 $ prestador ->setCpfCnpj ('00.000.000/0001-91 ' );
@@ -165,7 +161,8 @@ public function testValidPrestadorCreation()
165161 $ prestador ->setRegimeTributarioEspecial (0 );
166162 $ prestador ->setSimplesNacional (0 );
167163 $ prestador ->setTelefone ($ telefone );
168-
164+ $ prestador ->setNfse ($ nfse );
165+
169166 $ this ->assertSame ($ prestador ->getCertificado (), '5b855b0926ddb251e0f0ef42 ' );
170167 $ this ->assertSame ($ prestador ->getCpfCnpj (), '00000000000191 ' );
171168 $ this ->
assertSame (
$ prestador->
getEmail (),
'[email protected] ' );
@@ -179,7 +176,9 @@ public function testValidPrestadorCreation()
179176 $ this ->assertSame ($ prestador ->getRegimeTributarioEspecial (), 0 );
180177 $ this ->assertSame ($ prestador ->getSimplesNacional (), 0 );
181178 $ this ->assertSame ($ prestador ->getTelefone ()->getDdd (), '44 ' );
182- $ this ->assertSame ($ prestador ->getTelefone ()->getNumero (), '12341234 ' );
179+ $ this ->assertSame ($ prestador ->getTelefone ()->getNumero (), '12341234 ' );
180+ $ this ->assertSame ($ prestador ->getNfse ()->getAtivo (), true );
181+ $ this ->assertSame ($ prestador ->getNfse ()->getTipoContrato (), 1 );
183182 }
184183
185184 /**
@@ -193,6 +192,44 @@ public function testBuildFromArray()
193192 $ this ->assertSame ($ prestador ->getCertificado (), '5b855b0926ddb251e0f0ef42 ' );
194193 }
195194
195+ /**
196+ * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray
197+ */
198+ public function testBuildFromArrayWithNfse ()
199+ {
200+ $ data = [
201+ 'certificado ' => '5b855b0926ddb251e0f0ef42 ' ,
202+ 'nfse ' => [
203+ 'ativo ' => true ,
204+ 'tipoContrato ' => 1
205+ ]
206+ ];
207+ $ prestador = Prestador::fromArray ($ data );
208+ $ this ->assertInstanceOf (Prestador::class, $ prestador );
209+ $ this ->assertSame ($ prestador ->getCertificado (), '5b855b0926ddb251e0f0ef42 ' );
210+ $ this ->assertInstanceOf (Nfse::class, $ prestador ->getNfse ());
211+ }
212+
213+ /**
214+ * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray
215+ */
216+ public function testBuildFromArrayWithNfseInvalid ()
217+ {
218+ $ this ->expectExceptionMessage (
219+ 'Valor inválido para o TipoContrato. Valores aceitos: null, 0, 1 '
220+ );
221+
222+ $ data = [
223+ 'certificado ' => '5b855b0926ddb251e0f0ef42 ' ,
224+ 'nfse ' => [
225+ 'ativo ' => true ,
226+ 'tipoContrato ' => 3
227+ ]
228+ ];
229+ $ prestador = Prestador::fromArray ($ data );
230+ $ prestador ->validate ();
231+ }
232+
196233 /**
197234 * @covers TecnoSpeed\Plugnotas\Nfse\Prestador::fromArray
198235 */
@@ -248,7 +285,6 @@ public function testValidateWithValidObject()
248285 {
249286 $ data = [
250287 'cpfCnpj ' => '00.000.000/0001-91 ' ,
251- 'inscricaoMunicipal ' => '123456 ' ,
252288 'razaoSocial ' => 'Razao Social do Prestador ' ,
253289 'simplesNacional ' => false ,
254290 'endereco ' => [
@@ -295,10 +331,15 @@ public function testSend()
295331 'codigoCidade ' => '4115200 ' ,
296332 'cep ' => '87.050-800 '
297333 ]);
334+ $ nfse = Nfse::fromArray ([
335+ 'ativo ' => true ,
336+ 'tipoContrato ' => 1
337+ ]);
298338 $ prestador ->setCpfCnpj ('00.000.000/0001-91 ' );
299339 $ prestador ->setInscricaoMunicipal ('123456 ' );
300340 $ prestador ->setRazaoSocial ('Razao Social do Prestador ' );
301341 $ prestador ->setEndereco ($ endereco );
342+ $ prestador ->setNfse ($ nfse );
302343 $ prestador ->setSimplesNacional (false );
303344 $ response = $ prestador ->send ($ configuration );
304345
0 commit comments