Skip to content

Commit bf65004

Browse files
[11.x] Add some tests in RepositoryTest.php (#51041)
* Enhance test coverage by adding tests for the offsetExists method * Enhance test coverage by adding tests for the offsetSet method * Fix assertion order in testItGetsAsString method
1 parent 61716c9 commit bf65004

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/Config/RepositoryTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,21 @@ public function testAll()
221221

222222
public function testOffsetExists()
223223
{
224+
$data = [
225+
'foo' => 'bar',
226+
'null_value' => null,
227+
'empty_string' => '',
228+
'numeric_value' => 123,
229+
];
230+
$this->repository->set($data);
231+
224232
$this->assertTrue(isset($this->repository['foo']));
225233
$this->assertFalse(isset($this->repository['not-exist']));
234+
$this->assertTrue(isset($this->repository['null_value']));
235+
$this->assertTrue(isset($this->repository['empty_string']));
236+
$this->assertTrue(isset($this->repository['numeric_value']));
237+
$this->assertFalse(isset($this->repository[-1]));
238+
$this->assertFalse(isset($this->repository['non_numeric']));
226239
}
227240

228241
public function testOffsetGet()
@@ -242,6 +255,18 @@ public function testOffsetSet()
242255
$this->repository['key'] = 'value';
243256

244257
$this->assertSame('value', $this->repository['key']);
258+
259+
$this->repository['key'] = 'new_value';
260+
$this->assertSame('new_value', $this->repository['key']);
261+
262+
$this->repository['new_key'] = null;
263+
$this->assertNull($this->repository['new_key']);
264+
265+
$this->repository[''] = 'value';
266+
$this->assertSame('value', $this->repository['']);
267+
268+
$this->repository[123] = '123';
269+
$this->assertSame('123', $this->repository[123]);
245270
}
246271

247272
public function testOffsetUnset()
@@ -267,7 +292,7 @@ public function testsItIsMacroable()
267292
public function testItGetsAsString(): void
268293
{
269294
$this->assertSame(
270-
$this->repository->string('a.b'), 'c'
295+
'c', $this->repository->string('a.b')
271296
);
272297
}
273298

0 commit comments

Comments
 (0)