Skip to content

Commit 4751e1a

Browse files
committed
add test for creating a custom field for an importer resource
1 parent a9ea6ba commit 4751e1a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

test/unit/ImportPriceDraftTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Commercetools\UnitTest;
4+
5+
use Commercetools\Import\Models\Common\MoneyBuilder;
6+
use Commercetools\Import\Models\Common\TypeKeyReferenceBuilder;
7+
use Commercetools\Import\Models\Customfields\CustomBuilder;
8+
use Commercetools\Import\Models\Customfields\FieldContainerModel;
9+
use Commercetools\Import\Models\Productdrafts\PriceDraftImportBuilder;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class ImportPriceDraftTest extends TestCase
13+
{
14+
public function testPriceDraft()
15+
{
16+
$priceDraft = PriceDraftImportBuilder::of()
17+
->withCustomBuilder(
18+
CustomBuilder::of()
19+
->withTypeBuilder(TypeKeyReferenceBuilder::of()->withKey("mytypekey"))
20+
->withFields(
21+
FieldContainerModel::fromArray(
22+
[
23+
'foo' => MoneyBuilder::of()
24+
->withCurrencyCode('EUR')
25+
->withCentAmount(100)
26+
->build()
27+
]
28+
)
29+
)
30+
)
31+
;
32+
$this->assertJsonStringEqualsJsonString(
33+
'{
34+
"custom": {
35+
"fields": {
36+
"foo": {
37+
"centAmount": 100,
38+
"currencyCode": "EUR",
39+
"type": "centPrecision"
40+
}
41+
},
42+
"type": {
43+
"key": "mytypekey",
44+
"typeId": "type"
45+
}
46+
}
47+
}',
48+
json_encode($priceDraft->build())
49+
);
50+
}
51+
}

0 commit comments

Comments
 (0)