diff --git a/src/Traits/BBCComponentTrait.php b/src/Traits/BBCComponentTrait.php new file mode 100644 index 0000000..3034766 --- /dev/null +++ b/src/Traits/BBCComponentTrait.php @@ -0,0 +1,55 @@ +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' + ); + } +} diff --git a/src/Utils/PHPUnitBitrixUtils.php b/src/Utils/PHPUnitBitrixUtils.php new file mode 100644 index 0000000..8d17367 --- /dev/null +++ b/src/Utils/PHPUnitBitrixUtils.php @@ -0,0 +1,64 @@ + '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)]; + } +}