Skip to content

Commit db5825c

Browse files
authored
Merge pull request #15 from peter279k/test_enhancement
Fix issue #11 and test enhancement
2 parents 8cb5b59 + 31aec95 commit db5825c

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: php
22
php:
33
- '5.6'
44
- '7.0'
5+
- '7.1'
6+
- '7.2'
57

68
sudo: false
79

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
"human"
2222
],
2323
"require": {
24-
"php": ">=5.6"
24+
"php": ">=5.6",
25+
"ext-mbstring": "*"
2526
},
2627
"require-dev": {
27-
"phpunit/phpunit": "~4.0"
28+
"phpunit/phpunit": "^5.7 || ^6.5"
2829
},
2930
"autoload": {
3031
"psr-4": {
3132
"HJSON\\": "src/HJSON"
3233
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"HJSON\\Tests\\": "tests/"
38+
}
3339
}
3440
}

phpunit.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
<directory>./tests/</directory>
1616
</testsuite>
1717
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory suffix=".php">src/HJSON</directory>
21+
</whitelist>
22+
</filter>
1823
</phpunit>

src/HJSON/HJSONParser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ private function object($withoutBraces=false)
201201
$this->white();
202202
$this->next(':');
203203
// duplicate keys overwrite the previous value
204-
$object->$key = $this->value();
204+
if ($key !== '') {
205+
$object->$key = $this->value();
206+
}
205207
$wat = $this->at;
206208
$this->white();
207209
// in Hjson the comma is optional and trailing commas are allowed
@@ -331,7 +333,7 @@ private function keyname()
331333

332334
while (true) {
333335
if ($this->ch === ':') {
334-
if (!$name) $this->error("Found ':' but no key name (for an empty key name use quotes)");
336+
if ($name === '') $this->error("Found ':' but no key name (for an empty key name use quotes)");
335337
else if ($space >=0 && $space !== mb_strlen($name)) {
336338
$this->at = $start + $space;
337339
$this->error("Found whitespace in your key name (use quotes to include)");

tests/HJSONParserTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22

3+
namespace HJSON\Tests;
4+
35
use HJSON\HJSONParser;
46
use HJSON\HJSONStringifier;
57
use HJSON\HJSONException;
8+
use PHPUnit\Framework\TestCase;
69

710

8-
class HJSONParserTest extends PHPUnit_Framework_TestCase {
11+
class HJSONParserTest extends TestCase {
912

1013
public function setUp()
1114
{
@@ -52,8 +55,9 @@ private function runEach($name, $file, $isJson, $inputCr, $outputCr)
5255
$json2 = json_encode(json_decode($text));
5356
$this->assertEquals($json1, $json2);
5457
}
58+
} else {
59+
$this->markTestIncomplete('This runEach test has not been implemented yet.');
5560
}
56-
else $this->assertTrue(false);
5761
}
5862
catch (HJSONException $e) {
5963
if (!$shouldFail) throw $e;

0 commit comments

Comments
 (0)