Skip to content

Commit 91d5ffd

Browse files
Merge pull request #66 from Laragear/fix/4.x/parse-new-instance
[4.x] Fixes `parse` not returning a new instance.
2 parents 924ed3f + 0cb3396 commit 91d5ffd

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/Rut.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ public function __unserialize(array $data): void
313313
public static function parse(self|string|int|null $rut): static
314314
{
315315
// No need to parse a Rut that is already a Rut object.
316-
return $rut instanceof static ? $rut : new static(...static::split($rut));
316+
return $rut instanceof static
317+
? new static($rut->num, $rut->vd)
318+
: new static(...static::split($rut));
317319
}
318320

319321
/**

tests/RutTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ public function test_rut_serializes_to_raw_string(): void
266266
static::assertTrue($rut->isEqual(unserialize($serialized)));
267267
}
268268

269+
public function test_parses_instance_creating_new_instance(): void
270+
{
271+
$first = new Rut(99637702, 4);
272+
273+
$second = Rut::parse($first);
274+
275+
static::assertEquals($first, $second);
276+
static::assertNotSame($first, $second);
277+
}
278+
269279
public function test_parses_string(): void
270280
{
271281
$rut = Rut::parse('996377024');

0 commit comments

Comments
 (0)