File: ContainerResolveNonInstantiableTest.php

package info (click to toggle)
php-laravel-framework 8.83.26%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,444 kB
  • sloc: php: 167,609; sh: 162; makefile: 46
file content (75 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

namespace Illuminate\Tests\Container;

use Illuminate\Container\Container;
use PHPUnit\Framework\TestCase;

class ContainerResolveNonInstantiableTest extends TestCase
{
    public function testResolvingNonInstantiableWithDefaultRemovesWiths()
    {
        $container = new Container;
        $object = $container->make(ParentClass::class, ['i' => 42]);

        $this->assertSame(42, $object->i);
    }

    public function testResolvingNonInstantiableWithVariadicRemovesWiths()
    {
        $container = new Container;
        $parent = $container->make(VariadicParentClass::class, ['i' => 42]);

        $this->assertCount(0, $parent->child->objects);
        $this->assertSame(42, $parent->i);
    }
}

interface TestInterface
{
}

class ParentClass
{
    /**
     * @var int
     */
    public $i;

    public function __construct(TestInterface $testObject = null, int $i = 0)
    {
        $this->i = $i;
    }
}

class VariadicParentClass
{
    /**
     * @var \Illuminate\Tests\Container\ChildClass
     */
    public $child;

    /**
     * @var int
     */
    public $i;

    public function __construct(ChildClass $child, int $i = 0)
    {
        $this->child = $child;
        $this->i = $i;
    }
}

class ChildClass
{
    /**
     * @var array
     */
    public $objects;

    public function __construct(TestInterface ...$objects)
    {
        $this->objects = $objects;
    }
}