Skip to content

Commit d2ace30

Browse files
authored
Merge pull request #128 from microsoftgraph/dev
2.0.0-RC10
2 parents e6ade48 + a15278c commit d2ace30

File tree

9 files changed

+137
-16
lines changed

9 files changed

+137
-16
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
# File initially created using https://github.com/MIchaelMainer/policyservicetoolkit/blob/main/branch_protection_export.ps1.
5+
6+
name: msgraph-sdk-php-core-branch-protection
7+
description: Branch protection policy for the msgraph-sdk-php-core repository
8+
resource: repository
9+
configuration:
10+
branchProtectionRules:
11+
12+
- branchNamePattern: main
13+
# This branch pattern applies to the following branches as of 06/12/2023 10:31:17:
14+
# main
15+
16+
# Specifies whether this branch can be deleted. boolean
17+
allowsDeletions: false
18+
# Specifies whether forced pushes are allowed on this branch. boolean
19+
allowsForcePushes: false
20+
# Specifies whether new commits pushed to the matching branches dismiss pull request review approvals. boolean
21+
dismissStaleReviews: false
22+
# Specifies whether admins can overwrite branch protection. boolean
23+
isAdminEnforced: false
24+
# Indicates whether "Require a pull request before merging" is enabled. boolean
25+
requiresPullRequestBeforeMerging: true
26+
# Specifies the number of pull request reviews before merging. int (0-6). Should be null/empty if PRs are not required
27+
requiredApprovingReviewsCount: 1
28+
# Require review from Code Owners. Requires requiredApprovingReviewsCount. boolean
29+
requireCodeOwnersReview: false
30+
# Are commits required to be signed. boolean. TODO: all contributors must have commit signing on local machines.
31+
requiresCommitSignatures: false
32+
# Are conversations required to be resolved before merging? boolean
33+
requiresConversationResolution: true
34+
# Are merge commits prohibited from being pushed to this branch. boolean
35+
requiresLinearHistory: false
36+
# Required status checks to pass before merging. Values can be any string, but if the value does not correspond to any existing status check, the status check will be stuck on pending for status since nothing exists to push an actual status
37+
requiredStatusChecks:
38+
# Require branches to be up to date before merging. Requires requiredStatusChecks. boolean
39+
requiresStrictStatusChecks: true
40+
# Indicates whether there are restrictions on who can push. boolean. Should be set with whoCanPush.
41+
restrictsPushes: false
42+
# Restrict who can dismiss pull request reviews. boolean
43+
restrictsReviewDismissals: false
44+
45+
- branchNamePattern: dev
46+
# This branch pattern applies to the following branches as of 06/12/2023 10:31:17:
47+
# dev
48+
49+
# Specifies whether this branch can be deleted. boolean
50+
allowsDeletions: false
51+
# Specifies whether forced pushes are allowed on this branch. boolean
52+
allowsForcePushes: false
53+
# Specifies whether new commits pushed to the matching branches dismiss pull request review approvals. boolean
54+
dismissStaleReviews: true
55+
# Specifies whether admins can overwrite branch protection. boolean
56+
isAdminEnforced: false
57+
# Indicates whether "Require a pull request before merging" is enabled. boolean
58+
requiresPullRequestBeforeMerging: true
59+
# Specifies the number of pull request reviews before merging. int (0-6). Should be null/empty if PRs are not required
60+
requiredApprovingReviewsCount: 1
61+
# Require review from Code Owners. Requires requiredApprovingReviewsCount. boolean
62+
requireCodeOwnersReview: false
63+
# Are commits required to be signed. boolean. TODO: all contributors must have commit signing on local machines.
64+
requiresCommitSignatures: false
65+
# Are conversations required to be resolved before merging? boolean
66+
requiresConversationResolution: true
67+
# Are merge commits prohibited from being pushed to this branch. boolean
68+
requiresLinearHistory: false
69+
# Required status checks to pass before merging. Values can be any string, but if the value does not correspond to any existing status check, the status check will be stuck on pending for status since nothing exists to push an actual status
70+
requiredStatusChecks:
71+
# Require branches to be up to date before merging. Requires requiredStatusChecks. boolean
72+
requiresStrictStatusChecks: true
73+
# Indicates whether there are restrictions on who can push. boolean. Should be set with whoCanPush.
74+
restrictsPushes: false
75+
# Restrict who can dismiss pull request reviews. boolean
76+
restrictsReviewDismissals: false
77+

