Mercurial > hg > isophonics-drupal-site
comparison vendor/theseer/tokenizer/tests/TokenCollectionTest.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php declare(strict_types = 1); | |
2 namespace TheSeer\Tokenizer; | |
3 | |
4 use PHPUnit\Framework\TestCase; | |
5 | |
6 /** | |
7 * @covers \TheSeer\Tokenizer\TokenCollection | |
8 */ | |
9 class TokenCollectionTest extends TestCase { | |
10 | |
11 /** @var TokenCollection */ | |
12 private $collection; | |
13 | |
14 protected function setUp() { | |
15 $this->collection = new TokenCollection(); | |
16 } | |
17 | |
18 public function testCollectionIsInitiallyEmpty() { | |
19 $this->assertCount(0, $this->collection); | |
20 } | |
21 | |
22 public function testTokenCanBeAddedToCollection() { | |
23 $token = $this->createMock(Token::class); | |
24 $this->collection->addToken($token); | |
25 | |
26 $this->assertCount(1, $this->collection); | |
27 $this->assertSame($token, $this->collection[0]); | |
28 } | |
29 | |
30 public function testCanIterateOverTokens() { | |
31 $token = $this->createMock(Token::class); | |
32 $this->collection->addToken($token); | |
33 $this->collection->addToken($token); | |
34 | |
35 foreach($this->collection as $position => $current) { | |
36 $this->assertInternalType('integer', $position); | |
37 $this->assertSame($token, $current); | |
38 } | |
39 } | |
40 | |
41 public function testOffsetCanBeUnset() { | |
42 $token = $this->createMock(Token::class); | |
43 $this->collection->addToken($token); | |
44 | |
45 $this->assertCount(1, $this->collection); | |
46 unset($this->collection[0]); | |
47 $this->assertCount(0, $this->collection); | |
48 } | |
49 | |
50 public function testTokenCanBeSetViaOffsetPosition() { | |
51 $token = $this->createMock(Token::class); | |
52 $this->collection[0] = $token; | |
53 $this->assertCount(1, $this->collection); | |
54 $this->assertSame($token, $this->collection[0]); | |
55 } | |
56 | |
57 public function testTryingToUseNonIntegerOffsetThrowsException() { | |
58 $this->expectException(TokenCollectionException::class); | |
59 $this->collection['foo'] = $this->createMock(Token::class); | |
60 } | |
61 | |
62 public function testTryingToSetNonTokenAtOffsetThrowsException() { | |
63 $this->expectException(TokenCollectionException::class); | |
64 $this->collection[0] = 'abc'; | |
65 } | |
66 | |
67 public function testTryingToGetTokenAtNonExistingOffsetThrowsException() { | |
68 $this->expectException(TokenCollectionException::class); | |
69 $x = $this->collection[3]; | |
70 } | |
71 | |
72 } |