Skip to content

Commit 22748c0

Browse files
committed
Add a method to get an instance in a different format
1 parent 44e0cb9 commit 22748c0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/MagicConstant.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public function in(array $values): bool
150150
return false;
151151
}
152152

153+
public function toFormat(string $format): self
154+
{
155+
return new static($this->getValue($format));
156+
}
157+
153158
/**
154159
* @return string[]
155160
*/

tests/MagicConstantTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,21 @@ public function allFormatsDataProvider(): array
478478
],
479479
];
480480
}
481+
482+
/** @test */
483+
public function get_new_instance_in_specific_format()
484+
{
485+
/* *** Initialisation *** */
486+
$base = FakeMagicConstant::TYPE_ARRAY_FORMATS();
487+
488+
/* *** Process *** */
489+
$instanceFormatA = $base->toFormat(FakeMagicConstant::FORMAT_A);
490+
$instanceFormatB = $base->toFormat(FakeMagicConstant::FORMAT_B);
491+
$instanceFormatC = $base->toFormat(FakeMagicConstant::FORMAT_C);
492+
493+
/* *** Assertion *** */
494+
self::assertSame('value A', $instanceFormatA->getValue());
495+
self::assertSame('value B', $instanceFormatB->getValue());
496+
self::assertSame('value C', $instanceFormatC->getValue());
497+
}
481498
}

0 commit comments

Comments
 (0)