Skip to content

Commit 5049d75

Browse files
committed
MQE-2677: Add filter for groups
1 parent c9511f5 commit 5049d75

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\FunctionalTestingFramework\Filter\Test;
10+
11+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
12+
use Magento\FunctionalTestingFramework\Filter\FilterInterface;
13+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
14+
15+
/**
16+
* Class ExcludeGroup
17+
*/
18+
class ExcludeGroup implements FilterInterface
19+
{
20+
const ANNOTATION_TAG = 'group';
21+
22+
/**
23+
* @var array
24+
*/
25+
private $filterValues = [];
26+
27+
/**
28+
* Group constructor.
29+
*
30+
* @param array $filterValues
31+
* @throws TestFrameworkException
32+
*/
33+
public function __construct(array $filterValues = [])
34+
{
35+
$this->filterValues = $filterValues;
36+
}
37+
38+
/**
39+
* Filter tests by group.
40+
*
41+
* @param TestObject[] $tests
42+
* @return void
43+
*/
44+
public function filter(array &$tests)
45+
{
46+
if ($this->filterValues === []) {
47+
return;
48+
}
49+
/** @var TestObject $test */
50+
foreach ($tests as $testName => $test) {
51+
$groups = $test->getAnnotationByName(self::ANNOTATION_TAG);
52+
$testExcludeGroup = !empty(array_intersect($groups, $this->filterValues));
53+
if ($testExcludeGroup) {
54+
unset($tests[$testName]);
55+
}
56+
}
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\FunctionalTestingFramework\Filter\Test;
10+
11+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
12+
use Magento\FunctionalTestingFramework\Filter\FilterInterface;
13+
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
14+
15+
/**
16+
* Class IncludeGroup
17+
*/
18+
class IncludeGroup implements FilterInterface
19+
{
20+
const ANNOTATION_TAG = 'group';
21+
22+
/**
23+
* @var array
24+
*/
25+
private $filterValues = [];
26+
27+
/**
28+
* Group constructor.
29+
*
30+
* @param array $filterValues
31+
* @throws TestFrameworkException
32+
*/
33+
public function __construct(array $filterValues = [])
34+
{
35+
$this->filterValues = $filterValues;
36+
}
37+
38+
/**
39+
* Filter tests by group.
40+
*
41+
* @param TestObject[] $tests
42+
* @return void
43+
*/
44+
public function filter(array &$tests)
45+
{
46+
if ($this->filterValues === []) {
47+
return;
48+
}
49+
/** @var TestObject $test */
50+
foreach ($tests as $testName => $test) {
51+
$groups = $test->getAnnotationByName(self::ANNOTATION_TAG);
52+
$testIncludeGroup = empty(array_intersect($groups, $this->filterValues));
53+
if ($testIncludeGroup) {
54+
unset($tests[$testName]);
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)