Skip to content

Commit

Permalink
Start with restructuring integration tests and splitting them up per
Browse files Browse the repository at this point in the history
element type
  • Loading branch information
mvriel committed Jan 7, 2020
1 parent 93e5914 commit fca9ce5
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"autoload-dev": {
"psr-4": {
"phpDocumentor\\": [
"tests/component/",
"tests/integration/",
"tests/unit/phpDocumentor",
"tests/bench/"
]
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<testsuite name="unit">
<directory>./tests/unit/</directory>
</testsuite>
<testsuite name="component">
<directory>./tests/component/</directory>
<testsuite name="integration">
<directory>./tests/integration/</directory>
</testsuite>
</testsuites>
<filter>
Expand Down
152 changes: 152 additions & 0 deletions tests/integration/ClassesTest.php
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];
}
}
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;
Expand Down Expand Up @@ -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',
Expand All @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand Down Expand Up @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand Down
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;
Expand Down Expand Up @@ -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) ]
Expand Down
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.

0 comments on commit fca9ce5

Please sign in to comment.