BaseTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testContainer() 0 14 1
1
<?php
2
/**
3
 * Slim Framework controller creator (https://github.com/juliangut/slim-controller)
4
 *
5
 * @link https://github.com/juliangut/slim-controller for the canonical source repository
6
 *
7
 * @license https://raw.githubusercontent.com/juliangut/slim-controller/master/LICENSE
8
 */
9
10
namespace Jgut\Slim\Controller\Tests;
11
12
use Jgut\Slim\Controller\Base;
13
use Slim\Container;
14
15
/**
16
 * Base controller test class.
17
 */
18
class BaseTest extends \PHPUnit_Framework_TestCase
19
{
20
    public function testContainer()
21
    {
22
        $settings = ['a', 'b'];
23
24
        $container = new Container();
25
        $container['settings'] = $settings;
26
27
        $controller = new Base;
28
        $controller->setContainer($container);
29
30
        static::assertInstanceOf('\Slim\Container', $controller->getContainer());
31
        static::assertEquals(true, isset($controller->settings));
32
        static::assertEquals($settings, $controller->settings);
0 ignored issues
show
Documentation introduced by
The property settings does not exist on object<Jgut\Slim\Controller\Base>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
33
    }
34
}
35