Skip to content

Commit e9e5aeb

Browse files
committed
add test for different draft builders
1 parent 048598b commit e9e5aeb

File tree

4 files changed

+179
-45
lines changed

4 files changed

+179
-45
lines changed

phpunit.xml.dist

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
6-
bootstrap="vendor/autoload.php"
7-
backupGlobals="false"
8-
backupStaticAttributes="false"
9-
verbose="true"
10-
>
11-
<testsuites>
12-
<testsuite name="unit">
13-
<directory suffix="Test.php">test/unit</directory>
14-
<directory suffix="Test.php">lib/commercetools-base/test/unit</directory>
15-
<directory suffix="Test.php">lib/commercetools-api-tests/test/unit</directory>
16-
<directory suffix="Test.php">lib/commercetools-import-tests/test/unit</directory>
17-
<directory suffix="Test.php">lib/commercetools-ml-tests/test/unit</directory>
18-
</testsuite>
19-
<testsuite name="base">
20-
<directory suffix="Test.php">lib/commercetools-base/test/unit</directory>
21-
</testsuite>
22-
<testsuite name="api">
23-
<directory suffix="Test.php">lib/commercetools-api-tests/test/unit</directory>
24-
</testsuite>
25-
<testsuite name="import">
26-
<directory suffix="Test.php">lib/commercetools-import-tests/test/unit</directory>
27-
</testsuite>
28-
<testsuite name="ml">
29-
<directory suffix="Test.php">lib/commercetools-ml-tests/test/unit</directory>
30-
</testsuite>
31-
<testsuite name="integration">
32-
<directory suffix="Test.php">test/integration</directory>
33-
</testsuite>
34-
</testsuites>
35-
36-
<filter>
37-
<whitelist addUncoveredFilesFromWhitelist="true">
38-
<directory suffix=".php">src</directory>
39-
<directory suffix=".php">lib/commercetools-api/src</directory>
40-
<directory suffix=".php">lib/commercetools-base/src</directory>
41-
<directory suffix=".php">lib/commercetools-import/src</directory>
42-
</whitelist>
43-
</filter>
44-
<php>
45-
<ini name="memory_limit" value="-1"/>
46-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
verbose="true">
6+
<testsuites>
7+
<testsuite name="unit">
8+
<directory suffix="Test.php">test/unit</directory>
9+
<directory suffix="Test.php">lib/commercetools-base/test/unit</directory>
10+
<directory suffix="Test.php">lib/commercetools-api-tests/test/unit</directory>
11+
<directory suffix="Test.php">lib/commercetools-import-tests/test/unit</directory>
12+
<directory suffix="Test.php">lib/commercetools-ml-tests/test/unit</directory>
13+
</testsuite>
14+
<testsuite name="base">
15+
<directory suffix="Test.php">lib/commercetools-base/test/unit</directory>
16+
</testsuite>
17+
<testsuite name="api">
18+
<directory suffix="Test.php">lib/commercetools-api-tests/test/unit</directory>
19+
</testsuite>
20+
<testsuite name="import">
21+
<directory suffix="Test.php">lib/commercetools-import-tests/test/unit</directory>
22+
</testsuite>
23+
<testsuite name="ml">
24+
<directory suffix="Test.php">lib/commercetools-ml-tests/test/unit</directory>
25+
</testsuite>
26+
<testsuite name="integration">
27+
<directory suffix="Test.php">test/integration</directory>
28+
</testsuite>
29+
</testsuites>
30+
<coverage includeUncoveredFiles="true">
31+
<include>
32+
<directory suffix=".php">src</directory>
33+
<directory suffix=".php">lib/commercetools-api/src</directory>
34+
<directory suffix=".php">lib/commercetools-base/src</directory>
35+
<directory suffix=".php">lib/commercetools-import/src</directory>
36+
</include>
37+
</coverage>
38+
<php>
39+
<ini name="memory_limit" value="-1"/>
40+
</php>
4741
</phpunit>

