Upstream myclabs/DeepCopy state of the touched files before 6d74592b9e
This commit is contained in:
commit
0ea3878598
2 files changed
+58
No files matched your search
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace DeepCopy\TypeFilter\Date;
|
||||
|
||||
use DateInterval;
|
||||
use DeepCopy\TypeFilter\TypeFilter;
|
||||
|
||||
/**
|
||||
* @final
|
||||
*
|
||||
* @deprecated Will be removed in 2.0. This filter will no longer be necessary in PHP 7.1+.
|
||||
*/
|
||||
class DateIntervalFilter implements TypeFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param DateInterval $element
|
||||
*
|
||||
* @see http://news.php.net/php.bugs/205076
|
||||
*/
|
||||
public function apply(mixed $element)
|
||||
{
|
||||
$copy = new DateInterval('P0D');
|
||||
|
||||
foreach ($element as $propertyName => $propertyValue) {
|
||||
$copy->{$propertyName} = $propertyValue;
|
||||
}
|
||||
|
||||
return $copy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace DeepCopyTest\TypeFilter\Date;
|
||||
|
||||
use DateInterval;
|
||||
use DeepCopy\TypeFilter\Date\DateIntervalFilter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \DeepCopy\TypeFilter\Date\DateIntervalFilter
|
||||
*/
|
||||
class DateIntervalFilterTest extends TestCase
|
||||
{
|
||||
public function test_it_deep_copies_a_DateInterval()
|
||||
{
|
||||
$object = new DateInterval('P2D');;
|
||||
|
||||
$filter = new DateIntervalFilter();
|
||||
|
||||
$copy = $filter->apply($object);
|
||||
|
||||
$this->assertEquals($object, $copy);
|
||||
$this->assertNotSame($object, $copy);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user