-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start with restructuring integration tests and splitting them up per
element type
- Loading branch information
Showing
15 changed files
with
177 additions
and
23 deletions.
There are no files selected for viewing
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
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
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,152 @@ | ||
<?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 http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection; | ||
|
||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
use phpDocumentor\Reflection\File\LocalFile; | ||
use phpDocumentor\Reflection\Php\Class_; | ||
use phpDocumentor\Reflection\Php\Constant; | ||
use phpDocumentor\Reflection\Php\File as PhpFile; | ||
use phpDocumentor\Reflection\Php\ProjectFactory; | ||
use phpDocumentor\Reflection\Types\Integer; | ||
use phpDocumentor\Reflection\Types\Object_; | ||
|
||
/** | ||
* @coversNothing | ||
*/ | ||
final class ClassesTest extends MockeryTestCase | ||
{ | ||
const FILE_PIZZA = __DIR__ . '/data/Pizza.php'; | ||
const FILE_LUIGI_PIZZA = __DIR__ . '/data/Luigi/Pizza.php'; | ||
/** @var ProjectFactory */ | ||
private $fixture; | ||
|
||
/** @var Project */ | ||
private $project; | ||
|
||
protected function setUp() : void | ||
{ | ||
$this->fixture = ProjectFactory::createInstance(); | ||
$this->project = $this->fixture->create( | ||
'MyProject', | ||
[ | ||
new LocalFile(self::FILE_PIZZA), | ||
new LocalFile(self::FILE_LUIGI_PIZZA), | ||
] | ||
); | ||
} | ||
|
||
public function testItHasAllConstants() : void | ||
{ | ||
$file = $this->project->getFiles()[self::FILE_PIZZA]; | ||
|
||
$className = '\\Pizza'; | ||
$constantName = '\\Pizza::PACKAGING'; | ||
|
||
$class = $this->fetchClassFromFile($className, $file); | ||
|
||
$this->assertArrayHasKey($constantName, $class->getConstants()); | ||
$constant = $class->getConstants()[$constantName]; | ||
|
||
$this->assertInstanceOf(Constant::class, $constant); | ||
} | ||
|
||
public function testTypedPropertiesReturnTheirType() : void | ||
{ | ||
$fileName = self::FILE_LUIGI_PIZZA; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
); | ||
|
||
/** @var Class_ $pizzaClass */ | ||
$pizzaClass = $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']; | ||
$this->assertArrayHasKey('\\Luigi\\Pizza::$size', $pizzaClass->getProperties()); | ||
$this->assertEquals(new Integer(), $pizzaClass->getProperties()['\\Luigi\\Pizza::$size']->getType()); | ||
} | ||
|
||
public function testWithNamespacedClass() : void | ||
{ | ||
$fileName = self::FILE_LUIGI_PIZZA; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
); | ||
|
||
$this->assertArrayHasKey($fileName, $project->getFiles()); | ||
$this->assertArrayHasKey('\\Luigi\\Pizza', $project->getFiles()[$fileName]->getClasses()); | ||
$this->assertEquals('\Pizza', $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getParent()); | ||
$this->assertArrayHasKey( | ||
'\\Luigi\\Pizza::$instance', | ||
$project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getProperties() | ||
); | ||
|
||
$methods = $project->getFiles()[$fileName]->getClasses()['\\Luigi\\Pizza']->getMethods(); | ||
$this->assertArrayHasKey( | ||
'\\Luigi\\Pizza::__construct()', | ||
$methods | ||
); | ||
|
||
$this->assertEquals('style', $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getName()); | ||
$this->assertEquals( | ||
new Object_(new Fqsen('\\Luigi\\Pizza\Style')), | ||
$methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getType() | ||
); | ||
} | ||
|
||
public function testWithUsedParent() : void | ||
{ | ||
$fileName = __DIR__ . '/data/Luigi/StyleFactory.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
); | ||
|
||
$this->assertArrayHasKey($fileName, $project->getFiles()); | ||
$this->assertArrayHasKey('\\Luigi\\StyleFactory', $project->getFiles()[$fileName]->getClasses()); | ||
$this->assertEquals( | ||
'\\Luigi\\Pizza\\PizzaComponentFactory', | ||
$project->getFiles()[$fileName]->getClasses()['\\Luigi\\StyleFactory']->getParent() | ||
); | ||
} | ||
|
||
public function testWithInterface() : void | ||
{ | ||
$fileName = __DIR__ . '/data/Luigi/Valued.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
); | ||
|
||
$this->assertArrayHasKey('\\Luigi\\Valued', $project->getFiles()[$fileName]->getInterfaces()); | ||
} | ||
|
||
public function testWithTrait() : void | ||
{ | ||
$fileName = __DIR__ . '/data/Luigi/ExampleNestedTrait.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
); | ||
|
||
$this->assertArrayHasKey('\\Luigi\\ExampleNestedTrait', $project->getFiles()[$fileName]->getTraits()); | ||
} | ||
|
||
private function fetchClassFromFile(string $className, PhpFile $file) | ||
{ | ||
$this->assertArrayHasKey($className, $file->getClasses()); | ||
|
||
return $file->getClasses()[$className]; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<?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. | ||
* | ||
* @copyright 2010-2018 Mike van Riel<[email protected]> | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link http://phpdoc.org | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection; | ||
|
@@ -39,7 +40,7 @@ protected function setUp() : void | |
|
||
public function testCreateProjectWithFunctions() : void | ||
{ | ||
$fileName = __DIR__ . '/project/simpleFunction.php'; | ||
$fileName = __DIR__ . '/data/simpleFunction.php'; | ||
|
||
$project = $this->fixture->create( | ||
'MyProject', | ||
|
@@ -58,7 +59,7 @@ public function testCreateProjectWithFunctions() : void | |
|
||
public function testCreateProjectWithClass() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Pizza.php'; | ||
$fileName = __DIR__ . '/data/Pizza.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -77,7 +78,7 @@ public function testCreateProjectWithClass() : void | |
|
||
public function testTypedPropertiesReturnTheirType() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/Pizza.php'; | ||
$fileName = __DIR__ . '/data/Luigi/Pizza.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -91,7 +92,7 @@ public function testTypedPropertiesReturnTheirType() : void | |
|
||
public function testFileWithDocBlock() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Pizza.php'; | ||
$fileName = __DIR__ . '/data/Pizza.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -103,7 +104,7 @@ public function testFileWithDocBlock() : void | |
|
||
public function testWithNamespacedClass() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/Pizza.php'; | ||
$fileName = __DIR__ . '/data/Luigi/Pizza.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -132,7 +133,7 @@ public function testWithNamespacedClass() : void | |
|
||
public function testDocblockOfMethodIsProcessed() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/Pizza.php'; | ||
$fileName = __DIR__ . '/data/Luigi/Pizza.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -158,7 +159,7 @@ public function testDocblockOfMethodIsProcessed() : void | |
|
||
public function testWithUsedParent() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/StyleFactory.php'; | ||
$fileName = __DIR__ . '/data/Luigi/StyleFactory.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -174,7 +175,7 @@ public function testWithUsedParent() : void | |
|
||
public function testWithInterface() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/Valued.php'; | ||
$fileName = __DIR__ . '/data/Luigi/Valued.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -185,7 +186,7 @@ public function testWithInterface() : void | |
|
||
public function testWithTrait() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/ExampleNestedTrait.php'; | ||
$fileName = __DIR__ . '/data/Luigi/ExampleNestedTrait.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -196,7 +197,7 @@ public function testWithTrait() : void | |
|
||
public function testWithGlobalConstants() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/constants.php'; | ||
$fileName = __DIR__ . '/data/Luigi/constants.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -208,7 +209,7 @@ public function testWithGlobalConstants() : void | |
|
||
public function testInterfaceExtends() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/Packing.php'; | ||
$fileName = __DIR__ . '/data/Luigi/Packing.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -222,7 +223,7 @@ public function testInterfaceExtends() : void | |
|
||
public function testMethodReturnType() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Packing.php'; | ||
$fileName = __DIR__ . '/data/Packing.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
@@ -236,7 +237,7 @@ public function testMethodReturnType() : void | |
|
||
public function testFileDocblock() : void | ||
{ | ||
$fileName = __DIR__ . '/project/empty.php'; | ||
$fileName = __DIR__ . '/data/empty.php'; | ||
$project = $this->fixture->create( | ||
'MyProject', | ||
[new LocalFile($fileName)] | ||
|
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<?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. | ||
* | ||
* @copyright 2010-2018 Mike van Riel<[email protected]> | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link http://phpdoc.org | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection; | ||
|
@@ -35,7 +36,7 @@ protected function setUp() : void | |
|
||
public function testWithNamespacedClass() : void | ||
{ | ||
$fileName = __DIR__ . '/project/Luigi/Pizza.php'; | ||
$fileName = __DIR__ . '/data/Luigi/Pizza.php'; | ||
$project = $this->fixture->create( | ||
'My Project', | ||
[ new LocalFile($fileName) ] | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.