test/unit/CartDiscountTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Commercetools\UnitTest;
6+
7+
use Commercetools\Api\Models\CartDiscount\CartDiscountDraftBuilder;
8+
use Commercetools\Api\Models\CartDiscount\CartDiscountValueGiftLineItemDraftBuilder;
9+
use Commercetools\Api\Models\Common\LocalizedStringBuilder;
10+
use Commercetools\Api\Models\Product\ProductReferenceBuilder;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class CartDiscountTest extends TestCase
14+
{
15+
public function testVariantId()
16+
{
17+
$cartDiscountDraft = CartDiscountDraftBuilder::of()
18+
->withNameBuilder(LocalizedStringBuilder::of()->put('en', 'discount'))
19+
->withKey('cart-discount')
20+
->withCartPredicate("true")
21+
->withRequiresDiscountCode(false)
22+
->withSortOrder('0.903')
23+
->withValue(
24+
CartDiscountValueGiftLineItemDraftBuilder::of()
25+
->withProductBuilder(ProductReferenceBuilder::of()->withId("7be81688-0863-4f73-8ec6-1b249febc294"))
26+
->withVariantId(1)
27+
->build()
28+
)
29+
;
30+
$this->assertJsonStringEqualsJsonString(
31+
'{
32+
"cartPredicate": "true",
33+
"key": "cart-discount",
34+
"name": {
35+
"en": "discount"
36+
},
37+
"requiresDiscountCode": false,
38+
"sortOrder": "0.903",
39+
"value": {
40+
"product": {
41+
"id": "7be81688-0863-4f73-8ec6-1b249febc294",
42+
"typeId": "product"
43+
},
44+
"type": "giftLineItem",
45+
"variantId": 1
46+
}
47+
}',
48+
json_encode($cartDiscountDraft->build())
49+
);
50+
}
51+
}

test/unit/CartTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Commercetools\UnitTest;
6+
7+
use Commercetools\Api\Models\Cart\CartDraftBuilder;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class CartTest extends TestCase
11+
{
12+
public function testCartDraft()
13+
{
14+
$cartDraft = CartDraftBuilder::of()
15+
->withCurrency('EUR')
16+
->withDiscountCodes([
17+
'code-1',
18+
'code-2'
19+
]);
20+
$this->assertJsonStringEqualsJsonString(
21+
'{
22+
"currency": "EUR",
23+
"discountCodes": [
24+
"code-1",
25+
"code-2"
26+
]
27+
}',
28+
json_encode($cartDraft->build())
29+
);
30+
}
31+
}

test/unit/CustomFieldTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Commercetools\UnitTest;
6+
7+
use Commercetools\Api\Models\Common\MoneyBuilder;
8+
use Commercetools\Api\Models\Common\PriceDraftBuilder;
9+
use Commercetools\Api\Models\Customer\CustomerDraftBuilder;
10+
use Commercetools\Api\Models\Type\CustomFieldsDraftBuilder;
11+
use Commercetools\Api\Models\Type\FieldContainerBuilder;
12+
use Commercetools\Api\Models\Type\TypeResourceIdentifierBuilder;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class CustomFieldTest extends TestCase
16+
{
17+
public function testCustomField()
18+
{
19+
$customerDraft = CustomerDraftBuilder::of()
20+
->withCustomBuilder(
21+
CustomFieldsDraftBuilder::of()
22+
->withTypeBuilder(TypeResourceIdentifierBuilder::of()->withKey('mycustomtype'))
23+
->withFieldsBuilder(
24+
FieldContainerBuilder::of()
25+
->put(
26+
"price",
27+
PriceDraftBuilder::of()
28+
->withValueBuilder(
29+
MoneyBuilder::of()
30+
->withCurrencyCode('EUR')
31+
->withCentAmount(100)
32+
)
33+
->build()
34+
)
35+
)
36+
);
37+
38+
$this->assertJsonStringEqualsJsonString(
39+
'{
40+
"custom": {
41+
"fields": {
42+
"price": {
43+
"value": {
44+
"centAmount": 100,
45+
"currencyCode": "EUR"
46+
}
47+
}
48+
},
49+
"type": {
50+
"key": "mycustomtype",
51+
"typeId": "type"
52+
}
53+
}
54+
}',
55+
json_encode($customerDraft->build())
56+
);
57+
}
58+
}

0 commit comments

Comments
 (0)