Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] Exclude unreadable files when executing About command #40178

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

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 4 src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private static function formatFileSize(string $path): string
} else {
$size = 0;
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)) as $file) {
$size += $file->getSize();
if ($file->isReadable()) {
$size += $file->getSize();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand;

use Symfony\Bundle\FrameworkBundle\Command\AboutCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand\Fixture\TestAppKernel;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;

class AboutCommandTest extends TestCase
{
/** @var Filesystem */
private $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());

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

try {
$this->fs->remove($kernel->getProjectDir());
} catch (IOException $e) {
}
}

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

// skip test on Windows; PHP can't easily set file as unreadable on Windows
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test cannot run on Windows.');
michaljusiega marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

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

$this->fs->chmod($kernel->getCacheDir().'/unreadable_file', 0777);

try {
$this->fs->remove($kernel->getProjectDir());
} catch (IOException $e) {
}
}

private function createCommandTester(TestAppKernel $kernel): CommandTester
{
$application = new Application($kernel);
$application->add(new AboutCommand());

return new CommandTester($application->find('about'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand\Fixture;

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

class TestAppKernel extends Kernel
{
public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
];
}

public function getProjectDir(): string
{
return __DIR__.'/test';
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
}

protected function build(ContainerBuilder $container)
{
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.