File: DefaultEntriesTest.php

package info (click to toggle)
php-di 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,932 kB
  • sloc: php: 10,572; makefile: 42; xml: 17; sh: 10; pascal: 5
file content (83 lines) | stat: -rw-r--r-- 2,724 bytes parent folder | download | duplicates (2)
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
76
77
78
79
80
81
82
83
<?php

declare(strict_types=1);

namespace DI\Test\IntegrationTest;

use DI\Container;
use DI\ContainerBuilder;
use DI\FactoryInterface;
use Invoker\InvokerInterface;
use Psr\Container\ContainerInterface;

/**
 * Test entries registered by default.
 */
class DefaultEntriesTest extends BaseContainerTest
{
    /**
     * The container auto-registers itself.
     * @dataProvider provideContainer
     */
    #[\PHPUnit\Framework\Attributes\DataProvider('provideContainer')]
    public function testContainerIsRegistered(ContainerBuilder $builder)
    {
        $container = $builder->build();

        $this->assertSame($container, $container->get(Container::class));
    }

    /**
     * The container auto-registers itself (with the factory interface).
     * @dataProvider provideContainer
     */
    #[\PHPUnit\Framework\Attributes\DataProvider('provideContainer')]
    public function testFactoryInterfaceIsRegistered(ContainerBuilder $builder)
    {
        $container = $builder->build();

        $this->assertSame($container, $container->get(FactoryInterface::class));
    }

    /**
     * The container auto-registers itself (with the invoker interface).
     * @dataProvider provideContainer
     */
    #[\PHPUnit\Framework\Attributes\DataProvider('provideContainer')]
    public function testInvokerInterfaceIsRegistered(ContainerBuilder $builder)
    {
        $container = $builder->build();

        $this->assertSame($container, $container->get(InvokerInterface::class));
    }

    /**
     * The container auto-registers itself (with the container interface).
     * @dataProvider provideContainer
     */
    #[\PHPUnit\Framework\Attributes\DataProvider('provideContainer')]
    public function testContainerInterfaceIsRegistered(ContainerBuilder $builder)
    {
        $container = $builder->build();

        $this->assertSame($container, $container->get(ContainerInterface::class));
    }

    /**
     * @dataProvider provideContainer
     */
    #[\PHPUnit\Framework\Attributes\DataProvider('provideContainer')]
    public function testWithAWrapperContainer(ContainerBuilder $builder)
    {
        $wrapperContainer = new Container;

        $builder->wrapContainer($wrapperContainer);
        $container = $builder->build();

        $this->assertSame($wrapperContainer, $container->get(ContainerInterface::class));
        // These entries must point to the PHP-DI instance because the wrapper container is type-hinted as `ContainerInterface` only
        $this->assertSame($container, $container->get(Container::class));
        $this->assertSame($container, $container->get(InvokerInterface::class));
        $this->assertSame($container, $container->get(FactoryInterface::class));
    }
}