1<?php
2/*
3 * This file is part of PHPUnit.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11abstract class PHPUnit_Runner_Filter_GroupFilterIterator extends RecursiveFilterIterator
12{
13    /**
14     * @var array
15     */
16    protected $groupTests = [];
17
18    /**
19     * @param RecursiveIterator           $iterator
20     * @param array                       $groups
21     * @param PHPUnit_Framework_TestSuite $suite
22     */
23    public function __construct(RecursiveIterator $iterator, array $groups, PHPUnit_Framework_TestSuite $suite)
24    {
25        parent::__construct($iterator);
26
27        foreach ($suite->getGroupDetails() as $group => $tests) {
28            if (in_array($group, $groups)) {
29                $testHashes = array_map(
30                    function ($test) {
31                        return spl_object_hash($test);
32                    },
33                    $tests
34                );
35
36                $this->groupTests = array_merge($this->groupTests, $testHashes);
37            }
38        }
39    }
40
41    /**
42     * @return bool
43     */
44    public function accept()
45    {
46        $test = $this->getInnerIterator()->current();
47
48        if ($test instanceof PHPUnit_Framework_TestSuite) {
49            return true;
50        }
51
52        return $this->doAccept(spl_object_hash($test));
53    }
54
55    abstract protected function doAccept($hash);
56}
57