How to remove / cache memory for Symfony core after running tests?

When you run the test with Symfony, Kernelit creates the /cacheand directory /logs.

I am currently uploading my own bootstrap.phpfile with phpunit.xml:

<?php

require_once __DIR__.'/../vendor/autoload.php';

// clear cache
register_shutdown_function(function () {
    Nette\Utils\FileSystem::delete(__DIR__.'/cache');
    Nette\Utils\FileSystem::delete(__DIR__.'/logs');
});
  • I wonder if there is a better way to do this?
  • Best without this extra file bootstrap.php?

Note. I do not want to store the catalog /cacheand /logsthere, adding them in .gitignore.


Resources used without help:

+4
source share
1 answer

You can implement a test listener .

tests/ClearLogAndCacheTestListener.php

namespace Symplify\DefaultAutowire\Tests;



class ClearLogAndCacheTestListener extends \PHPUnit_Framework_BaseTestListener
{
    public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
    {
        \Nette\Utils\FileSystem::delete(__DIR__.'/cache');
        \Nette\Utils\FileSystem::delete(__DIR__.'/logs');
    }

}

phpunit.xml autoload.php :

phpunit.xml

<phpunit
    bootstrap="vendor/autoload.php"
    colors="true"
    syntaxCheck="true"
    verbose="true"
>
    <listeners>
        <listener class="Symplify\DefaultAutowire\Tests\ClearLogAndCacheTestListener">
        </listener>
    </listeners>
[...]
</phpunit>

+2

Source: https://habr.com/ru/post/1658324/


All Articles