Skip to content

Commit

Permalink
Merge pull request #10 from jakzal/phpunit-8.2
Browse files Browse the repository at this point in the history
Ignore base test case properties
  • Loading branch information
jakzal committed Jun 8, 2019
2 parents 71f6f99 + 5933cc8 commit 733da28
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/composer.lock
/vendor/
/.php_cs.cache
/.phpunit.result.cache
.phpunit.result.cache
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ tools/box:
curl -Ls https://github.com/humbug/box/releases/download/3.4.0/box.phar -o tools/box && chmod +x tools/box

tests/phar/tools/phpunit:
curl -Ls https://phar.phpunit.de/phpunit-8.1.phar -o tests/phar/tools/phpunit && chmod +x tests/phar/tools/phpunit
curl -Ls https://phar.phpunit.de/phpunit-8.phar -o tests/phar/tools/phpunit && chmod +x tests/phar/tools/phpunit

tests/phar/tools/phpunit.d/zalas-phpunit-doubles-extension.phar: build/zalas-phpunit-doubles-extension.phar
cp build/zalas-phpunit-doubles-extension.phar tests/phar/tools/phpunit.d/zalas-phpunit-doubles-extension.phar
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"require": {
"php": "^7.2",
"phpunit/phpunit": "^8.0,<8.2",
"phpunit/phpunit": "^8.0",
"phpdocumentor/reflection-docblock": "^4.0.1"
},
"require-dev": {
Expand Down
17 changes: 17 additions & 0 deletions src/PhpDocumentor/ReflectionExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@

final class ReflectionExtractor implements Extractor
{
/**
* @var string[]
*/
private $ignoredClasses;

/**
* @param string[] $ignoredClasses
*/
public function __construct(array $ignoredClasses)
{
$this->ignoredClasses = $ignoredClasses;
}

/**
* @param object $object
* @param callable $filter
Expand Down Expand Up @@ -41,6 +54,10 @@ private function extractFromReflection(\ReflectionClass $class, callable $filter
*/
private function mapClassToProperties(\ReflectionClass $class, callable $filter): array
{
if (\in_array($class->getName(), $this->ignoredClasses)) {
return [];
}

$docBlockFactory = DocBlockFactory::createInstance();
$classContext = (new ContextFactory())->createFromReflector($class);

Expand Down
4 changes: 3 additions & 1 deletion src/TestCase/TestDoubles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace Zalas\PHPUnit\Doubles\TestCase;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockBuilder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Zalas\PHPUnit\Doubles\Injector\PropertyAccessInjector;
use Zalas\PHPUnit\Doubles\PhpDocumentor\ReflectionExtractor;
Expand All @@ -21,7 +23,7 @@ abstract protected function prophesize($classOrInterface = null): ObjectProphecy
protected function initialiseTestDoubles(): void
{
$doubler = new Doubler(
new ReflectionExtractor(),
new ReflectionExtractor([TestCase::class, Assert::class]),
new PropertyAccessInjector(),
[
ObjectProphecy::class => function (array $types) {
Expand Down
21 changes: 14 additions & 7 deletions tests/PhpDocumentor/ReflectionExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Zalas\PHPUnit\Doubles\Tests\PhpDocumentor;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Zalas\PHPUnit\Doubles\Extractor\Extractor;
use Zalas\PHPUnit\Doubles\Extractor\Property;
Expand All @@ -15,16 +16,24 @@

class ReflectionExtractorTest extends TestCase
{
/**
* @var ReflectionExtractor
*/
private $extractor;

protected function setUp(): void
{
$this->extractor = new ReflectionExtractor([TestCase::class, Assert::class]);
}

public function test_it_is_an_extractor()
{
$this->assertInstanceOf(Extractor::class, new ReflectionExtractor());
$this->assertInstanceOf(Extractor::class, $this->extractor);
}

public function test_it_extracts_properties_from_the_given_object()
{
$extractor = new ReflectionExtractor();

$properties = $extractor->extract(new Discworld(), function () {
$properties = $this->extractor->extract(new Discworld(), function () {
return true;
});

Expand All @@ -40,9 +49,7 @@ public function test_it_extracts_properties_from_the_given_object()

public function test_it_filters_properties_out()
{
$extractor = new ReflectionExtractor();

$properties = $extractor->extract(new Discworld(), function (Property $property) {
$properties = $this->extractor->extract(new Discworld(), function (Property $property) {
return $property->hasType(Rincewind::class);
});

Expand Down

0 comments on commit 733da28

Please sign in to comment.