jeremykendall / php-domain-parser

Public Suffix List based domain parsing implemented in PHP
MIT License
1.16k stars 128 forks source link

Allowed memory issue with PHPUnit and Pdp library #318

Closed Man7asP closed 3 years ago

Man7asP commented 3 years ago

Issue summary

PHPUnit tests start failing after I install this dependency. In two projects where I decided to use this dependency, I'm getting "Fatal: Allowed memory size of * bytes exhausted." Test only failing with PHPUnit coverage. Any ideas what's wrong?

PHPUnit CLI command:

phpdbg -qrr ./vendor/bin/phpunit tests

System informations

Information Description
Pdp version 6.1.0
PHPUnit version 9.5.9
PHP version 7.4.23
OS Platform

Standalone code, or other way to reproduce the problem

I'm using this library to validate if the domain is valid

class DomainResolver
{
    private Rules $suffixList;

    public function __construct($config)
    {
        $this->suffixList = Rules::fromString((new TldSuffixList($config))->get());
    }

    public function resolve(string $domain): ResolvedDomainName
    {
        return $this->suffixList->resolve(Domain::fromIDNA2008($domain));
    }
}

PHPUnit xml

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         cacheResult="false"
         colors="true"
         convertErrorsToExceptions="false"
         convertNoticesToExceptions="false"
         convertWarningsToExceptions="false"
         verbose="true"
         processIsolation="false"
         stopOnFailure="false"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./src</directory>
        </include>
        <report>
            <clover outputFile="reports/clover.xml"/>
        </report>
    </coverage>
    <testsuites>
        <testsuite name="Integration">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>
    <logging>
        <junit outputFile="reports/junit.xml"/>
    </logging>
</phpunit>

Expected result

PHPUnit tests should pass without memory limit issues.

Actual result

image

nyamsprod commented 3 years ago

@mn7zDev thanks for using this library but I fail to understand why this error is related to the library. If you have issue with memory usage and PHPUnit maybe you need to look into your codebase to see if you can fix it ?

Man7asP commented 3 years ago

Well, I'm not sure if it code problem, everything was alright before I installed this library. It's a simple Laravel router without any big logic. The project has only 300tests and this library is used only for Laravel Rule validator. TldSuffix list is cached for 7days. And this problem appears not only in one project. And as I mentioned this happens only when PHPUnit clover.xml is generating.

nyamsprod commented 3 years ago

@mn7zDev again I understand your questionning but I fail to see the correlation with this library. Maybe something is wrong with your TlsSuffix list implementation that I am not aware of. If you are using Laravel I know there's a laravel package for this library https://github.com/kevindierkx/laravel-domain-parser. it might resolve your issue

nyamsprod commented 3 years ago

@mn7zDev I will close this issue and will open it again if more information are brought to my attention to further investigate the matter.