DITest::testDIinApp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
rs 9.2
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Wambo\Core;
4
5
use League\Flysystem\Filesystem;
6
use League\Flysystem\Memory\MemoryAdapter;
7
use PHPUnit\Framework\TestCase;
8
use Slim\Container;
9
use Wambo\Core\Module\JSONModuleStorage;
10
use Wambo\Core\Module\ModuleMapper;
11
use Wambo\Core\Module\ModuleRepository;
12
13
/**
14
 * Class DITest contains DI Tests
15
 *
16
 * @package Wambo\Core
17
 */
18
class DITest extends TestCase
19
{
20
21
    /**
22
     * @test
23
     */
24
    public function testDIinApp()
25
    {
26
        // arrange
27
        $container = new Container();
28
29
        $container['filesystem_adapter'] = function($c) { return new MemoryAdapter(); };
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
        $container['filesystem'] = function($c) { return new Filesystem($c['filesystem_adapter']); };
31
32
        $container['module_repository'] = function($c) {
33
            $storage = new JSONModuleStorage($c['filesystem'], 'modules.json');
34
            $mapper = new ModuleMapper();
35
            return new ModuleRepository($storage, $mapper);
36
        };
37
        $app = new App($container);
0 ignored issues
show
Documentation introduced by
$container is of type object<Slim\Container>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
39
        // act
40
        $filesystem = $app->getContainer()->get('filesystem');
41
        $hasFile = $filesystem->has('notExistingFile.txt');
42
43
        // assert
44
        $this->assertFalse($hasFile);
45
    }
46
}