composer update
This commit is contained in:
parent
f6abc3dce2
commit
71dfaca858
1753 changed files with 45274 additions and 14619 deletions
128
vendor/symfony/serializer/Tests/DeserializeNestedArrayOfObjectsTest.php
vendored
Normal file
128
vendor/symfony/serializer/Tests/DeserializeNestedArrayOfObjectsTest.php
vendored
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Serializer\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
|
||||
class DeserializeNestedArrayOfObjectsTest extends TestCase
|
||||
{
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
//from property PhpDoc
|
||||
array(Zoo::class),
|
||||
//from argument constructor PhpDoc
|
||||
array(ZooImmutable::class),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testPropertyPhpDoc($class)
|
||||
{
|
||||
//GIVEN
|
||||
$json = <<<EOF
|
||||
{
|
||||
"animals": [
|
||||
{"name": "Bug"}
|
||||
]
|
||||
}
|
||||
EOF;
|
||||
$serializer = new Serializer(array(
|
||||
new ObjectNormalizer(null, null, null, new PhpDocExtractor()),
|
||||
new ArrayDenormalizer(),
|
||||
), array('json' => new JsonEncoder()));
|
||||
//WHEN
|
||||
/** @var Zoo $zoo */
|
||||
$zoo = $serializer->deserialize($json, $class, 'json');
|
||||
//THEN
|
||||
self::assertCount(1, $zoo->getAnimals());
|
||||
self::assertInstanceOf(Animal::class, $zoo->getAnimals()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
class Zoo
|
||||
{
|
||||
/** @var Animal[] */
|
||||
private $animals = array();
|
||||
|
||||
/**
|
||||
* @return Animal[]
|
||||
*/
|
||||
public function getAnimals()
|
||||
{
|
||||
return $this->animals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Animal[] $animals
|
||||
*/
|
||||
public function setAnimals(array $animals)
|
||||
{
|
||||
$this->animals = $animals;
|
||||
}
|
||||
}
|
||||
|
||||
class ZooImmutable
|
||||
{
|
||||
/** @var Animal[] */
|
||||
private $animals = array();
|
||||
|
||||
/**
|
||||
* @param Animal[] $animals
|
||||
*/
|
||||
public function __construct(array $animals = array())
|
||||
{
|
||||
$this->animals = $animals;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Animal[]
|
||||
*/
|
||||
public function getAnimals()
|
||||
{
|
||||
return $this->animals;
|
||||
}
|
||||
}
|
||||
|
||||
class Animal
|
||||
{
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
echo '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
|
@ -78,6 +78,82 @@ class DateTimeNormalizerTest extends TestCase
|
|||
yield array('2016-12-01T09:00:00+09:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Japan'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider normalizeUsingTimeZonePassedInContextAndExpectedFormatWithMicrosecondsProvider
|
||||
*/
|
||||
public function testNormalizeUsingTimeZonePassedInContextAndFormattedWithMicroseconds($expected, $expectedFormat, $input, $timezone)
|
||||
{
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->normalizer->normalize(
|
||||
$input,
|
||||
null,
|
||||
array(
|
||||
DateTimeNormalizer::TIMEZONE_KEY => $timezone,
|
||||
DateTimeNormalizer::FORMAT_KEY => $expectedFormat,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function normalizeUsingTimeZonePassedInContextAndExpectedFormatWithMicrosecondsProvider()
|
||||
{
|
||||
yield array(
|
||||
'2018-12-01T18:03:06.067634',
|
||||
'Y-m-d\TH:i:s.u',
|
||||
\DateTime::createFromFormat(
|
||||
'Y-m-d\TH:i:s.u',
|
||||
'2018-12-01T18:03:06.067634',
|
||||
new \DateTimeZone('UTC')
|
||||
),
|
||||
null,
|
||||
);
|
||||
|
||||
yield array(
|
||||
'2018-12-01T18:03:06.067634',
|
||||
'Y-m-d\TH:i:s.u',
|
||||
\DateTime::createFromFormat(
|
||||
'Y-m-d\TH:i:s.u',
|
||||
'2018-12-01T18:03:06.067634',
|
||||
new \DateTimeZone('UTC')
|
||||
),
|
||||
new \DateTimeZone('UTC'),
|
||||
);
|
||||
|
||||
yield array(
|
||||
'2018-12-01T19:03:06.067634+01:00',
|
||||
'Y-m-d\TH:i:s.uP',
|
||||
\DateTimeImmutable::createFromFormat(
|
||||
'Y-m-d\TH:i:s.u',
|
||||
'2018-12-01T18:03:06.067634',
|
||||
new \DateTimeZone('UTC')
|
||||
),
|
||||
new \DateTimeZone('Europe/Rome'),
|
||||
);
|
||||
|
||||
yield array(
|
||||
'2018-12-01T20:03:06.067634+02:00',
|
||||
'Y-m-d\TH:i:s.uP',
|
||||
\DateTime::createFromFormat(
|
||||
'Y-m-d\TH:i:s.u',
|
||||
'2018-12-01T18:03:06.067634',
|
||||
new \DateTimeZone('UTC')
|
||||
),
|
||||
new \DateTimeZone('Europe/Kiev'),
|
||||
);
|
||||
|
||||
yield array(
|
||||
'2018-12-01T19:03:06.067634',
|
||||
'Y-m-d\TH:i:s.u',
|
||||
\DateTime::createFromFormat(
|
||||
'Y-m-d\TH:i:s.u',
|
||||
'2018-12-01T18:03:06.067634',
|
||||
new \DateTimeZone('UTC')
|
||||
),
|
||||
new \DateTimeZone('Europe/Berlin'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage The object must implement the "\DateTimeInterface".
|
||||
|
|
Reference in a new issue