Skip to content

Commit

Permalink
reflection: add test for class that inherits from class 'object'
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastavesely committed Oct 1, 2017
1 parent 4a77729 commit 8fbaaa6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
36 changes: 28 additions & 8 deletions packages/Reflection/tests/Parser/ObjectClassTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,24 +4,44 @@


use ApiGen\Reflection\Parser\Parser; use ApiGen\Reflection\Parser\Parser;
use ApiGen\Reflection\ReflectionStorage; use ApiGen\Reflection\ReflectionStorage;
use ApiGen\Reflection\Tests\Parser\Source\ChildOfObject;
use ApiGen\Reflection\Tests\Parser\Source\Object; use ApiGen\Reflection\Tests\Parser\Source\Object;
use ApiGen\Tests\AbstractContainerAwareTestCase; use ApiGen\Tests\AbstractContainerAwareTestCase;


final class ObjectClassTest extends AbstractContainerAwareTestCase final class ObjectClassTest extends AbstractContainerAwareTestCase
{ {
public function test(): void /**
* @var Parser
*/
private $parser;

/**
* @var ReflectionStorage
*/
private $reflectionStorage;

public function setUp(): void
{ {
/** @var Parser $parser */ $this->parser = $this->container->get(Parser::class);
$parser = $this->container->get(Parser::class); $this->parser->parseFilesAndDirectories([__DIR__ . '/Source']);
$parser->parseFilesAndDirectories([__DIR__ . '/Source']);


/** @var ReflectionStorage */ $this->reflectionStorage = $this->container->get(ReflectionStorage::class);
$reflectionStorage = $this->container->get(ReflectionStorage::class); }


$classReflections = $reflectionStorage->getClassReflections(); public function testDirect(): void
$this->assertCount(3, $classReflections); {
$classReflections = $this->reflectionStorage->getClassReflections();
$this->assertCount(4, $classReflections);


$this->assertArrayHasKey(Object::class, $classReflections); $this->assertArrayHasKey(Object::class, $classReflections);
$this->assertSame(Object::class, $classReflections[Object::class]->getName()); $this->assertSame(Object::class, $classReflections[Object::class]->getName());
} }

public function testGetParent(): void
{
$classReflections = $this->reflectionStorage->getClassReflections();

$classReflection = $classReflections[ChildOfObject::class]->getParentClass();
$this->assertSame(Object::class, $classReflection->getName());
}
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function test(): void
$this->parser->parseFilesAndDirectories([__DIR__ . '/Source']); $this->parser->parseFilesAndDirectories([__DIR__ . '/Source']);


$classReflections = $this->reflectionStorage->getClassReflections(); $classReflections = $this->reflectionStorage->getClassReflections();
$this->assertCount(3, $classReflections); $this->assertCount(4, $classReflections);


$classReflection = $classReflections[ClassWithParentFromAnotherSource::class]; $classReflection = $classReflections[ClassWithParentFromAnotherSource::class];


Expand Down
7 changes: 7 additions & 0 deletions packages/Reflection/tests/Parser/Source/ChildOfObject.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types=1);

namespace ApiGen\Reflection\Tests\Parser\Source;

final class ChildOfObject extends Object
{
}
2 changes: 1 addition & 1 deletion packages/Reflection/tests/Parser/Source/Object.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


namespace ApiGen\Reflection\Tests\Parser\Source; namespace ApiGen\Reflection\Tests\Parser\Source;


final class Object class Object
{ {
} }

0 comments on commit 8fbaaa6

Please sign in to comment.