Skip to content

Commit

Permalink
Add a test for custom setters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mopolo committed Nov 26, 2020
1 parent fb139c4 commit c9164b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/Fixture/CustomSetValueMagicConstant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

namespace CuyZ\MagicConstant\Tests\Fixture;

use CuyZ\MagicConstant\MagicConstant;

final class CustomSetValueMagicConstant extends MagicConstant
{
protected const A = 'foo';

protected function setValue($value): void
{
parent::setValue(strtolower($value));
}
}
10 changes: 10 additions & 0 deletions tests/MagicConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use CuyZ\MagicConstant\Exception\InvalidKeyException;
use CuyZ\MagicConstant\Exception\InvalidValueException;
use CuyZ\MagicConstant\MagicConstant;
use CuyZ\MagicConstant\Tests\Fixture\CustomSetValueMagicConstant;
use CuyZ\MagicConstant\Tests\Fixture\FakeMagicConstant;
use CuyZ\MagicConstant\Tests\Fixture\OtherMagicConstant;

Expand Down Expand Up @@ -558,4 +559,13 @@ public function test_return_values_in_all_formats(MagicConstant $magicConstant,
/* *** Assertion *** */
self::assertSame($expectedValues, $actualValues);
}

public function test_has_custom_value_setter()
{
$magicConstant1 = new CustomSetValueMagicConstant('FOO');
$magicConstant2 = new CustomSetValueMagicConstant('foo');

self::assertSame('foo', $magicConstant1->getValue());
self::assertSame('foo', $magicConstant2->getValue());
}
}

0 comments on commit c9164b8

Please sign in to comment.