From 64a703a8db4633a9dd6c4067dcef7b85ad78c6e8 Mon Sep 17 00:00:00 2001 From: Chris Lloyd Date: Sat, 31 Oct 2020 18:09:28 +0000 Subject: [PATCH] WIP --- src/Entity.php | 17 ++++++++++++----- tests/Unit/Queries/Entity/EntityTest.php | 9 +++++++++ ...ad_with_multiple_select_non_adjacent__1.json | 5 +++++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/Queries/Entity/__snapshots__/EntityTest__test_read_with_multiple_select_non_adjacent__1.json diff --git a/src/Entity.php b/src/Entity.php index f629428cc..7fb66ea1c 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -117,7 +117,13 @@ public function emit(Transaction $transaction): void } } - while ($this->properties->valid()) { + $requiresSeparator = false; + + while (true) { + if (!$this->properties->valid()) { + break; + } + /** @var PropertyValue $propertyValue */ $propertyValue = $this->properties->current(); @@ -126,6 +132,10 @@ public function emit(Transaction $transaction): void continue; } + if ($requiresSeparator) { + $transaction->outputJsonSeparator(); + } + if ($propertyValue->getProperty() instanceof NavigationProperty) { $propertyMetadata = $this->getExpansionMetadata($transaction, $propertyValue); @@ -144,11 +154,8 @@ public function emit(Transaction $transaction): void $transaction->outputJsonValue($value); } + $requiresSeparator = true; $this->properties->next(); - - if ($this->properties->valid() && $this->properties->current()->shouldEmit($transaction)) { - $transaction->outputJsonSeparator(); - } } $transaction->outputJsonObjectEnd(); diff --git a/tests/Unit/Queries/Entity/EntityTest.php b/tests/Unit/Queries/Entity/EntityTest.php index 8135a8f24..d47a13feb 100644 --- a/tests/Unit/Queries/Entity/EntityTest.php +++ b/tests/Unit/Queries/Entity/EntityTest.php @@ -106,6 +106,15 @@ public function test_read_with_multiple_select() ); } + public function test_read_with_multiple_select_non_adjacent() + { + $this->assertJsonResponse( + Request::factory() + ->path('/flights(1)') + ->query('$select', 'origin,gate') + ); + } + public function test_rejects_invalid_select() { $this->assertBadRequest( diff --git a/tests/Unit/Queries/Entity/__snapshots__/EntityTest__test_read_with_multiple_select_non_adjacent__1.json b/tests/Unit/Queries/Entity/__snapshots__/EntityTest__test_read_with_multiple_select_non_adjacent__1.json new file mode 100644 index 000000000..31a11847b --- /dev/null +++ b/tests/Unit/Queries/Entity/__snapshots__/EntityTest__test_read_with_multiple_select_non_adjacent__1.json @@ -0,0 +1,5 @@ +{ + "@context": "http://localhost/odata/$metadata#flights(origin,gate)/$entity", + "origin": "lhr", + "gate": null +}