Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tests] fixed compatbility of assertEquals(): void
- Loading branch information
Showing
4 changed files
with
62 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ymfony/Component/Form/Tests/Extension/Core/DataTransformer/Traits/DateTimeEqualsTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |