Skip to content

Commit

Permalink
#94: added ContextVeil
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGoryunov committed Sep 4, 2021
1 parent 94f0136 commit c3385ca
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ContextVeil.php
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);
}
}
32 changes: 32 additions & 0 deletions tests/src/ContextVeilTest.php
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()]
);
}
}

0 comments on commit c3385ca

Please sign in to comment.