From dc202f987aa4a44456add1becb93f07eb72f0469 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 16 Apr 2021 15:35:44 +0300 Subject: [PATCH] injectable factory test --- .../testClasses/Binding/SomeClass.php | 2 +- .../unit/Espo/Core/InjectableFactoryTest.php | 29 +++++++++++++- .../testClasses/Core/Binding/SomeClass0.php | 40 +++++++++++++++++++ .../testClasses/Core/Binding/SomeClass1.php | 40 +++++++++++++++++++ .../testClasses/Core/Binding/SomeClass2.php | 35 ++++++++++++++++ .../Core/Binding/SomeInterface1.php | 35 ++++++++++++++++ .../Core/Binding/SomeInterface2.php | 35 ++++++++++++++++ 7 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 tests/unit/testClasses/Core/Binding/SomeClass0.php create mode 100644 tests/unit/testClasses/Core/Binding/SomeClass1.php create mode 100644 tests/unit/testClasses/Core/Binding/SomeClass2.php create mode 100644 tests/unit/testClasses/Core/Binding/SomeInterface1.php create mode 100644 tests/unit/testClasses/Core/Binding/SomeInterface2.php diff --git a/tests/integration/testClasses/Binding/SomeClass.php b/tests/integration/testClasses/Binding/SomeClass.php index af62a8262b..b856849251 100644 --- a/tests/integration/testClasses/Binding/SomeClass.php +++ b/tests/integration/testClasses/Binding/SomeClass.php @@ -38,7 +38,7 @@ class SomeClass $this->someImplementation = $someImplementation; } - public function get() : SomeInterface + public function get(): SomeInterface { return $this->someImplementation; } diff --git a/tests/unit/Espo/Core/InjectableFactoryTest.php b/tests/unit/Espo/Core/InjectableFactoryTest.php index 9f024f17e1..30a2f562c2 100644 --- a/tests/unit/Espo/Core/InjectableFactoryTest.php +++ b/tests/unit/Espo/Core/InjectableFactoryTest.php @@ -42,9 +42,17 @@ use tests\integration\testClasses\Binding\{ SomeClass, }; +use tests\unit\testClasses\Core\Binding\{ + SomeClass0, + SomeClass1, + SomeInterface1, + SomeClass2, + SomeInterface2, +}; + class InjectableFactoryTest extends \PHPUnit\Framework\TestCase { - public function testCreateWithBinding(): void + public function testCreateWithBinding1(): void { $container = $this->createMock(Container::class); @@ -64,4 +72,23 @@ class InjectableFactoryTest extends \PHPUnit\Framework\TestCase $this->assertSame($instance, $obj->get()); } + + public function testCreateWithBinding2(): void + { + $container = $this->createMock(Container::class); + + $injectableFactory = new InjectableFactory($container); + + $bindingData = new BindingData(); + + $binder = new Binder($bindingData); + + $binder + ->bindImplementation(SomeInterface1::class, SomeClass1::class) + ->bindImplementation(SomeInterface2::class, SomeClass2::class); + + $obj = $injectableFactory->createWithBinding(SomeClass0::class, new BindingContainer($bindingData)); + + $this->assertNotNull($obj); + } } diff --git a/tests/unit/testClasses/Core/Binding/SomeClass0.php b/tests/unit/testClasses/Core/Binding/SomeClass0.php new file mode 100644 index 0000000000..a3f460e867 --- /dev/null +++ b/tests/unit/testClasses/Core/Binding/SomeClass0.php @@ -0,0 +1,40 @@ +dep = $dep; + } +} diff --git a/tests/unit/testClasses/Core/Binding/SomeClass1.php b/tests/unit/testClasses/Core/Binding/SomeClass1.php new file mode 100644 index 0000000000..60b2ae22e3 --- /dev/null +++ b/tests/unit/testClasses/Core/Binding/SomeClass1.php @@ -0,0 +1,40 @@ +dep = $dep; + } +} diff --git a/tests/unit/testClasses/Core/Binding/SomeClass2.php b/tests/unit/testClasses/Core/Binding/SomeClass2.php new file mode 100644 index 0000000000..60a46f61c3 --- /dev/null +++ b/tests/unit/testClasses/Core/Binding/SomeClass2.php @@ -0,0 +1,35 @@ +