Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Aug 26, 2019
1 parent 74b2802 commit 9e154e7
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 89 deletions.
Expand Up @@ -36,6 +36,13 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$loader->load(__DIR__.\DIRECTORY_SEPARATOR.'config.yml');
}

public function setAnnotatedClassCache(array $annotatedClasses)
{
$annotatedClasses = array_diff($annotatedClasses, ['Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController', 'Symfony\Bundle\TwigBundle\Controller\ExceptionController']);

parent::setAnnotatedClassCache($annotatedClasses);
}

protected function build(ContainerBuilder $container)
{
$container->register('logger', NullLogger::class);
Expand Down
Expand Up @@ -50,6 +50,8 @@ public static function decorate(?ContractsEventDispatcherInterface $dispatcher):
* {@inheritdoc}
*
* @param string|null $eventName
*
* @return object
*/
public function dispatch($event/*, string $eventName = null*/)
{
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\Form\FormTypeExtensionInterface;
Expand Down
Expand Up @@ -61,7 +61,7 @@ public function destroy($sessionId)
}

/**
* {@inheritdoc}
* @return bool
*/
public function gc($maxlifetime)
{
Expand Down
Expand Up @@ -60,14 +60,14 @@ class TestSessionHandler extends AbstractSessionHandler
$this->data = $data;
}

public function open($path, $name)
public function open($path, $name): bool
{
echo __FUNCTION__, "\n";

return parent::open($path, $name);
}

public function validateId($sessionId)
public function validateId($sessionId): bool
{
echo __FUNCTION__, "\n";

Expand All @@ -77,7 +77,7 @@ class TestSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
public function read($sessionId)
public function read($sessionId): string
{
echo __FUNCTION__, "\n";

Expand All @@ -87,7 +87,7 @@ class TestSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
public function updateTimestamp($sessionId, $data)
public function updateTimestamp($sessionId, $data): bool
{
echo __FUNCTION__, "\n";

Expand All @@ -97,7 +97,7 @@ class TestSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
public function write($sessionId, $data): bool
{
echo __FUNCTION__, "\n";

Expand All @@ -107,42 +107,42 @@ class TestSessionHandler extends AbstractSessionHandler
/**
* {@inheritdoc}
*/
public function destroy($sessionId)
public function destroy($sessionId): bool
{
echo __FUNCTION__, "\n";

return parent::destroy($sessionId);
}

public function close()
public function close(): bool
{
echo __FUNCTION__, "\n";

return true;
}

public function gc($maxLifetime)
public function gc($maxLifetime): bool
{
echo __FUNCTION__, "\n";

return true;
}

protected function doRead($sessionId)
protected function doRead($sessionId): string
{
echo __FUNCTION__.': ', $this->data, "\n";

return $this->data;
}

protected function doWrite($sessionId, $data)
protected function doWrite($sessionId, $data): bool
{
echo __FUNCTION__.': ', $data, "\n";

return true;
}

protected function doDestroy($sessionId)
protected function doDestroy($sessionId): bool
{
echo __FUNCTION__, "\n";

Expand Down
Expand Up @@ -160,7 +160,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
;
$file->expects($this->any())
->method('getClientSize')
->willReturn(INF)
->willReturn(PHP_INT_MAX)
;

$client->request('POST', '/', [], [$file]);
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/HttpKernel/Tests/Logger.php
Expand Up @@ -22,10 +22,7 @@ public function __construct()
$this->clear();
}

/**
* @return array
*/
public function getLogs($level = false)
public function getLogs($level = false): array
{
return false === $level ? $this->logs : $this->logs[$level];
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ public function getToken()
*/
public function setToken(TokenInterface $token = null)
{
if (null !== $token && !method_exists($token, 'getRoleNames')) {
if (null !== $token && !method_exists($token, 'getRoleNames') && !$token instanceof \PHPUnit\Framework\MockObject\MockObject && !$token instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
@trigger_error(sprintf('Not implementing the "%s::getRoleNames()" method in "%s" is deprecated since Symfony 4.3.', TokenInterface::class, \get_class($token)), E_USER_DEPRECATED);
}

Expand Down
Expand Up @@ -233,7 +233,7 @@ public function testAccessDecisionManagerCalledByVoter()
->method('vote')
->willReturnCallback(function (TokenInterface $token, $subject, array $attributes) use ($sut, $voter3) {
if (\in_array('attr2', $attributes) && $subject) {
$vote = $sut->decide($token, $attributes);
$vote = $sut->decide($token, $attributes) ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED;
} else {
$vote = VoterInterface::ACCESS_ABSTAIN;
}
Expand Down
Expand Up @@ -15,10 +15,12 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
Expand Down Expand Up @@ -155,26 +157,28 @@ private function getDenormalizerForDummyCollection()
public function testDenormalizeWithDiscriminatorMapUsesCorrectClassname()
{
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$loaderMock = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
$loaderMock->method('hasMetadataFor')->willReturnMap([
[
AbstractDummy::class,
true,
],
]);

$loaderMock->method('getMetadataFor')->willReturnMap([
[
AbstractDummy::class,
new ClassMetadata(
AbstractDummy::class,
new ClassDiscriminatorMapping('type', [
'first' => AbstractDummyFirstChild::class,
'second' => AbstractDummySecondChild::class,
])
),
],
]);
$loaderMock = new class() implements ClassMetadataFactoryInterface {
public function getMetadataFor($value): ClassMetadataInterface
{
if (AbstractDummy::class === $value) {
return new ClassMetadata(
AbstractDummy::class,
new ClassDiscriminatorMapping('type', [
'first' => AbstractDummyFirstChild::class,
'second' => AbstractDummySecondChild::class,
])
);
}

throw new InvalidArgumentException;
}

public function hasMetadataFor($value): bool
{
return $value === AbstractDummy::class;
}
};

$discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock);
$normalizer = new AbstractObjectNormalizerDummy($factory, null, new PhpDocExtractor(), $discriminatorResolver);
Expand Down
43 changes: 23 additions & 20 deletions src/Symfony/Component/Serializer/Tests/SerializerTest.php
Expand Up @@ -16,9 +16,11 @@
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
Expand Down Expand Up @@ -368,26 +370,27 @@ public function testDeserializeAndSerializeAbstractObjectsWithTheClassMetadataDi
$example = new AbstractDummyFirstChild('foo-value', 'bar-value');
$example->setQuux(new DummyFirstChildQuux('quux'));

$loaderMock = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
$loaderMock->method('hasMetadataFor')->willReturnMap([
[
AbstractDummy::class,
true,
],
]);

$loaderMock->method('getMetadataFor')->willReturnMap([
[
AbstractDummy::class,
new ClassMetadata(
AbstractDummy::class,
new ClassDiscriminatorMapping('type', [
'first' => AbstractDummyFirstChild::class,
'second' => AbstractDummySecondChild::class,
])
),
],
]);
$loaderMock = new class() implements ClassMetadataFactoryInterface {
public function getMetadataFor($value): ClassMetadataInterface
{
if (AbstractDummy::class === $value) {
return new ClassMetadata(
AbstractDummy::class,
new ClassDiscriminatorMapping('type', [
'first' => AbstractDummyFirstChild::class,
'second' => AbstractDummySecondChild::class,
])
);
}

throw new InvalidArgumentException();
}

public function hasMetadataFor($value): bool
{
return $value === AbstractDummy::class;
}
};

$discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock);
$serializer = new Serializer([new ObjectNormalizer(null, null, null, new PhpDocExtractor(), $discriminatorResolver)], ['json' => new JsonEncoder()]);
Expand Down
Expand Up @@ -27,7 +27,7 @@ abstract class AbstractFileExtractor
*/
protected function extractFiles($resource)
{
if (\is_array($resource) || $resource instanceof \Traversable) {
if (\is_iterable($resource)) {
$files = [];
foreach ($resource as $file) {
if ($this->canBeExtracted($file)) {
Expand Down
62 changes: 62 additions & 0 deletions src/Symfony/Component/Validator/Tests/ConstraintViolationTest.php
Expand Up @@ -108,4 +108,66 @@ public function testToStringOmitsEmptyCodes()

$this->assertSame($expected, (string) $violation);
}

public function testMessageCanBeStringableObject()
{
$message = new ToString();
$violation = new ConstraintViolation(
$message,
(string) $message,
[],
'Root',
'property.path',
null
);

$expected = <<<'EOF'
Root.property.path:
toString
EOF;
$this->assertSame($expected, (string) $violation);
$this->assertSame((string) $message, $violation->getMessage());
}

public function testMessageCannotBeArray()
{
$this->expectException(\TypeError::class);
$violation = new ConstraintViolation(
['cannot be an array'],
'',
[],
'Root',
'property.path',
null
);
}

public function testMessageObjectMustBeStringable()
{
$this->expectException(\TypeError::class);
$violation = new ConstraintViolation(
new CustomArrayObject(),
'',
[],
'Root',
'property.path',
null
);
}

public function testNonStringCode()
{
$violation = new ConstraintViolation(
'42 cannot be used here',
'this is the message template',
[],
['some_value' => 42],
'some_value',
null,
null,
42
);

self::assertSame(42, $violation->getCode());
}
}

0 comments on commit 9e154e7

Please sign in to comment.