Skip to content

Commit 592bbf3

Browse files
committed
Merge branch '2.8' into 3.4
* 2.8: improve docblocks around group sequences [WebProfilerBundle] added a note in the README [Filesystem] Skip tests on readable file when run with root user [FWBundle] Fix an error in WebTestCase::createClient's PHPDoc [HttpFoundation][Security] forward locale and format to subrequests [Console] Send the right exit code to console.terminate listeners Caching missed templates on cache warmup
2 parents 2a605c2 + 3359e62 commit 592bbf3

File tree

19 files changed

+168
-59
lines changed

19 files changed

+168
-59
lines changed

src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class WebTestCase extends KernelTestCase
2323
/**
2424
* Creates a Client.
2525
*
26-
* @param array $options An array of options to pass to the createKernel class
26+
* @param array $options An array of options to pass to the createKernel method
2727
* @param array $server An array of server parameters
2828
*
2929
* @return Client A Client instance

src/Symfony/Bundle/TwigBundle/TemplateIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getIterator()
6363
$this->templates = array_merge(
6464
$this->templates,
6565
$this->findTemplatesInDirectory($bundle->getPath().'/Resources/views', $name),
66-
$this->findTemplatesInDirectory($this->rootDir.'/'.$bundle->getName().'/views', $name),
66+
$this->findTemplatesInDirectory($this->rootDir.'/Resources/'.$bundle->getName().'/views', $name),
6767
$this->findTemplatesInDirectory($this->defaultPath.'/bundles/'.$bundle->getName(), $name)
6868
);
6969
}

src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/BarBundle/views/base.html.twig

Whitespace-only changes.

src/Symfony/Bundle/TwigBundle/Tests/TemplateIteratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testGetIterator()
3131
sort($sorted);
3232
$this->assertEquals(
3333
array(
34+
'@Bar/base.html.twig',
3435
'@Bar/index.html.twig',
3536
'@Bar/layout.html.twig',
3637
'@Foo/index.html.twig',

src/Symfony/Bundle/WebProfilerBundle/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
WebProfilerBundle
22
=================
33

4+
The Web profiler bundle is a **development tool** that gives detailed
5+
information about the execution of any request.
6+
7+
**Never** enable it on production servers as it will lead to major security
8+
vulnerabilities in your project.
9+
410
Resources
511
---------
612

src/Symfony/Component/Console/Application.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
153153

154154
$renderException($e);
155155

156-
$exitCode = $e->getCode();
157-
if (is_numeric($exitCode)) {
158-
$exitCode = (int) $exitCode;
159-
if (0 === $exitCode) {
160-
$exitCode = 1;
161-
}
162-
} else {
163-
$exitCode = 1;
164-
}
156+
$exitCode = $this->getExitCodeForThrowable($e);
165157
} finally {
166158
// if the exception handler changed, keep it
167159
// otherwise, unregister $renderException
@@ -1220,4 +1212,26 @@ private function init()
12201212
$this->add($command);
12211213
}
12221214
}
1215+
1216+
/**
1217+
* Type hint omitted to be PHP5 compatible.
1218+
*
1219+
* @param \Exception|\Throwable $throwable
1220+
*
1221+
* @return int
1222+
*/
1223+
private function getExitCodeForThrowable($throwable)
1224+
{
1225+
$exitCode = $throwable->getCode();
1226+
if (is_numeric($exitCode)) {
1227+
$exitCode = (int) $exitCode;
1228+
if (0 === $exitCode) {
1229+
$exitCode = 1;
1230+
}
1231+
} else {
1232+
$exitCode = 1;
1233+
}
1234+
1235+
return $exitCode;
1236+
}
12231237
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,31 @@ public function testRunReturnsIntegerExitCode()
912912
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
913913
}
914914

