1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Badcow DNS Library. |
7
|
|
|
* |
8
|
|
|
* (c) Samuel Williams <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Tests\Parser; |
15
|
|
|
|
16
|
|
|
use Badcow\DNS\Parser\ResourceRecordIterator; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
class ResourceRecordIteratorTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
public function testNavigation(): void |
22
|
|
|
{ |
23
|
|
|
$string = 'this is a string consisting of some words'; |
24
|
|
|
$iterator = new ResourceRecordIterator($string); |
25
|
|
|
|
26
|
|
|
$this->assertEquals(0, $iterator->key()); |
27
|
|
|
|
28
|
|
|
$iterator->end(); |
29
|
|
|
$this->assertEquals('words', $iterator->current()); |
30
|
|
|
|
31
|
|
|
$iterator->next(); |
32
|
|
|
$this->assertFalse($iterator->valid()); |
33
|
|
|
|
34
|
|
|
$iterator->prev(); |
35
|
|
|
$this->assertEquals('words', $iterator->current()); |
36
|
|
|
|
37
|
|
|
$iterator->seek(2); |
38
|
|
|
$this->assertEquals('a', $iterator->current()); |
39
|
|
|
|
40
|
|
|
$iterator->prev(); |
41
|
|
|
$this->assertEquals('is', $iterator->current()); |
42
|
|
|
|
43
|
|
|
$iterator->seek(0); |
44
|
|
|
$this->assertEquals('this', $iterator->current()); |
45
|
|
|
|
46
|
|
|
$this->expectException(\OutOfBoundsException::class); |
47
|
|
|
$iterator->prev(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testGetRemainingAsString(): void |
51
|
|
|
{ |
52
|
|
|
$string = 'this is a string consisting of some words'; |
53
|
|
|
$iterator = new ResourceRecordIterator($string); |
54
|
|
|
$iterator->seek(3); |
55
|
|
|
|
56
|
|
|
$this->assertEquals('string consisting of some words', $iterator->getRemainingAsString()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testToString(): void |
60
|
|
|
{ |
61
|
|
|
$string = 'this is a string consisting of some words'; |
62
|
|
|
$iterator = new ResourceRecordIterator($string); |
63
|
|
|
|
64
|
|
|
$this->assertEquals($string, (string) $iterator); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|