Skip to content

Commit a0b0bd4

Browse files
committed
move the BuilderTestCase from akeneo-plugin to phpunit-extension
1 parent 67a2c47 commit a0b0bd4

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/BuilderTestCase.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Kiboko\Component\PHPUnitExtension;
4+
5+
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
6+
use org\bovigo\vfs\vfsStream;
7+
use org\bovigo\vfs\vfsStreamDirectory;
8+
use PHPUnit\Framework\TestCase;
9+
10+
abstract class BuilderTestCase extends TestCase
11+
{
12+
private ?vfsStreamDirectory $fs = null;
13+
14+
protected function setUp(): void
15+
{
16+
$this->fs = vfsStream::setup();
17+
}
18+
19+
protected function tearDown(): void
20+
{
21+
$this->fs = null;
22+
}
23+
24+
protected function getBuilderCompilePath(): string
25+
{
26+
return $this->fs->url();
27+
}
28+
29+
public function pipelineRunner(): PipelineRunnerInterface
30+
{
31+
return new PipelineRunner();
32+
}
33+
}

src/PipelineRunner.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Kiboko\Component\PHPUnitExtension;
4+
5+
use Kiboko\Contract\Bucket\AcceptanceResultBucketInterface;
6+
use Kiboko\Contract\Bucket\RejectionResultBucketInterface;
7+
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
8+
use Kiboko\Contract\Pipeline\RejectionInterface;
9+
use Kiboko\Contract\Pipeline\StateInterface;
10+
11+
final class PipelineRunner implements PipelineRunnerInterface
12+
{
13+
public function run(
14+
\Iterator $source,
15+
\Generator $async,
16+
RejectionInterface $rejection,
17+
StateInterface $state,
18+
): \Iterator {
19+
$state->initialize();
20+
$rejection->initialize();
21+
22+
$source->rewind();
23+
$async->rewind();
24+
25+
while ($source->valid() && $async->valid()) {
26+
$bucket = $async->send($source->current());
27+
28+
if ($bucket instanceof RejectionResultBucketInterface) {
29+
foreach ($bucket->walkRejection() as $line) {
30+
$rejection->reject($line);
31+
$state->reject();
32+
}
33+
}
34+
if ($bucket instanceof AcceptanceResultBucketInterface) {
35+
yield from $bucket->walkAcceptance();
36+
$state->accept();
37+
}
38+
39+
$source->next();
40+
}
41+
42+
$rejection->teardown();
43+
$state->teardown();
44+
}
45+
}

0 commit comments

Comments
 (0)