Completed
Pull Request — master (#22)
by Daryl
07:43
created

TestLocationModel::testHasLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Clubdeuce\WPLib\Components\GoogleMaps\Tests\Unit;
4
5
use Clubdeuce\WPGoogleMaps\Location as MLoc;
6
use Clubdeuce\WPGoogleMaps\Location as Loc;
7
use Clubdeuce\WPLib\Components\GoogleMaps\Location_Model;
8
use Clubdeuce\WPLib\Components\GoogleMaps\Tests\TestCase;
9
10
/**
11
 * Class TestLocationModel
12
 * @package            Clubdeuce\WPLib\Components\GoogleMaps\Tests\Integration
13
 * @coversDefaultClass Clubdeuce\WPLib\Components\GoogleMaps\Location_Model
14
 * @group              Location
15
 */
16
class TestLocationModel extends TestCase {
17
18
	/**
19
	 * @var Location_Model
20
	 */
21
	private $_location;
22
23
	public function setUp() {
24
		$this->_location = new Location_Model(array('location' => $this->_getMockLocation()));
25
		parent::setUp();
26
	}
27
28
	/**
29
	 * @covers ::__construct
30
	 * @covers ::__call
31
	 */
32
	public function testConstruct() {
33
		$this->assertEquals(self::_getMockLocation(), $this->_location->location());
0 ignored issues
show
Bug introduced by
The method location() does not exist on Clubdeuce\WPLib\Componen...ogleMaps\Location_Model. Did you maybe mean has_location()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
	}
35
36
	/**
37
	 * @covers ::__construct
38
	 * @covers ::__call
39
	 */
40
	public function testConstructDefaults() {
41
		$location = new Location_Model();
42
		$this->assertTrue($location->has_location());
43
		$this->assertInstanceOf(Loc::class, $location->location());
0 ignored issues
show
Bug introduced by
The method location() does not exist on Clubdeuce\WPLib\Componen...ogleMaps\Location_Model. Did you maybe mean has_location()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
44
	}
45
46
	/**
47
	 * @covers ::__construct
48
	 * @covers ::has_location
49
	 */
50
	public function testHasLocation() {
51
		$this->assertTrue($this->_location->has_location());
52
	}
53
54
	/**
55
	 * @covers ::__call
56
	 */
57
	public function testMagicMethodCall() {
58
		$this->assertEquals('bar', $this->_location->foo());
0 ignored issues
show
Documentation Bug introduced by
The method foo does not exist on object<Clubdeuce\WPLib\C...gleMaps\Location_Model>? 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...
59
	}
60
61
	/**
62
	 * @covers ::__call
63
	 */
64
	public function testMagicMethodCallNull() {
65
		$location = new Location_Model(array('location' => null));
66
		$this->assertNull($location->latitude());
67
	}
68
69
	/**
70
	 * @return \Mockery\MockInterface
71
	 */
72
	private function _getMockLocation() {
73
		$location = \Mockery::mock(MLoc::class);
74
75
		$location->shouldReceive('foo')->andReturn('bar');
76
77
		return $location;
78
	}
79
}