forked from pengovbr/mod-sei-pen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: criado teste unitario que valida o metodo listarPendencias
- Loading branch information
Paul Richard Pereira Martins dos Anjos
committed
Dec 3, 2024
1 parent
81fda88
commit f7e21e6
Showing
3 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
tests_sei4/unitario/rn/ProcessoEletronicoRN/ListarPendenciasTest.php
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,67 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Classe de teste para o método listarPendencias da classe ProcessoEletronicoRN. | ||
* | ||
* Esta classe utiliza PHPUnit para verificar o comportamento do método listarPendencias | ||
* em diferentes cenários, garantindo que ele funcione conforme o esperado. | ||
*/ | ||
class ListarPendenciasTest extends TestCase | ||
{ | ||
/** | ||
* Mock da classe ProcessoEletronicoRN. | ||
* | ||
* @var ProcessoEletronicoRN|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $mockService; | ||
|
||
/** | ||
* Configuração inicial do teste. | ||
* | ||
* Este método cria um mock da classe ProcessoEletronicoRN e redefine | ||
* o método 'get' para simular comportamentos durante os testes. | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->mockService = $this->getMockBuilder(ProcessoEletronicoRN::class) | ||
->onlyMethods(['get']) | ||
->getMock(); | ||
} | ||
|
||
public function testListarPendenciasSucesso() | ||
{ | ||
$mockResponse = [ | ||
[ | ||
'status' => 2, | ||
'IDT' => 999 | ||
] | ||
]; | ||
|
||
// Configura o mock para retornar a resposta | ||
$this->mockService->expects($this->once()) | ||
->method('get') | ||
->willReturn($mockResponse); | ||
|
||
$resultado = $this->mockService->listarPendencias(true); | ||
|
||
$this->assertIsArray($resultado, 'O retorno deve ser um array.'); | ||
$this->assertCount(count($mockResponse), $resultado, 'A quantidade de objetos no retorno está incorreta.'); | ||
$this->assertInstanceOf(PendenciaDTO::class, $resultado[0], 'O primeiro objeto na lista deve ser uma instância da classe RepositorioDTO.'); | ||
} | ||
|
||
public function testListarPendenciasLancaExcecao() | ||
{ | ||
$this->mockService->expects($this->once()) | ||
->method('get') | ||
->willThrowException(new Exception('Erro na requisição')); | ||
|
||
$this->expectException(InfraException::class); | ||
$this->expectExceptionMessage('Falha na listagem de pendências de trâmite de processos'); | ||
|
||
$this->mockService->listarPendencias(true); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
tests_sei41/unitario/rn/ProcessoEletronicoRN/ListarPendenciasTest.php
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,67 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Classe de teste para o método listarPendencias da classe ProcessoEletronicoRN. | ||
* | ||
* Esta classe utiliza PHPUnit para verificar o comportamento do método listarPendencias | ||
* em diferentes cenários, garantindo que ele funcione conforme o esperado. | ||
*/ | ||
class ListarPendenciasTest extends TestCase | ||
{ | ||
/** | ||
* Mock da classe ProcessoEletronicoRN. | ||
* | ||
* @var ProcessoEletronicoRN|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $mockService; | ||
|
||
/** | ||
* Configuração inicial do teste. | ||
* | ||
* Este método cria um mock da classe ProcessoEletronicoRN e redefine | ||
* o método 'get' para simular comportamentos durante os testes. | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->mockService = $this->getMockBuilder(ProcessoEletronicoRN::class) | ||
->onlyMethods(['get']) | ||
->getMock(); | ||
} | ||
|
||
public function testListarPendenciasSucesso() | ||
{ | ||
$mockResponse = [ | ||
[ | ||
'status' => 2, | ||
'IDT' => 999 | ||
] | ||
]; | ||
|
||
// Configura o mock para retornar a resposta | ||
$this->mockService->expects($this->once()) | ||
->method('get') | ||
->willReturn($mockResponse); | ||
|
||
$resultado = $this->mockService->listarPendencias(true); | ||
|
||
$this->assertIsArray($resultado, 'O retorno deve ser um array.'); | ||
$this->assertCount(count($mockResponse), $resultado, 'A quantidade de objetos no retorno está incorreta.'); | ||
$this->assertInstanceOf(PendenciaDTO::class, $resultado[0], 'O primeiro objeto na lista deve ser uma instância da classe RepositorioDTO.'); | ||
} | ||
|
||
public function testListarPendenciasLancaExcecao() | ||
{ | ||
$this->mockService->expects($this->once()) | ||
->method('get') | ||
->willThrowException(new Exception('Erro na requisição')); | ||
|
||
$this->expectException(InfraException::class); | ||
$this->expectExceptionMessage('Falha na listagem de pendências de trâmite de processos'); | ||
|
||
$this->mockService->listarPendencias(true); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
tests_super/unitario/rn/ProcessoEletronicoRN/ListarPendenciasTest.php
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,67 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Classe de teste para o método listarPendencias da classe ProcessoEletronicoRN. | ||
* | ||
* Esta classe utiliza PHPUnit para verificar o comportamento do método listarPendencias | ||
* em diferentes cenários, garantindo que ele funcione conforme o esperado. | ||
*/ | ||
class ListarPendenciasTest extends TestCase | ||
{ | ||
/** | ||
* Mock da classe ProcessoEletronicoRN. | ||
* | ||
* @var ProcessoEletronicoRN|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $mockService; | ||
|
||
/** | ||
* Configuração inicial do teste. | ||
* | ||
* Este método cria um mock da classe ProcessoEletronicoRN e redefine | ||
* o método 'get' para simular comportamentos durante os testes. | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->mockService = $this->getMockBuilder(ProcessoEletronicoRN::class) | ||
->onlyMethods(['get']) | ||
->getMock(); | ||
} | ||
|
||
public function testListarPendenciasSucesso() | ||
{ | ||
$mockResponse = [ | ||
[ | ||
'status' => 2, | ||
'IDT' => 999 | ||
] | ||
]; | ||
|
||
// Configura o mock para retornar a resposta | ||
$this->mockService->expects($this->once()) | ||
->method('get') | ||
->willReturn($mockResponse); | ||
|
||
$resultado = $this->mockService->listarPendencias(true); | ||
|
||
$this->assertIsArray($resultado, 'O retorno deve ser um array.'); | ||
$this->assertCount(count($mockResponse), $resultado, 'A quantidade de objetos no retorno está incorreta.'); | ||
$this->assertInstanceOf(PendenciaDTO::class, $resultado[0], 'O primeiro objeto na lista deve ser uma instância da classe RepositorioDTO.'); | ||
} | ||
|
||
public function testListarPendenciasLancaExcecao() | ||
{ | ||
$this->mockService->expects($this->once()) | ||
->method('get') | ||
->willThrowException(new Exception('Erro na requisição')); | ||
|
||
$this->expectException(InfraException::class); | ||
$this->expectExceptionMessage('Falha na listagem de pendências de trâmite de processos'); | ||
|
||
$this->mockService->listarPendencias(true); | ||
} | ||
} |