/** * @test */ public function is_valid_sub_item_from_collection() { $structureItem = new StructureItem('a.path.with.key', StructureDefinition::COLLECTION); $cloneOfStructureItem = clone $structureItem; $subItem = $structureItem->subItem('subitem', StructureDefinition::STRING); $this->assertInstanceOf(get_class($structureItem), $subItem); $this->assertTrue($subItem->isSubItemOf($structureItem)); $this->assertEquals('a.path.with.key.$', $subItem->path()); $this->assertTrue($structureItem->sameValueAs($cloneOfStructureItem)); }
/** * @param string|StructureItem $aPathOrStructureItem * @return bool */ public function isSubItemOf($aPathOrStructureItem) { if ($aPathOrStructureItem instanceof StructureItem) { $aPath = $aPathOrStructureItem->pathWithKey(); } else { Assertion::string($aPathOrStructureItem); $aPath = $aPathOrStructureItem; } return strpos($this->path(), $aPath) === 0; }