Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/php_interface/wbs24.lib/tests/unit/ |
Upload File : |
<?php namespace Wbs24\Lib; use Bitrix\Main\Loader; class KitHelperTest extends BitrixTestCase { public function test_getProductIdsToPrices() { // входные параметры $productIds = [1]; // результат для проверки $expectedResult = [1 => 1000]; // заглушки Loader::includeModule('iblock'); $CIBlockResultStub = $this->createMock(\CIBlockResult::class); $fetchResults = [ [ 'ID' => 1, 'SCALED_PRICE_1' => 1000, ], false, ]; $CIBlockResultStub->method('Fetch') ->will($this->onConsecutiveCalls(...$fetchResults)); $CIBlockElementStub = $this->getMockBuilder(\stdClass::class) ->setMethods(['GetList']) ->getMock(); $CIBlockElementStub->method('GetList') ->willReturn($CIBlockResultStub); // вычисление результата $object = new Kit\Helper([ 'CIBlockElement' => $CIBlockElementStub, ]); $result = $object->getProductIdsToPrices($productIds); // проверка $this->assertEquals($expectedResult, $result); } public function test_calcKitPrice() { // входные параметры $ownerId = 1; // результат для проверки $expectedResult = 5000; // заглушки Loader::includeModule('catalog'); Loader::includeModule('iblock'); // для getKitProductIdsToQuantity() $CIBlockResultStub = $this->createMock(\CIBlockResult::class); $fetchResults = [ [ 'OWNER_ID' => 1, 'ITEM_ID' => 11, 'QUANTITY' => 5, ], false, ]; $CIBlockResultStub->method('Fetch') ->will($this->onConsecutiveCalls(...$fetchResults)); $CCatalogProductSetStub = $this->getMockBuilder(\stdClass::class) ->setMethods(['GetList']) ->getMock(); $CCatalogProductSetStub->method('GetList') ->willReturn($CIBlockResultStub); // для getProductIdsToPrices() $CIBlockResultStub = $this->createMock(\CIBlockResult::class); $fetchResults = [ [ 'ID' => 11, 'SCALED_PRICE_1' => 1000, ], false, ]; $CIBlockResultStub->method('Fetch') ->will($this->onConsecutiveCalls(...$fetchResults)); $CIBlockElementStub = $this->getMockBuilder(\stdClass::class) ->setMethods(['GetList']) ->getMock(); $CIBlockElementStub->method('GetList') ->willReturn($CIBlockResultStub); // доп. проверка $CIBlockElementStub->expects($this->once()) ->method('GetList') ->with( $this->anything(), $this->equalTo(["ID" => [11]]), $this->anything(), $this->anything(), $this->anything() ); // вычисление результата $object = new Kit\Helper([ 'CCatalogProductSet' => $CCatalogProductSetStub, 'CIBlockElement' => $CIBlockElementStub, ]); $result = $object->calcKitPrice($ownerId); // проверка $this->assertEquals($expectedResult, $result); } }