Skip to content

Commit fcebc33

Browse files
Merge branch '2.7' into 2.8
* 2.7: [VarDumper] Remove decoration from actual output in tests [Bridge/Doctrine] fix count() notice on PHP 7.2 [Security] Skip user checks if not implementing UserInterface [HttpFoundation] Add HTTP_EARLY_HINTS const [DoctrineBridge] Improve exception message at `IdReader::getIdValue()` fixed CS Use new PHP7.2 functions in hasColorSupport [VarDumper] Fix dumping of SplObjectStorage
2 parents ff96226 + bf8ed0a commit fcebc33

File tree

12 files changed

+200
-53
lines changed

12 files changed

+200
-53
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ public function getIdValue($object)
9595
}
9696

9797
if (!$this->om->contains($object)) {
98-
throw new RuntimeException(
99-
'Entities passed to the choice field must be managed. Maybe '.
100-
'persist them in the entity manager?'
101-
);
98+
throw new RuntimeException(sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', get_class($object)));
10299
}
103100

104101
$this->om->initializeObject($object);

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,32 @@ public function testEntityManagerNullObject()
522522

523523
$this->validator->validate($entity, $constraint);
524524
}
525+
526+
public function testValidateUniquenessOnNullResult()
527+
{
528+
$repository = $this->createRepositoryMock();
529+
$repository
530+
->method('find')
531+
->will($this->returnValue(null))
532+
;
533+
534+
$this->em = $this->createEntityManagerMock($repository);
535+
$this->registry = $this->createRegistryMock($this->em);
536+
$this->validator = $this->createValidator();
537+
$this->validator->initialize($this->context);
538+
539+
$constraint = new UniqueEntity(array(
540+
'message' => 'myMessage',
541+
'fields' => array('name'),
542+
'em' => self::EM_NAME,
543+
));
544+
545+
$entity = new SingleIntIdEntity(1, null);
546+
547+
$this->em->persist($entity);
548+
$this->em->flush();
549+
550+
$this->validator->validate($entity, $constraint);
551+
$this->assertNoViolation();
552+
}
525553
}

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,23 @@ public function validate($entity, Constraint $constraint)
133133
*/
134134
if ($result instanceof \Iterator) {
135135
$result->rewind();
136-
} elseif (is_array($result)) {
136+
if ($result instanceof \Countable && 1 < \count($result)) {
137+
$result = array($result->current(), $result->current());
138+
} else {
139+
$result = $result->current();
140+
$result = null === $result ? array() : array($result);
141+
}
142+
} elseif (\is_array($result)) {
137143
reset($result);
144+
} else {
145+
$result = null === $result ? array() : array($result);
138146
}
139147

140148
/* If no entity matched the query criteria or a single entity matched,
141149
* which is the same as the entity being validated, the criteria is
142150
* unique.
143151
*/
144-
if (0 === count($result) || (1 === count($result) && $entity === ($result instanceof \Iterator ? $result->current() : current($result)))) {
152+
if (!$result || (1 === \count($result) && current($result) === $entity)) {
145153
return;
146154
}
147155

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,38 @@ public static function register($mode = 0)
212212
}
213213
}
214214

215+
/**
216+
* Returns true if STDOUT is defined and supports colorization.
217+
*
218+
* Reference: Composer\XdebugHandler\Process::supportsColor
219+
* https://github.com/composer/xdebug-handler
220+
*
221+
* @return bool
222+
*/
215223
private static function hasColorSupport()
216224
{
217-
if ('\\' === DIRECTORY_SEPARATOR) {
218-
return
219-
defined('STDOUT') && function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT)
220-
|| '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD
225+
if (!defined('STDOUT')) {
226+
return false;
227+
}
228+
229+
if (DIRECTORY_SEPARATOR === '\\') {
230+
return (function_exists('sapi_windows_vt100_support')
231+
&& sapi_windows_vt100_support(STDOUT))
221232
|| false !== getenv('ANSICON')
222233
|| 'ON' === getenv('ConEmuANSI')
223234
|| 'xterm' === getenv('TERM');
224235
}
225236

226-
return defined('STDOUT') && function_exists('posix_isatty') && @posix_isatty(STDOUT);
237+
if (function_exists('stream_isatty')) {
238+
return stream_isatty(STDOUT);
239+
}
240+
241+
if (function_exists('posix_isatty')) {
242+
return posix_isatty(STDOUT);
243+
}
244+
245+
$stat = fstat(STDOUT);
246+
// Check if formatted mode is S_IFCHR
247+
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
227248
}
228249
}

