Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove debug for default PHPUnit config #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Nov 8, 2017

Q A
License MIT

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

@stof
Copy link
Member

stof commented Nov 9, 2017

Running tests in no-debug mode has the benefit of running tests much faster (as you don't need to check the cache freshness in each test, while the code would not have changed).
But this has one drawback: it requires you to have either a fresh cache for the test env or no cache. If you have an stale cache, tests will run using it (and will likely fail).

Here is how I solved it at Incenteev:

namespace Incenteev\Tests\Util;

use Symfony\Component\Filesystem\Filesystem;

class CacheClearer
{
    public function clearCache()
    {
        if (getenv('INCENTEEV_KEEP_CACHE')) {
            return;
        }

        $filesystem = new Filesystem();

        $filesystem->remove($this->getCacheFolders());
    }

    private function getCacheFolders()
    {
        return array(
            __DIR__.'/../../../var/api-cache/test',
            __DIR__.'/../../../var/api-cache/behat',
            __DIR__.'/../../../var/cache/test',
            __DIR__.'/../../../var/cache/behat',
        );
    }
}

And then, my PHPUnit bootstrap script is this:

require __DIR__.'/../app/autoload.php';

(new \Incenteev\Tests\Util\CacheClearer())->clearCache();

This ensures that a developer running tests locally does not have a stale cache (the env variable INCENTEEV_KEEP_CACHE allows to avoid clearing the cache on CI, where I know that the cache created by the previous CI command is not stale).

@fabpot
Copy link
Member Author

fabpot commented Nov 9, 2017

There is another issue with enabling debug, and that's a bunch of logs on the console. Maybe that should be fixed as well. /cc @dunglas

@dunglas
Copy link
Member

dunglas commented Nov 9, 2017

@fabpot maybe can we just remove the logger service in the test environment?

@fabpot
Copy link
Member Author

fabpot commented Nov 9, 2017

@dunglas Makes sense. How is it configured for the console (do we have the same issue)?

@javiereguiluz javiereguiluz changed the title Remov debug for default PHPUnit config Remove debug for default PHPUnit config Nov 9, 2017
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

@Pierstoval
Copy link
Contributor

Just by using this and enabling debug mode manually in certain tests (that need profiler or that test debug-related services) I made my tests run 3 times faster 👍

@dunglas
Copy link
Member

dunglas commented Nov 10, 2017

@fabpot see #248.

For the console, it's ok to write logs on stderr isn't it?

@fabpot
Copy link
Member Author

fabpot commented Nov 10, 2017

@dunglas Having logs entangled with some "real" output always looks like a bug to me.

@nicolas-grekas
Copy link
Member

What about setting the SHELL_VERBOSITY env var instead?

@fabpot
Copy link
Member Author

fabpot commented Nov 26, 2017

closing in favor of #281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants