lib-web icon indicating copy to clipboard operation
lib-web copied to clipboard

Remove Guzzle as dependency

Open Kekos opened this issue 7 months ago • 7 comments

The usage of the Guzzle lib inside this library was minimal, only used for URI parsing. Since I don't use Guzzle in my own projects, I thought it could be replaced in this package.

Kekos avatar May 25 '25 14:05 Kekos

Parse_url does not support relative urls.

Caution This function may not give correct results for relative or invalid URLs, and the results may not even match common behavior of HTTP clients. If URLs from untrusted input need to be parsed, extra validation is required, e.g. by using filter_var() with the FILTER_VALIDATE_URL filter.

SamMousa avatar May 25 '25 19:05 SamMousa

Yes, I can see that being a problem. I'll check on it some time.

Can I run the static analysis locally? Could only find PHPUnit as a dependency.

Kekos avatar May 25 '25 20:05 Kekos

Yes, just get phpstan. For example using phive.

SamMousa avatar May 25 '25 21:05 SamMousa

I'm not quite sure how a relative URL would apply to the use cases of the \Codeception\Util\Uri metods?

Kekos avatar May 26 '25 20:05 Kekos

Don't force push please. It makes reviewing harder!

SamMousa avatar May 27 '25 05:05 SamMousa

I'm not quite sure how a relative URL would apply to the use cases of the \Codeception\Util\Uri metods?

From the webdriver module:

private function filterNodesByHref(string $url, array $nodes): array
    {
        //current uri can be relative, merging it with configured base url gives absolute url
        $absoluteCurrentUrl = Uri::mergeUrls($this->_getUrl(), $this->_getCurrentUri());
        $expectedUrl = Uri::mergeUrls($absoluteCurrentUrl, $url);
        return array_filter(
            $nodes,
            function (WebDriverElement $e) use ($expectedUrl, $absoluteCurrentUrl): bool {
                $elementHref = Uri::mergeUrls($absoluteCurrentUrl, $e->getAttribute('href') ?? '');
                return $elementHref === $expectedUrl;
            }
        );
    }

SamMousa avatar May 27 '25 07:05 SamMousa

Thank you! I've checked the use-cases from the webdriver snippet and those seem to be covered by the unit tests.

The comment for $absoluteCurrentUrl tells that the "current uri" might be relative, it goes in the 2nd argument to mergeUrls(), which was never parsed by Guzzle code anyway.

But I must say, I'm very new to Codeception and it's highly possible I'm missing some very important context. Either way, I'm leaning towards using the PHAR version of Codeception instead.

Kekos avatar Jun 01 '25 14:06 Kekos