Skip to content

Commit d05b9b2

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #8 from microsoftgraph/functional-tests
Functional tests
2 parents 103f253 + 0629a60 commit d05b9b2

171 files changed

Lines changed: 2991 additions & 2770 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ composer.lock
33
/vendor/
44
/coverage
55
.idea/
6+
tests/Functional/TestConstants.php

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ install:
1212
- composer install --prefer-source --no-interaction --dev
1313

1414
script:
15-
- vendor/bin/phpunit
15+
- vendor/bin/phpunit --exclude-group functional

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ class UsageExample
6868

6969
### Run Tests
7070

71-
Run ```vendor/bin/phpunit``` from the base directory.
71+
Run
72+
```php
73+
vendor/bin/phpunit --exclude-group functional
74+
```
75+
from the base directory.
76+
77+
*The set of functional tests are meant to be run against a test account. Currently, the
78+
tests to do not restore state of the account.*
7279

7380

7481
## Documentation and resources

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "microsoft/microsoft-graph",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"type": "library",
55
"description": "The Microsoft Graph SDK for PHP",
66
"homepage": "https://graph.microsoft.io/en-us/",
@@ -21,6 +21,8 @@
2121
"mikey179/vfsStream": "~1"
2222
},
2323
"autoload": {
24-
"psr-4": { "Microsoft\\Graph\\": "src/" }
24+
"psr-4": { "Microsoft\\Graph\\": "src/",
25+
"Microsoft\\Graph\\Test\\": "tests/Functional/"
26+
}
2527
}
2628
}

phpunit.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
<filter>
99
<whitelist addUncoveredFilesFromWhitelist="true">
1010
<directory suffix=".php">src</directory>
11-
<exclude>
12-
<directory suffix=".php">src/Model</directory>
13-
<directory suffix=".php">src/Core</directory>
14-
</exclude>
11+
<exclude><directory suffix=".php">src/Model</directory></exclude>
1512
</whitelist>
1613
</filter>
1714
<logging>

src/Core/GraphConstants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GraphConstants
2424
const REST_ENDPOINT = "https://graph.microsoft.com/";
2525

2626
// Define HTTP request constants
27-
const SDK_VERSION = "0.1.0";
27+
const SDK_VERSION = "0.1.1";
2828

2929
// Define error constants
3030
const MAX_PAGE_SIZE = 999;
@@ -34,7 +34,7 @@ class GraphConstants
3434
// Define error message constants
3535
const BASE_URL_MISSING = "Base URL cannot be null or empty.";
3636
const REQUEST_TIMED_OUT = "The request timed out.";
37-
const UNABLE_TO_CREATE_INSTANCE_OF_TYPE = "Unable to create instance of type.";
37+
const UNABLE_TO_CREATE_INSTANCE_OF_TYPE = "Unable to create instance of type";
3838

3939
// Define user error constants
4040
const INVALID_FILE = "Unable to open file stream for the given path.";

src/Http/GraphCollectionRequest.php

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class GraphCollectionRequest extends GraphRequest
3737
*/
3838
protected $pageSize;
3939
/**
40-
* The skip token to use in calling a new page of results
40+
* The next link to use in calling a new page of results
4141
*
4242
* @var string
4343
*/
44-
protected $skipToken;
44+
protected $nextLink;
4545
/**
4646
* True if the user has reached the end of the collection
4747
*
@@ -54,12 +54,6 @@ class GraphCollectionRequest extends GraphRequest
5454
* @var string
5555
*/
5656
protected $originalEndpoint;
57-
/**
58-
* The return type that the user specified
59-
*
60-
* @var string
61-
*/
62-
protected $originalReturnType;
6357

6458
/**
6559
* Constructs a new GraphCollectionRequest object
@@ -107,7 +101,6 @@ public function count()
107101
/* The $count query parameter for the Graph API
108102
is available on several models but not all */
109103
trigger_error('Count unavailable for this collection');
110-
return null;
111104
}
112105

