Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support null versions in Since reflection #3286

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SinceAssembler extends BaseTagAssembler
public function buildDescriptor(object $data): SinceDescriptor
{
$descriptor = new SinceDescriptor($data->getName());
$descriptor->setVersion($data->getVersion());
$descriptor->setVersion($data->getVersion() ?? '');

return $descriptor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/

namespace phpDocumentor\Descriptor\Builder\Reflector\Tags;

use phpDocumentor\Descriptor\ProjectDescriptorBuilder;
use phpDocumentor\Descriptor\Tag\SinceDescriptor;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Tags\Since;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;

/**
* Test class for phpDocumentor\Descriptor\Builder\Reflector\Tags\SinceAssembler
*
* @coversDefaultClass \phpDocumentor\Descriptor\Builder\Reflector\Tags\SinceAssembler
* @covers ::<private>
*/
final class SinceAssemblerTest extends TestCase
{
use ProphecyTrait;

private SinceAssembler $fixture;

/** @var ProjectDescriptorBuilder|ObjectProphecy */
private ObjectProphecy $builderMock;

protected function setUp(): void
{
$this->builderMock = $this->prophesize(ProjectDescriptorBuilder::class);
$this->fixture = new SinceAssembler();
$this->fixture->setBuilder($this->builderMock->reveal());
}

/**
* @covers ::create
* @covers ::buildDescriptor
*/
public function testCreateSinceDescriptorFromSinceTag(): void
{
$name = 'since';
$description = 'a since tag';
$version = '1.0.0';

$sinceTagMock = $this->givenASinceTag($version, $description);

/** @var SinceDescriptor $descriptor */
$descriptor = $this->fixture->create($sinceTagMock);

self::assertSame($name, $descriptor->getName());
self::assertSame($description, (string) $descriptor->getDescription());
self::assertSame($version, $descriptor->getVersion());
self::assertSame([], $descriptor->getErrors()->getAll());
}

/**
* @covers ::create
* @covers ::buildDescriptor
*/
public function testCreateSinceDescriptorFromSinceTagWithEmptyVersion(): void
{
$name = 'since';
$description = 'a since tag';

$tag = $this->givenASinceTag(null, $description);

/** @var SinceDescriptor $descriptor */
$descriptor = $this->fixture->create($tag);

self::assertSame($name, $descriptor->getName());
self::assertSame($description, (string) $descriptor->getDescription());
self::assertSame('', $descriptor->getVersion());
self::assertSame([], $descriptor->getErrors()->getAll());
}

private function givenASinceTag(?string $version, string $description): Since
{
return new DocBlock\Tags\Since(
$version,
new DocBlock\Description($description)
);
}
}