Skip to content

Commit c3110db

Browse files
committed
Merge branch 'develop'
2 parents 1ba0eb0 + 59b3cdd commit c3110db

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Encoder/Encoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private function getEncodingParameters($data, DataAnalyzerInterface $analyzer, $
188188
/** @var SchemaProviderInterface $schema */
189189
list($isDataEmpty, , $schema) = $analyzer->analyze($data);
190190

191-
if ($isDataEmpty === true && $parameters === null) {
191+
if ($isDataEmpty === true) {
192192
return $this->factory->createEncodingParameters();
193193
} elseif ($parameters !== null && $parameters->getIncludePaths() !== null) {
194194
return $parameters;

tests/Encoder/EncodeSimpleObjectsTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use \Neomerx\Tests\JsonApi\BaseTestCase;
2323
use \Neomerx\JsonApi\Encoder\EncoderOptions;
2424
use \Neomerx\Tests\JsonApi\Data\AuthorSchema;
25+
use \Neomerx\JsonApi\Parameters\EncodingParameters;
2526

2627
/**
2728
* @package Neomerx\Tests\JsonApi
@@ -84,6 +85,33 @@ public function testEncodeEmpty()
8485
$this->assertEquals($expected, $actual);
8586
}
8687

88+
/**
89+
* Test encode empty array.
90+
*
91+
* Issue #50 @link https://github.com/neomerx/json-api/issues/50
92+
*/
93+
public function testEncodeEmptyWithParameters()
94+
{
95+
$endcoder = Encoder::instance([
96+
Author::class => AuthorSchema::class
97+
]);
98+
99+
$actual = $endcoder->encode([], null, null, new EncodingParameters(null, [
100+
// include only these attributes and links
101+
'authors' => [Author::ATTRIBUTE_FIRST_NAME, Author::LINK_COMMENTS],
102+
]));
103+
104+
$expected = <<<EOL
105+
{
106+
"data" : []
107+
}
108+
EOL;
109+
// remove formatting from 'expected'
110+
$expected = json_encode(json_decode($expected));
111+
112+
$this->assertEquals($expected, $actual);
113+
}
114+
87115
/**
88116
* Test encode simple object with attributes only.
89117
*/

0 commit comments

Comments
 (0)