Upstream myclabs/DeepCopy state of the touched files before 7fb5af511d
This commit is contained in:
1 parent
e6d94fc32a
commit
e23bc8d851
2 files changed
+1
-52
No files matched your search
@@ -22,18 +22,9 @@ class DateIntervalFilter implements TypeFilter
|
|||||||
*/
|
*/
|
||||||
public function apply(mixed $element)
|
public function apply(mixed $element)
|
||||||
{
|
{
|
||||||
$properties = get_object_vars($element);
|
|
||||||
|
|
||||||
// Since PHP 8.2 an interval from createFromDateString() exposes
|
|
||||||
// "from_string"/"date_string" instead of y/m/d/h/i/s, and "from_string" is
|
|
||||||
// ignored on assignment, so copying property by property would zero it.
|
|
||||||
if (!empty($properties['from_string'])) {
|
|
||||||
return DateInterval::createFromDateString($properties['date_string']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$copy = new DateInterval('P0D');
|
$copy = new DateInterval('P0D');
|
||||||
|
|
||||||
foreach ($properties as $propertyName => $propertyValue) {
|
foreach ($element as $propertyName => $propertyValue) {
|
||||||
$copy->{$propertyName} = $propertyValue;
|
$copy->{$propertyName} = $propertyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace DeepCopyTest\TypeFilter\Date;
|
namespace DeepCopyTest\TypeFilter\Date;
|
||||||
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTimeImmutable;
|
|
||||||
use DeepCopy\TypeFilter\Date\DateIntervalFilter;
|
use DeepCopy\TypeFilter\Date\DateIntervalFilter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@@ -23,45 +22,4 @@ class DateIntervalFilterTest extends TestCase
|
|||||||
$this->assertEquals($object, $copy);
|
$this->assertEquals($object, $copy);
|
||||||
$this->assertNotSame($object, $copy);
|
$this->assertNotSame($object, $copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_deep_copies_a_DateInterval_created_from_a_date_string()
|
|
||||||
{
|
|
||||||
$object = DateInterval::createFromDateString('2 days');
|
|
||||||
|
|
||||||
$filter = new DateIntervalFilter();
|
|
||||||
|
|
||||||
$copy = $filter->apply($object);
|
|
||||||
|
|
||||||
// The copy has to shift a date by the same amount as the original.
|
|
||||||
$base = new DateTimeImmutable('2026-01-01 00:00:00');
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
$base->add($object)->format('Y-m-d H:i:s'),
|
|
||||||
$base->add($copy)->format('Y-m-d H:i:s')
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals($object, $copy);
|
|
||||||
$this->assertNotSame($object, $copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_deep_copies_an_inverted_DateInterval_with_microseconds()
|
|
||||||
{
|
|
||||||
$object = new DateInterval('PT1S');
|
|
||||||
$object->invert = 1;
|
|
||||||
$object->f = 0.25;
|
|
||||||
|
|
||||||
$filter = new DateIntervalFilter();
|
|
||||||
|
|
||||||
$copy = $filter->apply($object);
|
|
||||||
|
|
||||||
$this->assertEquals($object, $copy);
|
|
||||||
$this->assertNotSame($object, $copy);
|
|
||||||
|
|
||||||
$base = new DateTimeImmutable('2026-01-01 00:00:00');
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
$base->add($object)->format('Y-m-d H:i:s.u'),
|
|
||||||
$base->add($copy)->format('Y-m-d H:i:s.u')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user