Skip to content

Commit

Permalink
Тесты
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 13, 2021
1 parent 1fa0be5 commit 1cdf839
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Utils/Loaders/PhpLoaderSettingsBitrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function load($resource, string $type = null)
}, $this, ProtectedPhpFileLoader::class);

try {
$callback = $load($path, $this->env);
if (is_array($callback)) {
$settings = $load($path, $this->env);
if (is_array($settings)) {
$adapter = new BitrixSettingsDiAdapter();
$adapter->importServices($container, $callback);
$adapter->importServices($container, $settings);
}
} finally {
$this->instanceof = [];
Expand Down Expand Up @@ -78,9 +78,9 @@ public function loadBitrixConfig(string $key, bool $loadModulesServices = true)
{
$mainBitrixServices = Configuration::getInstance()->get($key) ?? [];

// Собрать конфиги всех установленных модулей.
$servicesModules = [];

// Собрать конфиги всех установленных модулей.
if ($loadModulesServices) {
foreach (ModuleManager::getInstalledModules() as $module) {
$services = Configuration::getInstance($module['ID'])->get($key) ?? [];
Expand Down
124 changes: 124 additions & 0 deletions tests/Cases/PhpLoaderSettingsBitrixTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Prokl\ServiceProvider\Tests\Cases;

use Exception;
use Prokl\BitrixTestingTools\Base\BitrixableTestCase;
use Prokl\ServiceProvider\ServiceProvider;
use Prokl\ServiceProvider\Services\AppKernel;
use Prokl\ServiceProvider\Utils\Loaders\PhpLoaderSettingsBitrix;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Config\FileLocator;

/**
* Class PhpLoaderSettingsBitrixTest
* @package Prokl\ServiceProvider\Tests\Cases
*
* @since 13.07.2021
*/
class PhpLoaderSettingsBitrixTest extends BitrixableTestCase
{
/**
* @var PhpLoaderSettingsBitrix $obTestObject
*/
protected $obTestObject;

/**
* @var ContainerBuilder $dummyContainer
*/
private $dummyContainer;

/**
* @var AppKernel
*/
private $kernel;

/**
* @var string $pathYamlConfig Путь к конфигу.
*/
private $fixture = '/../../../../tests/Fixtures/Settings';

/**
* @var string $pathYamlConfig Путь к конфигу.
*/
private $pathYamlConfig = '../../../../tests/Fixtures/config/test_container.yaml';

/**
* @inheritDoc
* @throws Exception
*/
protected function setUp(): void
{
parent::setUp();

$_ENV['DEBUG'] = true;
$this->container = new ServiceProvider(
$this->pathYamlConfig
);

$this->dummyContainer = $this->container->container();

$this->kernel = $this->dummyContainer->get('kernel');
$locator = new FileLocator($this->kernel);

$this->obTestObject = new PhpLoaderSettingsBitrix(
$this->dummyContainer,
$locator
);
}

/**
* supports().
*
* @param string $file Файл.
*
* @return void
*
* @dataProvider dataProviderValidBitrixConfigFilename
*/
public function testSupports(string $file) : void
{
$result = $this->obTestObject->supports($file);

$this->assertTrue($result, 'Валидный конфиг не прошел проверку.');
}

/**
* @return array
*/
public function dataProviderValidBitrixConfigFilename() : array
{
return [
[$_SERVER['DOCUMENT_ROOT'] . $this->fixture . '/.settings.php'],
[$_SERVER['DOCUMENT_ROOT'] . $this->fixture . '/.settings_extra.php']
];
}

/**
* supports(). Невалидные файлы.
*
* @param string $file Файл.
*
* @return void
*
* @dataProvider dataProviderInvalidBitrixConfigFilename
*/
public function testSupportsInvalid(string $file) : void
{
$result = $this->obTestObject->supports($file);

$this->assertFalse($result, 'Невалидный конфиг прошел проверку.');
}

/**
* @return array
*/
public function dataProviderInvalidBitrixConfigFilename() : array
{
return [
[$_SERVER['DOCUMENT_ROOT'] . $this->fixture . '/.config.php'],
[$_SERVER['DOCUMENT_ROOT'] . $this->fixture . '/.settings.html'],
[$_SERVER['DOCUMENT_ROOT'] . $this->fixture . '/.settings_extra'],
];
}
}

0 comments on commit 1cdf839

Please sign in to comment.