Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 18... Línea 18...
18
 
18
 
19
use communication_matrix\local\command;
19
use communication_matrix\local\command;
20
use communication_matrix\local\spec\v1p7;
20
use communication_matrix\local\spec\v1p7;
21
use communication_matrix\local\spec\features;
21
use communication_matrix\local\spec\features;
22
use communication_matrix\tests\fixtures\mocked_matrix_client;
-
 
23
use core\http_client;
22
use communication_matrix\tests\fixtures\mocked_matrix_client;
24
use GuzzleHttp\Handler\MockHandler;
-
 
25
use GuzzleHttp\HandlerStack;
-
 
26
use GuzzleHttp\Middleware;
23
use GuzzleHttp\Handler\MockHandler;
27
use GuzzleHttp\Psr7\Response;
24
use GuzzleHttp\Psr7\Response;
Línea 28... Línea 25...
28
use moodle_exception;
25
use moodle_exception;
29
 
26
 
Línea 38... Línea 35...
38
 * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
35
 * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 * @covers \communication_matrix\matrix_client
37
 * @covers \communication_matrix\matrix_client
41
 * @coversDefaultClass \communication_matrix\matrix_client
38
 * @coversDefaultClass \communication_matrix\matrix_client
42
 */
39
 */
43
class matrix_client_test extends \advanced_testcase {
40
final class matrix_client_test extends \advanced_testcase {
44
    use matrix_client_test_trait;
41
    use matrix_client_test_trait;
Línea 45... Línea 42...
45
 
42
 
46
    /**
43
    /**
47
     * Data provider for valid calls to ::instance.
44
     * Data provider for valid calls to ::instance.
Línea 87... Línea 84...
87
     */
84
     */
88
    public function test_instance(
85
    public function test_instance(
89
        ?array $versions,
86
        ?array $versions,
90
        string $expectedversion,
87
        string $expectedversion,
91
    ): void {
88
    ): void {
92
        // Create a mock and queue two responses.
-
 
93
 
-
 
94
        $mock = new MockHandler([
-
 
95
            $this->get_mocked_version_response($versions),
-
 
96
        ]);
-
 
97
        $handlerstack = HandlerStack::create($mock);
-
 
98
        $container = [];
89
        $container = [];
99
        $history = Middleware::history($container);
90
        ['client' => $client, 'mock' => $mock] = $this->get_mocked_http_client(
100
        $handlerstack->push($history);
91
            history: $container,
-
 
92
        );
-
 
93
 
101
        $client = new http_client(['handler' => $handlerstack]);
94
        $mock->append($this->get_mocked_version_response($versions));
-
 
95
 
102
        mocked_matrix_client::set_client($client);
96
        mocked_matrix_client::set_client($client);
Línea 103... Línea 97...
103
 
97
 
104
        $instance = mocked_matrix_client::instance(
98
        $instance = mocked_matrix_client::instance(
105
            'https://example.com',
99
            'https://example.com',
Línea 119... Línea 113...
119
 
113
 
120
    /**
114
    /**
121
     * Test that the instance method returns a valid instance for the given versions.
115
     * Test that the instance method returns a valid instance for the given versions.
122
     */
116
     */
123
    public function test_instance_cached(): void {
-
 
124
        $mock = new MockHandler([
-
 
125
            $this->get_mocked_version_response(),
-
 
126
            $this->get_mocked_version_response(),
-
 
127
        ]);
-
 
128
        $handlerstack = HandlerStack::create($mock);
117
    public function test_instance_cached(): void {
-
 
118
        $container = [];
129
        $container = [];
119
        ['client' => $client, 'mock' => $mock] = $this->get_mocked_http_client(
-
 
120
            history: $container,
-
 
121
        );
130
        $history = Middleware::history($container);
122
 
131
        $handlerstack->push($history);
123
        // Queue two responses.
-
 
124
        $mock->append($this->get_mocked_version_response());
-
 
125
        $mock->append($this->get_mocked_version_response());
132
        $client = new http_client(['handler' => $handlerstack]);
126
 
Línea 133... Línea 127...
133
        mocked_matrix_client::set_client($client);
127
        mocked_matrix_client::set_client($client);
Línea 134... Línea 128...
134
 
128
 
Línea 151... Línea 145...
151
 
145
 
152
    /**
146
    /**
153
     * Test that the instance method throws an appropriate exception if no support is found.
147
     * Test that the instance method throws an appropriate exception if no support is found.
154
     */
148
     */
-
 
149
    public function test_instance_no_support(): void {
-
 
150
        ['client' => $client, 'mock' => $mock] = $this->get_mocked_http_client();
155
    public function test_instance_no_support(): void {
151
 
Línea 156... Línea -...
156
        // Create a mock and queue two responses.
-
 
157
 
-
 
158
        $mock = new MockHandler([
-
 
159
            $this->get_mocked_version_response(['v99.9']),
-
 
160
        ]);
-
 
161
        $handlerstack = HandlerStack::create($mock);
-
 
162
        $container = [];
-
 
163
        $history = Middleware::history($container);
-
 
164
        $handlerstack->push($history);
152
        $mock->append($this->get_mocked_version_response(['v99.9']));
Línea 165... Línea 153...
165
        $client = new http_client(['handler' => $handlerstack]);
153
 
166
        mocked_matrix_client::set_client($client);
154
        mocked_matrix_client::set_client($client);