8000 Merge branch '2.7' · symfony/symfony@303df69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 303df69

Browse files
committed
Merge branch '2.7'
* 2.7: [Debug] track and report deprecated classes and interfaces [Form] Remove a redundant test. use value of DIRECTORY_SEPARATOR to detect Windows Conflicts: src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php src/Symfony/Component/Security/Core/Util/SecureRandom.php
2 parents 479a938 + aedb247 commit 303df69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+156
-107
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9191
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
9292

9393
$filesystem->rename($realCacheDir, $oldCacheDir);
94-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
94+
if ('\\' === DIRECTORY_SEPARATOR) {
9595
sleep(1); // workaround for Windows PHP rename bug
9696
}
9797
$filesystem->rename($warmupDir, $realCacheDir);

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ public function getTerminalDimensions()
770770
return $this->terminalDimensions;
771771
}
772772

773-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
773+
if ('\\' === DIRECTORY_SEPARATOR) {
774774
// extract [w, H] from "wxh (WxH)"
775775
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
776776
return array((int) $matches[1], (int) $matches[2]);

src/Symfony/Component/Console/Helper/DialogHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function askConfirmation(OutputInterface $output, $question, $default = t
269269
*/
270270
public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
271271
{
272-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
272+
if ('\\' === DIRECTORY_SEPARATOR) {
273273
$exe = __DIR__.'/../Resources/bin/hiddeninput.exe';
274274

275275
// handle code running from a phar

src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function testAskWithAutocomplete()
100100
*/
101101
public function testAskHiddenResponse()
102102
{
103-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
103+
if ('\\' === DIRECTORY_SEPARATOR) {
104104
$this->markTestSkipped('This test is not supported on Windows');
105105
}
106106

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DebugClassLoader
3030
private $isFinder;
3131
private $wasFinder;
3232
private static $caseCheck;
33+
private static $deprecated = array();
3334

3435
/**
3536
* Constructor.
@@ -175,6 +176,22 @@ public function loadClass($class)
175176
if ($name !== $class && 0 === strcasecmp($name, $class)) {
176177
throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: %s vs %s', $class, $name));
177178
}
179+
180+
if (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
181+
self::$deprecated[$name] = preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]);
182+
} elseif (0 !== strpos($name, 'Symfony\\')) {
183+
$parent = $refl->getParentClass();
184+
185+
if ($parent && isset(self::$deprecated[$parent->name])) {
186+
trigger_error(sprintf('The %s class extends %s that is deprecated %s', $name, $parent->name, self::$deprecated[$parent->name]), E_USER_DEPRECATED);
187+
}
188+
189+
foreach ($refl->getInterfaceNames() as $interface) {
190+
if (isset(self::$deprecated[$interface]) && !($parent && $parent->implementsInterface($interface))) {
191+
trigger_error(sprintf('The %s %s %s that is deprecated %s', $name, $refl->isInterface() ? 'interface extends' : 'class implements', $interface, self::$deprecated[$interface]), E_USER_DEPRECATED);
192+
}
193+
}
194+
}
178195
}
179196

180197
if ($file) {

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,39 @@ public function testClassAlias()
156156
{
157157
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\ClassAlias', true));
158158
}
159+
160+
/**
161+
* @dataProvider provideDeprecatedSuper
162+
*/
163+
public function testDeprecatedSuper($class, $super, $type)
164+
{
165+
set_error_handler('var_dump', 0);
166+
$e = error_reporting(0);
167+
trigger_error('', E_USER_DEPRECATED);
168+
169+
class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true);
170+
171+
error_reporting($e);
172+
restore_error_handler();
173+
174+
$lastError = error_get_last();
175+
unset($lastError['file'], $lastError['line']);
176+
177+
$xError = array(
178+
'type' => E_USER_DEPRECATED,
179+
'message' => 'The Test\Symfony\Component\Debug\Tests\\'.$class.' class '.$type.' Symfony\Component\Debug\Tests\Fixtures\\'.$super.' that is deprecated but this is a test deprecation notice.',
180+
);
181+
182+
$this->assertSame($xError, $lastError);
183+
}
184+
185+
public function provideDeprecatedSuper()
186+
{
187+
return array(
188+
array('DeprecatedInterfaceClass', 'DeprecatedInterface', 'implements'),
189+
array('DeprecatedParentClass', 'DeprecatedClass', 'extends'),
190+
);
191+
}
159192
}
160193

161194
class ClassLoader
@@ -185,6 +218,12 @@ public function findFile($class)
185218
return __DIR__.'/Fixtures/reallyNotPsr0.php';
186219
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) {
187220
return __DIR__.'/Fixtures/notPsr0Bis.php';
221+
} elseif (__NAMESPACE__.'\Fixtures\DeprecatedInterface' === $class) {
222+
return __DIR__.'/Fixtures/DeprecatedInterface.php';
223+
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) {
224+
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
225+
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) {
226+
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}');
188227
}
189228
}
190229
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
/**
6+
* @deprecated but this is a test
7+
* deprecation notice.
8+
* @foobar
9+
*/
10+
class DeprecatedClass
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
/**
6+
* @deprecated but this is a test
7+
* deprecation notice.
8+
* @foobar
9+
*/
10+
interface DeprecatedInterface
11+
{
12+
}

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function remove($files)
164164
}
165165
} else {
166166
// https://bugs.php.net/bug.php?id=52176
167-
if (defined('PHP_WINDOWS_VERSION_MAJOR') && is_dir($file)) {
167+
if ('\\' === DIRECTORY_SEPARATOR && is_dir($file)) {
168168
if (true !== @rmdir($file)) {
169169
throw new IOException(sprintf('Failed to remove file "%s".', $file), 0, null, $file);
170170
}
@@ -307,7 +307,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
307307
if (true !== @symlink($originDir, $targetDir)) {
308308
$report = error_get_last();
309309
if (is_array($report)) {
310-
if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) {
310+
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
311311
throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
312312
}
313313
}
@@ -327,7 +327,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
327327
public function makePathRelative($endPath, $startPath)
328328
{
329329
// Normalize separators on Windows
330-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
330+
if ('\\' === DIRECTORY_SEPARATOR) {
331331
$endPath = strtr($endPath, '\\', '/');
332332
$startPath = strtr($startPath, '\\', '/');
333333
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ public function providePathsForMakePathRelative()
803803
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
804804
);
805805

806-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
806+
if ('\\' === DIRECTORY_SEPARATOR) {
807807
$paths[] = array('c:\var\lib/symfony/src/Symfony/', 'c:/var/lib/symfony/', 'src/Symfony/');
808808
}
809809

@@ -965,7 +965,7 @@ public function testDumpFile()
965965
$this->assertSame('bar', file_get_contents($filename));
966966

967967
// skip mode check on Windows
968-
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
968+
if ('\\' !== DIRECTORY_SEPARATOR) {
969969
$this->assertFilePermissions(753, $filename);
970970
}
971971
}
@@ -980,7 +980,7 @@ public function testDumpFileWithNullMode()
980980
$this->assertSame('bar', file_get_contents($filename));
981981

982982
// skip mode check on Windows
983-
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
983+
if ('\\' !== DIRECTORY_SEPARATOR) {
984984
$this->assertFilePermissions(600, $filename);
985985
}
986986
}

src/Symfony/Component/Finder/Iterator/PathFilterIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function accept()
2828
{
2929
$filename = $this->current()->getRelativePathname();
3030

31-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
31+
if ('\\' === DIRECTORY_SEPARATOR) {
3232
$filename = strtr($filename, '\\', '/');
3333
}
3434

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ public function getTestPathData()
745745
*/
746746
public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
747747
{
748-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
748+
if ('\\' === DIRECTORY_SEPARATOR) {
749749
$this->markTestSkipped('chmod is not supported on Windows');
750750
}
751751

@@ -784,7 +784,7 @@ public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
784784
*/
785785
public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapter)
786786
{
787-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
787+
if ('\\' === DIRECTORY_SEPARATOR) {
788788
$this->markTestSkipped('chmod is not supported on Windows');
789789
}
790790

src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/CsrfProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* @author Bernhard Schussek <bschussek@gmail.com>
3131
*
32-
* @deprecated Deprecated since version 2.4, to be removed in Symfony 3.0. Use
32+
* @deprecated since version 2.4, to be removed in Symfony 3.0. Use
3333
* {@link \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface}
3434
* instead.
3535
*/

src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -279,37 +279,6 @@ public function testValidateTokenOnSubmitIfRootAndCompoundUsesTypeClassAsIntenti
279279
$this->assertSame($valid, $form->isValid());
280280
}
281281

282-
/**
283-
* @dataProvider provideBoolean
284-
*/
285-
public function testValidateTokenOnBindIfRootAndCompoundUsesTypeClassAsIntentionIfEmptyFormName($valid)
286-
{
287-
$this->tokenManager->expects($this->once())
288-
->method('isTokenValid')
289-
->with(new CsrfToken('Symfony\Component\Form\Extension\Core\Type\FormType', 'token'))
290-
->will($this->returnValue($valid));
291-
292-
$form = $this->factory
293-
->createNamedBuilder('', 'form', null, array(
294-
'csrf_field_name' => 'csrf',
295-
'csrf_token_manager' => $this->tokenManager,
296-
'compound' => true,
297-
))
298-
->add('child', 'text')
299-
->getForm();
300-
301-
$form->submit(array(
302-
'child' => 'foobar',
303-
'csrf' => 'token',
304-
));
305-
306-
// Remove token from data
307-
$this->assertSame(array('child' => 'foobar'), $form->getData());
308-
309-
// Validate accordingly
310-
$this->assertSame($valid, $form->isValid());
311-
}
312-
313282
public function testFailIfRootAndCompoundAndTokenMissing()
314283
{
315284
$this->tokenManager->expects($this->never())

src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
4545
*/
4646
public static function isSupported()
4747
{
48-
return !defined('PHP_WINDOWS_VERSION_BUILD') && function_exists('passthru') && function_exists('escapeshellarg');
48+
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
4949
}
5050

5151
/**

src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testGuessWithIncorrectPath()
7171

7272
public function testGuessWithNonReadablePath()
7373
{
74-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
74+
if ('\\' === DIRECTORY_SEPARATOR) {
7575
$this->markTestSkipped('Can not verify chmod operations on Windows');
7676
}
7777

src/Symfony/Component/HttpKernel/HttpCache/EsiResponseCacheStrategyInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Fabien Potencier <fabien@symfony.com>
2323
*
24-
* @deprecated Deprecated since version 2.6, to be removed in 3.0. Use ResponseCacheStrategyInterface instead
24+
* @deprecated since version 2.6, to be removed in 3.0. Use ResponseCacheStrategyInterface instead.
2525
*/
2626
interface EsiResponseCacheStrategyInterface extends ResponseCacheStrategyInterface
2727
{

src/Symfony/Component/HttpKernel/Log/LoggerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Fabien Potencier <fabien@symfony.com>
2020
*
21-
* @deprecated since 2.2, to be removed in 3.0. Type-hint \Psr\Log\LoggerInterface instead.
21+
* @deprecated since version 2.2, to be removed in 3.0. Type-hint \Psr\Log\LoggerInterface instead.
2222
*
2323
* @api
2424
*/

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function doStuff()
270270

271271
// Heredocs are preserved, making the output mixing Unix and Windows line
272272
// endings, switching to "\n" everywhere on Windows to avoid failure.
273-
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
273+
if ('\\' === DIRECTORY_SEPARATOR) {
274274
$expected = str_replace("\r\n", "\n", $expected);
275275
$output = str_replace("\r\n", "\n", $output);
276276
}

src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* @author Bernhard Schussek <bschussek@gmail.com>
2222
*
23-
* @deprecated Deprecated since Symfony 2.6, to be removed in Symfony 3.0.
23+
* @deprecated since version 2.6, to be removed in Symfony 3.0.
2424
* Use {@link OptionsResolver} instead.
2525
*/
2626
interface OptionsResolverInterface

src/Symfony/Component/Process/ExecutableFinder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public function find($name, $default = null, array $extraDirs = array())
7272
}
7373

7474 EA32
$suffixes = array('');
75-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
75+
if ('\\' === DIRECTORY_SEPARATOR) {
7676
$pathExt = getenv('PATHEXT');
7777
$suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
7878
}
7979
foreach ($suffixes as $suffix) {
8080
foreach ($dirs as $dir) {
81-
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
81+
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
8282
return $file;
8383
}
8484
}

src/Symfony/Component/Process/PhpExecutableFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function find($includeArgs = true)
6060
}
6161

6262
$dirs = array(PHP_BINDIR);
63-
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
63+
if ('\\' === DIRECTORY_SEPARATOR) {
6464
$dirs[] = 'C:\xampp\php\\';
6565
}
6666

0 commit comments

Comments
 (0)
0