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\Foundation\Application; |
14
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
15
|
|
|
use ReflectionException; |
16
|
|
|
use Tfboe\FmLib\Providers\ServiceProvider; |
17
|
|
|
use Tfboe\FmLib\TestHelpers\UnitTestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class BaseControllerTest |
21
|
|
|
* @package Tests\Unit\App\Http\Controllers |
22
|
|
|
*/ |
23
|
|
|
class ServiceProviderTest extends UnitTestCase |
24
|
|
|
{ |
25
|
|
|
//tests also private method disable this tests as soon as all are used in public interfaces |
26
|
|
|
//<editor-fold desc="Public Methods"> |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @covers \Tfboe\FmLib\Providers\ServiceProvider::register |
30
|
|
|
* @throws ReflectionException |
31
|
|
|
* @throws ReflectionException |
32
|
|
|
*/ |
33
|
|
|
public function testRegister() |
34
|
|
|
{ |
35
|
|
|
$app = $this->createMock(Application::class); |
36
|
|
|
|
37
|
|
|
$app->expects(self::exactly(3))->method('singleton')->withConsecutive( |
38
|
|
|
['Interface', 'Implementation'], |
39
|
|
|
['ClassInterface', 'Class'], |
40
|
|
|
['OtherClass'] |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$provider = $this->provider($app); |
44
|
|
|
$prop = static::getProperty(ServiceProvider::class, 'singletons'); |
45
|
|
|
$prop->setValue($provider, ['Interface' => 'Implementation', 'ClassInterface', 'OtherClass']); |
46
|
|
|
|
47
|
|
|
$provider->register(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
//</editor-fold desc="Public Methods"> |
50
|
|
|
|
51
|
|
|
//<editor-fold desc="Private Methods"> |
52
|
|
|
/** |
53
|
|
|
* @param null|Application|MockObject $app |
54
|
|
|
* @return MockObject|ServiceProvider |
55
|
|
|
* @throws ReflectionException |
56
|
|
|
*/ |
57
|
|
|
private function provider($app = null): MockObject |
58
|
|
|
{ |
59
|
|
|
if ($app === null) { |
60
|
|
|
$app = $this->createMock(Application::class); |
61
|
|
|
} |
62
|
|
|
return $this->getMockForAbstractClass(ServiceProvider::class, [$app]); |
63
|
|
|
} |
64
|
|
|
//</editor-fold desc="Private Methods"> |
65
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: