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
|
|
|
{ |
19
|
|
|
use \Testbench\TCompiledContainer; |
20
|
|
|
|
21
|
|
|
public function testChats(): void |
22
|
|
|
{ |
23
|
|
|
/** @var IExampleChatControlFactory $factory */ |
24
|
|
|
$factory = $this->getService(IExampleChatControlFactory::class); |
25
|
|
|
Assert::type(IExampleChatControlFactory::class, $factory); |
26
|
|
|
Assert::same("", $factory->create()->characterProfileLink); |
27
|
|
|
$config = [ |
28
|
|
|
"chat" => [ |
29
|
|
|
"characterProfileLink" => "Abc:", |
30
|
|
|
] |
31
|
|
|
]; |
32
|
|
|
$this->refreshContainer($config); |
33
|
|
|
/** @var IExampleChatControlFactory $factory */ |
34
|
|
|
$factory = $this->getService(IExampleChatControlFactory::class); |
35
|
|
|
Assert::type(IExampleChatControlFactory::class, $factory); |
36
|
|
|
Assert::same("Abc:", $factory->create()->characterProfileLink); |
37
|
|
|
$config = [ |
38
|
|
|
"chat" => [ |
39
|
|
|
"chats" => [ |
40
|
|
|
"abc" => \Countable::class, |
41
|
|
|
], |
42
|
|
|
] |
43
|
|
|
]; |
44
|
|
|
Assert::exception(function () use ($config) { |
45
|
|
|
$this->refreshContainer($config); |
46
|
|
|
}, InvalidChatControlFactoryException::class); |
47
|
|
|
$config["chat"]["chats"]["abc"] = IFakeFactory::class; |
48
|
|
|
Assert::exception(function () use ($config) { |
49
|
|
|
$this->refreshContainer($config); |
50
|
|
|
}, InvalidChatControlFactoryException::class); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testMessageProcessors(): void |
54
|
|
|
{ |
55
|
|
|
$config = [ |
56
|
|
|
"chat" => [ |
57
|
|
|
"messageProcessors" => [ |
58
|
|
|
"abc" => \stdClass::class, |
59
|
|
|
], |
60
|
|
|
], |
61
|
|
|
]; |
62
|
|
|
Assert::exception(function () use ($config) { |
63
|
|
|
$this->refreshContainer($config); |
64
|
|
|
}, InvalidMessageProcessorException::class); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testDatabaseAdapter(): void |
68
|
|
|
{ |
69
|
|
|
$config = [ |
70
|
|
|
"chat" => [ |
71
|
|
|
"databaseAdapter" => \stdClass::class, |
72
|
|
|
], |
73
|
|
|
]; |
74
|
|
|
Assert::exception(function () use ($config) { |
75
|
|
|
$this->refreshContainer($config); |
76
|
|
|
}, InvalidDatabaseAdapterException::class); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testChatCommands(): void |
80
|
|
|
{ |
81
|
|
|
$config = [ |
82
|
|
|
"services" => [ |
83
|
|
|
TestCommand::class, Test2Command::class, |
84
|
|
|
] |
85
|
|
|
]; |
86
|
|
|
$this->refreshContainer($config); |
87
|
|
|
/** @var ChatCommandsProcessor $processor */ |
88
|
|
|
$processor = $this->getService(ChatCommandsProcessor::class); |
89
|
|
|
/** @var TestCommand $command1 */ |
90
|
|
|
$command1 = $this->getService(TestCommand::class); |
91
|
|
|
/** @var Test2Command $command2 */ |
92
|
|
|
$command2 = $this->getService(Test2Command::class); |
93
|
|
|
Assert::true($processor->hasCommand($command1->getName())); |
94
|
|
|
Assert::true($processor->hasCommand($command2->getName())); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$test = new ChatExtensionTest(); |
99
|
|
|
$test->run(); |
100
|
|
|
|