Asvae\ApiTester\Collections\RouteCollection::filterMatch PHP Method

filterMatch() public method

Include routes that match patterns.
public filterMatch ( $patterns ) : static
return static
    public function filterMatch($patterns)
    {
        $patterns = is_string($patterns) ? [$patterns] : $patterns;
        // String pattern is assumed to be path.
        foreach ($patterns as $key => $pattern) {
            if (is_string($pattern)) {
                $patterns[$key] = ['path' => $pattern];
            }
        }
        return $this->filter(function ($route) use($patterns) {
            // If any of patterns matches - route passes.
            foreach ($patterns as $pattern) {
                if ($this->isRouteMatchesPattern($route, $pattern)) {
                    return true;
                }
            }
            // If all patterns don't match - route is filtered out.
            return false;
        });
    }

Usage Example

 public function testMatchEmptyPattern()
 {
     $this->assertEquals(6, $this->routes->filterMatch([[]])->count());
 }