ChatExtensionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 45
c 0
b 0
f 0
dl 0
loc 73
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testDatabaseAdapter() 0 9 1
A testChats() 0 29 1
A testChatCommands() 0 15 1
A testMessageProcessors() 0 11 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Chat\DI;
5
6
require __DIR__ . "/../../../bootstrap.php";
7
8
use HeroesofAbenez\Chat\ChatCommandsProcessor;
9
use HeroesofAbenez\Chat\Test2Command;
10
use HeroesofAbenez\Chat\TestCommand;
11
use Tester\Assert;
12
use HeroesofAbenez\Chat\InvalidChatControlFactoryException;
13
use HeroesofAbenez\Chat\InvalidMessageProcessorException;
14
use HeroesofAbenez\Chat\InvalidDatabaseAdapterException;
15
use HeroesofAbenez\Chat\IExampleChatControlFactory;
16
17
final class ChatExtensionTest extends \Tester\TestCase {
18
  use \Testbench\TCompiledContainer;
19
  
20
  public function testChats(): void {
21
    /** @var IExampleChatControlFactory $factory */
22
    $factory = $this->getService(IExampleChatControlFactory::class);
23
    Assert::type(IExampleChatControlFactory::class, $factory);
24
    Assert::same("", $factory->create()->characterProfileLink);
25
    $config = [
26
      "chat" => [
27
        "characterProfileLink" => "Abc:",
28
      ]
29
    ];
30
    $this->refreshContainer($config);
31
    /** @var IExampleChatControlFactory $factory */
32
    $factory = $this->getService(IExampleChatControlFactory::class);
33
    Assert::type(IExampleChatControlFactory::class, $factory);
34
    Assert::same("Abc:", $factory->create()->characterProfileLink);
35
    $config = [
36
      "chat" => [
37
        "chats" => [
38
          "abc" => \Countable::class,
39
        ],
40
      ]
41
    ];
42
    Assert::exception(function() use($config) {
43
      $this->refreshContainer($config);
44
    }, InvalidChatControlFactoryException::class);
45
    $config["chat"]["chats"]["abc"] = IFakeFactory::class;
46
    Assert::exception(function() use($config) {
47
      $this->refreshContainer($config);
48
    }, InvalidChatControlFactoryException::class);
49
  }
50
  
51
  public function testMessageProcessors(): void {
52
    $config = [
53
      "chat" => [
54
        "messageProcessors" => [
55
          "abc" => \stdClass::class,
56
        ],
57
      ],
58
    ];
59
    Assert::exception(function() use($config) {
60
      $this->refreshContainer($config);
61
    }, InvalidMessageProcessorException::class);
62
  }
63
  
64
  public function testDatabaseAdapter(): void {
65
    $config = [
66
      "chat" => [
67
        "databaseAdapter" => \stdClass::class,
68
      ],
69
    ];
70
    Assert::exception(function() use($config) {
71
      $this->refreshContainer($config);
72
    }, InvalidDatabaseAdapterException::class);
73
  }
74
  
75
  public function testChatCommands(): void {
76
    $config = [
77
      "services" => [
78
        TestCommand::class, Test2Command::class,
79
      ]
80
    ];
81
    $this->refreshContainer($config);
82
    /** @var ChatCommandsProcessor $processor */
83
    $processor = $this->getService(ChatCommandsProcessor::class);
84
    /** @var TestCommand $command1 */
85
    $command1 = $this->getService(TestCommand::class);
86
    /** @var Test2Command $command2 */
87
    $command2 = $this->getService(Test2Command::class);
88
    Assert::true($processor->hasCommand($command1->getName()));
89
    Assert::true($processor->hasCommand($command2->getName()));
90
  }
91
}
92
93
$test = new ChatExtensionTest();
94
$test->run();
95
?>