-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathStringParserTest.php
More file actions
69 lines (56 loc) · 1.58 KB
/
StringParserTest.php
File metadata and controls
69 lines (56 loc) · 1.58 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
65
66
67
68
69
<?php
declare( strict_types = 1 );
namespace ValueParsers\Tests;
use DataValues\DataValue;
use DataValues\StringValue;
use PHPUnit\Framework\TestCase;
use ValueParsers\Normalizers\StringNormalizer;
use ValueParsers\ParseException;
use ValueParsers\StringParser;
/**
* @covers \ValueParsers\StringParser
*
* @group ValueParsers
* @group DataValueExtensions
*
* @license GPL-2.0-or-later
* @author Daniel Kinzler
*/
class StringParserTest extends TestCase {
public function provideParse() {
$normalizer = $this->createMock( StringNormalizer::class );
$normalizer->expects( $this->once() )
->method( 'normalize' )
->willReturnCallback( static 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, DataValue $expected ) {
$parser = new StringParser( $normalizer );
$value = $parser->parse( $input );
$this->assertInstanceOf( StringValue::class, $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->expectException( ParseException::class );
$parser->parse( $input );
}
}