Lai0712
Lai0712

Reputation: 55

phpunit Functional Tests assert array

I have a question,

I am using phpunit WebTestCase in symfony 3.4

but I don't know how to assert it

and I get

--- Expected

+++ Actual

@@ @@

Array (

-0 => 'amount' => 50

+0 => Array (...)

)

this is my ControllerTest


public function testmoneyIn()
{
    $client = static::createClient();
    $client->request('POST', '/bank/moneyin', array('amount' => 50));
    $query = $this->em->createQueryBuilder()
        ->select('b')
        ->from('BankBundle:entry', 'b')
        ->orderBy('b.created_at', 'DESC')
        ->setMaxResults(1);
    $data = $query->getQuery()->getArrayResult();
    $this->assertEquals(['amount' => 50],$data);

}

Upvotes: 0

Views: 276

Answers (1)

Nigel Ren
Nigel Ren

Reputation: 57131

As you are testing a result set, I would expect it to be an array of rows from the database, in

$this->assertEquals(['amount' => 50],$data);

you only have the data for 1 row of data, which is what you want, but I would expect it to be

$this->assertEquals([['amount' => 50]],$data);

Which means a row of data in a result set.

Upvotes: 2

Related Questions