first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,220 @@
<?php declare(strict_types=1);
/*
* This file is part of the Docblock package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace phpowermove\docblock\tests;
use InvalidArgumentException;
use phpowermove\docblock\Docblock;
use phpowermove\docblock\tags\AuthorTag;
use phpowermove\docblock\tags\ParamTag;
use phpowermove\docblock\tags\PropertyTag;
use phpowermove\docblock\tags\ReturnTag;
use phpowermove\docblock\tags\SeeTag;
use phpowermove\docblock\tags\SinceTag;
use phpowermove\docblock\tags\ThrowsTag;
use phpowermove\docblock\tags\UnknownTag;
use phpowermove\docblock\tests\fixtures\MyDocBlock;
use PHPUnit\Framework\TestCase;
class DocblockTest extends TestCase {
public function testShortDescription(): void {
$desc = 'Hello World';
$docblock = new Docblock();
$docblock->setShortDescription($desc);
$this->assertEquals($desc, $docblock->getShortDescription());
}
public function testLongDescription(): void {
$desc = 'Hello World';
$docblock = new Docblock();
$docblock->setLongDescription($desc);
$this->assertEquals($desc, $docblock->getLongDescription());
}
public function testSimpleReadWrite(): void {
$expected = '/**
* Short Description.
*
* Long Description.
*/';
$docblock = new Docblock($expected);
$this->assertEquals('Short Description.', $docblock->getShortDescription());
$this->assertEquals('Long Description.', $docblock->getLongDescription());
$this->assertEquals($expected, $docblock->toString());
}
public function testSingleLine(): void {
$docblock = new Docblock('/** Single Line Doc */');
$this->assertEquals('Single Line Doc', $docblock->getShortDescription());
}
public function testTags(): void {
$expected = '/**
* @see https://github.com/gossi/docblock
* @author gossi
* @author KH
* @since 28.5.2014
*/';
$docblock = new Docblock($expected);
$tags = $docblock->getTags();
$this->assertEquals(4, $tags->size());
$this->assertTrue($docblock->hasTag('see'));
$this->assertTrue($docblock->hasTag('author'));
$this->assertTrue($docblock->hasTag('since'));
$this->assertFalse($docblock->hasTag('license'));
$authors = $docblock->getTags('author');
$this->assertEquals(2, $authors->size());
$this->assertEquals($expected, $docblock->toString());
$this->assertSame($docblock, $docblock->appendTag(ThrowsTag::create()));
$tags = $docblock->getTags();
$this->assertEquals(5, $tags->size());
$this->assertTrue($docblock->hasTag('author'));
$this->assertFalse($docblock->hasTag('moooh'));
}
public function testInvalidTags(): void {
$this->expectException(InvalidArgumentException::class);
new MyDocBlock('');
}
public function testInvalidDocblockParameter(): void {
$this->expectException(\TypeError::class);
new Docblock(new \stdClass());
}
public function testMultilLongLineDescription(): void {
$expected = '/**
* Short Description.
*
* Long Description, which is very long and takes ages to reach the very last of the current line
* before it brakes onto the next line
*
* sdfasdf @tag
*
* @tag2 wurst multi-
* linee
*/';
$docblock = new Docblock($expected);
$this->assertEquals($expected, $docblock->toString());
}
public function testFromReflection(): void {
$expected = '/**
* Short Description.
*
* @author gossi
*/';
$reflection = new \ReflectionClass('\\phpowermove\\docblock\\tests\\fixtures\\ReflectionTestClass');
$docblock = Docblock::create($reflection);
$this->assertEquals($expected, '' . $docblock);
}
public function testTagSorting(): void {
$doc = new Docblock();
$doc->appendTag(new AuthorTag());
$doc->appendTag(new SeeTag());
$doc->appendTag(new ThrowsTag());
$doc->appendTag((new UnknownTag())->setTagName('wurst'));
$doc->appendTag(new SinceTag());
$doc->appendTag(new ParamTag());
$doc->appendTag(new ParamTag());
$doc->appendTag(new PropertyTag());
$doc->appendTag(new ReturnTag());
$actual = [];
$expected = ['wurst', 'see', 'author', 'property', 'since', 'param', 'param', 'throws', 'return'];
$sorted = $doc->getSortedTags();
foreach ($sorted as $tag) {
$actual[] = $tag->getTagName();
}
$this->assertEquals($expected, $actual);
}
public function testEmpty(): void {
$doc = new Docblock();
$this->assertTrue($doc->isEmpty());
$doc->setLongDescription('bla');
$this->assertFalse($doc->isEmpty());
$doc->setLongDescription();
$this->assertTrue($doc->isEmpty());
$doc->setShortDescription('bla');
$this->assertFalse($doc->isEmpty());
$doc->setShortDescription();
$this->assertTrue($doc->isEmpty());
$doc->appendTag(new SeeTag());
$this->assertFalse($doc->isEmpty());
}
public function testRemoveTag(): void {
$expected = '/**
* @see https://github.com/gossi/docblock
* @author gossi
* @author KH
* @since 28.5.2014
*/';
$docblock = new Docblock($expected);
$tags = $docblock->getTags();
$this->assertEquals(4, $tags->size());
$this->assertTrue($docblock->hasTag('see'));
$this->assertTrue($docblock->hasTag('author'));
$this->assertTrue($docblock->hasTag('since'));
$docblock->removeTags('author');
$tags = $docblock->getTags();
$this->assertEquals(2, $tags->size());
$this->assertTrue($docblock->hasTag('see'));
$this->assertTrue($docblock->hasTag('since'));
$this->assertFalse($docblock->hasTag('author'));
$docblock->removeTags('since');
$tags = $docblock->getTags();
$this->assertEquals(1, $tags->size());
$this->assertTrue($docblock->hasTag('see'));
$this->assertFalse($docblock->hasTag('since'));
}
public function testDocblockWithBlankLines(): void {
$text = '/**
* @param string $foo makes a fow
*
* @return bool true on success and false if it fails
*/';
$docblock = new Docblock($text);
$tags = $docblock->getTags();
$this->assertEquals(2, $tags->size());
$this->assertInstanceOf(ParamTag::class, $tags->get(0));
$this->assertEquals('makes a fow', $tags->get(0)->getDescription());
$this->assertInstanceOf(ReturnTag::class, $tags->get(1));
$this->assertEquals('true on success and false if it fails', $tags->get(1)->getDescription());
}
}

