Porting all TestMainApi tests
This commit is contained in:
parent
07bb38828c
commit
b299540a2a
4 changed files with 331 additions and 4 deletions
42
tests/BaseTestCase.php
Normal file
42
tests/BaseTestCase.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Aryess\PhpMatrixSdk;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Middleware;
|
||||
|
||||
abstract class BaseTestCase extends \PHPUnit\Framework\TestCase {
|
||||
const MATRIX_V2_API_PATH = "/_matrix/client/r0";
|
||||
protected $userId = "@alice:matrix.org";
|
||||
|
||||
/**
|
||||
* Call protected/private method of a class.
|
||||
*
|
||||
* @param object &$object Instantiated object that we will run method on.
|
||||
* @param string $methodName Method name to call
|
||||
* @param array $parameters Array of parameters to pass into method.
|
||||
*
|
||||
* @return mixed Method return.
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function invokePrivateMethod(&$object, $methodName, array $parameters = []) {
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$method = $reflection->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invokeArgs($object, $parameters);
|
||||
}
|
||||
|
||||
protected function getMockClientHandler(array $responses, array &$container): HandlerStack {
|
||||
$mock = new MockHandler($responses);
|
||||
$history = Middleware::history($container);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$handler->push($history);
|
||||
|
||||
return $handler;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue