7f1635e55f11a2b08bc62c0691eeee9ffd12a95f
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / Formatter / CodeFormatterTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\Test\Formatter;
13
14 use Psy\Formatter\CodeFormatter;
15
16 class CodeFormatterTest extends \PHPUnit\Framework\TestCase
17 {
18     private function ignoreThisMethod($arg)
19     {
20         echo 'whot!';
21     }
22
23     public function testFormat()
24     {
25         $expected = <<<'EOS'
26   > 18|     private function ignoreThisMethod($arg)
27     19|     {
28     20|         echo 'whot!';
29     21|     }
30 EOS;
31
32         $formatted = CodeFormatter::format(new \ReflectionMethod($this, 'ignoreThisMethod'));
33         $formattedWithoutColors = preg_replace('#' . chr(27) . '\[\d\d?m#', '', $formatted);
34
35         $this->assertEquals($expected, rtrim($formattedWithoutColors));
36         $this->assertNotEquals($expected, rtrim($formatted));
37     }
38
39     /**
40      * @dataProvider filenames
41      * @expectedException \Psy\Exception\RuntimeException
42      */
43     public function testCodeFormatterThrowsException($filename)
44     {
45         $reflector = $this->getMockBuilder('ReflectionClass')
46             ->disableOriginalConstructor()
47             ->getMock();
48
49         $reflector
50             ->expects($this->once())
51             ->method('getFileName')
52             ->will($this->returnValue($filename));
53
54         CodeFormatter::format($reflector);
55     }
56
57     public function filenames()
58     {
59         if (defined('HHVM_VERSION')) {
60             $this->markTestSkipped('We have issues with PHPUnit mocks on HHVM.');
61         }
62
63         return array(array(null), array('not a file'));
64     }
65 }