-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94f0136
commit c3385ca
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace MaxGoryunov\SavingIterator\Src; | ||
|
||
/** | ||
* Veil which applies context to origin if the condition is met. | ||
*/ | ||
final class ContextVeil implements Indifferent | ||
{ | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param mixed $origin original element. | ||
*/ | ||
public function __construct( | ||
/** | ||
* Original element. | ||
* | ||
* @var mixed | ||
*/ | ||
private mixed $origin | ||
) { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __call(string $name, array $arguments): mixed | ||
{ | ||
return $this->origin->$name(...$arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace MaxGoryunov\SavingIterator\Tests\Src; | ||
|
||
use ArrayIterator; | ||
use MaxGoryunov\SavingIterator\Src\ContextVeil; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass MaxGoryunov\SavingIterator\Src\ContextVeil | ||
*/ | ||
final class ContextVeilTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @covers ::__construct | ||
* @covers ::__call | ||
* | ||
* @small | ||
* | ||
* @return void | ||
*/ | ||
public function testReturnsOriginMethodResults(): void | ||
{ | ||
$origin = new ArrayIterator([23, 6, 26, 8, 4, 76, 94, 5]); | ||
$veil = new ContextVeil($origin); | ||
$this->assertEquals( | ||
[$origin->current(), $origin->key(), $origin->valid()], | ||
[$veil->current(), $veil->key(), $veil->valid()] | ||
); | ||
} | ||
} |