Completed
Push — master ( 6eb6e9...e41582 )
by Jakub
01:37
created

Tester.php$0 ➔ printInfo()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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