/** * Checks if the block or any of it's descendants match our grep filter or * do not match our except filter. * * Descendants are checked in order to retain a test even it's parent block * path does not match. */ protected function isFiltered(Block $block) { // Skip filtering on implicit Suite block. if ($block instanceof Suite) { return false; } $options =& $this->options; $isFiltered = function ($block) use(&$options) { $filtered = false; if ($options['grep']) { $filtered = $filtered || preg_match($options['grep'], $block->path(0)) === 0; } if ($options['except']) { $filtered = $filtered || preg_match($options['except'], $block->path(0)) === 1; } return $filtered; }; // Code smell. Consider moving this responsibility to the blocks. if ($block instanceof TestMethod) { return $isFiltered($block); } else { foreach ($block->tests() as $test) { if ($isFiltered($test) === false) { return false; } } foreach ($block->describes() as $describe) { if ($this->isFiltered($describe) === false) { return false; } } return true; } }