Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 993cddd

Browse files
author
Jens Schulze
committed
fix(Collection): fix add function for collection
1 parent 5468676 commit 993cddd

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

src/Model/Category/CategoryDraft.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
* @method CategoryDraft setExternalId(string $externalId = null)
2929
* @method CustomFieldObjectDraft getCustom()
3030
* @method CategoryDraft setCustom(CustomFieldObjectDraft $custom = null)
31+
* @method LocalizedString getMetaDescription()
32+
* @method CategoryDraft setMetaDescription(LocalizedString $metaDescription = null)
33+
* @method LocalizedString getMetaTitle()
34+
* @method CategoryDraft setMetaTitle(LocalizedString $metaTitle = null)
35+
* @method LocalizedString getMetaKeywords()
36+
* @method CategoryDraft setMetaKeywords(LocalizedString $metaKeywords = null)
3137
*/
3238
class CategoryDraft extends JsonObject
3339
{

src/Model/Common/AbstractJsonDeserializeObject.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(array $data = [], $context = null)
2929
{
3030
$this->setContext($context);
3131
if (!is_null($data)) {
32-
$this->rawData = $data;
32+
$this->rawData = $this->typeData = $data;
3333
}
3434
}
3535

@@ -158,7 +158,7 @@ protected function getTyped($offset)
158158
*/
159159
public function setRawData(array $rawData)
160160
{
161-
$this->rawData = $rawData;
161+
$this->rawData = $this->typeData = $rawData;
162162

163163
return $this;
164164
}
@@ -190,8 +190,7 @@ public function jsonSerialize()
190190
*/
191191
public function toArray()
192192
{
193-
$data = array_merge($this->rawData, $this->typeData);
194-
$data = array_filter($data, function ($value) {
193+
$data = array_filter($this->typeData, function ($value) {
195194
return !is_null($value);
196195
});
197196
$data = array_map(

src/Model/Common/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function initialize($offset)
142142
*/
143143
public function toArray()
144144
{
145-
$values = $this->rawData;
145+
$values = [];
146146
foreach ($this->typeData as $key => $value) {
147147
if ($value instanceof JsonDeserializeInterface) {
148148
$values[$key] = $value->toArray();

tests/unit/Model/Common/CollectionTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function testGetReturnRaw()
213213
[[new \DateTime('2015-01-01')]]
214214
);
215215
$collection->setType('\DateTime');
216-
$this->assertSame('2015-01-01', $collection->getAt(0)->format('Y-m-d'));
216+
$this->assertSame('2015-01-01', $collection->current()->format('Y-m-d'));
217217
}
218218

219219
public function testSetAt()
@@ -224,4 +224,15 @@ public function testSetAt()
224224

225225
$this->assertInstanceOf('\DateTime', $collection[1]);
226226
}
227+
228+
public function testAdd()
229+
{
230+
$collection = Collection::fromArray([
231+
['currencyCode' => 'EUR', 'centAmount' => 100],
232+
]);
233+
$collection->setType('\Commercetools\Core\Model\Common\Money');
234+
$collection->add(Money::ofCurrencyAndAmount('USD', 110));
235+
236+
$this->assertCount(2, $collection);
237+
}
227238
}

0 commit comments

Comments
 (0)