Repository navigation
Expand file tree
/
Copy pathFeatureTaskFactory.php
More file actions
68 lines (58 loc) · 1.89 KB
/
Copy pathFeatureTaskFactory.php
File metadata and controls
68 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace DMarynicz\BehatParallelExtension\Task;
use Behat\Gherkin\Node\FeatureNode;
use Behat\Testwork\Suite\Suite;
use ReflectionException;
use Symfony\Component\Console\Input\InputInterface;
final class FeatureTaskFactory implements TaskFactory
{
/** @var TestworkSpecificationsFinder */
private $finder;
/** @var ArgumentsBuilder */
private $argumentsBuilder;
public function __construct(TestworkSpecificationsFinder $finder, ArgumentsBuilder $argumentsBuilder)
{
$this->finder = $finder;
$this->argumentsBuilder = $argumentsBuilder;
}
/**
* @param string|null $path
*
* @return TaskEntity[]
*
* @throws ReflectionException
*/
public function createTasks(InputInterface $input, $path = null): array
{
$suites = $this->finder->findGroupedSpecifications($path);
$tasks = [];
$chunkSize = max((int) $input->getOption('parallel-chunk-size'), 1);
foreach ($suites as $suite) {
$tasks = array_merge($tasks, ChunkBuilder::buildChunks(
$suite,
$chunkSize,
function (array $chunk) use ($input, $suite) {
return $this->createTaskFromChunk($input, $suite->getSuite(), $chunk);
}
));
}
return $tasks;
}
/**
* @param FeatureNode[] $chunk
*/
private function createTaskFromChunk(InputInterface $input, Suite $suite, array $chunk): Task
{
$units = array_map(static function (FeatureNode $feature) {
return new TaskUnit($feature);
}, $chunk);
$paths = array_map(static function (TaskUnit $unit) {
return $unit->getPath();
}, $units);
return new Task(
$suite,
$units,
$this->argumentsBuilder->buildArguments($input, $paths)
);
}
}