113106
/**
@@ -136,9 +129,9 @@ public function setPageSize($pageSize)
136129
*
137130
* @return array of objects of class $returnType
138131
*/
139-
public function getPage($prev = false)
132+
public function getPage()
140133
{
141-
$this->setPageCallInfo($prev);
134+
$this->setPageCallInfo();
142135
$response = $this->execute();
143136

144137
return $this->processPageCallReturn($response);
@@ -151,31 +144,28 @@ public function getPage($prev = false)
151144
*
152145
* @return GraphCollectionRequest
153146
*/
154-
public function setPageCallInfo($prev)
147+
public function setPageCallInfo()
155148
{
156149
// Store these to add temporary query data to request
157150
$this->originalReturnType = $this->returnType;
158-
$this->originalEndpoint = $this->endpoint;
159151

160152
/* This allows processPageCallReturn to receive
161153
all of the response data, not just the objects */
162154
$this->returnType = null;
163155

164156
if ($this->end) {
165157
trigger_error('Reached end of collection');
166-
return null;
167158
}
168159

169-
// Build the page navigation query string
170-
$query = '$top=' . $this->pageSize;
171-
if ($this->skipToken) {
172-
$query .='&$skiptoken=' . $this->skipToken;
160+
if ($this->nextLink) {
161+
$baseLength = strlen($this->baseUrl) + strlen($this->apiVersion);
162+
$this->endpoint = substr($this->nextLink, $baseLength);
163+
} else {
164+
// This is the first request to the endpoint
165+
if ($this->pageSize) {
166+
$this->endpoint .= $this->getConcatenator() . '$top=' . $this->pageSize;
167+
}
173168
}
174-
if ($prev) {
175-
$query .='&previous-page=true';
176-
}
177-
178-
$this->endpoint = $this->endpoint . $this->getConcatenator() . $query;
179169
return $this;
180170
}
181171

@@ -190,11 +180,11 @@ public function setPageCallInfo($prev)
190180
*/
191181
public function processPageCallReturn($response)
192182
{
193-
$this->skipToken = $response->getSkipToken();
183+
$this->nextLink = $response->getNextLink();
194184

195185
/* If no skip token is returned, we have reached the end
196186
of the collection */
197-
if (!$this->skipToken) {
187+
if (!$this->nextLink) {
198188
$this->end = true;
199189
}
200190

@@ -206,23 +196,11 @@ public function processPageCallReturn($response)
206196
}
207197

208198
// Restore user-defined parameters
209-
$this->endpoint = $this->originalEndpoint;
210199
$this->returnType = $this->originalReturnType;
211200

212201
return $result;
213202
}
214203

215-
/**
216-
* Gets the previous page of results from the collection
217-
*
218-
* @return array of objects of class $returnType
219-
*/
220-
public function getPrevPage()
221-
{
222-
$this->end = false;
223-
return $this->getPage(true);
224-
}
225-
226204
/**
227205
* Gets whether the user has reached the end of the collection
228206
*

src/Http/GraphRequest.php

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function __construct($requestType, $endpoint, $accessToken, $baseUrl, $ap
136136
public function setReturnType($returnClass)
137137
{
138138
$this->returnType = $returnClass;
139-
if (strcasecmp($this->returnType, 'stream') == 0) {
139+
if ($this->returnType == "GuzzleHttp\Psr7\Stream") {
140140
$this->returnsStream = true;
141141
} else {
142142
$this->returnsStream = false;
@@ -181,16 +181,7 @@ public function attachBody($obj)
181181
if (is_string($obj) || is_a($obj, 'GuzzleHttp\\Psr7\\Stream')) {
182182
$this->requestBody = $obj;
183183
}
184-
// JSON-encode the model object's property dictionary
185-
else if (method_exists($obj, 'getProperties')) {
186-
$class = get_class($obj);
187-
$class = explode("\\", $class);
188-
$model = strtolower(end($class));
189-
190-
$body = $this->flattenDictionary($obj->getProperties());
191-
$this->requestBody = "{" . $model . ":" . json_encode($body) . "}";
192-
}
193-
// By default, JSON-encode (i.e. arrays)
184+
// By default, JSON-encode
194185
else {
195186
$this->requestBody = json_encode($obj);
196187
}
@@ -246,15 +237,10 @@ public function execute($client = null)
246237
]
247238
);
248239

249-
//Send back the bare response
250-
if ($this->returnsStream) {
251-
return $result;
252-
}
253-
254240
// Wrap response in GraphResponse layer
255241
$response = new GraphResponse(
256242
$this,
257-
$result->getBody()->getContents(),
243+
$result->getBody(),
258244
$result->getStatusCode(),
259245
$result->getHeaders()
260246
);
@@ -295,7 +281,7 @@ public function executeAsync($client = null)
295281
function ($result) {
296282
$response = new GraphResponse(
297283
$this,
298-
$result->getBody()->getContents(),
284+
$result->getBody(),
299285
$result->getStatusCode(),
300286
$result->getHeaders()
301287
);
@@ -443,28 +429,4 @@ protected function createGuzzleClient()
443429
);
444430
return $client;
445431
}
446-
447-
/**
448-
* Flattens the property dictionaries into
449-
* JSON-friendly arrays
450-
*
451-
* @param mixed $obj the object to flatten
452-
*
453-
* @return array flattened object
454-
*/
455-
protected function flattenDictionary($obj) {
456-
foreach ($obj as $arrayKey => $arrayValue) {
457-
if (method_exists($arrayValue, 'getProperties')) {
458-
$data = $arrayValue->getProperties();
459-
$obj[$arrayKey] = $data;
460-
} else {
461-
$data = $arrayValue;
462-
}
463-
if (is_array($data)) {
464-
$newItem = $this->flattenDictionary($data);
465-
$obj[$arrayKey] = $newItem;
466-
}
467-
}
468-
return $obj;
469-
}
470432
}

src/Http/GraphResponse.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
namespace Microsoft\Graph\Http;
1919

20+
use Microsoft\Graph\Exception\GraphException;
21+
use Microsoft\Graph\Core\GraphConstants;
22+
2023
/**
2124
* Class GraphResponse
2225
*
@@ -61,7 +64,7 @@ class GraphResponse
6164
* @param string $httpStatusCode The returned status code
6265
* @param array $headers The returned headers
6366
*/
64-
public function __construct($request, $body = null, $httpStatusCode = null, $headers = array())
67+
public function __construct($request, $body = null, $httpStatusCode = null, $headers = null)
6568
{
6669
$this->_request = $request;
6770
$this->_body = $body;
@@ -136,11 +139,22 @@ public function getResponseAsObject($returnType)
136139
$class = $returnType;
137140
$result = $this->getBody();
138141

142+
if ($returnType == "GuzzleHttp\Psr7\Stream") {
143+
return $this->_body;
144+
}
145+
139146
//If more than one object is returned
140147
if (array_key_exists('value', $result)) {
141148
$objArray = array();
142-
foreach ($result['value'] as $obj) {
143-
$objArray[] = new $class($obj);
149+
$values = $result['value'];
150+
151+
//Check that this is an object array instead of a value called "value"
152+
if ($values && is_array($values)) {
153+
foreach ($values as $obj) {
154+
$objArray[] = new $class($obj);
155+
}
156+
} else {
157+
return new $class($result);
144158
}
145159
return $objArray;
146160
} else {
@@ -149,21 +163,16 @@ public function getResponseAsObject($returnType)
149163
}
150164

151165
/**
152-
* Gets the skip token of a response object from OData
166+
* Gets the next link of a response object from OData
167+
* If the nextLink is null, there are no more pages
153168
*
154-
* @return string skip token, if provided
169+
* @return string nextLink, if provided
155170
*/
156-
public function getSkipToken()
171+
public function getNextLink()
157172
{
158173
if (array_key_exists("@odata.nextLink", $this->getBody())) {
159174
$nextLink = $this->getBody()['@odata.nextLink'];
160-
if (stripos($nextLink, "?") !== FALSE) {
161-
$url = explode("?", $nextLink)[1];
162-
if (stripos($url, "skiptoken=") !== FALSE) {
163-
$url = explode("skiptoken=", $url);
164-
return $url[1];
165-
}
166-
}
175+
return $nextLink;
167176
}
168177
return null;
169178
}

src/Model/ActivityDomain.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
4+
*
5+
* ActivityDomain File
6+
* PHP version 7
7+
*
8+
* @category Library
9+
* @package Microsoft.Graph
10+
* @copyright 2016 Microsoft Corporation
11+
* @license https://opensource.org/licenses/MIT MIT License
12+
* @version GIT: 0.1.0
13+
* @link https://graph.microsoft.io/
14+
*/
15+
namespace Microsoft\Graph\Model;
16+
17+
use Microsoft\Graph\Core\Enum;
18+
19+
/**
20+
* ActivityDomain class
21+
*
22+
* @category Model
23+
* @package Microsoft.Graph
24+
* @copyright 2016 Microsoft Corporation
25+
* @license https://opensource.org/licenses/MIT MIT License
26+
* @version Release: 0.1.0
27+
* @link https://graph.microsoft.io/
28+
*/
29+
class ActivityDomain extends Enum
30+
{
31+
/**
32+
* The Enum ActivityDomain
33+
*/
34+
const UNKNOWN = "0";
35+
const WORK = "1";
36+
const PERSONAL = "2";
37+
}

0 commit comments

Comments
 (0)