.github/workflows/pr-validation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
matrix:
2323
php-versions: ['7.4', '8.0', '8.1', '8.2']
2424
steps:
25-
- uses: actions/[email protected].2
25+
- uses: actions/[email protected].3
2626
with:
2727
submodules: 'true'
2828
- name: Setup PHP and Xdebug for Code Coverage report
@@ -41,7 +41,7 @@ jobs:
4141
- name: Fix code coverage paths
4242
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml
4343
- name: SonarCloud Scan
44-
if: ${{ matrix.php-versions == '8.0' }}
44+
if: ${{ matrix.php-versions == '8.0' && !github.event.pull_request.head.repo.fork }}
4545
uses: SonarSource/sonarcloud-github-action@master
4646
env:
4747
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tag-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
create-tag:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/[email protected].2
21+
- uses: actions/[email protected].3
2222

2323
- name: Get SDK version and set environment variable
2424
run: |

.github/workflows/update-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run-php-documentor:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/[email protected].2
18+
- uses: actions/[email protected].3
1919
with:
2020
ref: ${{ github.ref }}
2121

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To install the `microsoft-graph-core` library with Composer, either run `compose
88
```
99
{
1010
"require": {
11-
"microsoft/microsoft-graph-core": "^2.0.0-RC9"
11+
"microsoft/microsoft-graph-core": "^2.0.0-RC10"
1212
}
1313
}
1414
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"php": "^8.0 || ^7.4",
1616
"microsoft/kiota-authentication-phpleague": "^0.8.0",
1717
"microsoft/kiota-http-guzzle": "^0.8.0",
18-
"microsoft/kiota-serialization-json": "^0.5.0",
19-
"microsoft/kiota-serialization-text": "^0.6.0",
18+
"microsoft/kiota-serialization-json": "^0.6.0",
19+
"microsoft/kiota-serialization-text": "^0.7.0",
2020
"php-http/httplug": "^2.2",
2121
"ext-json": "*"
2222
},

src/GraphConstants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GraphConstants
2525
const REST_ENDPOINT = "https://graph.microsoft.com/";
2626

2727
// Define HTTP request constants
28-
const SDK_VERSION = "2.0.0-RC9";
28+
const SDK_VERSION = "2.0.0-RC10";
2929

3030
// Define error constants
3131
const MAX_PAGE_SIZE = 999;

src/Requests/BatchRequestItem.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Psr\Http\Message\RequestInterface;
1818
use Psr\Http\Message\StreamInterface;
1919
use Ramsey\Uuid\Uuid;
20-
use RuntimeException;
2120

