Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@..
Decoded Output download
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
class DateTimeImmutableToDateTimeTransformerTest extends TestCase
{
/**
* @dataProvider provider
*/
public function testTransform(\DateTime $expectedOutput, \DateTimeImmutable $input)
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$actualOutput = $transformer->transform($input);
$this->assertEquals($expectedOutput, $actualOutput);
$this->assertEquals($expectedOutput->getTimezone(), $actualOutput->getTimezone());
}
public static function provider(): array
{
return [
[
new \DateTime('2010-02-03 04:05:06 UTC'),
new \DateTimeImmutable('2010-02-03 04:05:06 UTC'),
],
[
(new \DateTime('2019-10-07 +11:00'))
->setTime(14, 27, 11, 10042),
(new \DateTimeImmutable('2019-10-07 +11:00'))
->setTime(14, 27, 11, 10042),
],
];
}
public function testTransformEmpty()
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$this->assertNull($transformer->transform(null));
}
public function testTransformFail()
{
$this->expectException(TransformationFailedException::class);
$this->expectExceptionMessage('Expected a \DateTimeImmutable.');
$transformer = new DateTimeImmutableToDateTimeTransformer();
$transformer->transform(new \DateTime());
}
/**
* @dataProvider provider
*/
public function testReverseTransform(\DateTime $input, \DateTimeImmutable $expectedOutput)
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$actualOutput = $transformer->reverseTransform($input);
$this->assertEquals($expectedOutput, $actualOutput);
$this->assertEquals($expectedOutput->getTimezone(), $actualOutput->getTimezone());
}
public function testReverseTransformEmpty()
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$this->assertNull($transformer->reverseTransform(null));
}
public function testReverseTransformFail()
{
$this->expectException(TransformationFailedException::class);
$this->expectExceptionMessage('Expected a \DateTime.');
$transformer = new DateTimeImmutableToDateTimeTransformer();
$transformer->reverseTransform(new \DateTimeImmutable());
}
}
?>
Did this file decode correctly?
Original Code
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
class DateTimeImmutableToDateTimeTransformerTest extends TestCase
{
/**
* @dataProvider provider
*/
public function testTransform(\DateTime $expectedOutput, \DateTimeImmutable $input)
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$actualOutput = $transformer->transform($input);
$this->assertEquals($expectedOutput, $actualOutput);
$this->assertEquals($expectedOutput->getTimezone(), $actualOutput->getTimezone());
}
public static function provider(): array
{
return [
[
new \DateTime('2010-02-03 04:05:06 UTC'),
new \DateTimeImmutable('2010-02-03 04:05:06 UTC'),
],
[
(new \DateTime('2019-10-07 +11:00'))
->setTime(14, 27, 11, 10042),
(new \DateTimeImmutable('2019-10-07 +11:00'))
->setTime(14, 27, 11, 10042),
],
];
}
public function testTransformEmpty()
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$this->assertNull($transformer->transform(null));
}
public function testTransformFail()
{
$this->expectException(TransformationFailedException::class);
$this->expectExceptionMessage('Expected a \DateTimeImmutable.');
$transformer = new DateTimeImmutableToDateTimeTransformer();
$transformer->transform(new \DateTime());
}
/**
* @dataProvider provider
*/
public function testReverseTransform(\DateTime $input, \DateTimeImmutable $expectedOutput)
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$actualOutput = $transformer->reverseTransform($input);
$this->assertEquals($expectedOutput, $actualOutput);
$this->assertEquals($expectedOutput->getTimezone(), $actualOutput->getTimezone());
}
public function testReverseTransformEmpty()
{
$transformer = new DateTimeImmutableToDateTimeTransformer();
$this->assertNull($transformer->reverseTransform(null));
}
public function testReverseTransformFail()
{
$this->expectException(TransformationFailedException::class);
$this->expectExceptionMessage('Expected a \DateTime.');
$transformer = new DateTimeImmutableToDateTimeTransformer();
$transformer->reverseTransform(new \DateTimeImmutable());
}
}
Function Calls
None |
Stats
MD5 | 66ea2c589e0319827ee7c067bb94a742 |
Eval Count | 0 |
Decode Time | 80 ms |