Passed
Push — developer ( e61241...995043 )
by Radosław
28:27 queued 12:46
created

MapCoordinates::testConvertExceptionFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Test file for `\App\Fields\MapCoordinates`.
4
 *
5
 * @see \App\Fields\MapCoordinates
6
 *
7
 * @package   Tests
8
 *
9
 * @copyright YetiForce S.A.
10
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
11
 * @author    Mariusz Krzaczkowski <[email protected]>
12
 */
13
14
namespace Tests\App\Fields;
15
16
/**
17
 * Test class for `\App\Fields\MapCoordinates`.
18
 */
19
class MapCoordinates extends \Tests\Base
20
{
21
	/** @return array Provide test data for testConvert function. */
22
	public function convertProvider(): array
23
	{
24
		return [
25
			['decimal', 'decimal', ['lat' => 52.23155431436567, 'lon' => 21.00499528120955], ['lat' => 52.23155431436567, 'lon' => 21.00499528120955]],
26
			['decimal', 'degrees', ['lat' => 52.23155431436567, 'lon' => 21.00499528120955], ['lat' => '52°13\'53.5955"N', 'lon' => '21°0\'17.983"E']],
27
			['decimal', 'degrees', ['lat' => 30, 'lon' => 33.3], ['lat' => '33°N', 'lon' => '33°18\'E']],
28
			['degrees', 'decimal', ['lat' => 'N 50°12\'13.1188"', 'lon' => 'E 21°0\'17.983"'], ['lat' => 50.203644111111, 'lon' => 21.004995277778]],
29
			['degrees', 'decimal', ['lat' => 'N50°12\'13.1188"', 'lon' => 'E21°0\'17.983"'], ['lat' => 50.203644111111, 'lon' => 21.004995277778]],
30
			['degrees', 'decimal', ['lat' => '50°12\'13.1188" N', 'lon' => '21°0\'17.983" E'], ['lat' => 50.203644111111, 'lon' => 21.004995277778]],
31
			['degrees', 'decimal', ['lat' => '50°12\'13.1188"N', 'lon' => '21°0\'17.983"E'], ['lat' => 50.203644111111, 'lon' => 21.004995277778]],
32
			['decimal', 'codeplus', ['lat' => 52.23155431436567, 'lon' => 21.00499528120955], '9G4362J3+JXH5'],
33
			['codeplus', 'decimal', '9G4362J3+GR', ['lat' => 52.2313125, 'lon' => 21.0045625]],
34
		];
35
	}
36
37
	/**
38
	 * Testing process `\App\Fields\MapCoordinates::convert` function.
39
	 *
40
	 * @dataProvider convertProvider
41
	 *
42
	 * @see \App\Fields\MapCoordinates::convert()
43
	 *
44
	 * @param string $from
45
	 * @param string $to
46
	 * @param mixed  $value
47
	 * @param mixed  $result
48
	 */
49
	public function testConvert(string $from, string $to, $value, $result): void
50
	{
51
		$this->assertSame($result, \App\Fields\MapCoordinates::convert($from, $to, $value));
52
	}
53
54
	/**
55
	 * Exception testing for conversion.
56
	 *
57
	 * @throws \App\Exceptions\AppException
58
	 */
59
	public function testConvertExceptionFrom(): void
60
	{
61
		$this->expectException(\App\Exceptions\AppException::class);
62
		\App\Fields\MapCoordinates::convert('test', 'decimal', ['lat' => 52.23155431436567, 'lon' => 21.00499528120955]);
63
	}
64
65
	/**
66
	 * Exception testing for conversion.
67
	 *
68
	 * @throws \App\Exceptions\AppException
69
	 */
70
	public function testConvertExceptionTo(): void
71
	{
72
		$this->expectException(\App\Exceptions\AppException::class);
73
		\App\Fields\MapCoordinates::convert('decimal', 'test', ['lat' => 52.23155431436567, 'lon' => 21.00499528120955]);
74
	}
75
}
76