1. Go to this page and download the library: Download kosmos/bitrix-tests 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/ */
kosmos / bitrix-tests example snippets
use PHPUnit\Framework\Attributes\DataProvider;
public static function exampleProvider(): array
{
return [
['id' => 1],
['id' => 2],
['id' => 3],
];
}
#[DataProvider('exampleProvider')]
public function testGetId(int $id): void
{
$entity = new Entity($id);
$this->assertEquals($id, $entity->getId());
}
use PHPUnit\Framework\Attributes\Before;
class SameServiceTest extends TestCase
{
protected SameServiceInterface $service;
#[Before] protected function setUpService(): void
{
Loader::
use Bitrix\Main\Result;
use Bitrix\Main\Error;
class SameService
{
public function getDetail($id): Result
{
$result = new Result();
if (!Access::canView($id)) {
return $result->addError(new Error('Access denied'));
}
return $result->setData(['entity' => $this->repository->get($id)]);
}
}
use Mockery;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
#[RunTestsInSeparateProcesses] class SameServiceTest extends TestCase
{
public function testGetDetail(): void
{
$access = Mockery::mock('overload:\Access');
$access->shouldReceive('canView')->once()->with(1)->andReturn(true);
$id = 1;
$result = $this->service->getDetail($id);
$this->assertResultSuccess($result);
}
}