Test Failed
Push — stable ( 2b96bd...069022 )
by Nuno
01:58
created

it_configures_using_configuration()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 2
eloc 14
nc 2
nop 0
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(
0 ignored issues
show
Documentation Bug introduced by
The method bind does not exist on object<LaravelZero\Framework\Application>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and 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 __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
19
            'foo',
20
            function () {
21
                return 'bar';
22
            }
23
        );
24
25
        $this->assertTrue('bar' === $app->make('foo'));
0 ignored issues
show
Documentation Bug introduced by
The method make does not exist on object<LaravelZero\Framework\Application>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and 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 __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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