object = new InstantActionQueue(); } public function testIsActionEnabledNoActionConfig(): void { $this->object->setOptions([]); $action = $this->createMock(QueuedAction::class); $action->method('getId')->willReturn('FAKE_ID'); $this->expectException(ActionQueueException::class); $this->object->isActionEnabled($action); } /** * @param string $actionId * @param array $options * @param bool $expected * @throws ActionQueueException * @throws \common_exception_Error * * @dataProvider dataProviderTestIsActionEnabled */ public function testIsActionEnabled(string $actionId, array $options, bool $expected): void { $this->object->setOptions($options); $action = $this->createMock(QueuedAction::class); $action->method('getId')->willReturn($actionId); $result = $this->object->isActionEnabled($action); static::assertSame($expected, $result, 'Result of checking if action is enabled must be as expected.'); } public function dataProviderTestIsActionEnabled(): array { return [ 'No restrictions' => [ 'actionId' => 'ACTION_1', 'options' => [ 'actions' => [ 'ACTION_1' => [] ] ], 'expected' => false, ], 'One restriction - disabled' => [ 'actionId' => 'ACTION_1', 'options' => [ 'actions' => [ 'ACTION_1' => [ 'restrictions' => [ 'restriction_1' => 0 ] ] ] ], 'expected' => false, ], 'One restriction - enabled (int)' => [ 'actionId' => 'ACTION_1', 'options' => [ 'actions' => [ 'ACTION_1' => [ 'restrictions' => [ 'restriction_1' => 1 ] ] ] ], 'expected' => true, ], 'One restriction - enabled (array)' => [ 'actionId' => 'ACTION_1', 'options' => [ 'actions' => [ 'ACTION_1' => [ 'restrictions' => [ 'restriction_1' => [] ] ] ] ], 'expected' => true, ], 'Multiple restrictions - disabled' => [ 'actionId' => 'ACTION_1', 'options' => [ 'actions' => [ 'ACTION_1' => [ 'restrictions' => [ 'restriction_1' => 0, 'restriction_2' => 0 ] ] ] ], 'expected' => false, ], 'Multiple restrictions - enabled' => [ 'actionId' => 'ACTION_1', 'options' => [ 'actions' => [ 'ACTION_1' => [ 'restrictions' => [ 'restriction_1' => 1, 'restriction_2' => 0 ] ] ] ], 'expected' => true, ], ]; } }