FqsenTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * phpDocumentor
  4. *
  5. * PHP Version 5.5
  6. *
  7. * @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
  8. * @license http://www.opensource.org/licenses/mit-license.php MIT
  9. * @link http://phpdoc.org
  10. */
  11. namespace phpDocumentor\Reflection;
  12. /**
  13. * Class FqsenTest
  14. * @coversDefaultClass phpDocumentor\Reflection\Fqsen
  15. */
  16. class FqsenTest extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * @param string $fqsen
  20. * @covers ::__construct
  21. * @dataProvider validFqsenProvider
  22. */
  23. public function testValidFormats($fqsen, $name)
  24. {
  25. $instance = new Fqsen($fqsen);
  26. $this->assertEquals($name, $instance->getName());
  27. }
  28. /**
  29. * Data provider for ValidFormats tests. Contains a complete list from psr-5 draft.
  30. *
  31. * @return array
  32. */
  33. public function validFqsenProvider()
  34. {
  35. return [
  36. ['\\', ''],
  37. ['\My\Space', 'Space'],
  38. ['\My\Space\myFunction()', 'myFunction'],
  39. ['\My\Space\MY_CONSTANT', 'MY_CONSTANT'],
  40. ['\My\Space\MY_CONSTANT2', 'MY_CONSTANT2'],
  41. ['\My\Space\MyClass', 'MyClass'],
  42. ['\My\Space\MyInterface', 'MyInterface'],
  43. ['\My\Space\MyTrait', 'MyTrait'],
  44. ['\My\Space\MyClass::myMethod()', 'myMethod'],
  45. ['\My\Space\MyClass::$my_property', 'my_property'],
  46. ['\My\Space\MyClass::MY_CONSTANT', 'MY_CONSTANT'],
  47. ];
  48. }
  49. /**
  50. * @param string $fqsen
  51. * @covers ::__construct
  52. * @dataProvider invalidFqsenProvider
  53. * @expectedException \InvalidArgumentException
  54. */
  55. public function testInValidFormats($fqsen)
  56. {
  57. new Fqsen($fqsen);
  58. }
  59. /**
  60. * Data provider for invalidFormats tests. Contains a complete list from psr-5 draft.
  61. *
  62. * @return array
  63. */
  64. public function invalidFqsenProvider()
  65. {
  66. return [
  67. ['\My\*'],
  68. ['\My\Space\.()'],
  69. ['My\Space'],
  70. ];
  71. }
  72. /**
  73. * @covers ::__construct
  74. * @covers ::__toString
  75. */
  76. public function testToString()
  77. {
  78. $className = new Fqsen('\\phpDocumentor\\Application');
  79. $this->assertEquals('\\phpDocumentor\\Application', (string)$className);
  80. }
  81. }