2221
/**
2322
* Class BatchRequestItem
@@ -31,6 +30,9 @@
3130
*/
3231
class BatchRequestItem implements Parsable
3332
{
33+
const API_VERSION_REGEX = '/\/(v1.0|beta)/';
34+
const ME_TOKEN_REGEX = '/\/users\/me-token-to-replace/';
35+
3436
/**
3537
* Unique identifier
3638
*
@@ -89,7 +91,7 @@ public function __construct(RequestInformation $requestInformation, string $id =
8991
$this->method = $requestInformation->httpMethod;
9092
$this->setUrl($requestInformation->getUri());
9193
$this->headers = $requestInformation->getHeaders();
92-
$this->body = $requestInformation->content;
94+
$this->setBody($requestInformation->content);
9395
$this->dependsOn($dependsOn);
9496
}
9597

@@ -134,13 +136,21 @@ public function setUrl(string $url): void
134136
}
135137
// Set relative URL
136138
// Remove API version
137-
$urlWithoutVersion = preg_replace("/\/(v1.0|beta)/", '', "{$urlParts['path']}");
138-
if (!$urlWithoutVersion) {
139+
$relativeUrl = preg_replace(self::API_VERSION_REGEX, '', "{$urlParts['path']}", 1);
140+
if (!$relativeUrl) {
139141
throw new InvalidArgumentException(
140142
"Error occurred during regex replacement of API version in URL string: $url"
141143
);
142144
}
143-
$this->url = $urlWithoutVersion;
145+
// Replace /users/me-token-to-replace with /me
146+
$relativeUrl = preg_replace(self::ME_TOKEN_REGEX, '/me', $relativeUrl, 1);
147+
if (!$relativeUrl) {
148+
throw new InvalidArgumentException(
149+
"Error occurred during regex replacement of '/users/me-token-to-replace' in URL string: $url"
150+
);
151+
}
152+
153+
$this->url = $relativeUrl;
144154
$this->url .= (array_key_exists('query', $urlParts)) ? "?{$urlParts['query']}" : '';
145155
$this->url .= (array_key_exists('fragment', $urlParts)) ? "#{$urlParts['fragment']}" : '';
146156
}

tests/Requests/BatchRequestItemTest.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Uri;
77
use GuzzleHttp\Psr7\Utils;
8+
use InvalidArgumentException;
89
use Microsoft\Graph\Core\Requests\BatchRequestItem;
910
use Microsoft\Kiota\Abstractions\HttpMethod;
1011
use Microsoft\Kiota\Abstractions\RequestInformation;
@@ -24,7 +25,7 @@ protected function setUp(): void
2425
$this->requestInformation->addHeaders(["test" => ["value", "value2"]]);
2526
$this->requestInformation->setUri(new Uri('https://graph.microsoft.com/v1.0/users?$top=2'));
2627

27-
$this->psrRequest = new Request(HttpMethod::POST, "https://graph.microsoft.com/v1.0/users", ["key" => ["value1", "value2"]], Utils::streamFor(json_encode(["key" => "val"])));
28+
$this->psrRequest = new Request(HttpMethod::POST, "https://graph.microsoft.com/beta/users", ["key" => ["value1", "value2"]], Utils::streamFor(json_encode(["key" => "val"])));
2829
}
2930

3031

@@ -38,6 +39,13 @@ public function testConstructor()
3839
$this->assertEquals('/users?$top=2', $batchRequestItem->getUrl()); // relative URL is set
3940
}
4041

42+
public function testInvalidRequestInformationThrowsException()
43+
{
44+
$this->expectException(InvalidArgumentException::class);
45+
$this->requestInformation->httpMethod = '';
46+
new BatchRequestItem($this->requestInformation);
47+
}
48+
4149
public function testCreateWithPsrRequest()
4250
{
4351
$batchRequestItem = BatchRequestItem::createWithPsrRequest($this->psrRequest);
@@ -79,13 +87,39 @@ public function testSerialization()
7987
$this->assertEquals($expectedJson, $jsonSerializationWriter->getSerializedContent()->getContents());
8088
}
8189

82-
public function testSettingInvalidUrl(): void
90+
public function testSettingInvalidUrlPathThrowsException(): void
8391
{
8492
$this->expectException(\InvalidArgumentException::class);
8593
$item = new BatchRequestItem($this->requestInformation);
8694
$item->setId('1243');
8795
$item->setMethod('GET');
88-
$item->setUrl('');
8996
$item->setHeaders([]);
97+
$item->getFieldDeserializers();
98+
$item->setUrl('https://a.b.com$1');
99+
}
100+
101+
public function testSetEmptyUrlThrowsException(): void
102+
{
103+
$this->expectException(\InvalidArgumentException::class);
104+
$item = new BatchRequestItem($this->requestInformation);
105+
$item->setUrl('');
106+
}
107+
108+
public function testMePlaceholderIsReplacedInUrls(): void
109+
{
110+
$meUrlPath = '/me';
111+
$tokenToReplaceUrl = 'https://graph.microsoft.com/v1.0/users/me-token-to-replace';
112+
113+
$this->requestInformation->setUri(new Uri('https://graph.microsoft.com/beta/me'));
114+
$this->assertEquals($meUrlPath, (new BatchRequestItem($this->requestInformation))->getUrl());
115+
116+
$this->requestInformation->setUri(new Uri($tokenToReplaceUrl));
117+
$this->assertEquals($meUrlPath, (new BatchRequestItem($this->requestInformation))->getUrl());
118+
119+
$this->requestInformation->setUri(new Uri("$tokenToReplaceUrl/messages"));
120+
$this->assertEquals("$meUrlPath/messages", (new BatchRequestItem($this->requestInformation))->getUrl());
121+
122+
$this->requestInformation->setUri(new Uri("$tokenToReplaceUrl/messages/123"));
123+
$this->assertEquals("$meUrlPath/messages/123", (new BatchRequestItem($this->requestInformation))->getUrl());
90124
}
91125
}

0 commit comments

Comments
 (0)