Completed
Push — master ( 67e18b...1f3c92 )
by Jakub
01:44
created

TestsRunner::execute()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 2
Metric Value
cc 5
eloc 17
c 6
b 0
f 2
nc 6
nop 0
dl 0
loc 23
rs 9.3888
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester\Bridges\NetteDI;
5
6
require_once __DIR__ . "/../../functions.php";
7
8
use MyTester\TestCase;
9
use MyTester\Environment;
10
use Nette\Utils\Finder;
11
12
/**
13
 * Tests Runner
14
 *
15
 * @author Jakub Konečný
16
 * @method void onExecute()
17
 */
18
final class TestsRunner {
19
  use \Nette\SmartObject;
20
21
  /** @var TestCase[] */
22
  private array $suits = [];
23
  /** @var array */
24
  public static array $autoloader = [];
25
  /** @var callable[] */
26
  public array $onExecute = [];
27
  
28
  public function addSuit(TestCase $suit): void {
29
    $this->suits[] = $suit;
30
  }
31
  
32
  /**
33
   * Autoloader for test suits
34
   */
35
  public static function autoload(string $class): void {
36
    foreach(static::$autoloader as $suit) {
37
      if($suit[0] === $class) {
38
        require $suit[1];
39
        return;
40
      }
41
    }
42
  }
43
  
44
  public function execute(): bool {
45
    $this->onExecute();
46
    $failed = false;
47
    foreach($this->suits as $suit) {
48
      if(!$suit->run()) {
49
        $failed = true;
50
      }
51
    }
52
    Environment::printLine("");
53
    Environment::printSkipped();
54
    if($failed) {
55
      Environment::printLine("Failed");
56
      Environment::printLine("");
57
      $files = Finder::findFiles("*.errors")->in(\getTestsDirectory());
58
      /** @var \SplFileInfo $file */
59
      foreach($files as $name => $file) {
60
        Environment::printLine("--- " . substr($file->getBasename(), 0, -7));
61
        echo file_get_contents($name);
62
      }
63
    } else {
64
      Environment::printLine("OK");
65
    }
66
    return $failed;
67
  }
68
}
69
?>