Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/test/Formatter/CodeFormatterTest.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 5fb285c0d0e3 |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
10 */ | 10 */ |
11 | 11 |
12 namespace Psy\Test\Formatter; | 12 namespace Psy\Test\Formatter; |
13 | 13 |
14 use Psy\Formatter\CodeFormatter; | 14 use Psy\Formatter\CodeFormatter; |
15 use Psy\Test\Formatter\Fixtures\SomeClass; | |
15 | 16 |
16 class CodeFormatterTest extends \PHPUnit\Framework\TestCase | 17 class CodeFormatterTest extends \PHPUnit\Framework\TestCase |
17 { | 18 { |
18 private function ignoreThisMethod($arg) | 19 /** |
20 * @dataProvider reflectors | |
21 */ | |
22 public function testFormat($reflector, $expected) | |
19 { | 23 { |
20 echo 'whot!'; | 24 $formatted = CodeFormatter::format($reflector); |
25 $formattedWithoutColors = preg_replace('#' . chr(27) . '\[\d\d?m#', '', $formatted); | |
26 | |
27 $this->assertEquals($expected, self::trimLines($formattedWithoutColors)); | |
28 $this->assertNotEquals($expected, self::trimLines($formatted)); | |
21 } | 29 } |
22 | 30 |
23 public function testFormat() | 31 public function reflectors() |
24 { | 32 { |
25 $expected = <<<'EOS' | 33 $expectClass = <<<'EOS' |
26 > 18| private function ignoreThisMethod($arg) | 34 > 14| class SomeClass |
27 19| { | 35 15| { |
28 20| echo 'whot!'; | 36 16| const SOME_CONST = 'some const'; |
29 21| } | 37 17| private $someProp = 'some prop'; |
38 18| | |
39 19| public function someMethod($someParam) | |
40 20| { | |
41 21| return 'some method'; | |
42 22| } | |
43 23| | |
44 24| public static function someClosure() | |
45 25| { | |
46 26| return function () { | |
47 27| return 'some closure'; | |
48 28| }; | |
49 29| } | |
50 30| } | |
30 EOS; | 51 EOS; |
31 | 52 |
32 $formatted = CodeFormatter::format(new \ReflectionMethod($this, 'ignoreThisMethod')); | 53 $expectMethod = <<<'EOS' |
33 $formattedWithoutColors = preg_replace('#' . chr(27) . '\[\d\d?m#', '', $formatted); | 54 > 19| public function someMethod($someParam) |
55 20| { | |
56 21| return 'some method'; | |
57 22| } | |
58 EOS; | |
34 | 59 |
35 $this->assertEquals($expected, rtrim($formattedWithoutColors)); | 60 $expectClosure = <<<'EOS' |
36 $this->assertNotEquals($expected, rtrim($formatted)); | 61 > 26| return function () { |
62 27| return 'some closure'; | |
63 28| }; | |
64 EOS; | |
65 | |
66 return [ | |
67 [new \ReflectionClass('Psy\Test\Formatter\Fixtures\SomeClass'), $expectClass], | |
68 [new \ReflectionObject(new SomeClass()), $expectClass], | |
69 [new \ReflectionMethod('Psy\Test\Formatter\Fixtures\SomeClass', 'someMethod'), $expectMethod], | |
70 [new \ReflectionFunction(SomeClass::someClosure()), $expectClosure], | |
71 ]; | |
72 } | |
73 | |
74 /** | |
75 * @dataProvider invalidReflectors | |
76 * @expectedException \Psy\Exception\RuntimeException | |
77 */ | |
78 public function testCodeFormatterThrowsExceptionForReflectorsItDoesntUnderstand($reflector) | |
79 { | |
80 CodeFormatter::format($reflector); | |
81 } | |
82 | |
83 public function invalidReflectors() | |
84 { | |
85 $reflectors = [ | |
86 [new \ReflectionExtension('json')], | |
87 [new \ReflectionParameter(['Psy\Test\Formatter\Fixtures\SomeClass', 'someMethod'], 'someParam')], | |
88 [new \ReflectionProperty('Psy\Test\Formatter\Fixtures\SomeClass', 'someProp')], | |
89 ]; | |
90 | |
91 if (version_compare(PHP_VERSION, '7.1.0', '>=')) { | |
92 $reflectors[] = [new \ReflectionClassConstant('Psy\Test\Formatter\Fixtures\SomeClass', 'SOME_CONST')]; | |
93 } | |
94 | |
95 return $reflectors; | |
37 } | 96 } |
38 | 97 |
39 /** | 98 /** |
40 * @dataProvider filenames | 99 * @dataProvider filenames |
41 * @expectedException \Psy\Exception\RuntimeException | 100 * @expectedException \Psy\Exception\RuntimeException |
42 */ | 101 */ |
43 public function testCodeFormatterThrowsException($filename) | 102 public function testCodeFormatterThrowsExceptionForMissingFile($filename) |
44 { | 103 { |
45 $reflector = $this->getMockBuilder('ReflectionClass') | 104 $reflector = $this->getMockBuilder('ReflectionClass') |
46 ->disableOriginalConstructor() | 105 ->disableOriginalConstructor() |
47 ->getMock(); | 106 ->getMock(); |
48 | 107 |
60 $this->markTestSkipped('We have issues with PHPUnit mocks on HHVM.'); | 119 $this->markTestSkipped('We have issues with PHPUnit mocks on HHVM.'); |
61 } | 120 } |
62 | 121 |
63 return [[null], ['not a file']]; | 122 return [[null], ['not a file']]; |
64 } | 123 } |
124 | |
125 private static function trimLines($code) | |
126 { | |
127 return rtrim(implode("\n", array_map('rtrim', explode("\n", $code)))); | |
128 } | |
65 } | 129 } |