Skip to content

Commit

Permalink
Мелкие дополнения.
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Apr 25, 2021
1 parent d5426da commit c629261
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Traits/BBCComponentTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Prokl\BitrixTestingTools\Traits;

use Prokl\TestingTools\Tools\PHPUnitUtils;
use ReflectionException;

/**
* Trait BBCComponentTrait
* Утилиты для тестирования Базовых битриксовых компонентов (https://github.com/bitrix-expert/bbc).
* @package Local\Tests\Traits
*/
trait BBCComponentTrait
{
/**
* Задать arParams компонента.
*
* @param array $arParams
*
* @return void
* @throws ReflectionException
*/
private function arParams(array $arParams = []) : void
{
PHPUnitUtils::setProtectedProperty(
$this->obTestObject,
'arParams',
$arParams
);
}

/**
* Выполнить executeMain.
*
* @param mixed $mock
*
* @return mixed
* @throws ReflectionException
*/
private function runExecuteMain($mock = null)
{
$mock = $mock ?: $this->obTestObject;

PHPUnitUtils::callMethod(
$mock,
'executeMain',
[]
);

return PHPUnitUtils::getProtectedProperty(
$mock,
'arResult'
);
}
}
64 changes: 64 additions & 0 deletions src/Utils/PHPUnitBitrixUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Prokl\BitrixTestingTools\Utils;

use CIBlock;

/**
* Class Prokl\BitrixTestingTools\Utils
* @package Local\Tests
*/
class PHPUnitBitrixUtils
{
/**
* Случайный ID инфоблока.
*
* @return integer
*/
public static function getRandomIdIblock() : int
{
$ib_list = CIBlock::GetList(
[],
[
"ACTIVE" => 'Y',
]
);

while ($ib = $ib_list->GetNext()) {
$arIds[] = $ib['ID'];
}

if (empty($arIds)) {
return 0;
}

return $arIds[rand(1, count($arIds) - 1)];
}

/**
* Случайный ID инфоблока с непустым полем DESCRIPTION.
*
* @return integer
*/
public static function getRandomIblockIdWithTextInfo() : int
{
$ibQuery = CIBlock::GetList(
[],
[
"ACTIVE" => 'Y',
]
);

while ($obIblock = $ibQuery->GetNext()) {
if (!empty($obIblock['DESCRIPTION'])) {
$arIds[] = $obIblock['ID'];
}
}

if (empty($arIds)) {
return 0;
}

return $arIds[rand(1, count($arIds) - 1)];
}
}

0 comments on commit c629261

Please sign in to comment.