DocblockFormatterTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2023 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\DocblockFormatter;
  12. use Symfony\Component\Console\Formatter\OutputFormatter;
  13. /**
  14. * @group isolation-fail
  15. */
  16. class DocblockFormatterTest extends \Psy\Test\TestCase
  17. {
  18. /**
  19. * This is a docblock!
  20. *
  21. * @author Justin Hileman <justin@justinhileman.info>
  22. *
  23. * @throws \InvalidArgumentException if $foo is empty
  24. *
  25. * @param mixed $foo It's a foo thing
  26. * @param int $bar
  27. *
  28. * @return string A string of no consequence
  29. */
  30. private function methodWithDocblock($foo, $bar = 1)
  31. {
  32. if (empty($foo)) {
  33. throw new \InvalidArgumentException();
  34. }
  35. return 'method called';
  36. }
  37. public function testFormat()
  38. {
  39. $escapedEmail = OutputFormatter::escape('<justin@justinhileman.info>');
  40. $expected = <<<EOS
  41. <comment>Description:</comment>
  42. This is a docblock!
  43. <comment>Throws:</comment>
  44. <info>\\InvalidArgumentException </info> if \$foo is empty
  45. <comment>Param:</comment>
  46. <info>mixed </info> <strong>\$foo </strong> It's a foo thing
  47. <info>int </info> <strong>\$bar </strong>
  48. <comment>Return:</comment>
  49. <info>string </info> A string of no consequence
  50. <comment>Author:</comment> Justin Hileman $escapedEmail
  51. EOS;
  52. $this->assertSame(
  53. $expected,
  54. DocblockFormatter::format(new \ReflectionMethod($this, 'methodWithDocblock'))
  55. );
  56. }
  57. }