* * 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:----Q/q7JsNsna4v91pgGvyMX10JaFOXQrWKU0t/8iBAEzzrjGLrJe8TPNGymWRLL4gDILLNAdeZs0/tcTIlMMPZTSQdYcRk3cNG5/ZI/A0L6KDgDimQHGF8ybuRW+/rtudLzOswYXGVJnXRq2l/M3j43kLabmSeoaBb4gQQzxjc8SeXhfmImLT7MqxkqdRMOq+YeuaRy3mPuQXbCqUMGS63fcPEX708STwM+7JWygxdAQVa69ucZB8n45GuYgzXEO+82+1Erk3ecQUR2U2Gjskq94Ws+rKiX9BoKNAM5LwvZGurOVnv3v1mAtU3pa0RtYSBDnXHkZ+81C0gVJA1m3nGFyW1x9VOHkXf/cUEnVb/pYrX63KURaTQ5wedYp3Ow9d/xT1Tg2RLG3/QvrxhO+Kf+9tsUtHcwTWi/IA8sS+KzoQWHGd8p5D3ykTr3fpY4agV6o/KeftjL+eGUq4MkHn4G+w8LQCndVTR30+cyC2SPq/SJWOEe0iLe8s1W57au558xBptbU1cXoAdp5PHdEiGNi7UA2haPj2dbHJY+r9dcX2Yi7vvUFhYB6dq8sn5v7uLq3L5AfwfDPnCNnUQlpq7F0rRPU/S7aOyNSULayWjxDYLdydBhezuDF3fSxX54NCtxddwUPWWgR8NSIe/711NLfrEoBE9PsJt/fIgYY2EnpI=----ATTACHMENT:----MTg5NDQxODk2OTcxODM4NyAyNDc5NTM0MTg5NzY0OTk5IDM3MDQ3ODQwOTk3MTk4Mw==