isRegex example

return $this->isAccepted($content);
    }

    /** * Converts string to regexp if necessary. * * @param string $str Pattern: string or regexp */
    protected function toRegex(string $str): string
    {
        return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
    }
}

    protected function toRegex(string $str): string
    {
        return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
    }
}
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Iterator\MultiplePcreFilterIterator;

class MultiplePcreFilterIteratorTest extends TestCase
{
    /** * @dataProvider getIsRegexFixtures */
    public function testIsRegex($string$isRegex$message)
    {
        $testIterator = new TestMultiplePcreFilterIterator();
        $this->assertEquals($isRegex$testIterator->isRegex($string)$message);
    }

    public static function getIsRegexFixtures()
    {
        yield ['foo', false, 'string'];
        yield [' foo ', false, '" " is not a valid delimiter'];
        yield ['\\foo\\', false, '"\\" is not a valid delimiter'];
        yield ['afooa', false, '"a" is not a valid delimiter'];
        yield ['//', false, 'the pattern should contain at least 1 character'];
        yield ['/a/', true, 'valid regex'];
        yield ['/foo/', true, 'valid regex'];
        
/** * Converts glob to regexp. * * PCRE patterns are left unchanged. * Glob strings are transformed with Glob::toRegex(). * * @param string $str Pattern: glob or regexp */
    protected function toRegex(string $str): string
    {
        return $this->isRegex($str) ? $str : Glob::toRegex($str);
    }
}
Home | Imprint | This part of the site doesn't use cookies.