UnleashedCustomerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
dl 0
loc 70
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAddressNameItems() 0 10 1
A setUp() 0 6 1
A testGetAddressNameFromOrder() 0 6 1
A testMatchCustomerAddress() 0 21 1
1
<?php
2
3
namespace AntonyThorpe\SilverShopUnleashed\Tests;
4
5
use AntonyThorpe\SilverShopUnleashed\Defaults;
6
use SilverShop\Model\Order;
0 ignored issues
show
Bug introduced by
The type SilverShop\Model\Order was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SilverShop\Tests\ShopTest;
0 ignored issues
show
Bug introduced by
The type SilverShop\Tests\ShopTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SilverStripe\Dev\SapphireTest;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Dev\SapphireTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class UnleashedCustomerTest extends SapphireTest
11
{
12
    public Order $order;
13
    protected static $fixture_file = [
14
        'vendor/silvershop/core/tests/php/Fixtures/ShopMembers.yml',
15
        'vendor/silvershop/core/tests/php/Fixtures/Orders.yml',
16
        'fixtures/models.yml'
17
    ];
18
19
    public function setUp(): void
20
    {
21
        Defaults::config()->send_sales_orders_to_unleashed = false;
22
        parent::setUp();
23
        ShopTest::setConfiguration(); //reset config
24
        $this->order = $this->objFromFixture(Order::class, "cart1");
25
    }
26
27
    public function testGetAddressNameFromOrder(): void
28
    {
29
        $this->assertSame(
30
            '201-203 BROADWAY AVE U 235 WEST BEACH',
31
            $this->order->getAddressName($this->order->ShippingAddress()),
32
            'Result matches 201-203 Broadway Ave U 235 West Beach'
33
        );
34
    }
35
36
    public function testGetAddressNameItems(): void
37
    {
38
        $apidata_array = (array) json_decode($this->jsondata, true);
39
        $apidata_array = reset($apidata_array);
40
        $items = $apidata_array['Items'];
41
42
        $this->assertSame(
43
            '31 Hurstmere Road RD1 Auckland',
44
            $this->order->getAddressName($items[0]['Addresses'][1]),
45
            'Result matches 31 Hurstmere Road RD1 Auckland'
46
        );
47
    }
48
49
    public function testMatchCustomerAddress(): void
50
    {
51
        $apidata_array = (array) json_decode($this->jsondata, true);
52
        $apidata_array = reset($apidata_array);
53
        $items = $apidata_array['Items'];
54
55
        // Test a failed match
56
        $this->assertFalse(
57
            $this->order->matchCustomerAddress($items, $this->order->ShippingAddress()),
58
            "The address in the API data does not match the order's shipping address"
59
        );
60
61
        // Test a direct match
62
        $shipping_address = $this->order->ShippingAddress();
63
        $shipping_address->Address = '31 Hurstmere Road';
64
        $shipping_address->AddressLine2 = 'RD1';
65
        $shipping_address->City = 'Auckland';
66
67
        $this->assertTrue(
68
            $this->order->matchCustomerAddress($items, $shipping_address),
69
            "The address in the API data matches the order's shipping address"
70
        );
71
    }
72
73
    /**
74
     * JSON data for test
75
     *
76
     * @link (Unleashed Software API Documentation, https://apidocs.unleashedsoftware.com/Products)
77
     * @var string
78
     */
79
    protected $jsondata = '[
80
        {
81
          "Pagination": {
82
            "NumberOfItems": 11,
83
            "PageSize": 200,
84
            "PageNumber": 1,
85
            "NumberOfPages": 1
86
          },
87
          "Items": [
88
            {
89
              "Addresses": [
90
                  {
91
                      "AddressType": "Postal",
92
                      "AddressName": "1 Queen St",
93
                      "StreetAddress": "1 Queen St",
94
                      "StreetAddress2": "RD 2",
95
                      "Suburb": "",
96
                      "City": "Pukekohe",
97
                      "Region": "Auckland",
98
                      "Country": "New Zealand",
99
                      "PostalCode": "0622"
100
                  },
101
                  {
102
                      "AddressType": "Physical",
103
                      "AddressName": "Main Warehouse",
104
                      "StreetAddress": "31 Hurstmere Road",
105
                      "StreetAddress2": "RD1",
106
                      "Suburb": "Takapuna",
107
                      "City": "Auckland",
108
                      "Region": "North Shore",
109
                      "Country": "New Zealand",
110
                      "PostalCode": "0622"
111
                  }
112
              ],
113
              "CustomerCode": "FRANCK",
114
              "CustomerName": "Franck & Co.",
115
              "GSTVATNumber": null,
116
              "BankName": null,
117
              "BankBranch": null,
118
              "BankAccount": null,
119
              "Website": null,
120
              "PhoneNumber": null,
121
              "FaxNumber": null,
122
              "MobileNumber": null,
123
              "DDINumber": null,
124
              "TollFreeNumber": null,
125
              "Email": null,
126
              "EmailCC": null,
127
              "Currency": {
128
                  "CurrencyCode": "USD",
129
                  "Description": "United States of America, Dollars",
130
                  "Guid": "3088672d-2a24-4d23-bb1c-c91813ed4c76",
131
                  "LastModifiedOn": "/Date(1458675959843)/"
132
              },
133
              "Notes": null,
134
              "Taxable": true,
135
              "XeroContactId": null,
136
              "SalesPerson": {
137
                  "FullName": "John Smith",
138
                  "Email": "[email protected]",
139
                  "Obsolete": false,
140
                  "Guid": "224ae802-88d3-43c1-b9cc-208d5d6d0ccf",
141
                  "LastModifiedOn": "/Date(1459218946890)/"
142
              },
143
              "DiscountRate": 0,
144
              "PrintPackingSlipInsteadOfInvoice": false,
145
              "PrintInvoice": false,
146
              "StopCredit": false,
147
              "Obsolete": false,
148
              "XeroSalesAccount": null,
149
              "XeroCostOfGoodsAccount": null,
150
              "SellPriceTier": "",
151
              "SellPriceTierReference": null,
152
              "CustomerType": "Cash",
153
              "PaymentTerm": "20th Month following",
154
              "ContactFirstName": null,
155
              "ContactLastName": null,
156
              "SourceId": null,
157
              "CreatedBy": "admin",
158
              "CreatedOn": "/Date(1411781315923)/",
159
              "Guid": "d32d0ca7-fd8e-4a99-9da6-be546ac5252b",
160
              "LastModifiedOn": "/Date(1459218740823)/"
161
            }
162
          ]
163
        }]';
164
}
165