PHP code example of proklung / bitrix-phpunit-testing-tools
1. Go to this page and download the library: Download proklung/bitrix-phpunit-testing-tools library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
proklung / bitrix-phpunit-testing-tools example snippets
protected function setupDatabaseData() : void
{
putenv('MYSQL_HOST=localhost');
putenv('MYSQL_DATABASE=bitrix_ci');
putenv('MYSQL_USER=root');
putenv('MYSQL_PASSWORD=');
}
protected function getDumpPath() : string
{
return $_SERVER['DOCUMENT_ROOT'] . '/Tests/dump/dump.sql';
}
protected function getPathSprintMigrations() : string
{
return __DIR__ . '../../../../../../Tests/sprint_migrations/';
}
protected function getMigrationsDir() : string
{
return __DIR__ . '/../migrations';
}
protected function makeMigration(string $name, string $template) : void
// ...
/**
* @label component
* @test
*/
public function useComponentInvoker() {
/** @var CBitrixComponent $componentObject */
$component = new \Prokl\BitrixTestingTools\Invokers\ComponentInvoker($componentObject);
$component->init();
$component->setParams(array("id" => 10));
$component->execute();
$this->getAssert()->equal($component->getResultValue("id"), 10, "Результат не верен");
}
/**
* @label component
* @test
*/
public function modifierForSomeTemplate() {
$rm = new \Prokl\BitrixTestingTools\Invokers\ResultModifierInvoker("project:test.with.class", "list");
$rm->setArResult(array("id" => 10));
$rm->execute();
$this->getAssert()->equal($rm->getArResultValue("id"), 10, "Параметры не равны");
}
// ...
/**
* @test
*/
public function handlersOfEventExist() {
$eventInvoker = new \Prokl\BitrixTestingTools\Invokers\EventInvoker("main", "OnPageStart");
$eventInvoker->setExecuteParams(array(
"IBLOCK_ID" => 12
));
$eventInvoker->execute();
$this->getAssert()->asTrue($eventInvoker->countOfHandlers() > 1);
}
$_GET['test'] = 'OK';
$this->goTo('/test/');
$url = $APPLICATION->GetCurPage(); // $url = '/test/index.php'
$request = Application::getInstance()->getContext()->getRequest();
$uriString = $request->getRequestUri(); // $uriString = '/test/'
$testGetParam = $request->getQuery('test'); // $testGetParam = 'OK'
getResultValue($name)
__construct($componentName, $template)
getArResultValue($name)
$name
__construct($module, $eventName)