function BanIpTest::setUp

Overrides RulesIntegrationTestBase::setUp

File

tests/src/Unit/Integration/RulesAction/BanIpTest.php, line 48

Class

BanIpTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\BanIp @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

protected function setUp() : void {
    parent::setUp();
    // Must enable the ban module.
    $this->enableModule('ban');
    $this->banManager = $this->prophesize(BanIpManagerInterface::class);
    $this->container
        ->set('ban.ip_manager', $this->banManager
        ->reveal());
    // Mock a request.
    $this->request = $this->prophesize(Request::class);
    // Mock the request_stack service, make it return our mocked request,
    // and register it in the container.
    $this->requestStack = $this->prophesize(RequestStack::class);
    $this->requestStack
        ->getCurrentRequest()
        ->willReturn($this->request
        ->reveal());
    $this->container
        ->set('request_stack', $this->requestStack
        ->reveal());
    // Mock the logger.factory service, make it return the Rules logger channel,
    // and register it in the container.
    $this->logger = $this->prophesize(LoggerChannelInterface::class);
    $logger_factory = $this->prophesize(LoggerChannelFactoryInterface::class);
    $logger_factory->get('rules')
        ->willReturn($this->logger
        ->reveal());
    $this->container
        ->set('logger.factory', $logger_factory->reveal());
    // Instantiate the rules_ban_ip action.
    $this->action = $this->actionManager
        ->createInstance('rules_ban_ip');
}