View File

@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* This file is part of the Docblock package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace phpowermove\docblock\tests;
use phootwork\collection\ArrayList;
use phpowermove\docblock\TagNameComparator;
use PHPUnit\Framework\TestCase;
class TagNameComparatorTest extends TestCase {
public function testComparison(): void {
$list = new ArrayList(['author', 'since', 'see', 'param', 'author']);
$list->sort(new TagNameComparator());
$this->assertEquals(['see', 'author', 'author', 'since', 'param'], $list->toArray());
}
public function testComparisonWithInvalidTag(): void {
$list = new ArrayList(['invalid_tag', 'author', 'since', 'see', 'param', 'author']);
$list->sort(new TagNameComparator());
$this->assertEquals(['invalid_tag', 'see', 'author', 'author', 'since', 'param'], $list->toArray());
}
}

View File

@@ -0,0 +1,10 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\fixtures;
use phpowermove\docblock\Docblock;
class MyDocBlock extends Docblock {
protected function splitDocblock($comment): array {
return ['', '', 'Invalid tag block'];
}
}

View File

@@ -0,0 +1,11 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\fixtures;
/**
* Short Description.
*
* @author gossi
*/
class ReflectionTestClass {
}

View File

@@ -0,0 +1,38 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\AuthorTag;
use PHPUnit\Framework\TestCase;
class AuthorTagTest extends TestCase {
public function testReadWrite(): void {
$author = new AuthorTag('gossi <hans@wurst.de>');
$this->assertEquals('gossi', $author->getName());
$this->assertEquals('hans@wurst.de', $author->getEmail());
$this->assertEquals('@author gossi <hans@wurst.de>', $author->toString());
$author = new AuthorTag('lil-g');
$this->assertEquals('lil-g', $author->getName());
$this->assertEmpty($author->getEmail());
$this->assertEquals('@author lil-g', $author->toString());
}
public function testName(): void {
$name = 'gossi';
$author = new AuthorTag();
$this->assertSame($author, $author->setName($name));
$this->assertEquals($name, $author->getName());
}
public function testEmail(): void {
$email = 'hans@wurst.de';
$author = new AuthorTag();
$this->assertSame($author, $author->setEmail($email));
$this->assertEquals($email, $author->getEmail());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\DeprecatedTag;
use PHPUnit\Framework\TestCase;
class DeprecatedTagTest extends TestCase {
public function testReadWrite(): void {
$deprecated = new DeprecatedTag();
$this->assertEquals('@deprecated', $deprecated->toString());
}
}

View File

@@ -0,0 +1,37 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\LicenseTag;
use PHPUnit\Framework\TestCase;
class LicenseTagTest extends TestCase {
public function testReadWrite(): void {
$license = new LicenseTag('MIT');
$this->assertEquals('MIT', $license->getLicense());
$this->assertEquals('@license MIT', $license->toString());
$license = new LicenseTag('http://opensource.org/licenses/MIT MIT');
$this->assertEquals('MIT', $license->getLicense());
$this->assertEquals('http://opensource.org/licenses/MIT', $license->getUrl());
$this->assertEquals('@license http://opensource.org/licenses/MIT MIT', $license->toString());
}
public function testLicense(): void {
$name = 'gossi';
$license = new LicenseTag();
$this->assertSame($license, $license->setLicense($name));
$this->assertEquals($name, $license->getLicense());
}
public function testUrl(): void {
$url = 'http://opensource.org/licenses/MIT';
$license = new LicenseTag();
$this->assertSame($license, $license->setUrl($url));
$this->assertEquals($url, $license->getUrl());
}
}

View File

@@ -0,0 +1,39 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\LinkTag;
use PHPUnit\Framework\TestCase;
class LinkTagTest extends TestCase {
public function testReadWrite(): void {
$link = new LinkTag('http://example.com');
$this->assertEquals('http://example.com', $link->getUrl());
$this->assertEquals('@link http://example.com', $link->toString());
$link = new LinkTag('http://example.com desc');
$this->assertEquals('http://example.com', $link->getUrl());
$this->assertEquals('desc', $link->getDescription());
$this->assertEquals('@link http://example.com desc', $link->toString());
$link = new LinkTag('http://.example.com desc');
$this->assertEmpty($link->getUrl());
$this->assertEquals('http://.example.com desc', $link->getDescription());
}
public function testUrl(): void {
$url = 'http://example.com';
$link = new LinkTag();
$this->assertSame($link, $link->setUrl($url));
$this->assertEquals($url, $link->getUrl());
}
public function testDescription(): void {
$desc = 'desc';
$link = new LinkTag();
$this->assertSame($link, $link->setDescription($desc));
$this->assertEquals($desc, $link->getDescription());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\MethodTag;
use PHPUnit\Framework\TestCase;
class MethodTagTest extends TestCase {
public function testReadWrite(): void {
$method = new MethodTag('string myMethod()');
$this->assertEquals('@method string myMethod()', $method->toString());
}
}

View File

@@ -0,0 +1,62 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\ParamTag;
use PHPUnit\Framework\TestCase;
class ParamTagTest extends TestCase {
public function testReadWrite(): void {
$param = new ParamTag('string $a the string');
$this->assertEquals('string', $param->getType());
$this->assertEquals('a', $param->getVariable());
$this->assertEquals('the string', $param->getDescription());
$this->assertFalse($param->isVariadic());
$this->assertEquals('@param string $a the string', $param->toString());
$param = new ParamTag('string ...$a');
$this->assertEmpty($param->getDescription());
$this->assertTrue($param->isVariadic());
$this->assertEquals('@param string ...$a', $param->toString());
}
public function testType(): void {
$type = 'int';
$param = new ParamTag();
$this->assertSame($param, $param->setType($type));
$this->assertEquals($type, $param->getType());
}
public function testVariable(): void {
$variable = '$v';
$param = new ParamTag();
$this->assertSame($param, $param->setVariable($variable));
$this->assertEquals($variable, $param->getExpression());
}
public function testVariadicVariable(): void {
$variable = '...$v';
$param = new ParamTag();
$this->assertSame($param, $param->setVariable($variable));
$this->assertEquals('$v', $param->getExpression());
$this->assertTrue($param->isVariadic());
}
public function testVariadic(): void {
$param = new ParamTag();
$this->assertSame($param, $param->setVariadic(true));
$this->assertTrue($param->isVariadic());
}
public function testGetVariableNameOnEmptyTag(): void {
$param = new ParamTag();
$this->assertEquals('', $param->getVariable());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\PropertyReadTag;
use PHPUnit\Framework\TestCase;
class PropertyReadTagTest extends TestCase {
public function testReadWrite(): void {
$prop = new PropertyReadTag('string $var');
$this->assertEquals('@property-read string $var', $prop->toString());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\PropertyTag;
use PHPUnit\Framework\TestCase;
class PropertyTagTest extends TestCase {
public function testReadWrite() {
$prop = new PropertyTag('string $var');
$this->assertEquals('@property string $var', $prop->toString());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\PropertyWriteTag;
use PHPUnit\Framework\TestCase;
class PropertyWriteTagTest extends TestCase {
public function testReadWrite() {
$prop = new PropertyWriteTag('string $var');
$this->assertEquals('@property-write string $var', $prop->toString());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\ReturnTag;
use PHPUnit\Framework\TestCase;
class ReturnTagTest extends TestCase {
public function testReadWrite() {
$return = new ReturnTag('Foo bar');
$this->assertEquals('@return Foo bar', $return->toString());
}
}

View File

@@ -0,0 +1,19 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\SeeTag;
use PHPUnit\Framework\TestCase;
class SeeTagTest extends TestCase {
public function testReadWrite(): void {
$see = new SeeTag('Dest::nation() 0815');
$this->assertEquals('@see Dest::nation() 0815', $see->toString());
}
public function testReference(): void {
$see = new SeeTag();
$this->assertSame($see, $see->setReference('hier-lang'));
$this->assertEquals('hier-lang', $see->getReference());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\SinceTag;
use PHPUnit\Framework\TestCase;
class SinceTagTest extends TestCase {
public function testReadWrite(): void {
$since = new SinceTag('1.0 baz');
$this->assertEquals('@since 1.0 baz', $since->toString());
}
}

View File

@@ -0,0 +1,22 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\AuthorTag;
use phpowermove\docblock\tags\TagFactory;
use phpowermove\docblock\tags\UnknownTag;
use PHPUnit\Framework\TestCase;
class TagFactoryTest extends TestCase {
public function testFactory(): void {
$factory = new TagFactory();
$author = $factory->create('author', 'lil-g');
$this->assertTrue($author instanceof AuthorTag);
$this->assertEquals('lil-g', $author->getName());
$unknown = $factory->create('wurst');
$this->assertTrue($unknown instanceof UnknownTag);
$this->assertEquals('wurst', $unknown->getTagName());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\ThrowsTag;
use PHPUnit\Framework\TestCase;
class ThrowsTagTest extends TestCase {
public function testReadWrite() {
$ex = new ThrowsTag('\Exception oups');
$this->assertEquals('@throws \Exception oups', $ex->toString());
}
}

View File

@@ -0,0 +1,13 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\TypeTag;
use PHPUnit\Framework\TestCase;
class TypeTagTest extends TestCase {
public function testReadWrite(): void {
$type = new TypeTag('Foo ...$bar');
$this->assertEquals('@type Foo ...$bar', $type->toString());
}
}

View File

@@ -0,0 +1,20 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\UnknownTag;
use PHPUnit\Framework\TestCase;
class UnknownTagTest extends TestCase {
public function testReadWrite(): void {
$unknown = new UnknownTag('description');
$unknown = $unknown->setTagName('my-tag');
$this->assertEquals('@my-tag description', $unknown->toString());
$this->assertEquals('my-tag', $unknown->getTagName());
$this->assertEquals($unknown->toString(), '' . $unknown);
$this->assertTrue(UnknownTag::create() instanceof UnknownTag);
}
}

View File

@@ -0,0 +1,29 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\Docblock;
use phpowermove\docblock\tags\VarTag;
use PHPUnit\Framework\TestCase;
class VarTagTest extends TestCase {
public function testReadWrite(): void {
$var = new VarTag('Foo ...$bar');
$this->assertEquals('@var Foo ...$bar', $var->toString());
}
public function testDocblock(): void {
$expected = '/**
* @var mixed $foo bar
*/';
$docblock = new Docblock();
$var = VarTag::create()
->setType('mixed')
->setVariable('foo')
->setDescription('bar')
;
$docblock->appendTag($var);
$this->assertEquals($expected, $docblock->toString());
}
}

View File

@@ -0,0 +1,17 @@
<?php declare(strict_types=1);
namespace phpowermove\docblock\tests\tags;
use phpowermove\docblock\tags\VersionTag;
use PHPUnit\Framework\TestCase;
class VersionTagTest extends TestCase {
public function testReadWrite(): void {
$version = new VersionTag('1.3.3.7 jupjup');
$this->assertEquals('@version 1.3.3.7 jupjup', $version->toString());
$this->assertEquals('jupjup', $version->getDescription());
$this->assertEquals('1.3.3.7', $version->getVersion());
$this->assertSame($version, $version->setVersion('3.14'));
$this->assertEquals('3.14', $version->getVersion());
}
}