0

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);

}

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

that is right, but when I try $this->assertEquals([['amount' => 50]],$data['amount']); I get Error: Call to undefined method PHPUnit\Util\ErrorHandler::handleError() what should I fix it. Thank a lot.
As $data is a multidimensional array, you would need to reference the element you want, so in this case $this->assertEquals(50,$data[0]['amount'])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.