Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for the @group annotation at the class level #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
<directory>tests/Queue/</directory>
<directory>tests/Process/</directory>
<directory>tests/Environment/</directory>
<exclude>tests/Queue/Fixture/</exclude>
</testsuite>
</testsuites>

52 changes: 50 additions & 2 deletions src/Queue/CreateTestsQueueFromPhpUnitXML.php
Original file line number Diff line number Diff line change
@@ -19,6 +19,18 @@ class_alias('\PHPUnit_Util_TestSuiteIterator', '\PHPUnit\Framework\TestSuiteIter
class_alias('\PHPUnit_Util_Fileloader', '\PHPUnit\Util\Fileloader');
}

if (class_exists('\PHPUnit_Runner_Filter_Factory')) {
class_alias('\PHPUnit_Runner_Filter_Factory', '\PHPUnit\Runner\Filter\Factory');
}

if (class_exists('\PHPUnit_Runner_Filter_ExcludeGroupFilterIterator')) {
class_alias('\PHPUnit_Runner_Filter_ExcludeGroupFilterIterator', '\PHPUnit\Runner\Filter\ExcludeGroupFilterIterator');
}

if (class_exists('\PHPUnit_Runner_Filter_IncludeGroupFilterIterator')) {
class_alias('\PHPUnit_Runner_Filter_IncludeGroupFilterIterator', '\PHPUnit\Runner\Filter\IncludeGroupFilterIterator');
}

/*
* Trigger autoload for possible file loader versions.
* This fixes the problem with PHP classes being case insensitive versus composer case sensitive autoloader.
@@ -34,16 +46,52 @@ public static function execute($xmlFile)
$testSuites = new TestsQueue();

self::handleBootstrap($configuration->getPHPUnitConfiguration());
self::processTestSuite($testSuites, $configuration->getTestSuiteConfiguration()->getIterator());
$testSuite = static::filterTestSuite($configuration);
self::processTestSuite($testSuites, $testSuite->getIterator());

return $testSuites;
}

private static function filterTestSuite(
\PHPUnit\Util\Configuration $configuration
) {
$testSuite = $configuration->getTestSuiteConfiguration();
$groupConfiguration = $configuration->getGroupConfiguration();

if (empty($groupConfiguration['exclude']) && empty($groupConfiguration['include'])) {
return $testSuite;
}

$filterFactory = new \PHPUnit\Runner\Filter\Factory();

if (!empty($groupConfiguration['exclude'])) {
$filterFactory->addFilter(
new \ReflectionClass(\PHPUnit\Runner\Filter\ExcludeGroupFilterIterator::class),
$groupConfiguration['exclude']
);
}

if (!empty($groupConfiguration['include'])) {
$filterFactory->addFilter(
new \ReflectionClass(\PHPUnit\Runner\Filter\IncludeGroupFilterIterator::class),
$groupConfiguration['include']
);
}

$testSuite->injectFilter($filterFactory);

return $testSuite;
}

private static function processTestSuite(
TestsQueue $testSuites,
\PHPUnit\Framework\TestSuiteIterator $testSuiteIterator
\RecursiveIterator $testSuiteIterator
) {
foreach ($testSuiteIterator as $testSuite) {
if (0 === $testSuite->count()) {
continue;
}

self::addTestFile($testSuites, $testSuite);

if ($testSuite instanceof \PHPUnit\Framework\TestSuite) {
9 changes: 9 additions & 0 deletions tests/Queue/CreateTestsQueueFromPhpUnitXMLTest.php
Original file line number Diff line number Diff line change
@@ -25,6 +25,11 @@ public function shouldCreateAnArrayOfTestSuitesFromXML()
'ProcessorCounterTest.php',
];

$dummyDir = __DIR__.'/Fixture/tests/';
$dummyFiles = [
'DummyIncludedTest.php',
];

$queue = new TestsQueue();

foreach ($infrastructureFiles as $file) {
@@ -35,6 +40,10 @@ public function shouldCreateAnArrayOfTestSuitesFromXML()
$queue->add($processesDir.$file);
}

foreach ($dummyFiles as $file) {
$queue->add($dummyDir.$file);
}

$this->assertEquals($queue, $output);
}
}
13 changes: 13 additions & 0 deletions tests/Queue/Fixture/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -8,5 +8,18 @@
<testsuite name="Processes Test Suite">
<directory>../../Process/</directory>
</testsuite>
<testsuite name="Dummy Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<groups>
<include>
<group>default</group>
<group>dummy-included</group>
</include>
<exclude>
<group>dummy-excluded</group>
</exclude>
</groups>
</phpunit>
14 changes: 14 additions & 0 deletions tests/Queue/Fixture/tests/DummyExcludedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Liuggio\Fastest\Queue\Fixture\tests;

/**
* @group dummy-excluded
*/
class DummyExcludedTest extends \PHPUnit\Framework\TestCase
{
public function testDummyAssert()
{
$this->assertTrue(true);
}
}
14 changes: 14 additions & 0 deletions tests/Queue/Fixture/tests/DummyIncludedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Liuggio\Fastest\Queue\Fixture\tests;

/**
* @group dummy-included
*/
class DummyIncludedTest extends \PHPUnit\Framework\TestCase
{
public function testDummyAssert()
{
$this->assertTrue(true);
}
}
9 changes: 9 additions & 0 deletions tests/Queue/ReadFromInputAndPushIntoTheQueueTest.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,11 @@ public function shouldPushIntoTheQueueTheXMLFile()
'ProcessorCounterTest.php',
];

$dummyDir = __DIR__.'/Fixture/tests/';
$dummyFiles = [
'DummyIncludedTest.php',
];

$assertion = new TestsQueue();

foreach ($files as $file) {
@@ -30,6 +35,10 @@ public function shouldPushIntoTheQueueTheXMLFile()
$assertion->add($processesDir.$file);
}

foreach ($dummyFiles as $file) {
$assertion->add($dummyDir.$file);
}

$queue = $this->createMock('\Liuggio\Fastest\Queue\QueueInterface');
$queue->expects($this->once())
->method('push')