From 0b5d838e74fc4c212bbcc371468728fb0bd50513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Thu, 4 Jan 2024 20:35:12 +0100 Subject: [PATCH] Tests: refactoring --- tests/.coveralls.yml | 4 - tests/.gitignore | 10 --- tests/Cases/Decorator/Decorator.phpt | 10 +-- .../Extension/ContainerAwareExtension.phpt | 10 +-- tests/Cases/Extension/MutableExtension.phpt | 10 +-- tests/Cases/Extension/ResourceExtension.phpt | 78 +++++++++---------- tests/Fixtures/Bar/BarService.php | 3 +- tests/Fixtures/Decorator/InjectService.php | 3 +- tests/Fixtures/Foo/FooBarService.php | 3 +- tests/Fixtures/Inject/Base.php | 2 +- tests/Fixtures/Scalar/Scalar2Service.php | 8 +- tests/Fixtures/Scalar/ScalarService.php | 8 +- tests/bootstrap.php | 7 +- 13 files changed, 61 insertions(+), 95 deletions(-) delete mode 100644 tests/.coveralls.yml delete mode 100644 tests/.gitignore diff --git a/tests/.coveralls.yml b/tests/.coveralls.yml deleted file mode 100644 index 8450382..0000000 --- a/tests/.coveralls.yml +++ /dev/null @@ -1,4 +0,0 @@ -# for php-coveralls -service_name: github-actions -coverage_clover: coverage.xml -json_path: coverage.json diff --git a/tests/.gitignore b/tests/.gitignore deleted file mode 100644 index f0d3402..0000000 --- a/tests/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Folders - recursive -*.expected -*.actual - -# Folders -/tmp - -# Files -/*.log -/*.html diff --git a/tests/Cases/Decorator/Decorator.phpt b/tests/Cases/Decorator/Decorator.phpt index 8b88199..ed72fcd 100644 --- a/tests/Cases/Decorator/Decorator.phpt +++ b/tests/Cases/Decorator/Decorator.phpt @@ -1,11 +1,9 @@ load(static function (Compiler $compiler): void { $extension = new class extends CompilerExtension { diff --git a/tests/Cases/Extension/ContainerAwareExtension.phpt b/tests/Cases/Extension/ContainerAwareExtension.phpt index e1131e2..591b9f3 100644 --- a/tests/Cases/Extension/ContainerAwareExtension.phpt +++ b/tests/Cases/Extension/ContainerAwareExtension.phpt @@ -1,11 +1,9 @@ load(static function (Compiler $compiler): void { $compiler->addExtension('aware', new ContainerAwareExtension()); $compiler->loadConfig(FileMock::create(' diff --git a/tests/Cases/Extension/MutableExtension.phpt b/tests/Cases/Extension/MutableExtension.phpt index e5d352e..da6b7c2 100644 --- a/tests/Cases/Extension/MutableExtension.phpt +++ b/tests/Cases/Extension/MutableExtension.phpt @@ -1,10 +1,8 @@ load(static function (Compiler $compiler): void { $mutable = new MutableExtension(); $mutable->onLoad[] = static function (CompilerExtension $ext, ContainerBuilder $builder): void { diff --git a/tests/Cases/Extension/ResourceExtension.phpt b/tests/Cases/Extension/ResourceExtension.phpt index 50c4cb3..b8ab238 100755 --- a/tests/Cases/Extension/ResourceExtension.phpt +++ b/tests/Cases/Extension/ResourceExtension.phpt @@ -1,10 +1,8 @@ load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -47,11 +47,11 @@ test(static function (): void { }); // Skip interface & abstract classes -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -67,11 +67,11 @@ test(static function (): void { }); // Multiple resources -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -92,11 +92,11 @@ test(static function (): void { }); // Exclude namespace -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -116,9 +116,9 @@ test(static function (): void { }); // Invalid resource - must end with / -test(static function (): void { +Toolkit::test(static function (): void { Assert::throws(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); $compiler->loadConfig(FileMock::create(' @@ -133,11 +133,11 @@ test(static function (): void { }); // Exclude whole namespace -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -159,11 +159,11 @@ test(static function (): void { }); // Decorate services - add tags -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -181,11 +181,11 @@ test(static function (): void { }); // Decorate services - add setup -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' services: - stdClass @@ -207,11 +207,11 @@ test(static function (): void { }); // Decorate services - add setup -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -229,11 +229,11 @@ test(static function (): void { }); // Register services manually -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' services: scalar: Tests\Fixtures\Scalar\ScalarService("foobar") @@ -257,12 +257,12 @@ test(static function (): void { }); // Register services manually (exception) -test(static function (): void { +Toolkit::test(static function (): void { Assert::exception(function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); + $loader = new ContainerLoader(Environment::getTestDir(), true); $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: @@ -274,12 +274,12 @@ test(static function (): void { }); // Register services manually -test(static function (): void { - $loader = new ContainerLoader(TEMP_DIR, true); +Toolkit::test(static function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); $class = $loader->load(static function (Compiler $compiler): void { $compiler->addExtension('autoload', new ResourceExtension()); $compiler->addExtension('inject', new InjectExtension()); - $compiler->addConfig(['parameters' => ['appDir' => TESTER_DIR]]); + $compiler->addConfig(['parameters' => ['appDir' => APP_DIR]]); $compiler->loadConfig(FileMock::create(' autoload: resources: diff --git a/tests/Fixtures/Bar/BarService.php b/tests/Fixtures/Bar/BarService.php index e6fe531..89e566c 100644 --- a/tests/Fixtures/Bar/BarService.php +++ b/tests/Fixtures/Bar/BarService.php @@ -7,8 +7,7 @@ final class BarService { - /** @var stdClass */ - private $logger; + private stdClass $logger; public function setLogger(stdClass $logger): void { diff --git a/tests/Fixtures/Decorator/InjectService.php b/tests/Fixtures/Decorator/InjectService.php index 22ca470..50f5196 100644 --- a/tests/Fixtures/Decorator/InjectService.php +++ b/tests/Fixtures/Decorator/InjectService.php @@ -5,8 +5,7 @@ class InjectService { - /** @var Authenticator */ - public $authenticator; + public Authenticator $authenticator; public function injectAuthenticator(Authenticator $authenticator): void { diff --git a/tests/Fixtures/Foo/FooBarService.php b/tests/Fixtures/Foo/FooBarService.php index 74446f5..6914763 100644 --- a/tests/Fixtures/Foo/FooBarService.php +++ b/tests/Fixtures/Foo/FooBarService.php @@ -5,8 +5,7 @@ final class FooBarService { - /** @var FooService */ - public $foo; + public FooService $foo; public function __construct(FooService $foo) { diff --git a/tests/Fixtures/Inject/Base.php b/tests/Fixtures/Inject/Base.php index 5c8e608..dece5bc 100644 --- a/tests/Fixtures/Inject/Base.php +++ b/tests/Fixtures/Inject/Base.php @@ -6,7 +6,7 @@ abstract class Base { /** @var mixed[] */ - public $setup = []; + public array $setup = []; public function setup(Tester $tester, string $bar): void { diff --git a/tests/Fixtures/Scalar/Scalar2Service.php b/tests/Fixtures/Scalar/Scalar2Service.php index f266db1..7ce1cc6 100644 --- a/tests/Fixtures/Scalar/Scalar2Service.php +++ b/tests/Fixtures/Scalar/Scalar2Service.php @@ -5,13 +5,9 @@ final class Scalar2Service { - /** @var string */ - public $text; + public string $text; - /** - * @param string $text - */ - public function __construct($text = 'default') + public function __construct(string $text = 'default') { $this->text = $text; } diff --git a/tests/Fixtures/Scalar/ScalarService.php b/tests/Fixtures/Scalar/ScalarService.php index d6fba85..b618bd1 100644 --- a/tests/Fixtures/Scalar/ScalarService.php +++ b/tests/Fixtures/Scalar/ScalarService.php @@ -5,13 +5,9 @@ final class ScalarService { - /** @var string */ - public $text; + public string $text; - /** - * @param string $text - */ - public function __construct($text) + public function __construct(string $text) { $this->text = $text; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f9ee4bc..86c92a0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,13 +1,10 @@