Codeception\Module\WPBrowser::grabCookiesWithPattern PHP Method

grabCookiesWithPattern() public method

Returns all the cookies whose name matches a regex pattern.
public grabCookiesWithPattern ( string $cookiePattern ) : Cookie | null
$cookiePattern string
return Symfony\Component\BrowserKit\Cookie | null
    public function grabCookiesWithPattern($cookiePattern)
    {
        /**
         * @var Cookie[]
         */
        $cookies = $this->client->getCookieJar()->all();
        if (!$cookies) {
            return null;
        }
        $matchingCookies = array_filter($cookies, function (Cookie $cookie) use($cookiePattern) {
            return preg_match($cookiePattern, $cookie->getName());
        });
        $cookieList = array_map(function (Cookie $cookie) {
            return sprintf('{"%s": "%s"}', $cookie->getName(), $cookie->getValue());
        }, $matchingCookies);
        $this->debug('Cookies matching pattern ' . $cookiePattern . ' : ' . implode(', ', $cookieList));
        return is_array($matchingCookies) ? $matchingCookies : null;
    }