|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace FastBillSdkTest\Customer; |
| 4 | + |
| 5 | +use FastBillSdk\Common\MissingPropertyException; |
| 6 | +use FastBillSdk\Customer\CustomerEntity; |
| 7 | +use FastBillSdk\Customer\CustomerSearchStruct; |
| 8 | +use FastBillSdk\Customer\CustomerService; |
| 9 | +use FastBillSdk\Customer\CustomerValidator; |
| 10 | +use FastBillSdkTest\Common\BaseTestTrait; |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | + |
| 13 | +class CustomerServiceTest extends TestCase |
| 14 | +{ |
| 15 | + use BaseTestTrait; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var CustomerService |
| 19 | + */ |
| 20 | + private $customerService; |
| 21 | + |
| 22 | + public function getCustomerService(): CustomerService |
| 23 | + { |
| 24 | + if (!$this->customerService) { |
| 25 | + $this->customerService = new CustomerService( |
| 26 | + $this->getApiClient(), |
| 27 | + $this->getXmlService(), |
| 28 | + new CustomerValidator() |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + return $this->customerService; |
| 33 | + } |
| 34 | + |
| 35 | + public function getCustomerServiceWithApiDummy(): CustomerService |
| 36 | + { |
| 37 | + if (!$this->customerService) { |
| 38 | + $this->customerService = new CustomerService( |
| 39 | + $this->getApiDummyClient(), |
| 40 | + $this->getXmlService(), |
| 41 | + new CustomerValidator() |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + return $this->customerService; |
| 46 | + } |
| 47 | + |
| 48 | + public function testGetCustomers() |
| 49 | + { |
| 50 | + $customers = $this->getCustomerService()->getCustomer(new CustomerSearchStruct()); |
| 51 | + foreach ($customers as $customer) { |
| 52 | + self::assertInstanceOf(CustomerEntity::class, $customer); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public function testGetCustomersWithFilters() |
| 57 | + { |
| 58 | + $searchStruct = new CustomerSearchStruct(); |
| 59 | + $searchStruct->setCustomerIdFilter(22); |
| 60 | + $searchStruct->setCustomerNumberFilter('KDNR33'); |
| 61 | + $searchStruct->setCustomerIdFilter(123); |
| 62 | + $searchStruct->setCityFilter('Musterstadt'); |
| 63 | + $searchStruct->setCountryCodeFilter('DE'); |
| 64 | + $searchStruct->setSearchTermFilter('Musterfirma'); |
| 65 | + |
| 66 | + $customers = $this->getCustomerservice()->getCustomer($searchStruct); |
| 67 | + |
| 68 | + self::assertCount(0, $customers); |
| 69 | + } |
| 70 | + |
| 71 | + public function testCreateCustomerWithEmptyEntity() |
| 72 | + { |
| 73 | + $customer = new CustomerEntity(); |
| 74 | + $customer->customerType = 'business'; |
| 75 | + |
| 76 | + $this->expectException(MissingPropertyException::class); |
| 77 | + $this->getCustomerServiceWithApiDummy()->createCustomer($customer); |
| 78 | + } |
| 79 | + |
| 80 | + public function testCreateCustomerWithMissingProperties() |
| 81 | + { |
| 82 | + $customer = new CustomerEntity(); |
| 83 | + $customer->customerType = 'consumer'; |
| 84 | + |
| 85 | + $this->expectException(MissingPropertyException::class); |
| 86 | + $this->getCustomerServiceWithApiDummy()->createCustomer($customer); |
| 87 | + } |
| 88 | + |
| 89 | + public function testUpdateCustomerWithEmptyEntity() |
| 90 | + { |
| 91 | + $customer = new CustomerEntity(); |
| 92 | + |
| 93 | + $this->expectException(MissingPropertyException::class); |
| 94 | + $this->getCustomerServiceWithApiDummy()->updateCustomer($customer); |
| 95 | + } |
| 96 | + |
| 97 | + public function testUpdateCustomer() |
| 98 | + { |
| 99 | + $customer = new CustomerEntity(); |
| 100 | + $customer->customerId = 111; |
| 101 | + $customer->customerType = 'business'; |
| 102 | + $customer->organization = 'Bullshit Productions'; |
| 103 | + |
| 104 | + self::assertEquals($this->getCustomerServiceWithApiDummy()->updateCustomer($customer), $customer); |
| 105 | + } |
| 106 | + |
| 107 | + public function testDeleteCustomerWithEmptyEntity() |
| 108 | + { |
| 109 | + $customer = new CustomerEntity(); |
| 110 | + |
| 111 | + $this->expectException(MissingPropertyException::class); |
| 112 | + $this->getCustomerServiceWithApiDummy()->deleteCustomer($customer); |
| 113 | + } |
| 114 | + |
| 115 | + public function testDeleteCustomer() |
| 116 | + { |
| 117 | + $customer = new CustomerEntity(); |
| 118 | + $customer->customerId = 1337; |
| 119 | + |
| 120 | + $this->getCustomerServiceWithApiDummy()->deleteCustomer($customer); |
| 121 | + |
| 122 | + self::assertNull($customer->customerId); |
| 123 | + } |
| 124 | +} |
0 commit comments