Completed
Push — master ( 15ea05...a6b9a5 )
by James
14s
created

ContainerFactoryTest::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace RoaveTest\BehatPsrContainer;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\Container\ContainerInterface;
8
use Roave\BehatPsrContainer\ContainerFactory;
9
use Roave\BehatPsrContainer\Exception\NotAPsrContainer;
10
11
/**
12
 * @covers \Roave\BehatPsrContainer\ContainerFactory
13
 */
14
final class ContainerFactoryTest extends TestCase
15
{
16
    /**
17
     * @var string
18
     */
19
    private $tempFilename;
20
21
    public function setUp() : void
22
    {
23
        $this->tempFilename = tempnam(sys_get_temp_dir(), str_replace('\\', '_', __CLASS__) . '_');
24
    }
25
26
    public function tearDown() : void
27
    {
28
        if (file_exists($this->tempFilename)) {
29
            unlink($this->tempFilename);
30
        }
31
    }
32
33
    public function testFactoryThrowsExceptionWhenFileDoesNotReturnContainer() : void
34
    {
35
        file_put_contents(
36
            $this->tempFilename,
37
            "<?php return new \stdClass();"
38
        );
39
40
        $this->expectException(NotAPsrContainer::class);
41
        ContainerFactory::createContainerFromIncludedFile($this->tempFilename);
42
    }
43
44
    public function testFactoryReturnsContainerIfIncluded() : void
45
    {
46
        file_put_contents(
47
            $this->tempFilename,
48
            '<?php return new class implements \Psr\Container\ContainerInterface {
49
                public function get($id) {}
50
                public function has($id) {}
51
            };'
52
        );
53
54
        $container = ContainerFactory::createContainerFromIncludedFile($this->tempFilename);
55
        self::assertInstanceOf(ContainerInterface::class, $container);
56
    }
57
}
58