forked from DataValues/Common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringParserTest.php
More file actions
64 lines (54 loc) · 1.56 KB
/
StringParserTest.php
File metadata and controls
64 lines (54 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace ValueParsers\Test;
use DataValues\DataValue;
use DataValues\StringValue;
use ValueParsers\Normalizers\StringNormalizer;
use ValueParsers\ParseException;
use ValueParsers\StringParser;
/**
* @covers ValueParsers\StringParser
*
* @group ValueParsers
* @group DataValueExtensions
*
* @license GPL-2.0+
* @author Daniel Kinzler
*/
class StringParserTest extends \PHPUnit_Framework_TestCase {
public function provideParse() {
$normalizer = $this->getMock( 'ValueParsers\Normalizers\StringNormalizer' );
$normalizer->expects( $this->once() )
->method( 'normalize' )
->will( $this->returnCallback( function( $value ) {
return strtolower( trim( $value ) );
} ) );
return [
'simple' => [ 'hello world', null, new StringValue( 'hello world' ) ],
'normalize' => [ ' Hello World ', $normalizer, new StringValue( 'hello world' ) ],
];
}
/**
* @dataProvider provideParse
*/
public function testParse( $input, StringNormalizer $normalizer = null, DataValue $expected ) {
$parser = new StringParser( $normalizer );
$value = $parser->parse( $input );
$this->assertInstanceOf( 'DataValues\StringValue', $value );
$this->assertEquals( $expected->toArray(), $value->toArray() );
}
public function nonStringProvider() {
return [
'null' => [ null ],
'array' => [ [] ],
'int' => [ 7 ],
];
}
/**
* @dataProvider nonStringProvider
*/
public function testGivenNonString_parseThrowsException( $input ) {
$parser = new StringParser();
$this->setExpectedException( ParseException::class );
$parser->parse( $input );
}
}