Merge branch '2.6' into 2.7
* 2.6: [Validator] remove partial deprecation annotation Updated UPGRADE-2.4.md [Form] Support DateTimeImmutable in transform() [Form] add test to avoid regression of #14891 without this change allways the legacy code get called [Form] Fix call to removed method (BC broken in 2.3) [HttpFoundation] Get response content as resource several times for PHP >= 5.6 Improved duplicated code in FileLocator
This commit is contained in:
commit
1750330831
@ -7,3 +7,44 @@ Form
|
|||||||
* The constructor parameter `$precision` in `IntegerToLocalizedStringTransformer`
|
* The constructor parameter `$precision` in `IntegerToLocalizedStringTransformer`
|
||||||
is now ignored completely, because a precision does not make sense for
|
is now ignored completely, because a precision does not make sense for
|
||||||
integers.
|
integers.
|
||||||
|
|
||||||
|
EventDispatcher
|
||||||
|
----------------
|
||||||
|
|
||||||
|
* The `getDispatcher()` and `getName()` methods from `Symfony\Component\EventDispatcher\Event`
|
||||||
|
are deprecated, the event dispatcher instance and event name can be received in the listener call instead.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
public function myFooListener(Event $event)
|
||||||
|
{
|
||||||
|
$dispatcher = $event->getDispatcher();
|
||||||
|
$eventName = $event->getName();
|
||||||
|
$dispatcher->dispatch('log', $event);
|
||||||
|
|
||||||
|
// ... more code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
public function myFooListener(Event $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||||
|
{
|
||||||
|
$dispatcher->dispatch('log', $event);
|
||||||
|
|
||||||
|
// ... more code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
@ -47,15 +47,15 @@ class FileLocator implements FileLocatorInterface
|
|||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filepaths = array();
|
$paths = $this->paths;
|
||||||
if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
|
|
||||||
if (true === $first) {
|
if (null !== $currentPath) {
|
||||||
return $file;
|
array_unshift($paths, $currentPath);
|
||||||
}
|
|
||||||
$filepaths[] = $file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->paths as $path) {
|
$filepaths = array();
|
||||||
|
|
||||||
|
foreach ($paths as $path) {
|
||||||
if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
|
if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
|
||||||
if (true === $first) {
|
if (true === $first) {
|
||||||
return $file;
|
return $file;
|
||||||
@ -65,7 +65,7 @@ class FileLocator implements FileLocatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$filepaths) {
|
if (!$filepaths) {
|
||||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ' : '', implode(', ', $this->paths)));
|
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_values(array_unique($filepaths));
|
return array_values(array_unique($filepaths));
|
||||||
|
@ -51,7 +51,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
|||||||
/**
|
/**
|
||||||
* Transforms a normalized date into a localized date.
|
* Transforms a normalized date into a localized date.
|
||||||
*
|
*
|
||||||
* @param \DateTime $dateTime Normalized date.
|
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
|
||||||
*
|
*
|
||||||
* @return array Localized date.
|
* @return array Localized date.
|
||||||
*
|
*
|
||||||
@ -72,14 +72,17 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
|||||||
), array_flip($this->fields));
|
), array_flip($this->fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime) {
|
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime.');
|
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$dateTime = clone $dateTime;
|
|
||||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||||
|
if (!$dateTime instanceof \DateTimeImmutable) {
|
||||||
|
$dateTime = clone $dateTime;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
|
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
/**
|
/**
|
||||||
* Transforms a normalized date into a localized date string/array.
|
* Transforms a normalized date into a localized date string/array.
|
||||||
*
|
*
|
||||||
* @param \DateTime $dateTime Normalized date.
|
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
|
||||||
*
|
*
|
||||||
* @return string|array Localized date string/array.
|
* @return string|array Localized date string/array.
|
||||||
*
|
*
|
||||||
@ -84,17 +84,11 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime) {
|
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime.');
|
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert time to UTC before passing it to the formatter
|
$value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());
|
||||||
$dateTime = clone $dateTime;
|
|
||||||
if ('UTC' !== $this->inputTimezone) {
|
|
||||||
$dateTime->setTimezone(new \DateTimeZone('UTC'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->getIntlDateFormatter()->format((int) $dateTime->format('U'));
|
|
||||||
|
|
||||||
if (intl_get_error_code() != 0) {
|
if (intl_get_error_code() != 0) {
|
||||||
throw new TransformationFailedException(intl_get_error_message());
|
throw new TransformationFailedException(intl_get_error_message());
|
||||||
|
@ -27,13 +27,13 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime) {
|
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime.');
|
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||||
$dateTime = clone $dateTime;
|
$dateTime = clone $dateTime;
|
||||||
$dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
|
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
|
||||||
}
|
}
|
||||||
|
|
||||||
return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c'));
|
return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c'));
|
||||||
|
@ -86,7 +86,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
* Transforms a DateTime object into a date string with the configured format
|
* Transforms a DateTime object into a date string with the configured format
|
||||||
* and timezone.
|
* and timezone.
|
||||||
*
|
*
|
||||||
* @param \DateTime $value A DateTime object
|
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
|
||||||
*
|
*
|
||||||
* @return string A value as produced by PHP's date() function
|
* @return string A value as produced by PHP's date() function
|
||||||
*
|
*
|
||||||
@ -100,13 +100,16 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof \DateTime) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime.');
|
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$value instanceof \DateTimeImmutable) {
|
||||||
$value = clone $value;
|
$value = clone $value;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$value->setTimezone(new \DateTimeZone($this->outputTimezone));
|
$value = $value->setTimezone(new \DateTimeZone($this->outputTimezone));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
|||||||
/**
|
/**
|
||||||
* Transforms a DateTime object into a timestamp in the configured timezone.
|
* Transforms a DateTime object into a timestamp in the configured timezone.
|
||||||
*
|
*
|
||||||
* @param \DateTime $value A \DateTime object
|
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
|
||||||
*
|
*
|
||||||
* @return int A timestamp
|
* @return int A timestamp
|
||||||
*
|
*
|
||||||
@ -38,18 +38,11 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof \DateTime) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime.');
|
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = clone $value;
|
return $value->getTimestamp();
|
||||||
try {
|
|
||||||
$value->setTimezone(new \DateTimeZone($this->outputTimezone));
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int) $value->format('U');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,13 +59,13 @@ class ValidatorExtension extends AbstractExtension
|
|||||||
|
|
||||||
public function loadTypeGuesser()
|
public function loadTypeGuesser()
|
||||||
{
|
{
|
||||||
// 2.4 API
|
// 2.5 API
|
||||||
if ($this->validator instanceof LegacyValidatorInterface) {
|
if ($this->validator instanceof ValidatorInterface) {
|
||||||
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
|
return new ValidatorTypeGuesser($this->validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.5 API - ValidatorInterface extends MetadataFactoryInterface
|
// 2.4 API
|
||||||
return new ValidatorTypeGuesser($this->validator);
|
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadTypeExtensions()
|
protected function loadTypeExtensions()
|
||||||
|
@ -93,11 +93,6 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
|||||||
*/
|
*/
|
||||||
public function getTypeExtensions()
|
public function getTypeExtensions()
|
||||||
{
|
{
|
||||||
// BC
|
|
||||||
if ($this->innerType instanceof AbstractType) {
|
|
||||||
return $this->innerType->getExtensions();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->typeExtensions;
|
return $this->typeExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +116,30 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
|
|||||||
$this->assertSame($output, $transformer->transform($input));
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTransformDateTimeImmutable()
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
$transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong');
|
||||||
|
|
||||||
|
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
|
||||||
|
|
||||||
|
$dateTime = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
|
||||||
|
$dateTime = $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
|
||||||
|
$output = array(
|
||||||
|
'year' => (string) (int) $dateTime->format('Y'),
|
||||||
|
'month' => (string) (int) $dateTime->format('m'),
|
||||||
|
'day' => (string) (int) $dateTime->format('d'),
|
||||||
|
'hour' => (string) (int) $dateTime->format('H'),
|
||||||
|
'minute' => (string) (int) $dateTime->format('i'),
|
||||||
|
'second' => (string) (int) $dateTime->format('s'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame($output, $transformer->transform($input));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
|
@ -141,6 +141,22 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||||||
$this->assertEquals('02*2010*03 04|05|06', $transformer->transform($this->dateTime));
|
$this->assertEquals('02*2010*03 04|05|06', $transformer->transform($this->dateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTransformDateTimeImmutableTimezones()
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
$transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong');
|
||||||
|
|
||||||
|
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
|
||||||
|
|
||||||
|
$dateTime = clone $input;
|
||||||
|
$dateTime = $dateTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
|
||||||
|
|
||||||
|
$this->assertEquals($dateTime->format('d.m.Y H:i'), $transformer->transform($input));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
|
@ -79,6 +79,20 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
|
|||||||
$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTime($from) : null));
|
$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTime($from) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider transformProvider
|
||||||
|
*/
|
||||||
|
public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to)
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
$transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz);
|
||||||
|
|
||||||
|
$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTimeImmutable($from) : null));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
|
@ -94,6 +94,21 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase
|
|||||||
$this->assertEquals($output, $transformer->transform($input));
|
$this->assertEquals($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTransformDateTimeImmutable()
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
$transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s');
|
||||||
|
|
||||||
|
$input = new \DateTimeImmutable('2010-02-03 12:05:06 America/New_York');
|
||||||
|
$output = $input->format('Y-m-d H:i:s');
|
||||||
|
$input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
|
||||||
|
|
||||||
|
$this->assertEquals($output, $transformer->transform($input));
|
||||||
|
}
|
||||||
|
|
||||||
public function testTransformExpectsDateTime()
|
public function testTransformExpectsDateTime()
|
||||||
{
|
{
|
||||||
$transformer = new DateTimeToStringTransformer();
|
$transformer = new DateTimeToStringTransformer();
|
||||||
|
@ -56,6 +56,21 @@ class DateTimeToTimestampTransformerTest extends DateTimeTestCase
|
|||||||
$this->assertEquals($output, $transformer->transform($input));
|
$this->assertEquals($output, $transformer->transform($input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTransformDateTimeImmutable()
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50500) {
|
||||||
|
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
|
||||||
|
|
||||||
|
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
|
||||||
|
$output = $input->format('U');
|
||||||
|
$input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
|
||||||
|
|
||||||
|
$this->assertEquals($output, $transformer->transform($input));
|
||||||
|
}
|
||||||
|
|
||||||
public function testTransformExpectsDateTime()
|
public function testTransformExpectsDateTime()
|
||||||
{
|
{
|
||||||
$transformer = new DateTimeToTimestampTransformer();
|
$transformer = new DateTimeToTimestampTransformer();
|
||||||
|
@ -17,7 +17,9 @@ class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function test2Dot5ValidationApi()
|
public function test2Dot5ValidationApi()
|
||||||
{
|
{
|
||||||
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
|
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
|
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
@ -36,6 +38,10 @@ class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method('addPropertyConstraint')
|
->method('addPropertyConstraint')
|
||||||
->with('children', $this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid'));
|
->with('children', $this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid'));
|
||||||
|
|
||||||
|
$validator
|
||||||
|
->expects($this->never())
|
||||||
|
->method('getMetadataFactory');
|
||||||
|
|
||||||
$extension = new ValidatorExtension($validator);
|
$extension = new ValidatorExtension($validator);
|
||||||
$guesser = $extension->loadTypeGuesser();
|
$guesser = $extension->loadTypeGuesser();
|
||||||
|
|
||||||
|
@ -1557,8 +1557,8 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function getContent($asResource = false)
|
public function getContent($asResource = false)
|
||||||
{
|
{
|
||||||
if (false === $this->content || (true === $asResource && null !== $this->content)) {
|
if (PHP_VERSION_ID < 50600 && (false === $this->content || (true === $asResource && null !== $this->content))) {
|
||||||
throw new \LogicException('getContent() can only be called once when using the resource return type.');
|
throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true === $asResource) {
|
if (true === $asResource) {
|
||||||
|
@ -975,11 +975,40 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetContentCantBeCalledTwiceWithResources($first, $second)
|
public function testGetContentCantBeCalledTwiceWithResources($first, $second)
|
||||||
{
|
{
|
||||||
|
if (PHP_VERSION_ID >= 50600) {
|
||||||
|
$this->markTestSkipped('PHP >= 5.6 allows to open php://input several times.');
|
||||||
|
}
|
||||||
|
|
||||||
$req = new Request();
|
$req = new Request();
|
||||||
$req->getContent($first);
|
$req->getContent($first);
|
||||||
$req->getContent($second);
|
$req->getContent($second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @dataProvider getContentCantBeCalledTwiceWithResourcesProvider
|
||||||
|
*/
|
||||||
|
public function testGetContentCanBeCalledTwiceWithResources($first, $second)
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50600) {
|
||||||
|
$this->markTestSkipped('PHP < 5.6 does not allow to open php://input several times.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$req = new Request();
|
||||||
|
$a = $req->getContent($first);
|
||||||
|
$b = $req->getContent($second);
|
||||||
|
|
||||||
|
if ($first) {
|
||||||
|
$a = stream_get_contents($a);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($second) {
|
||||||
|
$b = stream_get_contents($b);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($a, $b);
|
||||||
|
}
|
||||||
|
|
||||||
public function getContentCantBeCalledTwiceWithResourcesProvider()
|
public function getContentCantBeCalledTwiceWithResourcesProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
Reference in New Issue
Block a user