Completed
Push — master ( 283965...5ee203 )
by Jakub
01:42
created

Tester.php$0 ➔ getSuits()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester;
5
6
use MyTester\Bridges\NetteRobotLoader\TestSuitsFinder;
7
8
/**
9
 * Automated tests runner
10
 * 
11
 * @author Jakub Konečný
12
 * @property-read string[] $suits
13
 * @method void onExecute()
14
 */
15
final class Tester {
16
  use \Nette\SmartObject;
17
  
18
  /** @var string[] */
19
  private array $suits;
20
  /** @var callable[] */
21
  public array $onExecute = [
22
    Environment::class . "::setup",
23
    Environment::class . "::printInfo",
24
  ];
25
  public ITestSuitFactory $testSuitFactory;
26
  
27
  public function __construct(string $folder) {
28
    $this->suits = (new TestSuitsFinder())->getSuits($folder);
29
    $this->testSuitFactory = new class implements ITestSuitFactory {
30
      public function create(string $className): TestCase {
31
        return new $className();
32
      }
33
    };
34
  }
35
  
36
  /**
37
   * @return string[]
38
   */
39
  protected function getSuits(): array {
40
    return $this->suits;
41
  }
42
  
43
  /**
44
   * Execute all tests
45
   */
46
  public function execute(): void {
47
    $this->onExecute();
48
    $failed = false;
49
    foreach($this->suits as $suit) {
50
      $suit = $this->testSuitFactory->create($suit[0]);
51
      if(!$suit->run()) {
52
        $failed = true;
53
      }
54
    }
55
    Environment::printResults();
56
    exit((int) $failed);
57
  }
58
}
59
?>