5
5
namespace Steevanb \PhpCollection \Tests \Unit \AbstractCollection ;
6
6
7
7
use PHPUnit \Framework \TestCase ;
8
+ use Steevanb \PhpCollection \Exception \ReadOnlyException ;
8
9
10
+ /** @covers \Steevanb\PhpCollection\AbstractCollection::doReplace */
9
11
final class DoReplaceTest extends TestCase
10
12
{
11
- public function testConstructorValues (): void
13
+ public function testDoReplace (): void
12
14
{
13
- $ collection = new Collection ([10 , 11 , 12 , 13 ]);
15
+ $ collection = (new Collection ())
16
+ ->callDoReplace ([10 , 11 , 12 , 13 ]);
14
17
15
18
static ::assertCount (4 , $ collection );
16
19
static ::assertSame (10 , $ collection ->callDoGet (0 ));
@@ -19,15 +22,24 @@ public function testConstructorValues(): void
19
22
static ::assertSame (13 , $ collection ->callDoGet (3 ));
20
23
}
21
24
22
- public function testReplace (): void
25
+ public function testCalledFromConstructor (): void
23
26
{
24
- $ collection = (new Collection ())
25
- ->callDoReplace ([10 , 11 , 12 , 13 ]);
27
+ $ collection = new Collection ([10 , 11 , 12 , 13 ]);
26
28
27
29
static ::assertCount (4 , $ collection );
28
30
static ::assertSame (10 , $ collection ->callDoGet (0 ));
29
31
static ::assertSame (11 , $ collection ->callDoGet (1 ));
30
32
static ::assertSame (12 , $ collection ->callDoGet (2 ));
31
33
static ::assertSame (13 , $ collection ->callDoGet (3 ));
32
34
}
35
+
36
+ public function testReadOnly (): void
37
+ {
38
+ $ collection = (new Collection ([1 , 2 ]))->setReadOnly ();
39
+
40
+ $ this ->expectException (ReadOnlyException::class);
41
+ $ this ->expectExceptionMessage ('This collection is read only, you cannot edit it \'s values. ' );
42
+ $ this ->expectExceptionCode (0 );
43
+ $ collection ->callDoReplace ([3 , 4 ]);
44
+ }
33
45
}
0 commit comments