Repository navigation
Expand file tree
/
Copy pathConfigurations.php
More file actions
92 lines (74 loc) · 2.01 KB
/
Copy pathConfigurations.php
File metadata and controls
92 lines (74 loc) · 2.01 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace SOB;
/**
* @implements \Iterator<int, \SOB\Configuration>
*/
class Configurations implements \Countable, \Iterator
{
private int $iterations = 5000;
private array $parameters = []; // @phpstan-ignore-line
private bool $valid = true;
public function __construct(string $configFile)
{
$this->parameters = [];
if (\file_exists($configFile))
{
$this->parameters = include $configFile;
if (! \is_array($this->parameters)) // @phpstan-ignore-line
{
$this->parameters = [];
}
}
if (empty($this->parameters['tests']))
{
$source = __DIR__;
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item)
{
if ($item->isFile() && 'Tests.php' == $item->getFilename())
{
$fileName = \str_replace('\\', '/', $item->getPathname());
$parts = \explode('/', $fileName);
while ('SOB' != \array_shift($parts))
{
}
$this->parameters['tests'][] = ['namespace' => $parts[0], 'description' => 'sqlite::memory:', 'dbname' => ':memory:', ];
$this->parameters['tests'][] = ['namespace' => $parts[0], 'description' => 'sqlite file', ];
}
}
}
$this->iterations = $this->parameters['iterations'] ?? 5000;
$this->rewind();
}
public function count() : int
{
return \count($this->parameters['tests'] ?? []);
}
public function current() : \SOB\Configuration
{
return new \SOB\Configuration(\current($this->parameters['tests']), $this->iterations);
}
public function getIterations() : int
{
return $this->iterations;
}
public function key() : int
{
return \key($this->parameters['tests']);
}
public function next() : void
{
$this->valid = false !== \next($this->parameters['tests']);
}
public function rewind() : void
{
$this->valid = false !== \reset($this->parameters['tests']);
}
public function valid() : bool
{
return $this->valid;
}
}