Skip to content

Commit

Permalink
Add a method to get an instance in a different format
Browse files Browse the repository at this point in the history
  • Loading branch information
Mopolo committed Nov 2, 2020
1 parent 44e0cb9 commit 22748c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/MagicConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public function in(array $values): bool
return false;
}

public function toFormat(string $format): self
{
return new static($this->getValue($format));
}

/**
* @return string[]
*/
Expand Down
17 changes: 17 additions & 0 deletions tests/MagicConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,21 @@ public function allFormatsDataProvider(): array
],
];
}

/** @test */
public function get_new_instance_in_specific_format()
{
/* *** Initialisation *** */
$base = FakeMagicConstant::TYPE_ARRAY_FORMATS();

/* *** Process *** */
$instanceFormatA = $base->toFormat(FakeMagicConstant::FORMAT_A);
$instanceFormatB = $base->toFormat(FakeMagicConstant::FORMAT_B);
$instanceFormatC = $base->toFormat(FakeMagicConstant::FORMAT_C);

/* *** Assertion *** */
self::assertSame('value A', $instanceFormatA->getValue());
self::assertSame('value B', $instanceFormatB->getValue());
self::assertSame('value C', $instanceFormatC->getValue());
}
}

0 comments on commit 22748c0

Please sign in to comment.