0
Is there any way to define the order of execution of the test methods ?
When I put the function code testSelectDaInsercao
inside testInsercaoDeDados
the tests are executed successfully, but this way the test fails. I believe it is due to the execution order.
I looked in the documentation and saw only something about depends
and made it clear that this would not change the order. I already reversed 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 **/
show how you do it...
– Daniel Omine
I don’t understand the question, you want to see the error message ?
– David Santos
if you have error message, also show...
– Daniel Omine
to run you have to use phpunit, ta ai the error
– David Santos
of the same thing
– David Santos
so I put {@depends} as "comment". I did not put the return, based on the documentation it would not solve. It says : . Such dependencies do not define the order in which the test methods should be executed.https://phpunit.de/manual/current/pt_br/writing-tests-for-phpunit.html#writing-tests-for-phpunit.test-dependencies
– David Santos
I’ve already edited the question
– David Santos
so, qnd I put in the same function works, which means it’s entering. As for the id, it’s auto_increment. If you were not entering the first test you would not have passed, since it would return false.
– David Santos