Passed
Branch master (41ef34)
by Roberto
04:08
created

AddressComponentTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 19
c 0
b 0
f 0
rs 9.8333
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2018 - present
4
 * Google Maps PHP - AddressComponentTest.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 5/9/2018
8
 * MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\geocode\Tests;
12
13
use Biscolab\GoogleMaps\Fields\AddressComponentFields;
14
use Biscolab\GoogleMaps\Object\Address;
15
use Biscolab\GoogleMaps\Object\AddressComponent;
16
use PHPUnit\Framework\TestCase;
17
18
/**
19
 * Class AddressComponentTest
20
 * @package Biscolab\geocode\Tests
21
 */
22
class AddressComponentTest extends TestCase {
23
24
	/**
25
	 * @var AddressComponent
26
	 */
27
	private $address_component_1;
28
29
	/**
30
	 * @var AddressComponent
31
	 */
32
	private $address_component_2;
33
34
	public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ {
35
36
		parent::setUp(); // TODO: Change the autogenerated stub
37
38
		$this->address_component_1 = new AddressComponent([
39
			AddressComponentFields::LONG_NAME  => 'Location Long name',
40
			AddressComponentFields::SHORT_NAME => 'Location Short name',
41
			AddressComponentFields::TYPES      => [
42
				'type 1',
43
				'type 2',
44
			]
45
		]);
46
47
		$this->address_component_2 = new AddressComponent([
48
			AddressComponentFields::LONG_NAME  => 'Location Long name (second)',
49
			AddressComponentFields::SHORT_NAME => 'Location Short name (second)',
50
			AddressComponentFields::TYPES      => [
51
				'type 3',
52
				'type 4',
53
			]
54
		]);
55
	}
56
57
	/**
58
	 * @test
59
	 */
60
	public function testAddressComponentInit() {
61
62
		$address_component = $this->address_component_1;
63
64
		$this->assertEquals('Location Long name', $address_component->getLongName());
0 ignored issues
show
Bug introduced by
The method getLongName() does not exist on Biscolab\GoogleMaps\Object\AddressComponent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
		$this->assertEquals('Location Long name', $address_component->/** @scrutinizer ignore-call */ getLongName());
Loading history...
65
		$this->assertEquals('Location Short name', $address_component->getShortName());
0 ignored issues
show
Bug introduced by
The method getShortName() does not exist on Biscolab\GoogleMaps\Object\AddressComponent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
		$this->assertEquals('Location Short name', $address_component->/** @scrutinizer ignore-call */ getShortName());
Loading history...
66
		$this->assertEquals([
67
			'type 1',
68
			'type 2',
69
		], $address_component->getTypes());
0 ignored issues
show
Bug introduced by
The method getTypes() does not exist on Biscolab\GoogleMaps\Object\AddressComponent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
		], $address_component->/** @scrutinizer ignore-call */ getTypes());
Loading history...
70
71
		$this->assertEquals(2, count($address_component->getTypes()));
72
		$this->assertArrayNotHasKey(3, $address_component->getTypes());
73
74
	}
75
76
	/**
77
	 * @test
78
	 */
79
	public function testAddressItems() {
80
81
		$address = new Address();
82
83
		$address->addItem($this->address_component_1);
84
		$address->addItem($this->address_component_2);
85
86
		$this->assertEquals(2, $address->count());
87
		$this->assertEquals($this->address_component_1, $address->first());
88
		$this->assertEquals($this->address_component_2, $address->last());
89
		$this->assertEquals(1, $address->getLastIndex());
90
	}
91
92
	/**
93
	 * @test
94
	 */
95
	public function testAddressIndex() {
96
97
		$address = new Address();
98
99
		$address->addItem($this->address_component_1);
100
		$address->addItem($this->address_component_2);
101
102
		$this->assertEquals($this->address_component_1, $address->current());
103
104
		$address->seek(1);
105
		$this->assertEquals($this->address_component_2, $address->current());
106
	}
107
}
108