-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]; | ||
} | ||
} |