Skip to content

Commit

Permalink
Add test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
llupa committed Jun 12, 2024
1 parent 156b10c commit 3306d5f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
13 changes: 13 additions & 0 deletions fixtures/f014/ReadonlyObjectProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace DeepCopy\f014;

class ReadonlyObjectProperty
{
public readonly ReadonlyScalarProperty $foo;

public function __construct()
{
$this->foo = new ReadonlyScalarProperty();
}
}
17 changes: 17 additions & 0 deletions fixtures/f014/ReadonlyScalarProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace DeepCopy\f014;

class ReadonlyScalarProperty
{
public readonly string $foo;
public readonly int $bar;
public readonly array $baz;

public function __construct()
{
$this->foo = 'foo';
$this->bar = 1;
$this->baz = [];
}
}
17 changes: 7 additions & 10 deletions tests/DeepCopyTest/DeepCopyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use DeepCopy\f011;
use DeepCopy\f012\Suit;
use DeepCopy\f013;
use DeepCopy\f014;
use DeepCopy\Filter\ChainableFilter;
use DeepCopy\Filter\Doctrine\DoctrineProxyFilter;
use DeepCopy\Filter\KeepFilter;
Expand Down Expand Up @@ -547,20 +548,16 @@ public function test_it_can_copy_property_after_applying_doctrine_proxy_filter_w
*/
public function test_it_can_copy_object_with_readonly_property()
{
$object = new class extends \stdClass {
public readonly string $foo;

public function __construct()
{
$this->foo = 'foo';
}
};
$scalarProperties = new f014\ReadonlyScalarProperty();
$objectProperties = new f014\ReadonlyObjectProperty();

$deepCopy = new DeepCopy();

$copy = $deepCopy->copy($object);
$scalarPropertiesCopy = $deepCopy->copy($scalarProperties);
$objectPropertiesCopy = $deepCopy->copy($objectProperties);

$this->assertEqualButNotSame($object, $copy);
$this->assertEqualButNotSame($scalarProperties, $scalarPropertiesCopy);
$this->assertEqualButNotSame($objectProperties, $objectPropertiesCopy);
}

private function assertEqualButNotSame($expected, $val)
Expand Down

0 comments on commit 3306d5f

Please sign in to comment.