Completed
Push — master ( a3c7a7...bd72ff )
by Carlos
02:47
created

ShelfTest::shelf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4286
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: pjxh
6
 * Date: 15-11-1
7
 * Time: 下午5:10
8
 */
9
namespace Overtrue\Wechat\Test\Shop;
10
11
12
use Overtrue\Wechat\Image;
13
use Overtrue\Wechat\Shop\Data\Shelf as ShelfData;
14
use Overtrue\Wechat\Shop\Shelf;
15
use Overtrue\Wechat\Test\TestBase;
16
17
class ShelfTest extends TestBase
18
{
19
20
    protected $url;
21
22
    protected function setUp()
23
    {
24
        parent::setUp();
25
26
        $img = new Image($this->config->appId,$this->config->appSecret);
0 ignored issues
show
Documentation introduced by
The property appId does not exist on object<Overtrue\Wechat\Shop\Config>. 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...
Documentation introduced by
The property appSecret does not exist on object<Overtrue\Wechat\Shop\Config>. 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...
27
28
        $this->url = $img->upload(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Image'.DIRECTORY_SEPARATOR.'aa.jpg');
29
30
    }
31
32
    public static function shelf($arry = false)
33
    {
34
        $groupId = '207133170';
35
36
        $shelf = new ShelfData();
37
        $shelf->controlTwo(array($groupId,$groupId,$groupId));
38
39
        if ($arry) return $shelf->toArray();
40
41
        return $shelf;
42
    }
43
44 View Code Duplication
    public function testAdd()
45
    {
46
47
        $shelfData = $this->shelf();
48
49
        $shelf = new Shelf($this->http);
50
        $response = $shelf->add(function(ShelfData $shelf) use ($shelfData) {
0 ignored issues
show
Unused Code introduced by
The parameter $shelf 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...
51
            return $shelfData;
52
        },$this->url,'test');
53
        $this->assertTrue(is_array($response));
54
55
        return $response['shelf_id'];
56
    }
57
58
    /**
59
     * @depends testAdd
60
     */
61 View Code Duplication
    public function testUpdate($shelfId)
62
    {
63
64
        $shelfData = $this->shelf();
65
66
        $shelf = new Shelf($this->http);
67
        $response = $shelf->update(function(ShelfData $shelf) use ($shelfData) {
0 ignored issues
show
Unused Code introduced by
The parameter $shelf 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...
68
            return $shelfData;
69
        }, $shelfId, $this->url,'测试');
70
71
        $this->assertTrue($response);
72
    }
73
74
    public function testLists()
75
    {
76
        
77
        $shelf = new Shelf($this->http);
78
        $response = $shelf->lists();
79
        $this->assertTrue(is_array($response));
80
    }
81
82
    /**
83
     * @depends testAdd
84
     */
85
    public function testGetById($shelfId)
86
    {
87
        
88
        $shelf = new Shelf($this->http);
89
        $response = $shelf->getById($shelfId);
90
        $this->assertTrue(is_array($response));
91
    }
92
93
    /**
94
     * @depends testAdd
95
     */
96
    public function testDelete($shelfId)
97
    {
98
99
        $shelf = new Shelf($this->http);
100
        $response = $shelf->delete($shelfId);
101
        $this->assertTrue($response);
102
    }
103
}
104