1<?php 2 3namespace MatrixPhp; 4 5use GuzzleHttp\Client; 6use GuzzleHttp\Handler\MockHandler; 7use GuzzleHttp\HandlerStack; 8use GuzzleHttp\Psr7\Response; 9use GuzzleHttp\Psr7\Request; 10use GuzzleHttp\Middleware; 11 12abstract class BaseTestCase extends \PHPUnit\Framework\TestCase { 13 const MATRIX_V2_API_PATH = "/_matrix/client/r0"; 14 protected $userId = "@alice:matrix.org"; 15 16 /** 17 * Call protected/private method of a class. 18 * 19 * @param object &$object Instantiated object that we will run method on. 20 * @param string $methodName Method name to call 21 * @param array $parameters Array of parameters to pass into method. 22 * 23 * @return mixed Method return. 24 * @throws \ReflectionException 25 */ 26 protected function invokePrivateMethod(&$object, $methodName, array $parameters = []) { 27 $reflection = new \ReflectionClass(get_class($object)); 28 $method = $reflection->getMethod($methodName); 29 $method->setAccessible(true); 30 31 return $method->invokeArgs($object, $parameters); 32 } 33 34 protected function getMockClientHandler(array $responses, array &$container): HandlerStack { 35 $mock = new MockHandler($responses); 36 $history = Middleware::history($container); 37 $handler = HandlerStack::create($mock); 38 $handler->push($history); 39 40 return $handler; 41 } 42} 43