Refactoring
This commit is contained in:
157
lib/composer/vendor/victorjonsson/markdowndocs/test/ExampleClass.php
vendored
Normal file
157
lib/composer/vendor/victorjonsson/markdowndocs/test/ExampleClass.php
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
namespace Acme;
|
||||
|
||||
/**
|
||||
* This is a description
|
||||
* of this class
|
||||
*
|
||||
* @package Acme
|
||||
*/
|
||||
abstract class ExampleClass implements \Reflector {
|
||||
|
||||
/**
|
||||
* Description of a*a
|
||||
* @param $arg
|
||||
* @param array $arr
|
||||
* @param int $bool
|
||||
*/
|
||||
public function funcA($arg, array $arr, $bool=10) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of c
|
||||
* @deprecated This one is deprecated
|
||||
* @param $arg
|
||||
* @param array $arr
|
||||
* @param int $bool
|
||||
* @return \Acme\ExampleClass
|
||||
*/
|
||||
protected function funcC($arg, array $arr, $bool=10) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of b
|
||||
*
|
||||
* @example
|
||||
* <code>
|
||||
* <?php
|
||||
* $lorem = 'te';
|
||||
* $ipsum = 'dolor';
|
||||
* </code>
|
||||
*
|
||||
* @param int $arg
|
||||
* @param array $arr
|
||||
* @param int $bool
|
||||
*/
|
||||
function funcB($arg, array $arr, $bool=10) {
|
||||
|
||||
}
|
||||
|
||||
function funcD($arg, $arr=array(), ExampleInterface $depr=null, \stdClass $class) {
|
||||
|
||||
}
|
||||
|
||||
function getFunc() {}
|
||||
function hasFunc() {}
|
||||
abstract function isFunc();
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
function someFunc() {
|
||||
|
||||
}
|
||||
|
||||
private function privFunc() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This one is deprecated
|
||||
*
|
||||
* Lorem te ipsum
|
||||
*
|
||||
* @package Acme
|
||||
*/
|
||||
class ExampleClassDepr {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface ExampleInterface
|
||||
* @package Acme
|
||||
* @ignore
|
||||
*/
|
||||
interface ExampleInterface {
|
||||
|
||||
/**
|
||||
* @param string $arg
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function func($arg='a');
|
||||
|
||||
}
|
||||
|
||||
class SomeClass {
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function aMethod() {}
|
||||
|
||||
}
|
||||
|
||||
class ClassImplementingInterface extends SomeClass implements ExampleInterface {
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function func($arg='a') {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function aMethod() {}
|
||||
|
||||
/**
|
||||
* @return \FilesystemIterator
|
||||
*/
|
||||
public function methodReturnNativeClass() {}
|
||||
|
||||
/**
|
||||
* @return \FilesystemIterator[]
|
||||
*/
|
||||
public function methodReturningArrayNativeClass() {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ClassWithStaticFunc {
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
static function somStaticFunc() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
use PHPDocsMD\Console\CLI;
|
||||
|
||||
interface InterfaceReferringToImportedClass {
|
||||
|
||||
/**
|
||||
* @return CLI
|
||||
*/
|
||||
function theFunc();
|
||||
|
||||
/**
|
||||
* @return CLI[]
|
||||
*/
|
||||
function funcReturningArr();
|
||||
|
||||
}
|
||||
123
lib/composer/vendor/victorjonsson/markdowndocs/test/MDTableGeneratorTest.php
vendored
Normal file
123
lib/composer/vendor/victorjonsson/markdowndocs/test/MDTableGeneratorTest.php
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
class MDTableGeneratorTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testDeprecatedFunc()
|
||||
{
|
||||
$tbl = new \PHPDocsMD\MDTableGenerator();
|
||||
$tbl->openTable();
|
||||
|
||||
$deprecated = new \PHPDocsMD\FunctionEntity();
|
||||
$deprecated->isDeprecated(true);
|
||||
$deprecated->setDeprecationMessage('Is deprecated');
|
||||
$deprecated->setName('myFunc');
|
||||
$deprecated->setReturnType('mixed');
|
||||
|
||||
$this->assertTrue($deprecated->isDeprecated());
|
||||
|
||||
$tbl->addFunc($deprecated);
|
||||
|
||||
$tblMarkdown = $tbl->getTable();
|
||||
$expect = '| Visibility | Function |'.PHP_EOL.
|
||||
'|:-----------|:---------|'.PHP_EOL.
|
||||
'| public | <strike><strong>myFunc()</strong> : <em>mixed</em></strike><br /><em>DEPRECATED - Is deprecated</em> |';
|
||||
|
||||
$this->assertEquals($expect, $tblMarkdown);
|
||||
}
|
||||
|
||||
function testFunc()
|
||||
{
|
||||
$tbl = new \PHPDocsMD\MDTableGenerator();
|
||||
$tbl->openTable();
|
||||
|
||||
$func = new \PHPDocsMD\FunctionEntity();
|
||||
$func->setName('myFunc');
|
||||
$tbl->addFunc($func);
|
||||
|
||||
$tblMarkdown = $tbl->getTable();
|
||||
$expect = '| Visibility | Function |'.PHP_EOL.
|
||||
'|:-----------|:---------|'.PHP_EOL.
|
||||
'| public | <strong>myFunc()</strong> : <em>void</em> |';
|
||||
|
||||
$this->assertEquals($expect, $tblMarkdown);
|
||||
}
|
||||
|
||||
function testFuncWithAllFeatures()
|
||||
{
|
||||
$tbl = new \PHPDocsMD\MDTableGenerator();
|
||||
$tbl->openTable();
|
||||
|
||||
$func = new \PHPDocsMD\FunctionEntity();
|
||||
|
||||
$this->assertFalse($func->isStatic());
|
||||
$this->assertFalse($func->hasParams());
|
||||
$this->assertFalse($func->isDeprecated());
|
||||
$this->assertFalse($func->isAbstract());
|
||||
$this->assertEquals('public', $func->getVisibility());
|
||||
|
||||
$func->isStatic(true);
|
||||
$func->setVisibility('protected');
|
||||
$func->setName('someFunc');
|
||||
$func->setDescription('desc...');
|
||||
$func->setReturnType('\\stdClass');
|
||||
|
||||
$params = array();
|
||||
|
||||
$paramA = new \PHPDocsMD\ParamEntity();
|
||||
$paramA->setName('$var');
|
||||
$paramA->setType('mixed');
|
||||
$paramA->setDefault('null');
|
||||
$params[] = $paramA;
|
||||
|
||||
$paramB = new \PHPDocsMD\ParamEntity();
|
||||
$paramB->setName('$other');
|
||||
$paramB->setType('string');
|
||||
$paramB->setDefault("'test'");
|
||||
$params[] = $paramB;
|
||||
|
||||
$func->setParams($params);
|
||||
|
||||
$tbl->addFunc($func);
|
||||
|
||||
$this->assertTrue($func->isStatic());
|
||||
$this->assertTrue($func->hasParams());
|
||||
$this->assertEquals('protected', $func->getVisibility());
|
||||
|
||||
$tblMarkdown = $tbl->getTable();
|
||||
$expect = '| Visibility | Function |'.PHP_EOL.
|
||||
'|:-----------|:---------|'.PHP_EOL.
|
||||
'| protected static | <strong>someFunc(</strong><em>mixed</em> <strong>$var=null</strong>, <em>string</em> <strong>$other=\'test\'</strong>)</strong> : <em>\\stdClass</em><br /><em>desc...</em> |';
|
||||
|
||||
$this->assertEquals($expect, $tblMarkdown);
|
||||
}
|
||||
|
||||
function testToggleDeclaringAbstraction()
|
||||
{
|
||||
$tbl = new \PHPDocsMD\MDTableGenerator();
|
||||
$tbl->openTable();
|
||||
|
||||
$func = new \PHPDocsMD\FunctionEntity();
|
||||
$func->isAbstract(true);
|
||||
$func->setName('someFunc');
|
||||
|
||||
$tbl->addFunc($func);
|
||||
$tblMarkdown = $tbl->getTable();
|
||||
$expect = '| Visibility | Function |'.PHP_EOL.
|
||||
'|:-----------|:---------|'.PHP_EOL.
|
||||
'| public | <strong>abstract someFunc()</strong> : <em>void</em> |';
|
||||
|
||||
$this->assertEquals($expect, $tblMarkdown);
|
||||
|
||||
$tbl->openTable();
|
||||
$tbl->doDeclareAbstraction(false);
|
||||
$tbl->addFunc($func);
|
||||
|
||||
$tblMarkdown = $tbl->getTable();
|
||||
$expect = '| Visibility | Function |'.PHP_EOL.
|
||||
'|:-----------|:---------|'.PHP_EOL.
|
||||
'| public | <strong>someFunc()</strong> : <em>void</em> |';
|
||||
|
||||
$this->assertEquals($expect, $tblMarkdown);
|
||||
}
|
||||
|
||||
}
|
||||
160
lib/composer/vendor/victorjonsson/markdowndocs/test/ReflectorTest.php
vendored
Normal file
160
lib/composer/vendor/victorjonsson/markdowndocs/test/ReflectorTest.php
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
class ReflectorTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var \PHPDocsMD\Reflector
|
||||
*/
|
||||
private $reflector;
|
||||
|
||||
/**
|
||||
* @var \PHPDocsMD\ClassEntity
|
||||
*/
|
||||
private $class;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
require_once __DIR__ . '/ExampleClass.php';
|
||||
$this->reflector = new \PHPDocsMD\Reflector('Acme\\ExampleClass');
|
||||
$this->class = $this->reflector->getClassEntity();
|
||||
}
|
||||
|
||||
function testClass()
|
||||
{
|
||||
$this->assertEquals('\\Acme\\ExampleClass', $this->class->getName());
|
||||
$this->assertEquals('This is a description of this class', $this->class->getDescription());
|
||||
$this->assertEquals('Class: \\Acme\\ExampleClass (abstract)', $this->class->generateTitle());
|
||||
$this->assertEquals('class-acmeexampleclass-abstract', $this->class->generateAnchor());
|
||||
$this->assertFalse($this->class->isDeprecated());
|
||||
$this->assertFalse($this->class->hasIgnoreTag());
|
||||
|
||||
$refl = new \PHPDocsMD\Reflector('Acme\\ExampleClassDepr');
|
||||
$class = $refl->getClassEntity();
|
||||
$this->assertTrue($class->isDeprecated());
|
||||
$this->assertEquals('This one is deprecated Lorem te ipsum', $class->getDeprecationMessage());
|
||||
$this->assertFalse($class->hasIgnoreTag());
|
||||
|
||||
$refl = new \PHPDocsMD\Reflector('Acme\\ExampleInterface');
|
||||
$class = $refl->getClassEntity();
|
||||
$this->assertTrue($class->isInterface());
|
||||
$this->assertTrue($class->hasIgnoreTag());
|
||||
}
|
||||
|
||||
function testFunctions()
|
||||
{
|
||||
|
||||
$functions = $this->class->getFunctions();
|
||||
|
||||
$this->assertNotEmpty($functions);
|
||||
|
||||
$this->assertEquals('Description of a*a', $functions[0]->getDescription());
|
||||
$this->assertEquals(false, $functions[0]->isDeprecated());
|
||||
$this->assertEquals('funcA', $functions[0]->getName());
|
||||
$this->assertEquals('void', $functions[0]->getReturnType());
|
||||
$this->assertEquals('public', $functions[0]->getVisibility());
|
||||
|
||||
$this->assertEquals('Description of b', $functions[1]->getDescription());
|
||||
$this->assertEquals(false, $functions[1]->isDeprecated());
|
||||
$this->assertEquals('funcB', $functions[1]->getName());
|
||||
$this->assertEquals('void', $functions[1]->getReturnType());
|
||||
$this->assertEquals('public', $functions[1]->getVisibility());
|
||||
|
||||
|
||||
$this->assertEquals('', $functions[2]->getDescription());
|
||||
$this->assertEquals('funcD', $functions[2]->getName());
|
||||
$this->assertEquals('void', $functions[2]->getReturnType());
|
||||
$this->assertEquals('public', $functions[2]->getVisibility());
|
||||
$this->assertEquals(false, $functions[2]->isDeprecated());
|
||||
|
||||
// These function does not declare return type but the return
|
||||
// type should be guessable
|
||||
$this->assertEquals('mixed', $functions[3]->getReturnType());
|
||||
$this->assertEquals('bool', $functions[4]->getReturnType());
|
||||
$this->assertEquals('bool', $functions[5]->getReturnType());
|
||||
$this->assertTrue($functions[5]->isAbstract());
|
||||
$this->assertTrue($this->class->isAbstract());
|
||||
|
||||
// Protected function have been put last
|
||||
$this->assertEquals('Description of c', $functions[6]->getDescription());
|
||||
$this->assertEquals(true, $functions[6]->isDeprecated());
|
||||
$this->assertEquals('This one is deprecated', $functions[6]->getDeprecationMessage());
|
||||
$this->assertEquals('funcC', $functions[6]->getName());
|
||||
$this->assertEquals('\\Acme\\ExampleClass', $functions[6]->getReturnType());
|
||||
$this->assertEquals('protected', $functions[6]->getVisibility());
|
||||
|
||||
$this->assertTrue( empty($functions[7]) ); // Should be skipped since tagged with @ignore */
|
||||
}
|
||||
|
||||
function testStaticFunc() {
|
||||
$reflector = new \PHPDocsMD\Reflector('Acme\\ClassWithStaticFunc');
|
||||
$functions = $reflector->getClassEntity()->getFunctions();
|
||||
$this->assertNotEmpty($functions);
|
||||
$this->assertEquals('', $functions[0]->getDescription());
|
||||
$this->assertEquals(false, $functions[0]->isDeprecated());
|
||||
$this->assertEquals(true, $functions[0]->isStatic());
|
||||
$this->assertEquals('', $functions[0]->getDeprecationMessage());
|
||||
$this->assertEquals('somStaticFunc', $functions[0]->getName());
|
||||
$this->assertEquals('public', $functions[0]->getVisibility());
|
||||
$this->assertEquals('float', $functions[0]->getReturnType());
|
||||
}
|
||||
|
||||
function testParams()
|
||||
{
|
||||
$paramA = new ReflectionParameter(array('Acme\\ExampleClass', 'funcD'), 2);
|
||||
$paramB = new ReflectionParameter(array('Acme\\ExampleClass', 'funcD'), 3);
|
||||
$paramC = new ReflectionParameter(array('Acme\\ExampleClass', 'funcD'), 0);
|
||||
|
||||
$typeA = \PHPDocsMD\Reflector::getParamType($paramA);
|
||||
$typeB = \PHPDocsMD\Reflector::getParamType($paramB);
|
||||
$typeC = \PHPDocsMD\Reflector::getParamType($paramC);
|
||||
|
||||
$this->assertEmpty($typeC);
|
||||
$this->assertEquals('\\stdClass', $typeB);
|
||||
$this->assertEquals('\\Acme\\ExampleInterface', $typeA);
|
||||
|
||||
$functions = $this->class->getFunctions();
|
||||
|
||||
$this->assertTrue($functions[2]->hasParams());
|
||||
$this->assertFalse($functions[5]->hasParams());
|
||||
|
||||
$params = $functions[1]->getParams();
|
||||
$this->assertEquals('int', $params[0]->getType());
|
||||
|
||||
$params = $functions[2]->getParams();
|
||||
$this->assertEquals(4, count($params));
|
||||
$this->assertEquals(false, $params[0]->getDefault());
|
||||
$this->assertEquals('$arg', $params[0]->getName());
|
||||
$this->assertEquals('mixed', $params[0]->getType());
|
||||
$this->assertEquals('array()', $params[1]->getDefault());
|
||||
$this->assertEquals('$arr', $params[1]->getName());
|
||||
$this->assertEquals('array', $params[1]->getType());
|
||||
$this->assertEquals('null', $params[2]->getDefault());
|
||||
$this->assertEquals('$depr', $params[2]->getName());
|
||||
$this->assertEquals('\\Acme\\ExampleInterface', $params[2]->getType());
|
||||
}
|
||||
|
||||
function testInheritedDocs()
|
||||
{
|
||||
$reflector = new \PHPDocsMD\Reflector('Acme\\ClassImplementingInterface');
|
||||
$functions = $reflector->getClassEntity()->getFunctions();
|
||||
$this->assertEquals(4, count($functions));
|
||||
$this->assertEquals('aMethod', $functions[0]->getName());
|
||||
$this->assertEquals('int', $functions[0]->getReturnType());
|
||||
$this->assertFalse($functions[0]->isReturningNativeClass());
|
||||
$this->assertEquals('func', $functions[1]->getName());
|
||||
$this->assertEquals('\\stdClass', $functions[1]->getReturnType());
|
||||
$this->assertFalse($functions[1]->isAbstract());
|
||||
|
||||
$this->assertTrue($functions[2]->isReturningNativeClass());
|
||||
$this->assertTrue($functions[3]->isReturningNativeClass());
|
||||
}
|
||||
|
||||
|
||||
function testReferenceToImportedClass()
|
||||
{
|
||||
$reflector = new \PHPDocsMD\Reflector('Acme\\InterfaceReferringToImportedClass');
|
||||
$functions = $reflector->getClassEntity()->getFunctions();
|
||||
$this->assertEquals('\\PHPDocsMD\\Console\\CLI', $functions[1]->getReturnType());
|
||||
$this->assertEquals('\\PHPDocsMD\\Console\\CLI[]', $functions[0]->getReturnType());
|
||||
}
|
||||
}
|
||||
42
lib/composer/vendor/victorjonsson/markdowndocs/test/UseInspectorTest.php
vendored
Normal file
42
lib/composer/vendor/victorjonsson/markdowndocs/test/UseInspectorTest.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class UseInspectorTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testInspection()
|
||||
{
|
||||
$code = '
|
||||
Abra
|
||||
|
||||
use apa\\sten\\groda;
|
||||
use apa\\sten\\BjornGroda;
|
||||
use apa\\sten\\groda;
|
||||
use \\apa\\sten\\groda;
|
||||
use apa
|
||||
|
||||
use \\apa ;
|
||||
use \\apa\\Sten
|
||||
;
|
||||
|
||||
Kadabra
|
||||
use \apa ;
|
||||
|
||||
useBala;
|
||||
';
|
||||
|
||||
$expected = array(
|
||||
'\\apa\\sten\\groda',
|
||||
'\\apa\\sten\\BjornGroda',
|
||||
'\\apa\\sten\\groda',
|
||||
'\\apa\\sten\\groda',
|
||||
'\\apa',
|
||||
'\\apa',
|
||||
'\\apa\\Sten',
|
||||
'\\apa'
|
||||
);
|
||||
|
||||
$inspector = new \PHPDocsMD\UseInspector();
|
||||
$this->assertEquals($expected, $inspector->getUseStatementsInString($code));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user