As verified with phpunit:
$xml_1 = new SimpleXMLElement('<name>Bugs</name>'); $xml_2 = new SimpleXMLElement('<name>Bugs</name>'); $this->assertEquals($xml_1, $xml_2); // Passes $this->assertTrue($xml_1==$xml_2); // Fails
Um what?
EDIT: No, this is not a stupid question. In Python:
import unittest class TestEqualityIdentity(unittest.TestCase): def test_equality(self): x = 1 y = 1 self.assertTrue(x==y)
There is no reason PHP should behave like Python. But this is also not a stupid question in PHP.
$x = 1; $y = 1; $this->assertEquals($x, $y); // Passes $this->assertTrue($x==$y); // Passes
EDIT 2 Raymond answered below correctly, no matter that with this spelling it is 3 votes down.
FWIW, I needed to compare the comparison of textual node values โโof two XML objects and get them by translating them into strings.
$this->assertTrue((string) $xml_1== (string) $xml_2); // Passes, works in if test // Note that simply referring to a SimpleXMLElement _seems_ to give its // text node. $this->assertEquals($xml_1, 'Bugs'); // Passes // This seemed weird to me when I first saw it, and I can't // say I like it any better now
source share