Skip to content

Commit adafe41

Browse files
committed
feat(): improve and add test for readinifile class
1 parent edecbd5 commit adafe41

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
vendor
22
composer.lock
33
coverage
4-
index.php
5-
6-
# test file ini
7-
file.ini
84
tests/file_ini/*_test.ini

tests/ExceptionTest.php

+13-19
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,29 @@ class ExceptionTest extends TestCase
77
{
88
private $file = 'tests/file_ini/CorruptiniFile.ini';
99

10-
public function testLoadWithoutCorruptiniFile()
10+
public function testParseWithCorruptiniFile()
1111
{
12-
chmod($this->file, 0000);
13-
1412
try {
15-
$object = new WriteiniFile($this->file);
16-
} catch (\Exception $e) {
17-
$error = $e->getMessage();
13+
chmod($this->file, 0000);
14+
(new WriteiniFile($this->file));
15+
chmod($this->file, 0644);
16+
} catch (\Exception $error) {
1817
}
1918

20-
$this->assertEquals($error, "Unable to parse file ini: {$this->file}");
19+
$this->assertEquals("Unable to parse file ini: {$this->file}", $error->getMessage());
2120
}
2221

23-
public function testWriteInCorruptiniFile()
22+
public function testWriteinCorruptiniFile()
2423
{
25-
chmod($this->file, 0644);
26-
2724
try {
28-
$object = new WriteiniFile($this->file);
29-
$object->create([
30-
'section 1' => ['foo' => 'string']
31-
]);
25+
chmod($this->file, 0644);
26+
$test = (new WriteiniFile($this->file))->create(['section 1' => ['foo' => 'string']]);
3227
chmod($this->file, 0000);
33-
$object->write();
34-
} catch (\Exception $e) {
35-
$error = $e->getMessage();
28+
$test->write();
29+
chmod($this->file, 0644);
30+
} catch (\Exception $error) {
3631
}
3732

38-
$this->assertEquals($error, "Unable to write in the file ini: {$this->file}");
39-
chmod($this->file, 0644);
33+
$this->assertEquals("Unable to write in the file ini: {$this->file}", $error->getMessage());
4034
}
4135
}

tests/ReadiniFileTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use WriteiniFile\ReadiniFile;
5+
6+
class ReadiniFileTest extends TestCase
7+
{
8+
public function testFileiniDoesnotExist()
9+
{
10+
try {
11+
ReadiniFile::data('tests/file_ini/fileDoesnotExist.ini');
12+
} catch (\Exception $error) {
13+
}
14+
15+
$this->assertEquals('File ini does not exist: tests/file_ini/fileDoesnotExist.ini', $error->getMessage());
16+
}
17+
18+
public function testUnabletoParseFileini()
19+
{
20+
try {
21+
chmod('tests/file_ini/CorruptiniFile.ini', 0000);
22+
ReadiniFile::data('tests/file_ini/CorruptiniFile.ini');
23+
chmod('tests/file_ini/CorruptiniFile.ini', 0644);
24+
} catch (\Exception $error) {
25+
}
26+
27+
$this->assertEquals('Unable to parse file ini: tests/file_ini/CorruptiniFile.ini', $error->getMessage());
28+
}
29+
}

tests/WriteIniFileTest.php renamed to tests/WriteiniFileTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use WriteiniFile\ReadiniFile;
55
use WriteiniFile\WriteiniFile;
66

7-
class WriteIniFileTest extends TestCase
7+
class WriteiniFileTest extends TestCase
88
{
99
private $var = [
1010
'section 1' => [

0 commit comments

Comments
 (0)