1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 1/3/18 |
7
|
|
|
* Time: 3:53 PM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Service; |
11
|
|
|
|
12
|
|
|
use Illuminate\Contracts\Container\Container; |
13
|
|
|
use Tfboe\FmLib\Service\DynamicServiceLoadingService; |
14
|
|
|
use Tfboe\FmLib\Service\RankingSystem\RankingSystemInterface; |
15
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class EloRankingTest |
19
|
|
|
* @packageTfboe\FmLib\Tests\Unit\Service |
20
|
|
|
*/ |
21
|
|
|
class DynamicServiceLoadingServiceTest extends UnitTestCase |
22
|
|
|
{ |
23
|
|
|
//<editor-fold desc="Public Methods"> |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @covers \Tfboe\FmLib\Service\DynamicServiceLoadingService::__construct |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
public function testConstruct() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$app = $this->getMockForAbstractClass(Container::class); |
31
|
|
|
/** @var Container $app */ |
32
|
|
|
$entity = new DynamicServiceLoadingService($app); |
33
|
|
|
self::assertInstanceOf(DynamicServiceLoadingService::class, $entity); |
34
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
35
|
|
|
self::assertEquals($app, self::getProperty(get_class($entity), 'app')->getValue($entity)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @covers \Tfboe\FmLib\Service\DynamicServiceLoadingService::loadRankingSystemService |
41
|
|
|
* @covers \Tfboe\FmLib\Service\DynamicServiceLoadingService::getClassWithNamespace |
42
|
|
|
* @uses \Tfboe\FmLib\Service\DynamicServiceLoadingService::__construct |
43
|
|
|
*/ |
44
|
|
|
public function testLoadRankingSystemService() |
45
|
|
|
{ |
46
|
|
|
$app = $this->getMockForAbstractClass(Container::class); |
47
|
|
|
$instance = $this->getMockForAbstractClass(RankingSystemInterface::class); |
48
|
|
|
$app->expects(self::exactly(4))->method('make')->with('Tfboe\FmLib\Service\RankingSystem\TestInterface') |
49
|
|
|
->willReturn($instance); |
50
|
|
|
/** @var Container $app */ |
51
|
|
|
$entity = new DynamicServiceLoadingService($app); |
52
|
|
|
self::assertTrue($instance === $entity->loadRankingSystemService("Test")); |
53
|
|
|
self::assertTrue($instance === $entity->loadRankingSystemService("TestInterface")); |
54
|
|
|
self::assertTrue($instance === $entity->loadRankingSystemService("Tfboe\FmLib\Service\RankingSystem\Test")); |
55
|
|
|
self::assertTrue($instance === |
56
|
|
|
$entity->loadRankingSystemService("Tfboe\FmLib\Service\RankingSystem\TestInterface")); |
57
|
|
|
} |
58
|
|
|
//</editor-fold desc="Public Methods"> |
59
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.