1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Clubdeuce\WPLib\Components\GoogleMaps\Tests; |
4
|
|
|
|
5
|
|
|
use Mockery\Mock; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class TestCase |
9
|
|
|
* @package Clubdeuce\WPLib\Components\GoogleMaps\Tests |
10
|
|
|
*/ |
11
|
|
|
class TestCase extends \WP_UnitTestCase { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @param $class |
15
|
|
|
* @param $property |
16
|
|
|
* @return mixed |
17
|
|
|
*/ |
18
|
|
|
public function getReflectionPropertyValue( $class, $property ) |
19
|
|
|
{ |
20
|
|
|
$reflection = new \ReflectionProperty( $class, $property ); |
21
|
|
|
$reflection->setAccessible( true ); |
22
|
|
|
return $reflection->getValue( $class ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param $class |
27
|
|
|
* @param $property |
28
|
|
|
* @param $value |
29
|
|
|
*/ |
30
|
|
|
public function setReflectionPropertyValue( $class, $property, $value ) |
31
|
|
|
{ |
32
|
|
|
$reflection = new \ReflectionProperty( $class, $property ); |
33
|
|
|
$reflection->setAccessible( true ); |
34
|
|
|
return $reflection->setValue( $class, $value ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param $class |
39
|
|
|
* @param $method |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
public function reflectionMethodInvoke( $class, $method ) |
43
|
|
|
{ |
44
|
|
|
$reflection = new \ReflectionMethod( $class, $method ); |
45
|
|
|
$reflection->setAccessible( true ); |
46
|
|
|
if (is_string($class)) { |
47
|
|
|
$class = null; |
48
|
|
|
} |
49
|
|
|
return $reflection->invoke( $class ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $class |
54
|
|
|
* @param $method |
55
|
|
|
* @param $args |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
|
public function reflectionMethodInvokeArgs( $class, $method, $args ) |
59
|
|
|
{ |
60
|
|
|
$reflection = new \ReflectionMethod( $class, $method ); |
61
|
|
|
$reflection->setAccessible( true ); |
62
|
|
|
if (is_string($class)) { |
63
|
|
|
$class = null; |
64
|
|
|
} |
65
|
|
|
return $reflection->invoke( $class, $args ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
protected function get_sample_response() { |
72
|
|
|
|
73
|
|
|
return file_get_contents( __DIR__ . '/geocoder-response.json' ); |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return Mock |
79
|
|
|
*/ |
80
|
|
|
protected function mockGeocoder() { |
81
|
|
|
$geocoder = \Mockery::mock('\Clubdeuce\WPLib\Components\GoogleMaps\Geocoder'); |
82
|
|
|
$geocoder->shouldReceive('geocode')->andReturn($this->mockLocation()); |
83
|
|
|
|
84
|
|
|
return $geocoder; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return Mock |
89
|
|
|
*/ |
90
|
|
|
protected function mockLocation() { |
91
|
|
|
$location = \Mockery::mock('\Clubdeuce\WPLib\Components\GoogleMape\Location'); |
92
|
|
|
$location->shouldReceive('address')->andReturn('1600 Amphitheatre Parkway, Mountain View, CA 94043, USA'); |
93
|
|
|
$location->shouldReceive('formatted_address')->andReturn('1600 Amphitheatre Parkway, Mountain View, CA 94043, USA'); |
94
|
|
|
$location->shouldReceive('state')->andReturn('CA'); |
95
|
|
|
$location->shouldReceive('zip_code')->andReturn('94043'); |
96
|
|
|
$location->shouldReceive('latitude')->andReturn(37.4224764); |
97
|
|
|
$location->shouldReceive('longitude')->andReturn(-122.0842499); |
98
|
|
|
$location->shouldReceive('place_id')->andReturn('ChIJ2eUgeAK6j4ARbn5u_wAGqWA'); |
99
|
|
|
$location->shouldReceive('type')->andReturn('street_address'); |
100
|
|
|
$location->shouldReceive('viewport')->andReturn(array( |
101
|
|
|
'northeast' => array( |
102
|
|
|
'lat' => 37.4238253802915, |
103
|
|
|
'lng' => -122.0829009197085 |
104
|
|
|
), |
105
|
|
|
'sourhwest' => array( |
106
|
|
|
'lat' => 37.4211274197085, |
107
|
|
|
'lng' => -122.0855988802915 |
108
|
|
|
) |
109
|
|
|
)); |
110
|
|
|
|
111
|
|
|
return $location; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return \Mockery\MockInterface |
116
|
|
|
*/ |
117
|
|
|
protected function mockLabel() { |
118
|
|
|
$label = \Mockery::mock(); |
119
|
|
|
|
120
|
|
|
$label->shouldReceive('color')->andReturn('black'); |
121
|
|
|
$label->shouldReceive('font_family')->andReturn('Arial'); |
122
|
|
|
$label->shouldReceive('font_size')->andReturn('12px'); |
123
|
|
|
$label->shouldReceive('font_weight')->andReturn(900); |
124
|
|
|
$label->shouldReceive('text')->andReturn('Sample Label Text'); |
125
|
|
|
|
126
|
|
|
return $label; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return \Mockery\MockInterface |
131
|
|
|
*/ |
132
|
|
|
protected function mockMarker() { |
133
|
|
|
$marker = \Mockery::mock(); |
134
|
|
|
|
135
|
|
|
$marker->shouldReceive('label')->andReturn($this->mockLabel()); |
136
|
|
|
$marker->shouldReceive('position')->andReturn(array('lat' => 100, 'lng' => -100)); |
137
|
|
|
$marker->shouldReceive('title')->andReturn('Sample Title'); |
138
|
|
|
$marker->shouldReceive('info_window')->andReturn($this->mockInfoWindow()); |
139
|
|
|
|
140
|
|
|
return $marker; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return \Mockery\MockInterface |
145
|
|
|
*/ |
146
|
|
|
protected function mockInfoWindow() { |
147
|
|
|
$window = \Mockery::mock(); |
148
|
|
|
|
149
|
|
|
$window->shouldReceive('content')->andReturn('Sample Info Window Content'); |
150
|
|
|
$window->shouldReceive('pixel_offset')->andReturn(12); |
151
|
|
|
$window->shouldReceive('position')->andReturn(null); |
152
|
|
|
$window->shouldReceive('max_width')->andReturn(null); |
153
|
|
|
return $window; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param array $args |
158
|
|
|
* |
159
|
|
|
* @return \Mockery\MockInterface |
160
|
|
|
*/ |
161
|
|
|
protected function _mock($args = array()) { |
162
|
|
|
$mock = \Mockery::mock(); |
163
|
|
|
|
164
|
|
|
$args = wp_parse_args($args, array( |
165
|
|
|
'foo' => 'bar' |
166
|
|
|
)); |
167
|
|
|
|
168
|
|
|
foreach ($args as $key => $val) { |
169
|
|
|
$mock->shouldReceive($key)->andReturn($val); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return $mock; |
173
|
|
|
} |
174
|
|
|
} |