Skip to content

Commit 9237c3d

Browse files
committed
test: upgrade to the new version
Closes #24
1 parent 470b788 commit 9237c3d

File tree

3 files changed

+24
-52
lines changed

3 files changed

+24
-52
lines changed

tests/GetMethodTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function test_should_get_file_contents_as_object(): void
6868

6969
file_put_contents($this->filepath, json_encode($value));
7070

71-
$content = $jsonFile->get(false);
71+
$content = $jsonFile->get(asObject: true);
7272

7373
$this->assertEquals((object) $value, $content);
7474
}

tests/SetMethodTest.php

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,94 +24,50 @@
2424

2525
class SetMethodTest extends TestCase
2626
{
27-
private string $filepath = __DIR__ . '/filename.json';
27+
protected string $filepath = __DIR__ . '/filename.json';
2828

29-
public function setUp(): void
29+
protected function setUp(): void
3030
{
3131
parent::setup();
3232
}
3333

34-
public function tearDown(): void
34+
protected function tearDown(): void
3535
{
3636
if (file_exists($this->filepath)) {
3737
unlink($this->filepath);
3838
}
3939
}
4040

41-
public function test_should_set_an_associative_array_on_json_file(): void
41+
public function test_should_allow_set_any_type_of_data(): void
4242
{
4343
$jsonFile = new Json($this->filepath);
4444

4545
$value = ['foo' => 'bar'];
46-
4746
$result = $jsonFile->set($value);
48-
4947
$this->assertEquals($value, $result);
50-
}
51-
52-
public function test_should_set_a_numeric_array_on_json_file(): void
53-
{
54-
$jsonFile = new Json($this->filepath);
5548

5649
$value = ['foo', 'bar'];
57-
5850
$result = $jsonFile->set($value);
59-
6051
$this->assertEquals($value, $result);
61-
}
62-
63-
public function test_should_set_an_object_on_json_file(): void
64-
{
65-
$jsonFile = new Json($this->filepath);
6652

6753
$value = ['foo' => 'bar'];
68-
6954
$result = $jsonFile->set((object) $value);
70-
7155
$this->assertEquals($value, $result);
72-
}
73-
74-
public function test_should_set_a_boolean_on_json_file(): void
75-
{
76-
$jsonFile = new Json($this->filepath);
7756

7857
$value = false;
79-
8058
$result = $jsonFile->set($value);
81-
8259
$this->assertEquals($value, $result);
83-
}
84-
85-
public function test_should_set_an_integer_on_json_file(): void
86-
{
87-
$jsonFile = new Json($this->filepath);
8860

8961
$value = 8;
90-
9162
$result = $jsonFile->set($value);
92-
9363
$this->assertEquals($value, $result);
94-
}
95-
96-
public function test_should_set_a_string_on_json_file(): void
97-
{
98-
$jsonFile = new Json($this->filepath);
9964

10065
$value = 'foo';
101-
10266
$result = $jsonFile->set($value);
103-
10467
$this->assertEquals($value, $result);
105-
}
106-
107-
public function test_should_set_a_null_on_json_file(): void
108-
{
109-
$jsonFile = new Json($this->filepath);
11068

11169
$value = null;
112-
11370
$result = $jsonFile->set($value);
114-
11571
$this->assertEquals($value, $result);
11672
}
11773

tests/UnsetMethodTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,31 @@ public function tearDown(): void
3838
}
3939
}
4040

41-
public function test_should_unset_element(): void
41+
public function test_should_unset_element_by_numeric_key(): void
4242
{
4343
$jsonFile = new Json($this->filepath);
4444

4545
$jsonFile->set([1, 2, 3]);
4646

47-
$value = $jsonFile->unset(2);
47+
$value = $jsonFile->unset(1);
4848

49-
$this->assertEquals([1, 2], $value);
49+
$this->assertEquals([0 => 1, 2 => 3], $value);
50+
}
51+
52+
public function test_should_unset_element_by_numeric_key_and_reindexed(): void
53+
{
54+
$jsonFile = new Json($this->filepath);
55+
56+
$jsonFile->set([1, 2, 3]);
57+
58+
$value = $jsonFile->unset(1, reindexed: true);
59+
60+
$this->assertEquals([1, 3], $value);
61+
}
62+
63+
public function test_should_unset_element_by_string_key(): void
64+
{
65+
$jsonFile = new Json($this->filepath);
5066

5167
$jsonFile->set(['foo' => 'bar']);
5268

0 commit comments

Comments
 (0)