TestAppKernel example

class AboutCommandTest extends TestCase
{
    private Filesystem $fs;

    protected function setUp(): void
    {
        $this->fs = new Filesystem();
    }

    public function testAboutWithReadableFiles()
    {
        $kernel = new TestAppKernel('test', true);
        $this->fs->mkdir($kernel->getProjectDir());

        $this->fs->dumpFile($kernel->getCacheDir().'/readable_file', 'The file content.');
        $this->fs->chmod($kernel->getCacheDir().'/readable_file', 0777);

        $tester = $this->createCommandTester($kernel);
        $ret = $tester->execute([]);

        $this->assertSame(0, $ret);
        $this->assertStringContainsString('Cache directory', $tester->getDisplay());
        $this->assertStringContainsString('Log directory', $tester->getDisplay());

        
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;

class CacheClearCommandTest extends TestCase
{
    private TestAppKernel $kernel;
    private Filesystem $fs;

    protected function setUp(): void
    {
        $this->fs = new Filesystem();
        $this->kernel = new TestAppKernel('test', true);
        $this->fs->mkdir($this->kernel->getProjectDir());
    }

    protected function tearDown(): void
    {
        try {
            $this->fs->remove($this->kernel->getProjectDir());
        } catch (IOException $e) {
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.