0
I’m starting tests, and I wanted to know if I’m following correctly, use Portable, and have had some dilemmas to develop a test of a service
that I have. He does some operations in an app via API, but since I have no way to make a "mock" of this api I had to do the test "sequential" ( in production ):
<?php
namespace Tests\Feature;
use App\Exceptions\AppConnectionException;
use App\Exceptions\AppErrorException;
use App\Exceptions\AppNullException;
use App\Services\App\AppService;
use App\Services\App\Responses\Card;
use Tests\TestCase;
class AppServiceTest extends TestCase
{
/** @var AppService */
private $appService;
/** @var int */
private $pipeId,$destinationPhase;
protected function setUp(): void {
parent::setUp();
$this->appService = new AppService();
$this->pipeId = 533822;
$this->destinationPhase = 3656118;
}
/**
* @test
* @throws AppConnectionException
* @throws AppErrorException
* @throws AppNullException
*/
public function test(){
// CREATE
$title = 'teste '. now()->toTimeString();
$fields = ['nome_completo'=>'igor'];
$card = $this->appService->createCard($this->pipeId,$title,$fields);
$this->assertInstanceOf(Card::class,$card);
$this->assertEquals($title,$card->title);
// SHOW CARD
$card = $this->appService->showCard($card->id);
$this->assertInstanceOf(Card::class,$card);
$this->assertIsArray($card->rawData); // TODO: melhorar acerto verificando os fields criados acima
// UPDATE FIELD
$fielid = array_keys($fields)[0];
$newvalue = $fielid . " updated";
$mutation = $this->appService->updateField($card->id,$fielid,$newvalue);
$this->assertTrue($mutation);
// MOVE CARD
$card = $this->appService->moveCardToPhase($card->id,$this->destinationPhase);
$this->assertInstanceOf(Card::class,$card);
$this->assertEquals($card->currentPhase['id'],$this->destinationPhase);
}
}
I imagine that each test should be individual, right ? this sequence is very wrong ?