annotate vendor/psy/psysh/test/Formatter/SignatureFormatterTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of Psy Shell.
Chris@0 5 *
Chris@0 6 * (c) 2012-2018 Justin Hileman
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Psy\Test\Formatter;
Chris@0 13
Chris@0 14 use Psy\Formatter\SignatureFormatter;
Chris@0 15 use Psy\Reflection\ReflectionClassConstant;
Chris@0 16 use Psy\Reflection\ReflectionConstant_;
Chris@0 17
Chris@0 18 class SignatureFormatterTest extends \PHPUnit\Framework\TestCase
Chris@0 19 {
Chris@0 20 const FOO = 'foo value';
Chris@0 21 private static $bar = 'bar value';
Chris@0 22
Chris@0 23 private function someFakeMethod(array $one, $two = 'TWO', \Reflector $three = null)
Chris@0 24 {
Chris@0 25 }
Chris@0 26
Chris@0 27 /**
Chris@0 28 * @dataProvider signatureReflectors
Chris@0 29 */
Chris@0 30 public function testFormat($reflector, $expected)
Chris@0 31 {
Chris@0 32 $this->assertSame($expected, strip_tags(SignatureFormatter::format($reflector)));
Chris@0 33 }
Chris@0 34
Chris@0 35 public function signatureReflectors()
Chris@0 36 {
Chris@0 37 return [
Chris@0 38 [
Chris@0 39 new \ReflectionFunction('implode'),
Chris@0 40 defined('HHVM_VERSION') ? 'function implode($arg1, $arg2 = null)' : 'function implode($glue, $pieces)',
Chris@0 41 ],
Chris@0 42 [
Chris@0 43 ReflectionClassConstant::create($this, 'FOO'),
Chris@0 44 'const FOO = "foo value"',
Chris@0 45 ],
Chris@0 46 [
Chris@0 47 new \ReflectionMethod($this, 'someFakeMethod'),
Chris@0 48 'private function someFakeMethod(array $one, $two = \'TWO\', Reflector $three = null)',
Chris@0 49 ],
Chris@0 50 [
Chris@0 51 new \ReflectionProperty($this, 'bar'),
Chris@0 52 'private static $bar',
Chris@0 53 ],
Chris@0 54 [
Chris@0 55 new \ReflectionClass('Psy\CodeCleaner\CodeCleanerPass'),
Chris@0 56 'abstract class Psy\CodeCleaner\CodeCleanerPass '
Chris@0 57 . 'extends PhpParser\NodeVisitorAbstract '
Chris@0 58 . 'implements PhpParser\NodeVisitor',
Chris@0 59 ],
Chris@0 60 [
Chris@0 61 new \ReflectionFunction('array_chunk'),
Chris@0 62 'function array_chunk($arg, $size, $preserve_keys = unknown)',
Chris@0 63 ],
Chris@0 64 [
Chris@0 65 new \ReflectionClass('Psy\Test\Formatter\Fixtures\BoringTrait'),
Chris@0 66 'trait Psy\Test\Formatter\Fixtures\BoringTrait',
Chris@0 67 ],
Chris@0 68 [
Chris@0 69 new \ReflectionMethod('Psy\Test\Formatter\Fixtures\BoringTrait', 'boringMethod'),
Chris@0 70 'public function boringMethod($one = 1)',
Chris@0 71 ],
Chris@0 72 [
Chris@0 73 new ReflectionConstant_('E_ERROR'),
Chris@0 74 'define("E_ERROR", 1)',
Chris@0 75 ],
Chris@0 76 [
Chris@0 77 new ReflectionConstant_('PHP_VERSION'),
Chris@0 78 'define("PHP_VERSION", "' . PHP_VERSION . '")',
Chris@0 79 ],
Chris@0 80 [
Chris@0 81 new ReflectionConstant_('__LINE__'),
Chris@0 82 'define("__LINE__", null)', // @todo show this as `unknown` in red or something?
Chris@0 83 ],
Chris@0 84 ];
Chris@0 85 }
Chris@0 86
Chris@0 87 /**
Chris@0 88 * @expectedException \InvalidArgumentException
Chris@0 89 */
Chris@0 90 public function testSignatureFormatterThrowsUnknownReflectorExpeption()
Chris@0 91 {
Chris@0 92 $refl = $this->getMockBuilder('Reflector')->getMock();
Chris@0 93 SignatureFormatter::format($refl);
Chris@0 94 }
Chris@0 95 }