Skip to content

Commit f9146c5

Browse files
Merge branch '5.2' into 5.x
* 5.2: [ErrorHandler] Fix error caused by `include` + open_basedir [FrameworkBundle] Make the TestBrowserToken interchangeable with other tokens [Console] ProgressBar clears too many lines on update [FrameworkBundle] Exclude unreadable files when executing About command [Bridge\Twig] Add 'form-control-range' for range input type Be explicit about transparent background color of links in toolbar [Translation] fix test case name [Cache] Fix wrong namespace in test [DependencyInjection] Fix return type
2 parents 3c0d194 + b7b69d5 commit f9146c5

File tree

6 files changed

+145
-4
lines changed

6 files changed

+145
-4
lines changed

Command/AboutCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ private static function formatFileSize(string $path): string
114114
} else {
115115
$size = 0;
116116
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)) as $file) {
117-
$size += $file->getSize();
117+
if ($file->isReadable()) {
118+
$size += $file->getSize();
119+
}
118120
}
119121
}
120122

KernelBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function loginUser($user, string $firewallContext = 'main'): self
120120
throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, \is_object($user) ? \get_class($user) : \gettype($user)));
121121
}
122122

123-
$token = new TestBrowserToken($user->getRoles(), $user);
123+
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
124124
$token->setAuthenticated(true);
125125
$session = $this->getContainer()->get('test.service_container')->get('session.factory')->createSession();
126126
$session->set('_security_'.$firewallContext, serialize($token));

Test/TestBrowserToken.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@
2121
*/
2222
class TestBrowserToken extends AbstractToken
2323
{
24-
public function __construct(array $roles = [], UserInterface $user = null)
24+
private $firewallName;
25+
26+
public function __construct(array $roles = [], UserInterface $user = null, string $firewallName = 'main')
2527
{
2628
parent::__construct($roles);
2729

2830
if (null !== $user) {
2931
$this->setUser($user);
3032
}
33+
34+
$this->firewallName = $firewallName;
35+
}
36+
37+
public function getFirewallName(): string
38+
{
39+
return $this->firewallName;
3140
}
3241

3342
public function getCredentials()
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand;
13+
14+
use Symfony\Bundle\FrameworkBundle\Command\AboutCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
16+
use Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand\Fixture\TestAppKernel;
17+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
18+
use Symfony\Component\Console\Tester\CommandTester;
19+
use Symfony\Component\Filesystem\Exception\IOException;
20+
use Symfony\Component\Filesystem\Filesystem;
21+
22+
class AboutCommandTest extends TestCase
23+
{
24+
/** @var Filesystem */
25+
private $fs;
26+
27+
protected function setUp(): void
28+
{
29+
$this->fs = new Filesystem();
30+
}
31+
32+
public function testAboutWithReadableFiles()
33+
{
34+
$kernel = new TestAppKernel('test', true);
35+
$this->fs->mkdir($kernel->getProjectDir());
36+
37+
$this->fs->dumpFile($kernel->getCacheDir().'/readable_file', 'The file content.');
38+
$this->fs->chmod($kernel->getCacheDir().'/readable_file', 0777);
39+
40+
$tester = $this->createCommandTester($kernel);
41+
$ret = $tester->execute([]);
42+
43+
$this->assertSame(0, $ret);
44+
$this->assertStringContainsString('Cache directory', $tester->getDisplay());
45+
$this->assertStringContainsString('Log directory', $tester->getDisplay());
46+
47+
$this->fs->chmod($kernel->getCacheDir().'/readable_file', 0777);
48+
49+
try {
50+
$this->fs->remove($kernel->getProjectDir());
51+
} catch (IOException $e) {
52+
}
53+
}
54+
55+
public function testAboutWithUnreadableFiles()
56+
{
57+
$kernel = new TestAppKernel('test', true);
58+
$this->fs->mkdir($kernel->getProjectDir());
59+
60+
// skip test on Windows; PHP can't easily set file as unreadable on Windows
61+
if ('\\' === \DIRECTORY_SEPARATOR) {
62+
$this->markTestSkipped('This test cannot run on Windows.');
63+
}
64+
65+
$this->fs->dumpFile($kernel->getCacheDir().'/unreadable_file', 'The file content.');
66+
$this->fs->chmod($kernel->getCacheDir().'/unreadable_file', 0222);
67+
68+
$tester = $this->createCommandTester($kernel);
69+
$ret = $tester->execute([]);
70+
71+
$this->assertSame(0, $ret);
72+
$this->assertStringContainsString('Cache directory', $tester->getDisplay());
73+
$this->assertStringContainsString('Log directory', $tester->getDisplay());
74+
75+
$this->fs->chmod($kernel->getCacheDir().'/unreadable_file', 0777);
76+
77+
try {
78+
$this->fs->remove($kernel->getProjectDir());
79+
} catch (IOException $e) {
80+
}
81+
}
82+
83+
private function createCommandTester(TestAppKernel $kernel): CommandTester
84+
{
85+
$application = new Application($kernel);
86+
$application->add(new AboutCommand());
87+
88+
return new CommandTester($application->find('about'));
89+
}
90+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command\AboutCommand\Fixture;
13+
14+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
15+
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\HttpKernel\Kernel;
18+
19+
class TestAppKernel extends Kernel
20+
{
21+
public function registerBundles(): iterable
22+
{
23+
return [
24+
new FrameworkBundle(),
25+
];
26+
}
27+
28+
public function getProjectDir(): string
29+
{
30+
return __DIR__.'/test';
31+
}
32+
33+
public function registerContainerConfiguration(LoaderInterface $loader)
34+
{
35+
}
36+
37+
protected function build(ContainerBuilder $container)
38+
{
39+
}
40+
}

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ protected function createContainerFromFile($file, $data = [], $resetCompilerPass
17591759
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
17601760
}
17611761
$container->getCompilerPassConfig()->setBeforeOptimizationPasses([new LoggerPass()]);
1762-
$container->getCompilerPassConfig()->setBeforeRemovingPasses([new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')]);
1762+
$container->getCompilerPassConfig()->setBeforeRemovingPasses([new AddConstraintValidatorsPass(), new TranslatorPass()]);
17631763
$container->getCompilerPassConfig()->setAfterRemovingPasses([new AddAnnotationsCachedReaderPass()]);
17641764

17651765
if (!$compile) {

0 commit comments

Comments
 (0)