PropertyPathTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Symfony\Tests\Components\Form;
  3. use Symfony\Components\Form\PropertyPath;
  4. class PropertyPathTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testValidPropertyPath()
  7. {
  8. $path = new PropertyPath('reference.traversable[index].property');
  9. $this->assertEquals('reference', $path->getCurrent());
  10. $this->assertTrue($path->hasNext());
  11. $this->assertTrue($path->isProperty());
  12. $this->assertFalse($path->isIndex());
  13. $path->next();
  14. $this->assertEquals('traversable', $path->getCurrent());
  15. $this->assertTrue($path->hasNext());
  16. $this->assertTrue($path->isProperty());
  17. $this->assertFalse($path->isIndex());
  18. $path->next();
  19. $this->assertEquals('index', $path->getCurrent());
  20. $this->assertTrue($path->hasNext());
  21. $this->assertFalse($path->isProperty());
  22. $this->assertTrue($path->isIndex());
  23. $path->next();
  24. $this->assertEquals('property', $path->getCurrent());
  25. $this->assertFalse($path->hasNext());
  26. $this->assertTrue($path->isProperty());
  27. $this->assertFalse($path->isIndex());
  28. }
  29. public function testToString()
  30. {
  31. $path = new PropertyPath('reference.traversable[index].property');
  32. $this->assertEquals('reference.traversable[index].property', $path->__toString());
  33. }
  34. public function testInvalidPropertyPath_noDotBeforeProperty()
  35. {
  36. $this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
  37. new PropertyPath('[index]property');
  38. }
  39. public function testInvalidPropertyPath_dotAtTheBeginning()
  40. {
  41. $this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
  42. new PropertyPath('.property');
  43. }
  44. public function testInvalidPropertyPath_unexpectedCharacters()
  45. {
  46. $this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
  47. new PropertyPath('property.$field');
  48. }
  49. public function testInvalidPropertyPath_empty()
  50. {
  51. $this->setExpectedException('Symfony\Components\Form\Exception\InvalidPropertyPathException');
  52. new PropertyPath('');
  53. }
  54. public function testNextThrowsExceptionIfNoNextElement()
  55. {
  56. $path = new PropertyPath('property');
  57. $this->setExpectedException('OutOfBoundsException');
  58. $path->next();
  59. }
  60. }