SignatureFormatterTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2018 Justin Hileman
  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 Psy\Test\Formatter;
  11. use Psy\Formatter\SignatureFormatter;
  12. use Psy\Reflection\ReflectionClassConstant;
  13. use Psy\Reflection\ReflectionConstant_;
  14. class SignatureFormatterTest extends \PHPUnit\Framework\TestCase
  15. {
  16. const FOO = 'foo value';
  17. private static $bar = 'bar value';
  18. private function someFakeMethod(array $one, $two = 'TWO', \Reflector $three = null)
  19. {
  20. }
  21. /**
  22. * @dataProvider signatureReflectors
  23. */
  24. public function testFormat($reflector, $expected)
  25. {
  26. $this->assertSame($expected, \strip_tags(SignatureFormatter::format($reflector)));
  27. }
  28. public function signatureReflectors()
  29. {
  30. return [
  31. [
  32. new \ReflectionFunction('implode'),
  33. \defined('HHVM_VERSION') ? 'function implode($arg1, $arg2 = null)' : 'function implode($glue, $pieces)',
  34. ],
  35. [
  36. ReflectionClassConstant::create($this, 'FOO'),
  37. 'const FOO = "foo value"',
  38. ],
  39. [
  40. new \ReflectionMethod($this, 'someFakeMethod'),
  41. 'private function someFakeMethod(array $one, $two = \'TWO\', Reflector $three = null)',
  42. ],
  43. [
  44. new \ReflectionProperty($this, 'bar'),
  45. 'private static $bar',
  46. ],
  47. [
  48. new \ReflectionClass('Psy\CodeCleaner\CodeCleanerPass'),
  49. 'abstract class Psy\CodeCleaner\CodeCleanerPass '
  50. . 'extends PhpParser\NodeVisitorAbstract '
  51. . 'implements PhpParser\NodeVisitor',
  52. ],
  53. [
  54. new \ReflectionFunction('array_chunk'),
  55. 'function array_chunk($arg, $size, $preserve_keys = unknown)',
  56. ],
  57. [
  58. new \ReflectionClass('Psy\Test\Formatter\Fixtures\BoringTrait'),
  59. 'trait Psy\Test\Formatter\Fixtures\BoringTrait',
  60. ],
  61. [
  62. new \ReflectionMethod('Psy\Test\Formatter\Fixtures\BoringTrait', 'boringMethod'),
  63. 'public function boringMethod($one = 1)',
  64. ],
  65. [
  66. new ReflectionConstant_('E_ERROR'),
  67. 'define("E_ERROR", 1)',
  68. ],
  69. [
  70. new ReflectionConstant_('PHP_VERSION'),
  71. 'define("PHP_VERSION", "' . PHP_VERSION . '")',
  72. ],
  73. [
  74. new ReflectionConstant_('__LINE__'),
  75. 'define("__LINE__", null)', // @todo show this as `unknown` in red or something?
  76. ],
  77. ];
  78. }
  79. /**
  80. * @expectedException \InvalidArgumentException
  81. */
  82. public function testSignatureFormatterThrowsUnknownReflectorExpeption()
  83. {
  84. $refl = $this->getMockBuilder('Reflector')->getMock();
  85. SignatureFormatter::format($refl);
  86. }
  87. }