src/Symfony/Component/Console/Output/StreamOutput.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,34 @@ protected function doWrite($message, $newline)
8383
*
8484
* Colorization is disabled if not supported by the stream:
8585
*
86-
* - the stream is redirected (eg php file.php >log)
87-
* - Windows without VT100 support, Ansicon, ConEmu, Mintty
88-
* - non tty consoles
86+
* This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo
87+
* terminals via named pipes, so we can only check the environment.
88+
*
89+
* Reference: Composer\XdebugHandler\Process::supportsColor
90+
* https://github.com/composer/xdebug-handler
8991
*
9092
* @return bool true if the stream supports colorization, false otherwise
9193
*/
9294
protected function hasColorSupport()
9395
{
94-
if (function_exists('stream_isatty') && !@stream_isatty($this->stream)) {
95-
return false;
96-
}
9796
if (DIRECTORY_SEPARATOR === '\\') {
98-
if (function_exists('sapi_windows_vt100_support')) {
99-
$vt100Enabled = @sapi_windows_vt100_support($this->stream);
100-
} else {
101-
$vt100Enabled = '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD;
102-
}
103-
104-
return
105-
$vt100Enabled
97+
return (function_exists('sapi_windows_vt100_support')
98+
&& @sapi_windows_vt100_support($this->stream))
10699
|| false !== getenv('ANSICON')
107100
|| 'ON' === getenv('ConEmuANSI')
108101
|| 'xterm' === getenv('TERM');
109102
}
110103

111-
return function_exists('posix_isatty') && @posix_isatty($this->stream);
104+
if (function_exists('stream_isatty')) {
105+
return @stream_isatty($this->stream);
106+
}
107+
108+
if (function_exists('posix_isatty')) {
109+
return @posix_isatty($this->stream);
110+
}
111+
112+
$stat = @fstat($this->stream);
113+
// Check if formatted mode is S_IFCHR
114+
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
112115
}
113116
}

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Response
2121
const HTTP_CONTINUE = 100;
2222
const HTTP_SWITCHING_PROTOCOLS = 101;
2323
const HTTP_PROCESSING = 102; // RFC2518
24+
const HTTP_EARLY_HINTS = 103; // RFC8297
2425
const HTTP_OK = 200;
2526
const HTTP_CREATED = 201;
2627
const HTTP_ACCEPTED = 202;

src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testCollectDefault()
6767

6868
ob_start();
6969
$collector->collect(new Request(), new Response());
70-
$output = ob_get_clean();
70+
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
7171

7272
if (\PHP_VERSION_ID >= 50400) {
7373
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
@@ -125,10 +125,11 @@ public function testFlush()
125125

126126
ob_start();
127127
$collector->__destruct();
128+
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
128129
if (\PHP_VERSION_ID >= 50400) {
129-
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
130+
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
130131
} else {
131-
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
132+
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output);
132133
}
133134
}
134135

@@ -141,10 +142,11 @@ public function testFlushNothingWhenDataDumperIsProvided()
141142
ob_start();
142143
$collector->dump($data);
143144
$line = __LINE__ - 1;
145+
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
144146
if (\PHP_VERSION_ID >= 50400) {
145-
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
147+
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
146148
} else {
147-
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
149+
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output);
148150
}
149151

150152
ob_start();

src/Symfony/Component/Security/Core/Authentication/Provider/SimpleAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function authenticate(TokenInterface $token)
5454
$user = $this->userProvider->loadUserByUsername($user);
5555

5656
if (!$user instanceof UserInterface) {
57-
throw new AuthenticationServiceException('The user provider must return a UserInterface object.');
57+
return $authToken;
5858
}
5959
} catch (UsernameNotFoundException $e) {
6060
$e->setUsername($user);

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/SimpleAuthenticationProviderTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Security\Core\Exception\DisabledException;
1615
use Symfony\Component\Security\Core\Authentication\Provider\SimpleAuthenticationProvider;
16+
use Symfony\Component\Security\Core\Exception\DisabledException;
1717
use Symfony\Component\Security\Core\Exception\LockedException;
1818
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
19+
use Symfony\Component\Security\Core\User\UserChecker;
1920

2021
class SimpleAuthenticationProviderTest extends TestCase
2122
{
@@ -121,6 +122,20 @@ public function testUsernameNotFound()
121122
$this->getProvider($authenticator, $userProvider)->authenticate($token);
122123
}
123124

125+
public function testAuthenticateSkipsUserChecksForNonUserInterfaceObjects()
126+
{
127+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
128+
$token->expects($this->any())
129+
->method('getUser')
130+
->will($this->returnValue('string-user'));
131+
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock();
132+
$authenticator->expects($this->once())
133+
->method('authenticateToken')
134+
->will($this->returnValue($token));
135+
136+
$this->assertSame($token, $this->getProvider($authenticator, null, new UserChecker())->authenticate($token));
137+
}
138+
124139
protected function getProvider($simpleAuthenticator = null, $userProvider = null, $userChecker = null, $key = 'test')
125140
{
126141
if (null === $userChecker) {

src/Symfony/Component/VarDumper/Caster/SplCaster.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $s
180180
$storage = array();
181181
unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967
182182

183-
foreach (clone $c as $obj) {
183+
$clone = clone $c;
184+
foreach ($clone as $obj) {
184185
$storage[spl_object_hash($obj)] = array(
185186
'object' => $obj,
186-
'info' => $c->getInfo(),
187+
'info' => $clone->getInfo(),
187188
);
188189
}
189190

0 commit comments

Comments
 (0)