Phpunit : What is the best way to test a list?

Asked

Viewed 16 times

0

I’m doing it this way, but it makes a mistake:

public function test_get_list_without_criteria() {
    $data = ["specialist_name" => "o especialista"];
    $data2 = ["specialist_name" => "o especialista 2"];
    $data3 = ["specialist_name" => "o especialista 3"];

    $res = $this->specialists_model->insert($data);
    $res2 = $this->specialists_model->insert($data2);
    $res3 = $this->specialists_model->insert($data3);

    $subset = new \ArrayObject();
    $specialist = new \App\Entity\SpecialistEntity($data);
    $specialist2 = new \App\Entity\SpecialistEntity($data2);
    $specialist3 = new \App\Entity\SpecialistEntity($data3);

    $subset->append($specialist);
    $subset->append($specialist2);
    $subset->append($specialist3);

    $list = $this->specialists_model->getList();

    $this->assertArraySubset($subset, $list);
}

1 answer

0

It was divergence in the array indexes. I did otherwise and it worked. What’s the best way to do that?

public function test_get_list_without_criteria() {
    $data = ["specialist_name" => "o especialista"];
    $data2 = ["specialist_name" => "o especialista 2"];
    $data3 = ["specialist_name" => "o especialista 3"];

    $res = $this->specialists_model->insert($data);
    $res2 = $this->specialists_model->insert($data2);
    $res3 = $this->specialists_model->insert($data3);

    $subset = new \ArrayObject();

    $subset->offsetSet($res->getEntityId(), $res);
    $subset->offsetSet($res2->getEntityId(), $res2);
    $subset->offsetSet($res3->getEntityId(), $res3);

    $list = $this->specialists_model->getList();

    $this->assertArraySubset($subset, $list);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.