1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\DataValues\Geo\Parsers; |
4
|
|
|
|
5
|
|
|
use DataValues\DataValue; |
6
|
|
|
use ValueParsers\ParseException; |
7
|
|
|
use ValueParsers\ValueParser; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @deprecated |
11
|
|
|
* TODO: remove |
12
|
|
|
* This is a copy of ValueParserTestBase from DataValues Common, |
13
|
|
|
* created so we can stop depending on that comment even though we |
14
|
|
|
* did not refactor away the inheritance abuse here yet. |
15
|
|
|
* |
16
|
|
|
* @license GPL-2.0+ |
17
|
|
|
*/ |
18
|
|
|
abstract class ParserTestBase extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return array[] |
22
|
|
|
*/ |
23
|
|
|
abstract public function validInputProvider(); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return array[] |
27
|
|
|
*/ |
28
|
|
|
abstract public function invalidInputProvider(); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return ValueParser |
32
|
|
|
*/ |
33
|
|
|
abstract protected function getInstance(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @dataProvider validInputProvider |
37
|
|
|
* @param mixed $value |
38
|
|
|
* @param mixed $expected |
39
|
|
|
* @param ValueParser|null $parser |
40
|
|
|
*/ |
41
|
|
|
public function testParseWithValidInputs( $value, $expected, ValueParser $parser = null ) { |
42
|
|
|
if ( $parser === null ) { |
43
|
|
|
$parser = $this->getInstance(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->assertSmartEquals( $expected, $parser->parse( $value ) ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param DataValue|mixed $expected |
51
|
|
|
* @param DataValue|mixed $actual |
52
|
|
|
*/ |
53
|
|
|
private function assertSmartEquals( $expected, $actual ) { |
54
|
|
|
if ( $expected instanceof DataValue && $actual instanceof DataValue ) { |
55
|
|
|
$msg = "testing equals():\n" |
56
|
|
|
. preg_replace( '/\s+/', ' ', print_r( $actual->toArray(), true ) ) . " should equal\n" |
57
|
|
|
. preg_replace( '/\s+/', ' ', print_r( $expected->toArray(), true ) ); |
58
|
|
|
} else { |
59
|
|
|
$msg = 'testing equals()'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->assertTrue( $expected->equals( $actual ), $msg ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider invalidInputProvider |
67
|
|
|
* @param mixed $value |
68
|
|
|
* @param ValueParser|null $parser |
69
|
|
|
*/ |
70
|
|
|
public function testParseWithInvalidInputs( $value, ValueParser $parser = null ) { |
71
|
|
|
if ( $parser === null ) { |
72
|
|
|
$parser = $this->getInstance(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->setExpectedException( ParseException::class ); |
76
|
|
|
$parser->parse( $value ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|