BaseNodeTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Config\Tests\Definition;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\BaseNode;
  13. use Symfony\Component\Config\Definition\NodeInterface;
  14. class BaseNodeTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider providePath
  18. */
  19. public function testGetPathForChildNode($expected, array $params)
  20. {
  21. $constructorArgs = [];
  22. $constructorArgs[] = $params[0];
  23. if (isset($params[1])) {
  24. // Handle old PHPUnit version for PHP 5.5
  25. $parent = method_exists($this, 'createMock')
  26. ? $this->createMock(NodeInterface::class)
  27. : $this->getMock(NodeInterface::class);
  28. $parent->method('getPath')->willReturn($params[1]);
  29. $constructorArgs[] = $parent;
  30. if (isset($params[2])) {
  31. $constructorArgs[] = $params[2];
  32. }
  33. }
  34. $node = $this->getMockForAbstractClass(BaseNode::class, $constructorArgs);
  35. $this->assertSame($expected, $node->getPath());
  36. }
  37. public function providePath()
  38. {
  39. return [
  40. 'name only' => ['root', ['root']],
  41. 'name and parent' => ['foo.bar.baz.bim', ['bim', 'foo.bar.baz']],
  42. 'name and separator' => ['foo', ['foo', null, '/']],
  43. 'name, parent and separator' => ['foo.bar/baz/bim', ['bim', 'foo.bar/baz', '/']],
  44. ];
  45. }
  46. }