|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Tests\TestCase; |
|
6
|
|
|
use Tests\FakeExtraCommand; |
|
7
|
|
|
use Tests\FakeDefaultCommand; |
|
8
|
|
|
use Illuminate\Container\Container; |
|
9
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
10
|
|
|
|
|
11
|
|
|
class ApplicationTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** @test */ |
|
14
|
|
|
public function it_proxies_all_calls_into_container(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$app = $this->createApplication(); |
|
17
|
|
|
|
|
18
|
|
|
$app->bind( |
|
|
|
|
|
|
19
|
|
|
'foo', |
|
20
|
|
|
function () { |
|
21
|
|
|
return 'bar'; |
|
22
|
|
|
} |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertTrue('bar' === $app->make('foo')); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** @test */ |
|
29
|
|
|
public function it_proxies_array_access_into_container(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$app = $this->createApplication(); |
|
32
|
|
|
|
|
33
|
|
|
$app['bar'] = function () { |
|
34
|
|
|
return 'foo'; |
|
35
|
|
|
}; |
|
36
|
|
|
$this->assertTrue(isset($app['bar'])); |
|
37
|
|
|
$this->assertEquals('foo', $app['bar']); |
|
38
|
|
|
unset($app['bar']); |
|
39
|
|
|
$this->assertFalse(isset($app['bar'])); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** @test */ |
|
43
|
|
|
public function it_binds_core_alias(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$container = $this->createApplication() |
|
46
|
|
|
->getContainer(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertTrue(Container::getInstance() === $container); |
|
49
|
|
|
$this->assertTrue($container->make('app') === $container); |
|
50
|
|
|
$this->assertTrue($container->make(Container::class) === $container); |
|
51
|
|
|
$this->assertInstanceOf(Repository::class, $container->make('config')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** @test */ |
|
55
|
|
|
public function it_configures_using_configuration() |
|
56
|
|
|
{ |
|
57
|
|
|
// @todo Test production config. |
|
58
|
|
|
$app = $this->createApplication(); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertTrue($app->getName() === 'Test name'); |
|
61
|
|
|
$this->assertTrue($app->getVersion() === 'Test version'); |
|
62
|
|
|
|
|
63
|
|
|
$commands = [ |
|
64
|
|
|
FakeDefaultCommand::class, |
|
65
|
|
|
FakeExtraCommand::class, |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
|
|
$appCommands = collect($app->all()) |
|
69
|
|
|
->map( |
|
70
|
|
|
function ($command) { |
|
71
|
|
|
return get_class($command); |
|
72
|
|
|
} |
|
73
|
|
|
) |
|
74
|
|
|
->toArray(); |
|
75
|
|
|
|
|
76
|
|
|
foreach ($commands as $command) { |
|
77
|
|
|
$this->assertTrue(in_array($command, $appCommands)); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** @test */ |
|
82
|
|
|
public function it_register_service_providers() |
|
83
|
|
|
{ |
|
84
|
|
|
$app = $this->createApplication(); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertTrue( |
|
87
|
|
|
$app->getContainer() |
|
88
|
|
|
->make('foo') === 'bar' |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: