Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
50cfb6c
Updated NationalCloud tests and Exception tests
Ndiritu Jul 12, 2021
e20238b
Add AbstractGraphClient tests
Ndiritu Jul 12, 2021
c18bf80
Add GraphRequest tests
Ndiritu Jul 26, 2021
ed45e10
Fix GraphCollectionRequest tests
Ndiritu Aug 4, 2021
7a58e0f
Fix GraphRequestUtil tests
Ndiritu Aug 4, 2021
1c54d1d
Fix GraphResponse tests
Ndiritu Aug 4, 2021
f29255a
Remove unnecessary test class
Ndiritu Aug 4, 2021
5e29901
Minor fixes to failing tests
Ndiritu Aug 4, 2021
10c3b87
Fix merge conflicts
Ndiritu Aug 4, 2021
cbcb26f
Use existing test data models
Ndiritu Aug 4, 2021
908be4e
Minor tweaks
Ndiritu Aug 4, 2021
9fbe9e9
Merge branch 'philip/feat/graph-request-changes' into philip/fix/tests
Ndiritu Aug 4, 2021
807ae85
Use phpstan/phpstan
Ndiritu Aug 10, 2021
354ac97
Make all full endpoint urls valid
Ndiritu Aug 10, 2021
160a67b
Prevent sending tokens to non-graph endpoints
Ndiritu Aug 10, 2021
a5b2578
Refactor validation of base urls and national cloud host urls
Ndiritu Aug 10, 2021
3629482
Fix failing Graph request constructor test
Ndiritu Aug 11, 2021
aeb7c4e
Support only StreamInterface as valid stream return type
Ndiritu Aug 11, 2021
b4855fb
Add code coverage output to validation workflow
Ndiritu Aug 16, 2021
d0b9097
Resolve merge conflicts
Ndiritu Aug 18, 2021
e2ce12d
Address static analysis issues
Ndiritu Aug 19, 2021
af3f36b
Add upgrade guide
Ndiritu Aug 16, 2021
147bb24
Update sdk version header
Ndiritu Aug 31, 2021
c242188
minor updates
Ndiritu Sep 1, 2021
caa15e9
Merge pull request #16 from microsoftgraph/fix/sdk-version-header
Ndiritu Sep 2, 2021
3d79614
Address PR feedback
Ndiritu Sep 14, 2021
9cabb6f
Merge branch 'philip/fix/tests' of github.com:microsoftgraph/msgraph-…
Ndiritu Sep 14, 2021
8d4e9f3
Update page iterator story + link highlights to description sections
Ndiritu Sep 14, 2021
fff1d93
Merge pull request #7 from microsoftgraph/feat/upgrade-guide
Ndiritu Sep 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# top-most EditorConfig file
root = true
# All PHP files MUST use the Unix LF (linefeed) line ending.
# Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting.
# All PHP files MUST end with a single blank line.
# There MUST NOT be trailing whitespace at the end of non-blank lines.
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# PHP-Files, Composer.json, MD-Files
[{*.php,composer.json,*.md}]
indent_style = space
indent_size = 4
# HTML-Files LESS-Files SASS-Files CSS-Files JS-Files JSON-Files
[{*.html,*.less,*.sass,*.css,*.js,*.json}]
indent_style = tab
indent_size = 4
# Gitlab-CI, Travis-CI
[*.yml]
indent_style = space
indent_size = 2
# top-most EditorConfig file
root = true

# All PHP files MUST use the Unix LF (linefeed) line ending.
# Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting.
# All PHP files MUST end with a single blank line.
# There MUST NOT be trailing whitespace at the end of non-blank lines.
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# PHP-Files, Composer.json, MD-Files
[{*.php,composer.json,*.md}]
indent_style = space
indent_size = 4

# HTML-Files LESS-Files SASS-Files CSS-Files JS-Files JSON-Files
[{*.html,*.less,*.sass,*.css,*.js,*.json}]
indent_style = tab
indent_size = 4

