* * 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\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; class DateTimeToTimestampTransformerTest extends TestCase { public function testTransform() { $transformer = new DateTimeToTimestampTransformer('UTC', 'UTC'); $input = new \DateTime('2010-02-03 04:05:06 UTC'); $output = $input->format('U'); $this->assertEquals($output, $transformer->transform($input)); } public function testTransformEmpty() { $transformer = new DateTimeToTimestampTransformer(); $this->assertNull($transformer->transform(null)); } public function testTransformWithDifferentTimezones() { $transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York'); $input = new \DateTime('2010-02-03 04:05:06 America/New_York'); $output = $input->format('U'); $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); $this->assertEquals($output, $transformer->transform($input)); } public function testTransformFromDifferentTimezone() { $transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'UTC'); $input = new \DateTime('2010-02-03 04:05:06 Asia/Hong_Kong'); $dateTime = clone $input; $dateTime->setTimezone(new \DateTimeZone('UTC')); $output = $dateTime->format('U'); $this->assertEquals($output, $transformer->transform($input)); } public function testTransformDateTimeImmutable() { $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() { $transformer = new DateTimeToTimestampTransformer(); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $transformer->transform('1234'); } public function testReverseTransform() { $reverseTransformer = new DateTimeToTimestampTransformer('UTC', 'UTC'); $output = new \DateTime('2010-02-03 04:05:06 UTC'); $input = $output->format('U'); $this->assertEquals($output, $reverseTransformer->reverseTransform($input)); } public function testReverseTransformEmpty() { $reverseTransformer = new DateTimeToTimestampTransformer(); $this->assertNull($reverseTransformer->reverseTransform(null)); } public function testReverseTransformWithDifferentTimezones() { $reverseTransformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York'); $output = new \DateTime('2010-02-03 04:05:06 America/New_York'); $input = $output->format('U'); $output->setTimezone(new \DateTimeZone('Asia/Hong_Kong')); $this->assertEquals($output, $reverseTransformer->reverseTransform($input)); } public function testReverseTransformExpectsValidTimestamp() { $reverseTransformer = new DateTimeToTimestampTransformer(); $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); $reverseTransformer->reverseTransform('2010-2010-2010'); } } __halt_compiler();----SIGNATURE:----NFvKVWuEDDqzScRHtf+yGNNlA8t4b36ObEGKh/lf7uPCo39N+uJFt/b+SPB9BNHLOYataldwO7JyPkMURt/K5fTqio+KufG9956LzmZW7/dmC9RscqTZ39wQC4eR6hNFPJ4aBeQo+40Jv3VVuylfTdNBCDUaG1BXVzwLlQY/Dvm6HhlFKHM0tmmyMWZNsvGuScpa1ObNy5aFoymARQYuf0QbTt+LLQhsc7wNYEbykiE+eJrFjq0+UCSDXfdOX7eg3ifeG6XbAhKob+4DJ0dPuKCFdGkKC+1VoD8d0ueHdtStloENNV089A84huzZ0XB+hIHcDtpf14MUJVs4uk7h21JK0MLSLjBwW9Cwu9HXFBVR0Yj12S8ZCrsJbKxnwjzi28HjBKX/7AoErfmikd7GZc7iD5cpT7aMD0/0ZXz7BkWHerXOSt6spenpLan0a5ExzG1VNGSBysHROqGcnT30tMKZlvqaiTWqm0fwo+1TFGwefHSldjjGOug8vns4HvtcEtAEyx+glwNy6Rx43VJaZP4JrsxQBNB/NMvOcArZga55NTP6zUqWDeahYa5n6DAs83EFG4+lCD5LXg8T2q/ZYu9sk3f8EVOcYKjd5YnNSGWLkpiBqBoE9zz2m3V9E9/64QkoIIClhVUhFxHebakJGrHT/31dj7x7rhOuhub7pAc=----ATTACHMENT:----MzIzMDI4MzUwNzQwNzc5IDM2NjM0NzYwMzk5NDAwNTggMjg1MDU3NDgwNjMxMDI4MQ==