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

0

I'm doing it this way, but it gives error:

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);
}
    
asked by anonymous 31.05.2018 / 20:07

1 answer

0

It was divergent in array indices. I did it another way and it worked. What is the best way to do this?

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);
}
    
31.05.2018 / 20:19