Skip to content

Commit 92ef1d6

Browse files
committed
Remove PHP 7.1 support, added utf-8 support for csv conversion #13
1 parent 5037623 commit 92ef1d6

File tree

8 files changed

+28
-12
lines changed

8 files changed

+28
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
composer.lock
33
vendor
4+
*.cache

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 7.1
54
- 7.2
65
- 7.3
76
- 7.4

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use OzdemirBurak\JsonCsv\File\Json;
2626
$json = new Json(__DIR__ . '/above.json');
2727
// To convert JSON to CSV string
2828
$csvString = $json->convert();
29-
// To convert JSON to CSV and save
29+
// To set a conversion option then convert JSON to CSV and save
30+
$json->setConversionKey('utf8_encoding', true);
3031
$json->convertAndSave(__DIR__ . '/above.csv');
3132
// To convert JSON to CSV and force download on browser
3233
$json->convertAndDownload();

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@
1212
}
1313
],
1414
"require": {
15-
"php" : "~7.1",
15+
"php" : "~7.2",
1616
"ext-json": "*"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit" : "~6.0|~7.0"
19+
"phpunit/phpunit" : "~7.0|~8.0",
20+
"squizlabs/php_codesniffer": "~3.5"
2021
},
2122
"autoload": {
2223
"psr-4": { "OzdemirBurak\\JsonCsv\\": "src" }
2324
},
2425
"autoload-dev": {
2526
"psr-4": { "OzdemirBurak\\JsonCsv\\Tests\\": "tests" }
2627
},
27-
"scripts": { "test": "vendor/bin/phpunit" }
28+
"scripts": {
29+
"test": "vendor/bin/phpunit",
30+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
31+
"check-style": "vendor/bin/phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
32+
"fix-style": "vendor/bin/phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
33+
}
2834
}

src/AbstractFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class AbstractFile
2626
*/
2727
public function __construct($filepath)
2828
{
29-
list($this->filename, $this->data) = [pathinfo($filepath, PATHINFO_FILENAME), file_get_contents($filepath)];
29+
[$this->filename, $this->data] = [pathinfo($filepath, PATHINFO_FILENAME), file_get_contents($filepath)];
3030
}
3131

3232
/**

src/File/Json.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public function convert(): string
4444
protected function toCsvString(array $data): string
4545
{
4646
$f = fopen('php://temp', 'wb');
47-
if($this->conversion["utf8_encoding"]) {
48-
fprintf($f, chr(0xEF).chr(0xBB).chr(0xBF));
47+
if ($this->conversion['utf8_encoding']) {
48+
fprintf($f, chr(0xEF) . chr(0xBB) . chr(0xBF));
4949
}
5050
$this->putCsv($f, array_keys(current($data)));
5151
array_walk($data, function ($row) use (&$f) {

tests/CsvTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CsvTest extends TestCase
2020
public function testFileReading()
2121
{
2222
$this->assertEquals('iris', ($csv = $this->initCsv())->getFilename());
23-
$this->assertContains('6.3,3.3,6.0,2.5,Iris-virginica', $csv->getData());
23+
$this->assertStringContainsString('6.3,3.3,6.0,2.5,Iris-virginica', $csv->getData());
2424
}
2525

2626
/**
@@ -51,7 +51,7 @@ public function testConversionAndSave()
5151
$this->initCsv()->convertAndSave($path);
5252
$this->assertFileExists($path);
5353
$json = '{"SL":"6.3","SW":"3.3","PL":"6.0","PW":"2.5","Name":"Iris-virginica"}';
54-
$this->assertContains($json, file_get_contents($path));
54+
$this->assertStringContainsString($json, file_get_contents($path));
5555
unlink($path);
5656
$this->assertFileNotExists($path);
5757
}

tests/JsonTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ class JsonTest extends TestCase
2020
public function testFileReading()
2121
{
2222
$this->assertEquals('countries', ($json = $this->initJson())->getFilename());
23-
$this->assertContains('"common": "Turkey"', $json->getData());
23+
$this->assertStringContainsString('"common": "Turkey"', $json->getData());
24+
}
25+
26+
/**
27+
* @group json-basic-test
28+
*/
29+
public function testSetter()
30+
{
31+
$conversion = $this->initJson()->setConversionKey('utf8_encoding', true);
32+
$this->assertEquals(true, $conversion['utf8_encoding']);
2433
}
2534

2635
/**
@@ -64,7 +73,7 @@ public function testConversionAndSave()
6473
$path = $this->path('iris', 'countries');
6574
$this->initJson()->convertAndSave($path);
6675
$this->assertFileExists($path);
67-
$this->assertContains("Turkey,\"Republic of Turkey\",Türkiye,783562,39,35\n", file_get_contents($path));
76+
$this->assertStringContainsString("Turkey,\"Republic of Turkey\",Türkiye,783562,39,35\n", file_get_contents($path));
6877
unlink($path);
6978
$this->assertFileNotExists($path);
7079
}

0 commit comments

Comments
 (0)