915+
public function testRunDispatchesIntegerExitCode()
916+
{
917+
$passedRightValue = false;
918+
919+
// We can assume here that some other test asserts that the event is dispatched at all
920+
$dispatcher = new EventDispatcher();
921+
$self = $this;
922+
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($self, &$passedRightValue) {
923+
$passedRightValue = (4 === $event->getExitCode());
924+
});
925+
926+
$application = new Application();
927+
$application->setDispatcher($dispatcher);
928+
$application->setAutoExit(false);
929+
930+
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
931+
throw new \Exception('', 4);
932+
});
933+
934+
$tester = new ApplicationTester($application);
935+
$tester->run(array('command' => 'test'));
936+
937+
$this->assertTrue($passedRightValue, '-> exit code 4 was passed in the console.terminate event');
938+
}
939+
915940
public function testRunReturnsExitCodeOneForExceptionCodeZero()
916941
{
917942
$exception = new \Exception('', 0);
@@ -927,6 +952,31 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
927952
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
928953
}
929954

955+
public function testRunDispatchesExitCodeOneForExceptionCodeZero()
956+
{
957+
$passedRightValue = false;
958+
959+
// We can assume here that some other test asserts that the event is dispatched at all
960+
$dispatcher = new EventDispatcher();
961+
$self = $this;
962+
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($self, &$passedRightValue) {
963+
$passedRightValue = (1 === $event->getExitCode());
964+
});
965+
966+
$application = new Application();
967+
$application->setDispatcher($dispatcher);
968+
$application->setAutoExit(false);
969+
970+
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
971+
throw new \Exception();
972+
});
973+
974+
$tester = new ApplicationTester($application);
975+
$tester->run(array('command' => 'test'));
976+
977+
$this->assertTrue($passedRightValue, '-> exit code 1 was passed in the console.terminate event');
978+
}
979+
930980
/**
931981
* @expectedException \LogicException
932982
* @expectedExceptionMessage An option with shortcut "e" already exists.

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public function testCopyUnreadableFileFails()
5050
$this->markTestSkipped('This test cannot run on Windows.');
5151
}
5252

53+
if (!getenv('USER') || 'root' === getenv('USER')) {
54+
$this->markTestSkipped('This test will fail if run under superuser');
55+
}
56+
5357
$sourceFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_source_file';
5458
$targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file';
5559

@@ -124,6 +128,10 @@ public function testCopyWithOverrideWithReadOnlyTargetFails()
124128
$this->markTestSkipped('This test cannot run on Windows.');
125129
}
126130

131+
if (!getenv('USER') || 'root' === getenv('USER')) {
132+
$this->markTestSkipped('This test will fail if run under superuser');
133+
}
134+
127135
$sourceFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_source_file';
128136
$targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file';
129137

src/Symfony/Component/Filesystem/Tests/LockHandlerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function testErrorHandlingInLockIfLockPathBecomesUnwritable()
5252
$this->markTestSkipped('This test cannot run on Windows.');
5353
}
5454

55+
if (!getenv('USER') || 'root' === getenv('USER')) {
56+
$this->markTestSkipped('This test will fail if run under superuser');
57+
}
58+
5559
$lockPath = sys_get_temp_dir().'/'.uniqid('', true);
5660
$e = null;
5761
$wrongMessage = null;

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function validate($form, Constraint $constraint)
137137
/**
138138
* Returns the validation groups of the given form.
139139
*
140-
* @return array The validation groups
140+
* @return string|GroupSequence|(string|GroupSequence)[] The validation groups
141141
*/
142142
private static function getValidationGroups(FormInterface $form)
143143
{
@@ -172,10 +172,10 @@ private static function getValidationGroups(FormInterface $form)
172172
/**
173173
* Post-processes the validation groups option for a given form.
174174
*
175-
* @param array|callable $groups The validation groups
176-
* @param FormInterface $form The validated form
175+
* @param string|GroupSequence|(string|GroupSequence)[]|callable $groups The validation groups
176+
* @param FormInterface $form The validated form
177177
*
178-
* @return array The validation groups
178+
* @return (string|GroupSequence)[] The validation groups
179179
*/
180180
private static function resolveValidationGroups($groups, FormInterface $form)
181181
{

0 commit comments

Comments
 (0)