Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 65... Línea 65...
65
    protected function get_mocked_instance_for_version(
65
    protected function get_mocked_instance_for_version(
66
        string $version,
66
        string $version,
67
        array &$historycontainer = [],
67
        array &$historycontainer = [],
68
        ?MockHandler $mock = null,
68
        ?MockHandler $mock = null,
69
    ): matrix_client {
69
    ): matrix_client {
-
 
70
        // If no mock is provided, use get_mocked_http_client to create the mock and client.
70
        if ($mock === null) {
71
        if ($mock === null) {
-
 
72
            ['mock' => $mock, 'client' => $client] = $this->get_mocked_http_client(
-
 
73
                history: $historycontainer
-
 
74
            );
-
 
75
        } else {
-
 
76
            // If mock is provided, create the handlerstack and history middleware.
-
 
77
            $handlerstack = HandlerStack::create($mock);
-
 
78
            $history = Middleware::history($historycontainer);
71
            $mock = new MockHandler();
79
            $handlerstack->push($history);
-
 
80
            $client = new http_client(['handler' => $handlerstack]);
72
        }
81
        }
73
        // Add the version response.
82
        // Add the version response.
74
        $mock->append($this->get_mocked_version_response([$version]));
83
        $mock->append($this->get_mocked_version_response([$version]));
Línea 75... Línea -...
75
 
-
 
76
        $handlerstack = HandlerStack::create($mock);
-
 
77
        $history = Middleware::history($historycontainer);
-
 
78
        $handlerstack->push($history);
-
 
79
        $client = new http_client(['handler' => $handlerstack]);
84
 
Línea 80... Línea 85...
80
        mocked_matrix_client::set_client($client);
85
        mocked_matrix_client::set_client($client);
81
 
86
 
82
        $client = mocked_matrix_client::instance(
87
        $instance = mocked_matrix_client::instance(
83
            'https://example.com',
88
            'https://example.com',
Línea 84... Línea 89...
84
            'testtoken',
89
            'testtoken',
85
        );
90
        );
Línea 86... Línea 91...
86
 
91
 
87
        // Remove the request that is required to fetch the version from the history.
92
        // Remove the request that is required to fetch the version from the history.
Línea 88... Línea 93...
88
        array_shift($historycontainer);
93
        array_shift($historycontainer);
89
 
94
 
90
        return $client;
95
        return $instance;
91
    }
96
    }
92
 
97
 
93
    /**
98
    /**
94
     * Get a mocked response for the /versions well-known URI.
99
     * Get a mocked response for the /versions well-known URI.
95
     *
100
     *
96
     * @param array|null $versions
101
     * @param array|null $versions
97
     * @param array|null $unstablefeatures
102
     * @param array|null $unstablefeatures
98
     * @return Response
103
     * @return Response
99
     */
104
     */
100
    protected function get_mocked_version_response(
105
    protected function get_mocked_version_response(
101
        array $versions = null,
106
        ?array $versions = null,
102
        array $unstablefeatures = null,
107
        ?array $unstablefeatures = null,