Skip to content

Commit

Permalink
[Tests] fixed compatbility of assertEquals(): void
Browse files Browse the repository at this point in the history
  • Loading branch information
HeahDude committed Mar 18, 2019
1 parent 42c08b8 commit 2d7a06b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 29 deletions.
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 @@ -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 @@ -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
@@ -0,0 +1,54 @@
<?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\Form\Tests\Extension\Core\DataTransformer\Traits;

use PHPUnit\Framework\TestCase;

// Auto-adapt to PHPUnit 8 that added a `void` return-type to the assertEquals method

if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'assertEquals'))->hasReturnType()) {
eval('
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer\Traits;
/**
* @internal
*/
trait DateTimeEqualsTrait
{
public static function assertEquals($expected, $actual, string $message = \'\', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void
{
if ($expected instanceof \DateTime && $actual instanceof \DateTime) {
$expected = $expected->format(\'c\');
$actual = $actual->format(\'c\');
}
parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
}
}
');
} else {
/**
* @internal
*/
trait DateTimeEqualsTrait
{
public static function assertEquals($expected, $actual, $message = '', $delta = 0.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);
}
}
}

0 comments on commit 2d7a06b

Please sign in to comment.