public function testEquals() { $this->assertTrue($this->string->equals($this->string)); $this->assertTrue($this->string->equals(clone $this->string)); $this->assertTrue($this->string->equals(new String(self::STRING_VALUE))); $this->assertFalse($this->string->equals(new String(self::STRING_VALUE . ' '))); $this->assertFalse($this->string->equals(new ObjectClass())); $this->assertFalse($this->string->equals(null)); }
/** * Returns the current value, consisting of the {@code prefix}, the values * added so far separated by the {@code delimiter}, and the {@code suffix}, * unless no elements have been added in which case, the * {@code prefix + suffix} or the {@code emptyValue} characters are returned * * @return \PHPJ\Lang\String * the string representation of this {@code StringJoiner} */ public function toString() { if ($this->value == null) { return $this->emptyValue; } if ($this->suffix->equals(new String(""))) { return $this->value->toString(); } $initialLength = $this->value->length(); $result = $this->value->append($this->suffix)->toString(); // reset value to pre-append initialLength $this->value->setLength($initialLength); return $result; }