Chris@13
|
1 <?php
|
Chris@13
|
2
|
Chris@13
|
3 /*
|
Chris@13
|
4 * This file is part of Psy Shell.
|
Chris@13
|
5 *
|
Chris@13
|
6 * (c) 2012-2018 Justin Hileman
|
Chris@13
|
7 *
|
Chris@13
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@13
|
9 * file that was distributed with this source code.
|
Chris@13
|
10 */
|
Chris@13
|
11
|
Chris@13
|
12 namespace Psy\Test\Formatter;
|
Chris@13
|
13
|
Chris@13
|
14 use Psy\Formatter\SignatureFormatter;
|
Chris@13
|
15 use Psy\Reflection\ReflectionConstant;
|
Chris@13
|
16
|
Chris@13
|
17 class SignatureFormatterTest extends \PHPUnit\Framework\TestCase
|
Chris@13
|
18 {
|
Chris@13
|
19 const FOO = 'foo value';
|
Chris@13
|
20 private static $bar = 'bar value';
|
Chris@13
|
21
|
Chris@13
|
22 private function someFakeMethod(array $one, $two = 'TWO', \Reflector $three = null)
|
Chris@13
|
23 {
|
Chris@13
|
24 }
|
Chris@13
|
25
|
Chris@13
|
26 /**
|
Chris@13
|
27 * @dataProvider signatureReflectors
|
Chris@13
|
28 */
|
Chris@13
|
29 public function testFormat($reflector, $expected)
|
Chris@13
|
30 {
|
Chris@13
|
31 $this->assertSame($expected, strip_tags(SignatureFormatter::format($reflector)));
|
Chris@13
|
32 }
|
Chris@13
|
33
|
Chris@13
|
34 public function signatureReflectors()
|
Chris@13
|
35 {
|
Chris@13
|
36 return [
|
Chris@13
|
37 [
|
Chris@13
|
38 new \ReflectionFunction('implode'),
|
Chris@13
|
39 defined('HHVM_VERSION') ? 'function implode($arg1, $arg2 = null)' : 'function implode($glue, $pieces)',
|
Chris@13
|
40 ],
|
Chris@13
|
41 [
|
Chris@13
|
42 new ReflectionConstant($this, 'FOO'),
|
Chris@13
|
43 'const FOO = "foo value"',
|
Chris@13
|
44 ],
|
Chris@13
|
45 [
|
Chris@13
|
46 new \ReflectionMethod($this, 'someFakeMethod'),
|
Chris@13
|
47 'private function someFakeMethod(array $one, $two = \'TWO\', Reflector $three = null)',
|
Chris@13
|
48 ],
|
Chris@13
|
49 [
|
Chris@13
|
50 new \ReflectionProperty($this, 'bar'),
|
Chris@13
|
51 'private static $bar',
|
Chris@13
|
52 ],
|
Chris@13
|
53 [
|
Chris@13
|
54 new \ReflectionClass('Psy\CodeCleaner\CodeCleanerPass'),
|
Chris@13
|
55 'abstract class Psy\CodeCleaner\CodeCleanerPass '
|
Chris@13
|
56 . 'extends PhpParser\NodeVisitorAbstract '
|
Chris@13
|
57 . 'implements PhpParser\NodeVisitor',
|
Chris@13
|
58 ],
|
Chris@13
|
59 ];
|
Chris@13
|
60 }
|
Chris@13
|
61
|
Chris@13
|
62 /**
|
Chris@13
|
63 * @expectedException \InvalidArgumentException
|
Chris@13
|
64 */
|
Chris@13
|
65 public function testSignatureFormatterThrowsUnknownReflectorExpeption()
|
Chris@13
|
66 {
|
Chris@13
|
67 $refl = $this->getMockBuilder('Reflector')->getMock();
|
Chris@13
|
68 SignatureFormatter::format($refl);
|
Chris@13
|
69 }
|
Chris@13
|
70 }
|