# Gitlab-CI, Travis-CI
[*.yml]
indent_style = space
indent_size = 2
9 changes: 7 additions & 2 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Setup PHP and Xdebug for Code Coverage report
uses: shivammathur/setup-php@v2
with:
php-version: '7.x'
coverage: xdebug
- name: Validate composer file
run: |
composer validate
Expand All @@ -28,7 +33,7 @@ jobs:
composer install
- name: Run tests
run : |
vendor/bin/phpunit --exclude-group functional
vendor/bin/phpunit --coverage-text
run-static-analysis:
runs-on: ubuntu-latest
steps:
Expand All @@ -39,6 +44,6 @@ jobs:
- name: Composer install
run: |
composer install
- name: Run static analysis
- name: Run static analysis
run: |
vendor/bin/phpstan analyse --memory-limit=500M --error-format=github
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"phpunit/phpunit": "^9.0",
"mikey179/vfsstream": "^1.2",
"phpstan/phpstan": "^0.12.90"
},
Expand All @@ -31,8 +31,7 @@
},
"autoload-dev": {
"psr-4": {
"Microsoft\\Graph\\Test\\": "tests/",
"Microsoft\\Graph\\Http\\Test\\": "tests/Http/"
"Microsoft\\Graph\\Test\\": "tests/"
}
}
}
}
15 changes: 9 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<coverage includeUncoveredFiles="true"
pathCoverage="true">
<include>
<directory suffix=".php">src</directory>
<exclude><directory suffix=".php">src/Model</directory></exclude>
</whitelist>
</filter>
</phpunit>
</include>
<report>
<html outputDirectory="coverage"/>
</report>
</coverage>
</phpunit>
22 changes: 16 additions & 6 deletions src/Core/NationalCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ final class NationalCloud
* @return bool
*/
public static function containsNationalCloudHost(string $url): bool {
self::initHosts();
$validUrlParts = parse_url($url);
return $validUrlParts
&& array_key_exists("scheme", $validUrlParts)
&& $validUrlParts["scheme"] == "https"
&& array_key_exists("host", $validUrlParts)
&& array_key_exists(strtolower($validUrlParts["host"]), self::$hosts);
return self::containsNationalCloudHostFromUrlParts($validUrlParts);
}

/**
* Checks if $urlParts contain a valid National Cloud host
*
* @param array<string, string>|false $urlParts return value of parse_url()
* @return bool
*/
public static function containsNationalCloudHostFromUrlParts($urlParts): bool {
self::initHosts();
return $urlParts
&& array_key_exists("scheme", $urlParts)
&& $urlParts["scheme"] == "https"
&& array_key_exists("host", $urlParts)
&& array_key_exists(strtolower($urlParts["host"]), self::$hosts);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Exception/GraphClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
namespace Microsoft\Graph\Exception;

/**
* Class ClientInitialisationException
*
* Class GraphClientException
* @package Microsoft\Graph\Exception
* @copyright 2021 Microsoft Corporation
* @license https://opensource.org/licenses/MIT MIT License
Expand Down
12 changes: 5 additions & 7 deletions src/Http/AbstractGraphClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

namespace Microsoft\Graph\Http;

use Microsoft\Graph\Core\GraphConstants;
use Microsoft\Graph\Core\NationalCloud;
use Microsoft\Graph\Exception\GraphClientException;
use Microsoft\Graph\Exception\GraphException;

/**
* Class BaseClient
Expand Down Expand Up @@ -58,7 +56,7 @@ public function __construct(?string $nationalCloud = NationalCloud::GLOBAL,
?HttpClientInterface $httpClient = null)
{
$this->nationalCloud = ($nationalCloud) ?: NationalCloud::GLOBAL;
$this->httpClient = ($httpClient) ?: HttpClientFactory::nationalCloud($nationalCloud)::createAdapter();
$this->httpClient = ($httpClient) ?: HttpClientFactory::nationalCloud($this->nationalCloud)::createAdapter();
}

/**
Expand All @@ -79,7 +77,7 @@ public function setAccessToken(string $accessToken): self
/**
* @return string
*/
public function getAccessToken(): string {
public function getAccessToken(): ?string {
return $this->accessToken;
}

Expand Down Expand Up @@ -107,7 +105,7 @@ public function getHttpClient(): HttpClientInterface
*
* @return GraphRequest The request object, which can be used to
* make queries against Graph
* @throws GraphException
* @throws GraphClientException
*/
public function createRequest(string $requestType, string $endpoint): GraphRequest
{
Expand All @@ -127,9 +125,9 @@ public function createRequest(string $requestType, string $endpoint): GraphReque
*
* @return GraphCollectionRequest The request object, which can be
* used to make queries against Graph
* @throws GraphException
* @throws GraphClientException
*/
public function createCollectionRequest(string $requestType, string $endpoint): GraphRequest
public function createCollectionRequest(string $requestType, string $endpoint): GraphCollectionRequest
{
return new GraphCollectionRequest(
$requestType,
Expand Down
32 changes: 22 additions & 10 deletions src/Http/GraphCollectionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
namespace Microsoft\Graph\Http;

use GuzzleHttp\Psr7\Uri;
use Microsoft\Graph\Core\GraphConstants;
use Microsoft\Graph\Exception\GraphClientException;
use Microsoft\Graph\Exception\GraphException;
use Microsoft\Graph\Core\GraphConstants;
use Psr\Http\Client\ClientExceptionInterface;

/**
* Class GraphCollectionRequest
Expand Down Expand Up @@ -48,7 +49,7 @@ class GraphCollectionRequest extends GraphRequest
/**
* The return type that the user specified
*
* @var object
* @var string
*/
protected $originalReturnType;

Expand Down Expand Up @@ -76,22 +77,25 @@ public function __construct(string $requestType, string $endpoint, AbstractGraph
* Gets the number of entries in the collection
*
* @return int the number of entries
* @throws \Psr\Http\Client\ClientExceptionInterface
* @throws ClientExceptionInterface|GraphClientException
*/
public function count()
{
$query = '$count=true';
$requestUri = $this->getRequestUri();
$this->setRequestUri(new Uri( $requestUri . GraphRequestUtil::getQueryParamConcatenator($requestUri) . $query));
$result = $this->execute()->getBody();
// Temporarily disable returnType in order to get GraphResponse object returned by execute()
$this->originalReturnType = $this->returnType;
$this->returnType = null;
$result = $this->execute();

if (array_key_exists("@odata.count", $result)) {
return $result['@odata.count'];
if (is_a($result, GraphResponse::class) && $result->getCount()) {
return $result->getCount();
}

/* The $count query parameter for the Graph API
is available on several models but not all */
trigger_error('Count unavailable for this collection');
throw new GraphClientException('Count unavailable for this collection');
}

/**
Expand All @@ -117,7 +121,7 @@ public function setPageSize(int $pageSize): self
* Gets the next page of results
*
* @return array of objects of class $returnType
* @throws \Psr\Http\Client\ClientExceptionInterface
* @throws ClientExceptionInterface
*/
public function getPage()
{
Expand All @@ -132,7 +136,7 @@ public function getPage()
*
* @return GraphCollectionRequest
*/
public function setPageCallInfo(): self
private function setPageCallInfo(): self
{
// Store these to add temporary query data to request
$this->originalReturnType = $this->returnType;
Expand Down Expand Up @@ -167,7 +171,7 @@ public function setPageCallInfo(): self
* @return mixed result of the call, formatted according
* to the returnType set by the user
*/
public function processPageCallReturn(GraphResponse $response)
private function processPageCallReturn(GraphResponse $response)
{
$this->nextLink = $response->getNextLink();
$this->deltaLink = $response->getDeltaLink();
Expand Down Expand Up @@ -211,4 +215,12 @@ public function getDeltaLink(): ?string
{
return $this->deltaLink;
}

/**
* Get page size
* @return int
*/
public function getPageSize(): int {
return $this->pageSize;
}
}
Loading