UnicomponentTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRegisterComponent() 0 8 1
A testConfigurationComponents() 0 7 1
A testGetComponent() 0 8 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: reallyli
5
 * Date: 18/10/11
6
 * Time: 下午2:39.
7
 */
8
9
namespace Reallyli\LaravelUnicomponent\Tests;
10
11
use PHPUnit\Framework\TestCase;
12
use Reallyli\LaravelUnicomponent\Components\Pusher\Pusher;
13
use Reallyli\LaravelUnicomponent\Tests\Example\ExampleService;
14
use Reallyli\LaravelUnicomponent\UnicomponentServiceManager;
15
16
class UnicomponentTest extends TestCase
17
{
18
    /**
19
     * Method description:Test Register Component.
20
     *
21
     * @author reallyli <[email protected]>
22
     * @since 18/10/11
23
     * @return mixed
24
     * 返回值类型:string,array,object,mixed(多种,不确定的),void(无返回值)
25
     */
26
    public function testRegisterComponent()
27
    {
28
        $unicomponentServiceManager = new UnicomponentServiceManager([]);
29
30
        $unicomponentServiceManager->registerComponent(new ExampleService());
31
32
        $this->assertEquals('test', $unicomponentServiceManager->example()->test());
0 ignored issues
show
Documentation Bug introduced by
The method example does not exist on object<Reallyli\LaravelU...omponentServiceManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
33
    }
34
35
    /**
36
     * Method description:testConfigurationComponents.
37
     *
38
     * @author reallyli <[email protected]>
39
     * @since 18/10/11
40
     * @return mixed
41
     * 返回值类型:string,array,object,mixed(多种,不确定的),void(无返回值)
42
     */
43
    public function testConfigurationComponents()
44
    {
45
        $unicompoentConfig = include_once __DIR__.'/unicomponentConfig.php';
46
        $unicomponentServiceManager = new UnicomponentServiceManager($unicompoentConfig);
47
48
        $this->assertClassHasAttribute('test', get_class($unicomponentServiceManager->example()));
0 ignored issues
show
Documentation Bug introduced by
The method example does not exist on object<Reallyli\LaravelU...omponentServiceManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
    }
50
51
    /**
52
     * Method description:Test Get Component.
53
     *
54
     * @author reallyli <[email protected]>
55
     * @since 18/10/11
56
     * @return mixed
57
     * 返回值类型:string,array,object,mixed(多种,不确定的),void(无返回值)
58
     */
59
    public function testGetComponent()
60
    {
61
        $unicompoentConfig = include_once __DIR__.'/../config/unicomponent.php';
62
63
        $unicomponentServiceManager = new UnicomponentServiceManager($unicompoentConfig);
64
65
        $this->assertInstanceOf(Pusher::class, $unicomponentServiceManager->pusher);
0 ignored issues
show
Documentation introduced by
The property pusher does not exist on object<Reallyli\LaravelU...omponentServiceManager>. 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...
66
    }
67
}
68