* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\PropertyAccess\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\PropertyAccess\PropertyPath; class PropertyPathTest extends TestCase { public function testToString() { $path = new PropertyPath('reference.traversable[index].property'); $this->assertEquals('reference.traversable[index].property', $path->__toString()); } /** * @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException */ public function testDotIsRequiredBeforeProperty() { new PropertyPath('[index]property'); } /** * @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException */ public function testDotCannotBePresentAtTheBeginning() { new PropertyPath('.property'); } public function providePathsContainingUnexpectedCharacters() { return array( array('property.'), array('property.['), array('property..'), array('property['), array('property[['), array('property[.'), array('property[]'), ); } /** * @dataProvider providePathsContainingUnexpectedCharacters * @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException */ public function testUnexpectedCharacters($path) { new PropertyPath($path); } /** * @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException */ public function testPathCannotBeEmpty() { new PropertyPath(''); } /** * @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidArgumentException */ public function testPathCannotBeNull() { new PropertyPath(null); } /** * @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidArgumentException */ public function testPathCannotBeFalse() { new PropertyPath(false); } public function testZeroIsValidPropertyPath() { $propertyPath = new PropertyPath('0'); $this->assertSame('0', (string) $propertyPath); } public function testGetParentWithDot() { $propertyPath = new PropertyPath('grandpa.parent.child'); $this->assertEquals(new PropertyPath('grandpa.parent'), $propertyPath->getParent()); } public function testGetParentWithIndex() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $this->assertEquals(new PropertyPath('grandpa.parent'), $propertyPath->getParent()); } public function testGetParentWhenThereIsNoParent() { $propertyPath = new PropertyPath('path'); $this->assertNull($propertyPath->getParent()); } public function testCopyConstructor() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $copy = new PropertyPath($propertyPath); $this->assertEquals($propertyPath, $copy); } public function testGetElement() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $this->assertEquals('child', $propertyPath->getElement(2)); } /** * @expectedException \OutOfBoundsException */ public function testGetElementDoesNotAcceptInvalidIndices() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $propertyPath->getElement(3); } /** * @expectedException \OutOfBoundsException */ public function testGetElementDoesNotAcceptNegativeIndices() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $propertyPath->getElement(-1); } public function testIsProperty() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $this->assertTrue($propertyPath->isProperty(1)); $this->assertFalse($propertyPath->isProperty(2)); } /** * @expectedException \OutOfBoundsException */ public function testIsPropertyDoesNotAcceptInvalidIndices() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $propertyPath->isProperty(3); } /** * @expectedException \OutOfBoundsException */ public function testIsPropertyDoesNotAcceptNegativeIndices() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $propertyPath->isProperty(-1); } public function testIsIndex() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $this->assertFalse($propertyPath->isIndex(1)); $this->assertTrue($propertyPath->isIndex(2)); } /** * @expectedException \OutOfBoundsException */ public function testIsIndexDoesNotAcceptInvalidIndices() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $propertyPath->isIndex(3); } /** * @expectedException \OutOfBoundsException */ public function testIsIndexDoesNotAcceptNegativeIndices() { $propertyPath = new PropertyPath('grandpa.parent[child]'); $propertyPath->isIndex(-1); } } __halt_compiler();----SIGNATURE:----F7Qf0u1ZCIqBpnPVlxcGSXjG/VTVKacWB/UPw418zI/NKLx/6vJQpMVpKZ8Do0AltRurUHLqAY8cFurzAVSJQP7Wv/8F87hMG9/4tgyY1n4GpIF+z3igkuW2wTd3aZ3riH2uG5+znELve9C2TFxUGjdGXhfuSwyl3xlZMvLxVDSEWXR19u6QLRQxascH9jW4mS/CxeAHChC7hg9ToUNGRQHHS9jRI6fqdQDSxQ5cSOpiJy0UVGr/BE0fbA7tIls15bOXXo9bwfltBOIbfCbbHphu2oYFCjFGsa3GtVOVQfpIhU1dWv8kbOwzHttgLnEFpVS0x4Q92H1YNd3t/yQ7oczgncnqVJog2qprP1bfJ2KSxnOD+ajG1/QC0x1tTP5UV2HwCmKaiX4mOip+47+reHTy5e932Oqz7ZXi2lq/SzrdVMt1QUlNfUfFvh5JMah/YSG+cPcRHwSH1pEFEq7DRlM//rxiGzgeHZG2qJPdP8pRsyd8c3yQTON85Y1N8mqoaV6PAYpPGc4lUrfKhh32OzMcPQ0pWnTpmdnaggjZ+DhQWTrMtACYFerw1Mh40d8FWKR7oP6IXdzHV2mlEfdtRuIPySR3PXgVr4ncX/spGc9bVkz0ZpakWmDpPS/Oju9IsIfsrRBAuOx0nl1NY29OVzBR1lWq9lT7gNN4q5e3J7c=----ATTACHMENT:----NTQ4MjMzNzAyODgzNDIxOSA1MTI0Njg2NzM1MjAzNjQzIDYzMjkyOTYyMDI2MTA2MDE=