1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Created by PhpStorm. |
6
|
|
|
* User: benedikt |
7
|
|
|
* Date: 9/17/17 |
8
|
|
|
* Time: 12:33 AM |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Providers; |
12
|
|
|
|
13
|
|
|
use Illuminate\Contracts\Container\Container; |
14
|
|
|
use Illuminate\Routing\Router; |
15
|
|
|
use Laravel\Lumen\Application; |
16
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
17
|
|
|
use Tfboe\FmLib\Http\Middleware\Authenticate; |
18
|
|
|
use Tfboe\FmLib\Providers\FmLibServiceProvider; |
19
|
|
|
use Tfboe\FmLib\Service\RankingSystem\EloRankingInterface; |
20
|
|
|
use Tfboe\FmLib\TestHelpers\UnitTestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class BaseControllerTest |
24
|
|
|
* @package Tests\Unit\App\Http\Controllers |
25
|
|
|
*/ |
26
|
|
|
class FmLibServiceProviderTest extends UnitTestCase |
27
|
|
|
{ |
28
|
|
|
//tests also private method disable this tests as soon as all are used in public interfaces |
29
|
|
|
//<editor-fold desc="Public Methods"> |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @covers \Tfboe\FmLib\Providers\FmLibServiceProvider::boot |
33
|
|
|
*/ |
34
|
|
|
public function testBoot() |
35
|
|
|
{ |
36
|
|
|
$app = $this->createMock(Application::class); |
37
|
|
|
$app->expects(self::once())->method('configure')->with('fm-lib'); |
38
|
|
|
$provider = $this->provider($app); |
39
|
|
|
$provider->boot(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @covers \Tfboe\FmLib\Providers\FmLibServiceProvider::register |
44
|
|
|
* @uses \Tfboe\FmLib\Providers\ServiceProvider::register |
45
|
|
|
* @uses \Tfboe\FmLib\Service\RankingSystem\EntityComparerByTimeStartTimeAndLocalIdentifier::__construct |
46
|
|
|
* @uses \Tfboe\FmLib\Service\RankingSystem\RankingSystemService::__construct |
47
|
|
|
*/ |
48
|
|
|
public function testRegister() |
49
|
|
|
{ |
50
|
|
|
$app = $this->createMock(Application::class); |
51
|
|
|
$router = $this->createMock(Router::class); |
52
|
|
|
$app->expects(self::once())->method('make')->with('router')->willReturn($router); |
53
|
|
|
$app->expects(self::once())->method('routeMiddleware')->with(['auth' => Authenticate::class]); |
54
|
|
|
$app->expects(self::atLeastOnce())->method('singleton')->willReturnCallback(function ($x, $y) { |
55
|
|
|
if ($x === EloRankingInterface::class) { |
56
|
|
|
$app2 = $this->createMock(Container::class); |
57
|
|
|
$app2->method('make')->willReturnCallback(function ($c) { |
58
|
|
|
return $this->createStub($c); |
59
|
|
|
}); |
60
|
|
|
$inst = $y($app2); |
61
|
|
|
self::assertInstanceOf(EloRankingInterface::class, $inst); |
62
|
|
|
} |
63
|
|
|
}); |
64
|
|
|
$provider = $this->provider($app); |
65
|
|
|
$provider->register(); |
66
|
|
|
} |
67
|
|
|
//</editor-fold desc="Public Methods"> |
68
|
|
|
|
69
|
|
|
//<editor-fold desc="Private Methods"> |
70
|
|
|
/** |
71
|
|
|
* @param null|Application|MockObject|\Illuminate\Contracts\Foundation\Application $app |
72
|
|
|
* @return FmLibServiceProvider |
73
|
|
|
*/ |
74
|
|
|
private function provider($app = null): FmLibServiceProvider |
75
|
|
|
{ |
76
|
|
|
if ($app === null) { |
77
|
|
|
$app = $this->createMock(Application::class); |
78
|
|
|
} |
79
|
|
|
return new FmLibServiceProvider($app); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
//</editor-fold desc="Private Methods"> |
82
|
|
|
} |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.