Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_www/vendor/microsoft/microsoft-graph/tests/Http/ |
Upload File : |
<?php
use PHPUnit\Framework\TestCase;
use Microsoft\Graph\Graph;
use Microsoft\Graph\Http\GraphRequest;
use Microsoft\Graph\Http\GraphResponse;
use Microsoft\Graph\Exception\GraphException;
use Microsoft\Graph\Model;
class GraphResponseTest extends TestCase
{
public $client;
public $request;
public $response;
public $responseBody;
public function setUp(): void
{
$this->responseBody = array('body' => 'content', 'displayName' => 'Bob Barker');
$body = json_encode($this->responseBody);
$multiBody = json_encode(array('value' => array('1' => array('givenName' => 'Bob'), '2' => array('givenName' => 'Drew'))));
$valueBody = json_encode(array('value' => 'Bob Barker'));
$emptyMultiBody = json_encode(array('value' => array()));
$mock = new GuzzleHttp\Handler\MockHandler([
new GuzzleHttp\Psr7\Response(200, ['foo' => 'bar'], $body),
new GuzzleHttp\Psr7\Response(200, ['foo' => 'bar'], $body),
new GuzzleHttp\Psr7\Response(200, ['foo' => 'bar'], $multiBody),
new GuzzleHttp\Psr7\Response(200, ['foo' => 'bar'], $valueBody),
new GuzzleHttp\Psr7\Response(200, ['foo' => 'bar'], $emptyMultiBody),
]);
$handler = GuzzleHttp\HandlerStack::create($mock);
$this->client = new GuzzleHttp\Client(['handler' => $handler]);
$this->request = new GraphRequest("GET", "/endpoint", "token", "baseUrl", "version");
$this->response = new GraphResponse($this->request, "{response}", "200", ["foo" => "bar"]);
}
public function testGetResponseAsObject()
{
$this->request->setReturnType(Model\User::class);
$response = $this->request->execute($this->client);
$this->assertInstanceOf(Model\User::class, $response);
$this->assertEquals($this->responseBody['displayName'], $response->getDisplayName());
}
public function testGetResponseHeaders()
{
$response = $this->request->execute($this->client);
$headers = $response->getHeaders();
$this->assertEquals(["foo" => ["bar"]], $headers);
}
public function testGetNextLink()
{
$body = json_encode(array('@odata.nextLink' => 'https://url.com/resource?$top=4&skip=4'));
$response = new GraphResponse($this->request, $body);
$nextLink = $response->getNextLink();
$this->assertEquals('https://url.com/resource?$top=4&skip=4', $nextLink);
}
public function testDecodeBody()
{
//Temporarily make decodeBody() public
$reflectionMethod = new ReflectionMethod('Microsoft\Graph\Http\GraphResponse', '_decodeBody');
$reflectionMethod->setAccessible(true);
$response = new GraphResponse($this->request, json_encode($this->responseBody));
$decodedBody = $reflectionMethod->invokeArgs($response, array());
$this->assertEquals($this->responseBody, $decodedBody);
}
public function testDecodeEmptyBody()
{
//Temporarily make decodeBody() public
$reflectionMethod = new ReflectionMethod('Microsoft\Graph\Http\GraphResponse', '_decodeBody');
$reflectionMethod->setAccessible(true);
$response = new GraphResponse($this->request);
$decodedBody = $reflectionMethod->invokeArgs($response, array());
$this->assertEquals(array(), $decodedBody);
}
public function testGetHeaders()
{
$headers = $this->response->getHeaders();
$this->assertEquals(["foo" => "bar"], $headers);
}
public function testGetBody()
{
$response = $this->request->execute($this->client);
$this->assertInstanceOf(GraphResponse::class, $response);
$body = $response->getBody();
$this->assertEquals($this->responseBody, $body);
}
public function testGetRawBody()
{
$response = $this->request->execute($this->client);
$body = $response->getRawBody();
$this->assertInstanceOf(\Psr\Http\Message\StreamInterface::class, $body);
$this->assertIsNotString($body);
$this->assertEquals(json_encode($this->responseBody), $body);
}
public function testGetStatus()
{
$response = $this->request->execute($this->client);
$this->assertEquals('200', $response->getStatus());
}
public function testGetMultipleObjects()
{
$this->request->execute($this->client);
$this->request->execute($this->client);
$hosts = $this->request->setReturnType(Model\User::class)->execute($this->client);
$this->assertIsArray($hosts);
$this->assertContainsOnlyInstancesOf(Model\User::class, $hosts);
$this->assertSame(array_values($hosts), $hosts);
$this->assertEquals(2, count($hosts));
$this->assertEquals("Bob", $hosts[0]->getGivenName());
}
public function testGetValueObject()
{
$this->request->execute($this->client);
$this->request->execute($this->client);
$this->request->execute($this->client);
$response = $this->request->setReturnType(Model\User::class)->execute($this->client);
$this->assertInstanceOf(Model\User::class, $response);
}
public function testGetZeroMultipleObjects()
{
$this->request->execute($this->client);
$this->request->execute($this->client);
$this->request->execute($this->client);
$this->request->execute($this->client);
$response = $this->request->setReturnType(Model\User::class)->execute($this->client);
$this->assertSame(array(), $response);
}
}