DocblockFormatterTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\DocblockFormatter;
  12. class DocblockFormatterTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * This is a docblock!
  16. *
  17. * @author Justin Hileman <justin@justinhileman.info>
  18. *
  19. * @throws InvalidArgumentException if $foo is empty
  20. *
  21. * @param mixed $foo It's a foo thing
  22. * @param int $bar This is definitely bar
  23. *
  24. * @return string A string of no consequence
  25. */
  26. private function methodWithDocblock($foo, $bar = 1)
  27. {
  28. if (empty($foo)) {
  29. throw new \InvalidArgumentException();
  30. }
  31. return 'method called';
  32. }
  33. public function testFormat()
  34. {
  35. $expected = <<<EOS
  36. <comment>Description:</comment>
  37. This is a docblock!
  38. <comment>Throws:</comment>
  39. <info>InvalidArgumentException </info> if \$foo is empty
  40. <comment>Param:</comment>
  41. <info>mixed </info> <strong>\$foo </strong> It's a foo thing
  42. <info>int </info> <strong>\$bar </strong> This is definitely bar
  43. <comment>Return:</comment>
  44. <info>string </info> A string of no consequence
  45. <comment>Author:</comment> Justin Hileman \<justin@justinhileman.info>
  46. EOS;
  47. $this->assertSame(
  48. $expected,
  49. DocblockFormatter::format(new \ReflectionMethod($this, 'methodWithDocblock'))
  50. );
  51. }
  52. }