diff --git a/src/Model/Service/Customer.php b/src/Model/Service/Customer.php index 3c865c9..9a91d94 100644 --- a/src/Model/Service/Customer.php +++ b/src/Model/Service/Customer.php @@ -79,13 +79,17 @@ class Customer implements CustomerManagerInterface 'index' => $billing->getPostcode(), 'region' => $billing->getRegion(), 'city' => $billing->getCity(), - 'street' => $billing->getStreet(), + 'street' => is_array($billing->getStreet()) + ? implode(', ', $billing->getStreet()) + : $billing->getStreet(), 'text' => sprintf( '%s %s %s %s', $billing->getPostcode(), $billing->getRegion(), $billing->getCity(), - $billing->getStreet() + is_array($billing->getStreet()) + ? implode(', ', $billing->getStreet()) + : $billing->getStreet() ) ] ]; diff --git a/src/Test/Helpers/FieldsetTest.php b/src/Test/Helpers/FieldsetTest.php index 3e32f75..b14142f 100644 --- a/src/Test/Helpers/FieldsetTest.php +++ b/src/Test/Helpers/FieldsetTest.php @@ -20,8 +20,9 @@ class FieldsetTest extends TestCase protected $testElementId = 'test_element_id'; protected $testFieldSetCss = 'test_fieldset_css'; protected $objectFactory; + protected $secureRenderer; - public function setUp() + public function setUp(): void { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $factoryMock = $this->createMock(\Magento\Framework\Data\Form\Element\Factory::class); @@ -88,6 +89,20 @@ class FieldsetTest extends TestCase $factoryCollection->expects($this->any())->method('create')->willReturn($elementCollection); $rendererMock = $this->createMock(\Magento\Framework\Data\Form\Element\Renderer\RendererInterface::class); + $this->secureRenderer = $this->createMock(\Magento\Framework\View\Helper\SecureHtmlRenderer::class); + $this->secureRenderer->method('renderEventListenerAsTag') + ->willReturnCallback( + function (string $event, string $js, string $selector): string { + return ""; + } + ); + $this->secureRenderer->method('renderStyleAsTag') + ->willReturnCallback( + function (string $style, string $selector): string { + return ""; + } + ); + $this->urlModelMock = $this->createMock(\Magento\Backend\Model\Url::class); $this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class); $this->groupMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Group::class); @@ -100,7 +115,8 @@ class FieldsetTest extends TestCase $this->helperMock = $this->createMock(\Magento\Framework\View\Helper\Js::class); $this->form = $this->createPartialMock( \Magento\Config\Block\System\Config\Form::class, - ['getElements', 'getRequest'] + //['getElements', 'getRequest'] + ['getRequest'] ); //$this->form->expects($this->any())->method('getElements')->willReturn($elementCollection); $this->form->expects($this->any())->method('getRequest')->willReturn($this->requestMock); diff --git a/src/Test/TestCase.php b/src/Test/TestCase.php index d1e5be2..43e6b2a 100644 --- a/src/Test/TestCase.php +++ b/src/Test/TestCase.php @@ -8,7 +8,7 @@ if (!class_exists('\PHPUnit\Framework\TestCase')) { abstract class TestCase extends \PHPUnit\Framework\TestCase { - public function createMock($originalClassName) + public function createMock(string $originalClassName): \PHPUnit\Framework\MockObject\MockObject { if (method_exists(\PHPUnit\Framework\TestCase::class, 'createMock')) { return parent::createMock($originalClassName); @@ -40,7 +40,7 @@ if (!class_exists('\PHPUnit\Framework\TestCase')) { abstract class TestCase extends \PHPUnit\Framework\TestCase { - public function createMock($originalClassName) + public function createMock(string $originalClassName): \PHPUnit\Framework\MockObject\MockObject { if (method_exists(\PHPUnit\Framework\TestCase::class, 'createMock')) { return parent::createMock($originalClassName); diff --git a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/PaymentTest.php b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/PaymentTest.php index 1d46690..6a041ee 100644 --- a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/PaymentTest.php +++ b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/PaymentTest.php @@ -52,7 +52,8 @@ class PaymentTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest 'client' => $client, 'paymentConfig' => $paymentConfig, 'context' => $this->context, - 'objectFactory' => $this->objectFactory + 'objectFactory' => $this->objectFactory, + 'secureRenderer' => $this->secureRenderer ]; $payment = $this->objectManager->getObject( @@ -65,15 +66,15 @@ class PaymentTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest $html = $payment->render($this->elementMock); - $this->assertContains($this->testElementId, $html); - $this->assertContains($this->testFieldSetCss, $html); + $this->assertStringContainsString($this->testElementId, $html); + $this->assertStringContainsString($this->testFieldSetCss, $html); if (!$isConfigured) { $expected = sprintf( '
%s
', __('Enter API of your URL and API key') ); - $this->assertContains($expected, $html); + $this->assertStringContainsString($expected, $html); } } diff --git a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/ShippingTest.php b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/ShippingTest.php index 63c9f96..4a8f45e 100644 --- a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/ShippingTest.php +++ b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/ShippingTest.php @@ -52,7 +52,8 @@ class ShippingTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest 'client' => $client, 'shippingConfig' => $shippingConfig, 'context' => $this->context, - 'objectFactory' => $this->objectFactory + 'objectFactory' => $this->objectFactory, + 'secureRenderer' => $this->secureRenderer ]; $shipping = $this->objectManager->getObject( @@ -65,15 +66,15 @@ class ShippingTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest $html = $shipping->render($this->elementMock); - $this->assertContains($this->testElementId, $html); - $this->assertContains($this->testFieldSetCss, $html); + $this->assertStringContainsString($this->testElementId, $html); + $this->assertStringContainsString($this->testFieldSetCss, $html); if (!$isConfigured) { $expected = sprintf( '
%s
', __('Enter API of your URL and API key') ); - $this->assertContains($expected, $html); + $this->assertStringContainsString($expected, $html); } } diff --git a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SiteTest.php b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SiteTest.php index 930781d..d7acf61 100644 --- a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SiteTest.php +++ b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SiteTest.php @@ -43,7 +43,8 @@ class SiteTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest 'data' => ['group' => $this->groupMock], 'client' => $client, 'context' => $this->context, - 'objectFactory' => $this->objectFactory + 'objectFactory' => $this->objectFactory, + 'secureRenderer' => $this->secureRenderer ]; $site = $this->objectManager->getObject( @@ -56,15 +57,15 @@ class SiteTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest $html = $site->render($this->elementMock); - $this->assertContains($this->testElementId, $html); - $this->assertContains($this->testFieldSetCss, $html); + $this->assertStringContainsString($this->testElementId, $html); + $this->assertStringContainsString($this->testFieldSetCss, $html); if (!$isConfigured) { $expected = sprintf( '
%s
', __('Enter API of your URL and API key') ); - $this->assertContains($expected, $html); + $this->assertStringContainsString($expected, $html); } } diff --git a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SitesTest.php b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SitesTest.php index 8ce18ae..4fd19f5 100644 --- a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SitesTest.php +++ b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/SitesTest.php @@ -55,7 +55,8 @@ class SitesTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest 'client' => $client, 'storeManager' => $storeManager, 'context' => $this->context, - 'objectFactory' => $this->objectFactory + 'objectFactory' => $this->objectFactory, + 'secureRenderer' => $this->secureRenderer ]; $sites = $this->objectManager->getObject( @@ -68,15 +69,15 @@ class SitesTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest $html = $sites->render($this->elementMock); - $this->assertContains($this->testElementId, $html); - $this->assertContains($this->testFieldSetCss, $html); + $this->assertStringContainsString($this->testElementId, $html); + $this->assertStringContainsString($this->testFieldSetCss, $html); if (!$isConfigured) { $expected = sprintf( '
%s
', __('Enter API of your URL and API key') ); - $this->assertContains($expected, $html); + $this->assertStringContainsString($expected, $html); } } diff --git a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/StatusTest.php b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/StatusTest.php index e993c76..243a7e7 100644 --- a/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/StatusTest.php +++ b/src/Test/Unit/Block/Adminhtml/System/Config/Form/Fieldset/StatusTest.php @@ -52,7 +52,8 @@ class StatusTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest 'client' => $client, 'statusCollection' => $statusCollection, 'context' => $this->context, - 'objectFactory' => $this->objectFactory + 'objectFactory' => $this->objectFactory, + 'secureRenderer' => $this->secureRenderer ]; $status = $this->objectManager->getObject( @@ -65,15 +66,15 @@ class StatusTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest $html = $status->render($this->elementMock); - $this->assertContains($this->testElementId, $html); - $this->assertContains($this->testFieldSetCss, $html); + $this->assertStringContainsString($this->testElementId, $html); + $this->assertStringContainsString($this->testFieldSetCss, $html); if (!$isConfigured) { $expected = sprintf( '
%s
', __('Enter API of your URL and API key') ); - $this->assertContains($expected, $html); + $this->assertStringContainsString($expected, $html); } } diff --git a/src/Test/Unit/Block/Frontend/DaemonCollectorTest.php b/src/Test/Unit/Block/Frontend/DaemonCollectorTest.php index 0c43b2c..bb0451c 100644 --- a/src/Test/Unit/Block/Frontend/DaemonCollectorTest.php +++ b/src/Test/Unit/Block/Frontend/DaemonCollectorTest.php @@ -11,7 +11,7 @@ class DaemonCollectorTest extends TestCase const SITE_KEY = 'RC-XXXXXXX-X'; - public function setUp() + public function setUp(): void { $context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); $customerSession = $this->createMock(\Magento\Customer\Model\Session::class); @@ -57,11 +57,11 @@ class DaemonCollectorTest extends TestCase $js = $this->unit->buildScript()->getJs(); - $this->assertContains('', $js); - $this->assertContains('_rc(\'send\', \'pageView\');', $js); - $this->assertContains(self::SITE_KEY, $js); - $this->assertContains('customerId', $js); + $this->assertStringContainsString('', $js); + $this->assertStringContainsString('_rc(\'send\', \'pageView\');', $js); + $this->assertStringContainsString(self::SITE_KEY, $js); + $this->assertStringContainsString('customerId', $js); } public function testGetJSWithoutCustomer() @@ -72,10 +72,10 @@ class DaemonCollectorTest extends TestCase $js = $this->unit->buildScript()->getJs(); - $this->assertContains('', $js); - $this->assertContains('_rc(\'send\', \'pageView\');', $js); - $this->assertContains(self::SITE_KEY, $js); - $this->assertNotContains('customerId', $js); + $this->assertStringContainsString('', $js); + $this->assertStringContainsString('_rc(\'send\', \'pageView\');', $js); + $this->assertStringContainsString(self::SITE_KEY, $js); + $this->assertStringNotContainsString('customerId', $js); } } diff --git a/src/Test/Unit/Model/Observer/CustomerTest.php b/src/Test/Unit/Model/Observer/CustomerTest.php index 769b101..b44b337 100644 --- a/src/Test/Unit/Model/Observer/CustomerTest.php +++ b/src/Test/Unit/Model/Observer/CustomerTest.php @@ -16,7 +16,7 @@ class CustomerTest extends TestCase private $helper; private $mockServiceCustomer; - public function setUp() + public function setUp(): void { $this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class) ->disableOriginalConstructor() diff --git a/src/Test/Unit/Model/Observer/OrderCreateTest.php b/src/Test/Unit/Model/Observer/OrderCreateTest.php index 675fa34..4cf7e21 100644 --- a/src/Test/Unit/Model/Observer/OrderCreateTest.php +++ b/src/Test/Unit/Model/Observer/OrderCreateTest.php @@ -25,7 +25,7 @@ class OrderCreateTest extends TestCase private $mockServiceCustomer; private $mockCustomer; - public function setUp() + public function setUp(): void { $this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class) ->disableOriginalConstructor() diff --git a/src/Test/Unit/Model/Observer/OrderUpdateTest.php b/src/Test/Unit/Model/Observer/OrderUpdateTest.php index edfcc17..ae1693f 100644 --- a/src/Test/Unit/Model/Observer/OrderUpdateTest.php +++ b/src/Test/Unit/Model/Observer/OrderUpdateTest.php @@ -16,7 +16,7 @@ class OrderUpdateTest extends TestCase private $mockPayment; private $registry; - public function setUp() + public function setUp(): void { $this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class) ->disableOriginalConstructor() diff --git a/src/Test/Unit/Model/Service/CustomerTest.php b/src/Test/Unit/Model/Service/CustomerTest.php index 89fb636..a588a01 100644 --- a/src/Test/Unit/Model/Service/CustomerTest.php +++ b/src/Test/Unit/Model/Service/CustomerTest.php @@ -12,7 +12,7 @@ class CustomerTest extends TestCase private $mockOrder; private $mockBillingAddress; - public function setUp() + public function setUp(): void { $this->mockData = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Data::class) ->disableOriginalConstructor() @@ -72,14 +72,14 @@ class CustomerTest extends TestCase $result = $this->unit->prepareCustomerFromOrder($this->mockOrder); $this->assertNotEmpty($result); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertArrayNotHasKey('externalId', $result); $this->assertArrayHasKey('email', $result); $this->assertArrayHasKey('firstName', $result); $this->assertArrayHasKey('lastName', $result); $this->assertArrayHasKey('patronymic', $result); $this->assertArrayHasKey('address', $result); - $this->assertInternalType('array', $result['address']); + $this->assertIsArray($result['address']); $this->assertArrayHasKey('countryIso', $result['address']); $this->assertArrayHasKey('index', $result['address']); $this->assertArrayHasKey('region', $result['address']); @@ -167,7 +167,7 @@ class CustomerTest extends TestCase $result = $this->unit->process($this->mockCustomer); $this->assertNotEmpty($result); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertArrayHasKey('externalId', $result); $this->assertNotEmpty($result['externalId']); $this->assertEquals($this->getAfterSaveCustomerTestData()['id'], $result['externalId']); diff --git a/src/Test/Unit/Model/Service/IntegrationModuleTest.php b/src/Test/Unit/Model/Service/IntegrationModuleTest.php index ba87bed..d4a872d 100644 --- a/src/Test/Unit/Model/Service/IntegrationModuleTest.php +++ b/src/Test/Unit/Model/Service/IntegrationModuleTest.php @@ -13,7 +13,7 @@ class IntegrationModuleTest extends TestCase const ACCOUNT_URL = 'test'; - public function setUp() + public function setUp(): void { $this->mockData = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Data::class) ->disableOriginalConstructor() @@ -76,7 +76,7 @@ class IntegrationModuleTest extends TestCase $configuration['logo'] ); $this->assertArrayHasKey('code', $configuration); - $this->assertContains( + $this->assertStringContainsString( \Retailcrm\Retailcrm\Model\Service\IntegrationModule::INTEGRATION_CODE, $configuration['code'] ); @@ -90,7 +90,7 @@ class IntegrationModuleTest extends TestCase $this->assertArrayHasKey('accountUrl', $configuration); $this->assertEquals(self::ACCOUNT_URL, $configuration['accountUrl']); $this->assertArrayHasKey('integrationCode', $configuration); - $this->assertContains( + $this->assertStringContainsString( \Retailcrm\Retailcrm\Model\Service\IntegrationModule::INTEGRATION_CODE, $configuration['integrationCode'] ); diff --git a/src/Test/Unit/Model/Service/InventoriesUploadTest.php b/src/Test/Unit/Model/Service/InventoriesUploadTest.php index 9dfac27..e0f4c6c 100644 --- a/src/Test/Unit/Model/Service/InventoriesUploadTest.php +++ b/src/Test/Unit/Model/Service/InventoriesUploadTest.php @@ -11,7 +11,7 @@ class InventoriesUploadTest extends TestCase private $mockResponse; private $mockProduct; - public function setUp() + public function setUp(): void { $this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class) ->disableOriginalConstructor() diff --git a/src/Test/Unit/Model/Service/OrderTest.php b/src/Test/Unit/Model/Service/OrderTest.php index 5fec64c..b9402a0 100644 --- a/src/Test/Unit/Model/Service/OrderTest.php +++ b/src/Test/Unit/Model/Service/OrderTest.php @@ -13,7 +13,7 @@ class OrderTest extends TestCase private $mockOrder; private $unit; - public function setUp() + public function setUp(): void { $this->mockProductRepository = $this->getMockBuilder(\Magento\Catalog\Model\ProductRepository::class) ->disableOriginalConstructor()