Completed
Push — master ( 51cf8d...934849 )
by Daryl
01:38
created

testMapModel::testWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Clubdeuce\WPLib\Components\GoogleMaps\Tests\UnitTests;
4
5
use Clubdeuce\WPLib\Components\GoogleMaps\Map_Model;
6
use Clubdeuce\WPLib\Components\GoogleMaps\Tests\TestCase;
7
8
/**
9
 * Class testMapModel
10
 * @package Clubdeuce\WPLib\Components\GoogleMaps\Tests\UnitTests
11
 * @coversDefaultClass Clubdeuce\WPLib\Components\GoogleMaps\Map_Model
12
 * @group Map
13
 */
14
class testMapModel extends TestCase {
15
16
    /**
17
     * @var array
18
     */
19
    private $_center = array( 'lat' => 100.23435532, 'lng' => -100.1234642345325 );
20
21
    /**
22
     * @var Map_Model
23
     */
24
    private $_model;
25
    
26
    public function setUp() {
27
        
28
        $this->_model = new Map_Model(array('center' => $this->_center, 'markers' => array('foo', 'bar', 'baz'), 'zoom' => 12));
29
        
30
    }
31
32
    /**
33
     * @covers ::center
34
     */
35
    public function testCenter() {
36
37
        $this->assertEquals($this->_center, $this->_model->center());
38
39
    }
40
41
    /**
42
     * @covers ::markers
43
     */
44
    public function testMarkers() {
45
46
        $this->assertEquals(array('foo','bar','baz'), $this->_model->markers());
47
48
    }
49
50
    /**
51
     * @depends testMarkers
52
     * @covers ::add_marker
53
     */
54
    function testAddMarker() {
55
56
        $this->_model->add_marker('foobar');
0 ignored issues
show
Documentation introduced by
'foobar' is of type string, but the function expects a object<Clubdeuce\WPLib\C...ents\GoogleMaps\Marker>.

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...
57
58
        $this->assertContains('foobar', $this->_model->markers());
59
60
    }
61
62
    /**
63
     * @depends testMarkers
64
     * @covers ::add_markers
65
     */
66
    function testAddMarkers() {
67
68
        $this->_model->add_markers(array('foobar', 'barbaz'));
0 ignored issues
show
Documentation introduced by
array('foobar', 'barbaz') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a array<integer,object<Clu...nts\GoogleMaps\Marker>>.

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...
69
70
        $markers = $this->_model->markers();
71
72
        $this->assertContains('foobar', $markers);
73
        $this->assertContains('barbaz', $markers);
74
75
    }
76
77
    /**
78
     * @covers ::zoom
79
     */
80
    public function testZoom() {
81
        $this->assertEquals(12, $this->_model->zoom());
82
    }
83
84
	/**
85
	 * @covers ::make_args
86
	 */
87
    public function testMakeArgs() {
88
89
    	$args = $this->_model->make_args();
90
91
	    $this->assertInternalType('array', $args);
92
	    $this->assertArrayHasKey('center', $args);
93
	    $this->assertArrayHasKey('zoom', $args);
94
	    $this->assertInternalType('array', $args['center']);
95
	    $this->assertInternalType('integer', $args['zoom']);
96
	    $this->assertArrayHasKey('lat', $args['center']);
97
	    $this->assertArrayHasKey('lat', $args['center']);
98
	    $this->assertInternalType('float', $args['center']['lat']);
99
	    $this->assertInternalType('float', $args['center']['lng']);
100
101
    }
102
103
	/**
104
	 * @covers ::height
105
	 */
106
    public function testHeight() {
107
108
    	$this->assertEquals('400px', $this->_model->height());
109
110
    }
111
112
	/**
113
	 * @covers ::width
114
	 */
115
    public function testWidth() {
116
117
    	$this->assertEquals('100%', $this->_model->width());
118
119
    }
120
}
121