1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Integration; |
4
|
|
|
|
5
|
|
|
use Tests\TestCase; |
6
|
|
|
use Illuminate\Container\Container; |
7
|
|
|
use Illuminate\Support\Facades\Config; |
8
|
|
|
use Illuminate\Contracts\Config\Repository; |
9
|
|
|
use Tests\Application\App\Commands\FakeFooCommand; |
10
|
|
|
use Tests\Application\App\Commands\FakeDefaultCommand; |
11
|
|
|
use Tests\Application\App\OtherCommands\FakeOtherCommand; |
12
|
|
|
use LaravelZero\Framework\Contracts\Application as ApplicationContract; |
13
|
|
|
|
14
|
|
|
class ApplicationTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** @test */ |
17
|
|
|
public function it_binds_core_alias(): void |
18
|
|
|
{ |
19
|
|
|
$container = $this->app->getContainer(); |
20
|
|
|
|
21
|
|
|
$this->assertSame($container, Container::getInstance()); |
22
|
|
|
$this->assertSame($container, $container->make('app')); |
23
|
|
|
$this->assertSame($container, $container->make(Container::class)); |
24
|
|
|
$this->assertSame($this->app, $container->make(ApplicationContract::class)); |
25
|
|
|
$this->assertInstanceOf(Repository::class, $container->make('config')); |
26
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'app', $container->make('path')); |
27
|
|
|
$this->assertEquals(BASE_PATH.DIRECTORY_SEPARATOR.'storage', $container->make('path.storage')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** @test */ |
31
|
|
|
public function it_reads_configuration_files() |
32
|
|
|
{ |
33
|
|
|
// @todo Test production config. |
34
|
|
|
|
35
|
|
|
$this->assertSame('Test name', $this->app->getName()); |
36
|
|
|
$this->assertSame('Test version', $this->app->getVersion()); |
37
|
|
|
$this->assertEquals( |
38
|
|
|
$this->app->getContainer() |
|
|
|
|
39
|
|
|
->environment(), |
40
|
|
|
'development' |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$this->assertEquals( |
44
|
|
|
$this->app->getContainer() |
45
|
|
|
->make('config') |
46
|
|
|
->get('foo.bar'), |
47
|
|
|
10 |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** @test */ |
52
|
|
|
public function it_register_commands() |
53
|
|
|
{ |
54
|
|
|
$commands = [ |
55
|
|
|
FakeDefaultCommand::class, |
56
|
|
|
FakeFooCommand::class, |
57
|
|
|
FakeOtherCommand::class, |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
$appCommands = collect($this->app->all()) |
61
|
|
|
->map( |
62
|
|
|
function ($command) { |
63
|
|
|
return get_class($command); |
64
|
|
|
} |
65
|
|
|
) |
66
|
|
|
->toArray(); |
67
|
|
|
|
68
|
|
|
foreach ($commands as $command) { |
69
|
|
|
$this->assertContains($command, $appCommands); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** @test */ |
74
|
|
|
public function it_defines_core_constants() |
75
|
|
|
{ |
76
|
|
|
$this->assertEquals(ARTISAN_BINARY, base_path('phpunit')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** @test */ |
80
|
|
|
public function it_allows_using_facades() |
81
|
|
|
{ |
82
|
|
|
$this->assertEquals( |
83
|
|
|
Config::get('app.name'), |
84
|
|
|
'Test name' |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** @test */ |
89
|
|
|
public function it_register_service_providers() |
90
|
|
|
{ |
91
|
|
|
$app = $this->createApplication(); |
92
|
|
|
|
93
|
|
|
$this->assertSame( |
94
|
|
|
'bar', |
95
|
|
|
$app->getContainer() |
96
|
|
|
->make('foo') |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** @test */ |
101
|
|
|
public function it_guards_the_running_command() |
102
|
|
|
{ |
103
|
|
|
$app = $this->createApplication(); |
104
|
|
|
|
105
|
|
|
$app->call('fake:default'); |
106
|
|
|
|
107
|
|
|
$this->assertInstanceOf(FakeDefaultCommand::class, $app->getRunningCommand()); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: