Is there any way to set the order of execution of test methods?
When I put the code for the testSelectDaInsercao
function inside testInsercaoDeDados
the tests run successfully, but this way the test fails. I believe it's due to the order of execution.
I looked in the documentation and saw only something about depends
and it made it clear that this would not change the order. I already invested the order of the methods, but the test also failed!
use Application\Conn;
use Application\operacao;
use PHPUnit\Framework\TestCase;
class PHPTest extends TestCase
{
private $conn;
public function setUp()
{
$this->conn = new Conn();
$this->conn = $this->conn->retornaConexao();
}
public function testInsercaoDeDados()
{
$stmt = $this->conn->prepare("INSERT INTO usuario values (?, ?)");
$stmt->bindValue(1, 'teste', \PDO::PARAM_STR);
$stmt->bindValue(2, '123456', \PDO::PARAM_STR);
$resul = $stmt->execute();
$this->assertTrue($resul);
}
public function testSelectDaInsercao()
{
$resul = $this->conn->query("SELECT count(usuario.nome) as id
FROM usuario WHERE nome = 'teste'
AND senha = '123456'");
$resul = $resul->fetch(\PDO::FETCH_ASSOC);
$resul = (int) $resul['id'];
$this->assertEquals(1, $resul, 'erro ao comparar insercao');
}
public function tearDown()
{
$this->conn->query("truncate table usuario");
}
}
using depends
/** * @depends testInsercaoDeDados **/