Skip to content

Commit

Permalink
Тесты
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jun 26, 2021
1 parent 7c70af6 commit f047c67
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Framework/AutoconfigureConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@ class AutoconfigureConfig
* AutoconfigureConfig constructor.
*
* @param string[] $autoConfigure Дополнительные конфигураторы для тэгов.
*
* @throws RuntimeException Когда необходимая зависимость не существует.
*/
public function __construct(array $autoConfigure = [])
{
$this->autoConfigure = array_merge($this->autoConfigure, $autoConfigure);

$this->checkDependency();
}

/**
* Карта автоконфигурируемых тэгов.
*
* @return string[]
* @throws RuntimeException Когда необходимая зависимость не существует.
*/
public function getAutoConfigure(): array
{
$this->checkDependency();

return $this->autoConfigure;
}

Expand Down
82 changes: 82 additions & 0 deletions tests/Cases/AutoconfigureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Prokl\ServiceProvider\Tests\Cases;

use Prokl\ServiceProvider\Framework\AutoconfigureConfig;
use Prokl\TestingTools\Base\BaseTestCase;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\ObjectInitializerInterface;

/**
* Class AutoconfigureTest
* @package Prokl\ServiceProvider\Tests\Cases
* @coversDefaultClass AutoconfigureConfig
*
* @since 26.06.2021
*/
class AutoconfigureTest extends BaseTestCase
{
/**
* @var AutoconfigureConfig $obTestObject
*/
protected $obTestObject;

/**
* @inheritDoc
*/
protected function setUp(): void
{
parent::setUp();
$this->obTestObject = new AutoconfigureConfig();
}

/**
* getAutoConfigure(). Валидные классы.
*
* @return void
*/
public function testGetAutoConfigureValidClasses() : void
{
$result = $this->obTestObject->getAutoConfigure();

$this->assertArrayHasKey('controller.service_arguments', $result);
$this->assertSame(AbstractController::class, $result['controller.service_arguments']);

$this->assertArrayHasKey('controller.argument_value_resolver', $result);
$this->assertSame(ArgumentValueResolverInterface::class, $result['controller.argument_value_resolver']);

$this->assertArrayHasKey('container.service_locator', $result);
$this->assertSame(ServiceLocator::class, $result['container.service_locator']);

$this->assertArrayHasKey('kernel.event_subscriber', $result);
$this->assertSame(EventSubscriberInterface::class, $result['kernel.event_subscriber']);

$this->assertArrayHasKey('validator.constraint_validator', $result);
$this->assertSame(ConstraintValidatorInterface::class, $result['validator.constraint_validator']);

$this->assertArrayHasKey('validator.initializer', $result);
$this->assertSame(ObjectInitializerInterface::class, $result['validator.initializer']);
}

/**
* getAutoConfigure(). Несуществующий класс.
*
* @return void
*/
public function testGetAutoConfigureNotValidClasses() : void
{
$this->obTestObject = new AutoconfigureConfig(
[
'fake.key' => Fake::class
]
);

$this->expectException(RuntimeException::class);
$this->obTestObject->getAutoConfigure();
}
}

0 comments on commit f047c67

Please sign in to comment.