Skip to content

Commit be6fbcc

Browse files
authored
Merge pull request #49 from microsoftgraph/dev
Merge new changes to main
2 parents c14425e + ffff0c3 commit be6fbcc

File tree

15 files changed

+394
-21
lines changed

15 files changed

+394
-21
lines changed

.github/workflows/pr-validation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
validate-pull-request:
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v2.3.5
22+
- uses: actions/checkout@v2.4.0
2323
- name: Setup PHP and Xdebug for Code Coverage report
2424
uses: shivammathur/setup-php@v2
2525
with:
@@ -37,7 +37,7 @@ jobs:
3737
run-static-analysis:
3838
runs-on: ubuntu-latest
3939
steps:
40-
- uses: actions/checkout@v2.3.5
40+
- uses: actions/checkout@v2.4.0
4141
- name: Validate composer file
4242
run: |
4343
composer validate

.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/checkout@v2.3.5
21+
- uses: actions/checkout@v2.4.0
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/checkout@v2.3.4
18+
- uses: actions/checkout@v2.4.0
1919
with:
2020
ref: ${{ github.ref }}
2121

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ To install the `microsoft-graph-core` library with Composer, either run `compose
77
```
88
{
99
"require": {
10-
"microsoft/microsoft-graph-core": "^2.0.0-RC1"
10+
"microsoft/microsoft-graph-core": "^2.0.0-RC2"
1111
}
1212
}
1313
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"phpunit/phpunit": "^9.0",
2424
"mikey179/vfsstream": "^1.2",
25-
"phpstan/phpstan": "^0.12.90"
25+
"phpstan/phpstan": "^0.12.90 || ^1.0.0"
2626
},
2727
"autoload": {
2828
"psr-4": {

docs/packages/default.html

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,9 @@ <h3 class="phpdocumentor-sidebar__root-package"><a href="indices/files.html">Fil
8484
</ul>
8585

8686
<article class="phpdocumentor-element -package">
87-
<h2 class="phpdocumentor-content__title">API Documentation</h2>
88-
89-
<h3 id="packages">
90-
Packages
91-
<a href="#packages" class="headerlink"><i class="fas fa-link"></i></a>
92-
</h3>
93-
94-
<dl class="phpdocumentor-table-of-contents">
95-
<dt class="phpdocumentor-table-of-contents__entry -package"><a href="packages/Microsoft.html"><abbr title="\Microsoft">Microsoft</abbr></a></dt>
96-
<dt class="phpdocumentor-table-of-contents__entry -package"><a href="packages/Default.html"><abbr title="\Default">Default</abbr></a></dt>
97-
</dl>
87+
<h2 class="phpdocumentor-content__title">Default</h2>
9888

89+
9990

10091

10192

@@ -117,7 +108,7 @@ <h2 class="phpdocumentor-search-results__title">Search results</h2>
117108
</section>
118109
</div>
119110
</div>
120-
<a href="packages/default.html#top" class="phpdocumentor-back-to-top"><i class="fas fa-chevron-circle-up"></i></a>
111+
<a href="packages/Default.html#top" class="phpdocumentor-back-to-top"><i class="fas fa-chevron-circle-up"></i></a>
121112

122113
</main>
123114

src/Core/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-RC1";
28+
const SDK_VERSION = "2.0.0-RC2";
2929

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

src/Core/Models/Byte.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
4+
* Licensed under the MIT License. See License in the project root
5+
* for license information.
6+
*/
7+
8+
namespace Microsoft\Graph\Core\Models;
9+
10+
use InvalidArgumentException;
11+
use JsonSerializable;
12+
13+
/**
14+
* This class is a wrapper around unsigned int values upto 255.
15+
*/
16+
class Byte implements JsonSerializable
17+
{
18+
/**
19+
* The byte value
20+
* @var int $value
21+
*/
22+
private $value = 0;
23+
24+
/**
25+
* @param int $value The byte value
26+
*/
27+
public function __construct(int $value) {
28+
if($value < 0 || $value > 255) {
29+
throw new InvalidArgumentException("Byte should be a value between 0-255 inclusive {$value} given");
30+
}
31+
$this->value = $value;
32+
}
33+
34+
/**
35+
* @return int
36+
*/
37+
public function jsonSerialize(): int {
38+
return $this->value;
39+
}
40+
41+
public function __toString(): string
42+
{
43+
return (string)$this->value;
44+
}
45+
}

src/Core/Models/Date.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
4+
* Licensed under the MIT License. See License in the project root
5+
* for license information.
6+
*/
7+
8+
namespace Microsoft\Graph\Core\Models;
9+
10+
use DateTime;
11+
use Exception;
12+
13+
class Date implements \JsonSerializable {
14+
/**
15+
* @var string $value
16+
*/
17+
private $value;
18+
19+
/**
20+
* @param string $dateString The date value in string format YYYY-MM-DD.
21+
* Y - Year
22+
* M - Month
23+
* D - Day
24+
* @throws Exception
25+
*/
26+
public function __construct(string $dateString) {
27+
$this->value = (new DateTime($dateString))->format('Y-m-d');
28+
}
29+
30+
/**
31+
* Creates a date object from a DateTime object
32+
* @param DateTime $dateTime
33+
* @return Date
34+
* @throws Exception
35+
*/
36+
public static function createFromDateTime(DateTime $dateTime): Date {
37+
return new self($dateTime->format('Y-m-d'));
38+
}
39+
40+
/**
41+
* Creates a new Date object from $year,$month and $day
42+
* @param int $year
43+
* @param int $month
44+
* @param int $day
45+
* @return Date
46+
* @throws Exception
47+
*/
48+
public static function createFrom(int $year, int $month, int $day): Date {
49+
$date = new DateTime('1970-12-12T00:00:00Z');
50+
$date->setDate($year, $month, $day);
51+
return self::createFromDateTime($date);
52+
}
53+
54+
/**
55+
* @return string
56+
*/
57+
public function __toString() {
58+
return $this->value;
59+
}
60+
61+
public function jsonSerialize(): string {
62+
return $this->__toString();
63+
}
64+
}

src/Core/Models/TimeOfDay.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
4+
* Licensed under the MIT License. See License in the project root
5+
* for license information.
6+
*/
7+
8+
namespace Microsoft\Graph\Core\Models;
9+
10+
use DateTime;
11+
use Exception;
12+
use JsonSerializable;
13+
14+
/**
15+
* This object represents time in hours minutes and seconds
16+
*/
17+
class TimeOfDay implements JsonSerializable
18+
{
19+
20+
/**
21+
* The final string representation of the TimeOfDay
22+
* @var string $value
23+
*/
24+
private $value;
25+
26+
/**
27+
* @param string $timeString The time value in string format HH:MM:SS
28+
* H - Hour
29+
* M - Minutes
30+
* S - Seconds
31+
* @throws Exception
32+
*/
33+
public function __construct(string $timeString) {
34+
$this->value = (new DateTime($timeString))->format('H:i:s');
35+
}
36+
37+
/**
38+
* Creates a TimeOfDay object from a DateTime object
39+
* @param DateTime $dateTime
40+
* @return TimeOfDay
41+
* @throws Exception
42+
*/
43+
public static function createFromDateTime(DateTime $dateTime): TimeOfDay {
44+
return new self($dateTime->format('H:i:s'));
45+
}
46+
47+
/**
48+
* Creates a new TimeOfDay object from $hour,$minute and $seconds
49+
* @param int $hour
50+
* @param int $minutes
51+
* @param int $seconds
52+
* @return TimeOfDay
53+
* @throws Exception
54+
*/
55+
public static function createFrom(int $hour, int $minutes, int $seconds = 0): TimeOfDay {
56+
$date = new DateTime('1970-12-12T00:00:00Z');
57+
$date->setTime($hour, $minutes, $seconds);
58+
return self::createFromDateTime($date);
59+
}
60+
61+
/**
62+
* @return string
63+
*/
64+
public function __toString() {
65+
return $this->value;
66+
}
67+
68+
69+
/**
70+
* Serialize for json serialization
71+
* @return string
72+
*/
73+
public function jsonSerialize(): string {
74+
return $this->__toString();
75+
}
76+
}

tests/Core/Models/ByteTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
4+
* Licensed under the MIT License. See License in the project root
5+
* for license information.
6+
*/
7+
8+
namespace Microsoft\Graph\Test\Core\Models;
9+
10+
use InvalidArgumentException;
11+
use Microsoft\Graph\Core\Models\Byte;
12+
use Microsoft\Graph\Test\TestData\Model\Entity;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class ByteTest extends TestCase {
16+
17+
/**
18+
* @var Entity|null
19+
*/
20+
private $byteObject;
21+
22+
protected function setUp(): void {
23+
$this->byteObject = new Entity(['size' => new Byte(200)]);
24+
}
25+
26+
public function testCanCreateCorrectObject(): void{
27+
$this->assertInstanceOf(Byte::class, $this->byteObject->getProperties()['size']);
28+
}
29+
30+
public function testWillThrowExceptionOnInvalidValue(): void {
31+
$this->expectException(InvalidArgumentException::class);
32+
new Byte(-12929);
33+
}
34+
35+
/**
36+
* @throws \JsonException
37+
*/
38+
public function testSerialization(): void {
39+
$serialized = json_decode(json_encode($this->byteObject, JSON_THROW_ON_ERROR), true,512, JSON_THROW_ON_ERROR);
40+
$this->assertEquals(200, $serialized['size']);
41+
}
42+
protected function tearDown(): void {
43+
parent::tearDown();
44+
$this->byteObject = null;
45+
}
46+
}

tests/Core/Models/DateTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright (c) Microsoft Corporation. All Rights Reserved.
4+
* Licensed under the MIT License. See License in the project root
5+
* for license information.
6+
*/
7+
8+
namespace Microsoft\Graph\Test\Core\Models;
9+
10+
use DateTime;
11+
use Exception;
12+
use JsonException;
13+
use Microsoft\Graph\Core\Models\Date;
14+
use Microsoft\Graph\Core\Models\TimeOfDay;
15+
use Microsoft\Graph\Test\TestData\Model\Event;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class DateTest extends TestCase {
19+
private $event;
20+
21+
protected function setUp(): void {
22+
$this->event = new Event(['startTime' => new TimeOfDay('12:30:24'),
23+
'eventDate' => new Date('2021-11-17 12:30:24.000000'),
24+
'timestamp' => new DateTime('2021-11-17T12:29:24+00:00') ]);
25+
}
26+
27+
/**
28+
* @throws JsonException
29+
*/
30+
public function testCanSeeCorrectlyHandleDate(): void {
31+
$encoded = json_decode(json_encode($this->event, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
32+
$this->assertEquals('2021-11-17', $encoded['eventDate']);
33+
}
34+
35+
/**
36+
* @throws Exception
37+
*/
38+
public function testCanCreateFromDateTimeObject(): void {
39+
$eventCopy = $this->event;
40+
$eventCopy->setEventDate(Date::createFromDateTime(new DateTime('2021-11-18 12:30:24.000000')));
41+
$decoded = json_decode(json_encode($eventCopy, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
42+
$this->assertEquals('2021-11-18', $decoded['eventDate']);
43+
}
44+
45+
/**
46+
* @throws Exception
47+
*/
48+
public function testCanCreateFromYearMonthDay(): void {
49+
$eventCopy = $this->event;
50+
$this->event->setEventDate(Date::createFrom(2020, 12, 31));
51+
$decoded = json_decode(json_encode($eventCopy, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
52+
$this->assertEquals('2020-12-31', $decoded['eventDate']);
53+
}
54+
}

0 commit comments

Comments
 (0)