forked from phpDocumentor/phpDocumentor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request phpDocumentor#3675 from phpDocumentor/fix/test-for…
…-descriptor-repository Add test for DescriptorRepository
- Loading branch information
Showing
1 changed file
with
138 additions
and
0 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
tests/unit/phpDocumentor/Compiler/DescriptorRepositoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?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\Compiler; | ||
|
||
use phpDocumentor\Descriptor\ApiSetDescriptor; | ||
use phpDocumentor\Descriptor\Collection; | ||
use phpDocumentor\Descriptor\VersionDescriptor; | ||
use phpDocumentor\Faker\Faker; | ||
use phpDocumentor\Reflection\Fqsen; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
/** | ||
* @coversDefaultClass \phpDocumentor\Compiler\DescriptorRepository | ||
* @covers ::<private> | ||
*/ | ||
final class DescriptorRepositoryTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
use Faker; | ||
|
||
private Fqsen $fqsen; | ||
private DescriptorRepository $descriptorRepository; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->fqsen = $this->faker()->fqsen(); | ||
$this->descriptorRepository = new DescriptorRepository(); | ||
} | ||
|
||
/** | ||
* @uses VersionDescriptor | ||
* @uses Collection | ||
* | ||
* @covers ::setVersionDescriptor | ||
*/ | ||
public function testSetVersionDescriptorMethod(): void | ||
{ | ||
$versionDescriptor = $this->faker()->versionDescriptor([]); | ||
|
||
$this->descriptorRepository->setVersionDescriptor($versionDescriptor); | ||
|
||
$this->assertSame( | ||
$versionDescriptor, | ||
$this->descriptorRepository->getVersionDescriptor(), | ||
'The set and retrieved version descriptors must be the same.', | ||
); | ||
} | ||
|
||
/** | ||
* @uses VersionDescriptor | ||
* @uses Collection | ||
* | ||
* @covers ::getVersionDescriptor | ||
*/ | ||
public function testGetVersionDescriptorMethod(): void | ||
{ | ||
$versionDescriptor = $this->faker()->versionDescriptor([]); | ||
|
||
$this->descriptorRepository->setVersionDescriptor($versionDescriptor); | ||
|
||
$this->assertSame( | ||
$versionDescriptor, | ||
$this->descriptorRepository->getVersionDescriptor(), | ||
); | ||
} | ||
|
||
/** | ||
* @uses VersionDescriptor | ||
* @uses ApiSetDescriptor | ||
* | ||
* @covers ::findDescriptorByFqsen | ||
*/ | ||
public function testItCanFindDescriptorByFqsen(): void | ||
{ | ||
$classDescriptor = $this->faker()->classDescriptor($this->fqsen); | ||
|
||
$apiSetDescriptor = $this->faker()->apiSetDescriptor(); | ||
$apiSetDescriptor->getIndex('elements')->set((string) $this->fqsen, $classDescriptor); | ||
|
||
$this->descriptorRepository->setVersionDescriptor($this->faker()->versionDescriptor([$apiSetDescriptor])); | ||
|
||
$this->assertSame( | ||
$classDescriptor, | ||
$this->descriptorRepository->findDescriptorByFqsen($this->fqsen), | ||
); | ||
} | ||
|
||
/** | ||
* @uses VersionDescriptor | ||
* @uses ApiSetDescriptor | ||
* | ||
* @covers ::findDescriptorByFqsen | ||
*/ | ||
public function testItReturnsNullWhenNoDescriptorIsFoundByFqsen(): void | ||
{ | ||
$this->descriptorRepository->setVersionDescriptor( | ||
$this->faker()->versionDescriptor([$this->faker()->apiSetDescriptor()]), | ||
); | ||
|
||
$this->assertNull($this->descriptorRepository->findDescriptorByFqsen($this->fqsen)); | ||
} | ||
|
||
/** | ||
* @uses VersionDescriptor | ||
* @uses ApiSetDescriptor | ||
* | ||
* @covers ::findDescriptorByTypeAndFqsen | ||
*/ | ||
public function testItCanFindDescriptorByTypeAndFqsen(): void | ||
{ | ||
$classDescriptor = $this->faker()->classDescriptor($this->fqsen); | ||
|
||
$apiSetDescriptor = $this->faker()->apiSetDescriptor(); | ||
$apiSetDescriptor | ||
->getIndex('classes') | ||
->set((string) $this->fqsen, $classDescriptor); | ||
|
||
$this->descriptorRepository | ||
->setVersionDescriptor($this->faker()->versionDescriptor([$apiSetDescriptor])); | ||
|
||
$this->assertSame( | ||
$classDescriptor, | ||
$this->descriptorRepository->findDescriptorByTypeAndFqsen('class', $this->fqsen), | ||
); | ||
} | ||
} |