public function is(LimeTesterInterface $expected) { // allow comparison with strings if object implements __toString() if ($expected instanceof LimeTesterString && method_exists($this->object, '__toString')) { if ($expected->value != (string) $this->object) { throw new LimeAssertionFailedException($this, $expected); } } else { // don't compare twice to allow for cyclic dependencies if (in_array(array($this->value, $expected->value), self::$equal, true) || in_array(array($expected->value, $this->value), self::$equal, true)) { return; } self::$equal[] = array($this->value, $expected->value); // don't compare objects if they are identical // this helps to avoid the error "maximum function nesting level reached" // CAUTION: this conditional clause is not tested if (!$expected instanceof self || $this->object !== $expected->object) { parent::is($expected); } } }
$expected = new LimeTesterArray(array('b' => 2, 'a' => 1)); // test $t->expect('LimeAssertionFailedException'); $actual->same($expected); // @Test: is() throws no exception if values match // fixtures $actual = new LimeTesterArray(array(0 => 1)); $expected = new LimeTesterArray(array(0 => 1)); // test $actual->is($expected); // @Test: is() throws no exception if values match // fixtures $actual = new LimeTesterArray(array(0 => new LimeError("message", "file", 11))); $expected = new LimeTesterArray(array(0 => new LimeError("message", "file", 11))); // test $actual->is($expected); // @Test: isnt() throws an exception if the arrays are equal // fixtures $actual = new LimeTesterArray(array(0 => 1)); $expected = new LimeTesterArray(array(0 => 1)); // test $t->expect('LimeAssertionFailedException'); $actual->isnt($expected); // @Test: isnt() throws no exception if the arrays differ // fixtures $actual = new LimeTesterArray(array(0 => 1, 1 => 2)); $expected = new LimeTesterArray(array(0 => 1, 1 => 3)); // test $actual->isnt($expected); // @Test: same() throws an exception if keys are missing // fixtures