-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
237 serializer test #308
237 serializer test #308
Changes from 22 commits
0e685c3
76d68d7
ef264a9
2f5b094
179a2ac
cce3d06
4feb8b4
ea30810
568a508
385de8e
67b0b48
ea84841
53b855f
fdcbb21
22c4e70
e42100f
e1037c9
3c45698
5b837e4
ba6fbe8
c496fd7
a05285e
c75b49e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
namespace Bitrix24\SDK\Services\CRM\Deal\Result; | ||
|
||
use Bitrix24\SDK\Core\Exceptions\BaseException; | ||
use Bitrix24\SDK\Core\Response\Response; | ||
use Bitrix24\SDK\Core\Result\AbstractResult; | ||
use Money\Currency; | ||
|
||
/** | ||
* Class DealProductRowItemsResult | ||
|
@@ -15,15 +17,23 @@ | |
*/ | ||
class DealProductRowItemsResult extends AbstractResult | ||
{ | ||
private Currency $currency; | ||
|
||
public function __construct(Response $coreResponse,Currency $currency) | ||
{ | ||
parent::__construct($coreResponse); | ||
$this->currency = $currency; | ||
} | ||
|
||
/** | ||
* @return DealProductRowItemResult[] | ||
* @throws BaseException | ||
*/ | ||
public function getProductRows(): array | ||
{ | ||
$res = []; | ||
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $productRow) { | ||
$res[] = new DealProductRowItemResult($productRow); | ||
foreach ($this->getCoreResponse()->getResponseData()->getResult()['result']['rows'] as $productRow) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему ты тут добавил? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вообщем у меня с этим сейчас возникли проблемы , но я вроде бы пофиксил это добавив дополнительное условие. Проблема была в том что наш метод очень умный getSuperSuperSmart(get). И если мы принимаем только айдишник сделки, то у нас выполняется batch запрос в котором мы возвращаем саму сделку и строку товара, это все у нас записывается в переменную $res. Потом мы ее добавляем в наш объект DealProductRowItemsResult. После чего нам приходится дополнительно указывать [result][rows] , так как есть еще выбор выбрать [result][deal]. А вот если мы указываем в нашем методе и айдишник и валюту , то тогда в DealProductRowItemsResult у нас приходит лишь один запрос с одним массивом и нам не нужно указывать [result][rows]. |
||
$res[] = new DealProductRowItemResult($productRow,$this->currency); | ||
} | ||
|
||
return $res; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
use Bitrix24\SDK\Core\Result\UpdatedItemResult; | ||
use Bitrix24\SDK\Services\AbstractService; | ||
use Bitrix24\SDK\Services\CRM\Deal\Result\DealProductRowItemsResult; | ||
use Bitrix24\SDK\Services\CRM\Deal\Result\DealResult; | ||
use Money\Currency; | ||
|
||
/** | ||
* Class DealProductRows | ||
|
@@ -23,20 +25,74 @@ class DealProductRows extends AbstractService | |
* @link https://training.bitrix24.com/rest_help/crm/deals/crm_deal_productrows_get.php | ||
* | ||
* @param int $dealId | ||
* | ||
* @param \Money\Currency $currency | ||
* @return DealProductRowItemsResult | ||
* @throws BaseException | ||
* @throws TransportException | ||
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException | ||
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException | ||
*/ | ||
public function get(int $dealId): DealProductRowItemsResult | ||
public function getStupid(int $dealId, Currency $currency): DealProductRowItemsResult | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. С этим понятно всё, как отладим, можно удалять There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. готово |
||
{ | ||
return new DealProductRowItemsResult( | ||
$this->core->call( | ||
'crm.deal.productrows.get', | ||
[ | ||
'id' => $dealId, | ||
] | ||
) | ||
), | ||
$currency | ||
); | ||
} | ||
|
||
/** | ||
* @param int $dealId | ||
* @return \Bitrix24\SDK\Services\CRM\Deal\Result\DealProductRowItemsResult | ||
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException | ||
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException | ||
*/ | ||
public function getSuperSmart(int $dealId): DealProductRowItemsResult | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. с этим тоже понятно, как отладим, можно удалять There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. готово |
||
{ | ||
$res = $this->core->call('batch',[ | ||
mesilov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'halt'=>0, | ||
'cmd'=>[ | ||
'deal' => sprintf('crm.deal.get?ID=%s', $dealId), | ||
'rows' => sprintf('crm.deal.productrows.get?ID=%s', $dealId) | ||
], | ||
]); | ||
$data = $res->getResponseData()->getResult(); | ||
$currency = new Currency($data['result']['deal']['CURRENCY_ID']); | ||
return new DealProductRowItemsResult($res,$currency); | ||
} | ||
|
||
/** | ||
* @param int $dealId | ||
* @param \Money\Currency|null $currency | ||
* @return \Bitrix24\SDK\Services\CRM\Deal\Result\DealProductRowItemsResult | ||
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException | ||
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException | ||
*/ | ||
public function getSuperSuperSmart(int $dealId, Currency $currency = null): DealProductRowItemsResult | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. переименовать в get( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. готово |
||
{ | ||
if ($currency === null){ | ||
$res = $this->core->call('batch',[ | ||
'halt'=>0, | ||
'cmd'=>[ | ||
'deal' => sprintf('crm.deal.get?ID=%s', $dealId), | ||
'rows' => sprintf('crm.deal.productrows.get?ID=%s', $dealId) | ||
], | ||
]); | ||
$data = $res->getResponseData()->getResult(); | ||
$currency = new Currency($data['result']['deal']['CURRENCY_ID']); | ||
return new DealProductRowItemsResult($res,$currency); | ||
} | ||
|
||
return new DealProductRowItemsResult( | ||
$this->core->call( | ||
'crm.deal.productrows.get', | ||
[ | ||
'id' => $dealId, | ||
] | ||
), | ||
$currency | ||
); | ||
} | ||
|
||
|
@@ -78,7 +134,7 @@ public function set(int $dealId, array $productRows): UpdatedItemResult | |
$this->core->call( | ||
'crm.deal.productrows.set', | ||
[ | ||
'id' => $dealId, | ||
'id' => $dealId, | ||
'rows' => $productRows, | ||
] | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ | |
use Bitrix24\SDK\Services\CRM\Deal\Service\Deal; | ||
use Bitrix24\SDK\Services\CRM\Deal\Service\DealProductRows; | ||
use Bitrix24\SDK\Tests\Integration\Fabric; | ||
use Money\Currencies\ISOCurrencies; | ||
use Money\Currency; | ||
use Money\Formatter\DecimalMoneyFormatter; | ||
use Money\Money; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Причеши тесты, оставь тест на get( с двумя вариантами:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KarlsonComplete а сейчас? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ну тесты я делаю не очень , надеюсь готово) |
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
|
@@ -28,46 +32,64 @@ class DealProductRowsTest extends TestCase | |
*/ | ||
public function testSet(): void | ||
{ | ||
|
||
$callCosts = new Money(1050, new Currency('RUB')); | ||
$currencies = new ISOCurrencies(); | ||
|
||
$moneyFormatter = new DecimalMoneyFormatter($currencies); | ||
$newDealId = $this->dealService->add(['TITLE' => 'test deal'])->getId(); | ||
$this::assertCount(0, $this->dealProductRowsService->get($newDealId)->getProductRows()); | ||
$this::assertCount(0, $this->dealProductRowsService->getSuperSmart($newDealId)->getProductRows()); | ||
$this::assertTrue( | ||
$this->dealProductRowsService->set( | ||
$newDealId, | ||
[ | ||
[ | ||
'PRODUCT_NAME' => 'qqqq', | ||
'PRICE'=> $moneyFormatter->format($callCosts), | ||
], | ||
] | ||
)->isSuccess() | ||
); | ||
$this::assertCount(1, $this->dealProductRowsService->get($newDealId)->getProductRows()); | ||
$this::assertCount(1, $this->dealProductRowsService->getSuperSmart($newDealId)->getProductRows()); | ||
$mas = $this->dealProductRowsService->getSuperSmart($newDealId)->getProductRows()[0]; | ||
$money = $moneyFormatter->format($mas->PRICE); | ||
|
||
|
||
} | ||
|
||
/** | ||
* @throws BaseException | ||
* @throws TransportException | ||
* @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealProductRows::get | ||
*/ | ||
public function testGet(): void | ||
{ | ||
$newDealId = $this->dealService->add(['TITLE' => 'test deal'])->getId(); | ||
$this::assertCount(0, $this->dealProductRowsService->get($newDealId)->getProductRows()); | ||
$callCosts = new Money(1050, new Currency('EUR')); | ||
$currencies = new ISOCurrencies(); | ||
|
||
$moneyFormatter = new DecimalMoneyFormatter($currencies); | ||
$newDealId = $this->dealService->add(['TITLE' => 'test deal','CURRENCY_ID'=>$callCosts->getCurrency()->getCode()])->getId(); | ||
$this::assertTrue( | ||
$this->dealProductRowsService->set( | ||
$newDealId, | ||
[ | ||
[ | ||
'PRODUCT_NAME' => 'qqqq', | ||
'PRICE'=> $moneyFormatter->format($callCosts), | ||
], | ||
] | ||
)->isSuccess() | ||
); | ||
$this::assertCount(1, $this->dealProductRowsService->get($newDealId)->getProductRows()); | ||
$currency = $callCosts->getCurrency(); | ||
$res = $this->dealProductRowsService->getSuperSuperSmart($newDealId); | ||
foreach ($res->getProductRows() as $productRow){ | ||
var_dump($productRow->PRICE); | ||
} | ||
} | ||
|
||
public function setUp(): void | ||
{ | ||
$this->dealService = Fabric::getServiceBuilder()->getCRMScope()->deal(); | ||
$this->dealProductRowsService = Fabric::getServiceBuilder()->getCRMScope()->dealProductRows(); | ||
$this->core=Fabric::getCore(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавь остальные поля
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KarlsonComplete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
готово