Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToHtml5LocalDateTimeTransformer;
use Symfony\Component\Form\Tests\Extension\Core\DataTransformer\Traits\DateTimeEqualsTrait;

class DateTimeToHtml5LocalDateTimeTransformerTest extends TestCase
{
public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
{
if ($expected instanceof \DateTime && $actual instanceof \DateTime) {
$expected = $expected->format('c');
$actual = $actual->format('c');
}

parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
}
use DateTimeEqualsTrait;

public function transformProvider()
{
Expand Down Expand Up @@ -96,7 +89,7 @@ public function testReverseTransform($toTz, $fromTz, $to, $from)
$transformer = new DateTimeToHtml5LocalDateTimeTransformer($toTz, $fromTz);

if (null !== $to) {
$this->assertEquals(new \DateTime($to), $transformer->reverseTransform($from));
$this->assertDateTimeEquals(new \DateTime($to), $transformer->reverseTransform($from));
} else {
$this->assertNull($transformer->reverseTransform($from));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
use Symfony\Component\Form\Tests\Extension\Core\DataTransformer\Traits\DateTimeEqualsTrait;
use Symfony\Component\Intl\Util\IntlTestHelper;

class DateTimeToLocalizedStringTransformerTest extends TestCase
{
use DateTimeEqualsTrait;

protected $dateTime;
protected $dateTimeWithoutSeconds;

Expand All @@ -39,16 +42,6 @@ protected function tearDown()
$this->dateTimeWithoutSeconds = null;
}

public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
{
if ($expected instanceof \DateTime && $actual instanceof \DateTime) {
$expected = $expected->format('c');
$actual = $actual->format('c');
}

parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
}

public function dataProvider()
{
return [
Expand Down Expand Up @@ -152,7 +145,7 @@ public function testReverseTransformWithNoConstructorParameters()

$dateTime = new \DateTime('2010-02-03 04:05');

$this->assertEquals(
$this->assertDateTimeEquals(
$dateTime->format('c'),
$transformer->reverseTransform('03.02.2010, 04:05')->format('c')
);
Expand Down Expand Up @@ -217,14 +210,14 @@ public function testReverseTransform($dateFormat, $timeFormat, $pattern, $input,

$output = new \DateTime($output);

$this->assertEquals($output, $transformer->reverseTransform($input));
$this->assertDateTimeEquals($output, $transformer->reverseTransform($input));
}

public function testReverseTransformFullTime()
{
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL);

$this->assertEquals($this->dateTime, $transformer->reverseTransform('03.02.2010, 04:05:06 GMT+00:00'));
$this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('03.02.2010, 04:05:06 GMT+00:00'));
}

public function testReverseTransformFromDifferentLocale()
Expand All @@ -233,7 +226,7 @@ public function testReverseTransformFromDifferentLocale()

$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC');

$this->assertEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('Feb 3, 2010, 04:05 AM'));
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('Feb 3, 2010, 04:05 AM'));
}

public function testReverseTransformWithDifferentTimezones()
Expand All @@ -243,7 +236,7 @@ public function testReverseTransformWithDifferentTimezones()
$dateTime = new \DateTime('2010-02-03 04:05:00 Asia/Hong_Kong');
$dateTime->setTimezone(new \DateTimeZone('America/New_York'));

$this->assertEquals($dateTime, $transformer->reverseTransform('03.02.2010, 04:05'));
$this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('03.02.2010, 04:05'));
}

public function testReverseTransformOnlyDateWithDifferentTimezones()
Expand All @@ -252,21 +245,21 @@ public function testReverseTransformOnlyDateWithDifferentTimezones()

$dateTime = new \DateTime('2017-01-10 11:00', new \DateTimeZone('Europe/Berlin'));

$this->assertEquals($dateTime, $transformer->reverseTransform('2017-01-10'));
$this->assertDateTimeEquals($dateTime, $transformer->reverseTransform('2017-01-10'));
}

public function testReverseTransformWithDifferentPatterns()
{
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'MM*yyyy*dd HH|mm|ss');

$this->assertEquals($this->dateTime, $transformer->reverseTransform('02*2010*03 04|05|06'));
$this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('02*2010*03 04|05|06'));
}

public function testReverseTransformDateOnlyWithDstIssue()
{
$transformer = new DateTimeToLocalizedStringTransformer('Europe/Rome', 'Europe/Rome', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, 'dd/MM/yyyy');

$this->assertEquals(
$this->assertDateTimeEquals(
new \DateTime('1978-05-28', new \DateTimeZone('Europe/Rome')),
$transformer->reverseTransform('28/05/1978')
);
Expand All @@ -276,7 +269,7 @@ public function testReverseTransformDateOnlyWithDstIssueAndEscapedText()
{
$transformer = new DateTimeToLocalizedStringTransformer('Europe/Rome', 'Europe/Rome', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, \IntlDateFormatter::GREGORIAN, "'day': dd 'month': MM 'year': yyyy");

$this->assertEquals(
$this->assertDateTimeEquals(
new \DateTime('1978-05-28', new \DateTimeZone('Europe/Rome')),
$transformer->reverseTransform('day: 28 month: 05 year: 1978')
);
Expand Down Expand Up @@ -330,7 +323,7 @@ public function testReverseTransformWithNonExistingDate()
{
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', \IntlDateFormatter::SHORT);

$this->assertEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('31.04.10 04:05'));
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('31.04.10 04:05'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToRfc3339Transformer;
use Symfony\Component\Form\Tests\Extension\Core\DataTransformer\Traits\DateTimeEqualsTrait;

class DateTimeToRfc3339TransformerTest extends TestCase
{
use DateTimeEqualsTrait;

protected $dateTime;
protected $dateTimeWithoutSeconds;

Expand All @@ -33,16 +36,6 @@ protected function tearDown()
$this->dateTimeWithoutSeconds = null;
}

public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
{
if ($expected instanceof \DateTime && $actual instanceof \DateTime) {
$expected = $expected->format('c');
$actual = $actual->format('c');
}

parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
}

public function allProvider()
{
return [
Expand Down Expand Up @@ -108,7 +101,7 @@ public function testReverseTransform($toTz, $fromTz, $to, $from)
$transformer = new DateTimeToRfc3339Transformer($toTz, $fromTz);

if (null !== $to) {
$this->assertEquals(new \DateTime($to), $transformer->reverseTransform($from));
$this->assertDateTimeEquals(new \DateTime($to), $transformer->reverseTransform($from));
} else {
$this->assertNull($transformer->reverseTransform($from));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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\Traits;

/**
* @internal
*/
trait DateTimeEqualsTrait
{
public static function assertDateTimeEquals($expected, $actual)
{
if ($expected instanceof \DateTime && $actual instanceof \DateTime) {
$expected = $expected->format('c');
$actual = $actual->format('c');
}

parent::assertEquals($expected, $actual);
}
}