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 : /proc/thread-self/cwd/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\Exception\GraphException;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
use org\bovigo\vfs\vfsStreamWrapper;
use org\bobigo\vfs\vfsStreamDirectory;
class StreamTest extends TestCase
{
private $root;
private $client;
private $body;
private $container;
public function setUp(): void
{
$this->root = vfsStream::setup('testDir');
$this->body = json_encode(array('body' => 'content'));
$stream = GuzzleHttp\Psr7\Utils::streamFor('content');
$mock = new GuzzleHttp\Handler\MockHandler([
new GuzzleHttp\Psr7\Response(200, ['foo' => 'bar'], $this->body),
new GuzzleHttp\Psr7\Response(200,['foo' => 'bar'], $stream),
new GuzzleHttp\Psr7\Response(200, ['foo' => 'bar'], 'hello')
]);
$this->container = [];
$history = GuzzleHttp\Middleware::history($this->container);
$handler = GuzzleHttp\HandlerStack::create($mock);
$handler->push($history);
$this->client = new GuzzleHttp\Client(['handler' => $handler]);
}
public function testUpload()
{
$file = new VfsStreamFile('foo.txt');
$this->root->addChild($file);
$file->setContent('data');
$request = new GraphRequest("GET", "/me", "token", "url", "v1.0");
$request->upload($file->url(), $this->client);
$this->assertEquals($this->container[0]['request']->getBody()->getContents(), $file->getContent());
}
public function testInvalidUpload()
{
$this->expectException(Microsoft\Graph\Exception\GraphException::class);
$file = new VfsStreamFile('foo.txt', 0000);
$this->root->addChild($file);
$request = new GraphRequest("GET", "/me", "token", "url", "v1.0");
$request->upload($file->url(), $this->client);
}
public function testDownload()
{
$request = new GraphRequest("GET", "/me", "token", "url", "v1.0");
$file = new VfsStreamFile('foo.txt');
$this->root->addChild($file);
$request->download($file->url(), $this->client);
$this->assertEquals($this->body, $file->getContent());
}
public function testInvalidDownload()
{
set_error_handler(function() {});
try {
$this->expectException(Microsoft\Graph\Exception\GraphException::class);
$file = new VfsStreamFile('foo.txt', 0000);
$this->root->addChild($file);
$request = new GraphRequest("GET", "/me", "token", "url", "v1.0");
$request->download($file->url(), $this->client);
} finally {
restore_error_handler();
}
}
public function testSetReturnStream()
{
$request = new GraphRequest("GET", "/me", "token", "url", "v1.0");
$request->setReturnType(GuzzleHttp\Psr7\Stream::class);
$this->assertTrue($request->getReturnsStream());
$response = $request->execute($this->client);
$this->assertInstanceOf(GuzzleHttp\Psr7\Stream::class, $response);
$response = $request->execute($this->client);
$this->assertInstanceOf(GuzzleHttp\Psr7\Stream::class, $response);
}
}