search

Home  >  Q&A  >  body text

Can PHPUnit use assert equals to strictly compare two arrays containing objects?

I have two arrays of objects. I want to test if these two arrays are equal, but using a strict comparison such as 'false' !== 0.

Is it possible to achieve this in phpunit without requiring custom comparators or other methods?

P粉162773626P粉162773626303 days ago1698

reply all(1)I'll reply

  • P粉489081732

    P粉4890817322024-04-06 11:55:11

    Using symfony VarExporter solved the problem:

    self::assertSame(VarExporter::export($firstArrayOfObjects), VarExporter::export($secondArrayOfObjects));

    reply
    0
  • Cancelreply