Skip to content

Commit

Permalink
fixes support for std template v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Oct 28, 2024
1 parent af54ee6 commit eba7076
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.4.1]

### Changed

- Update to support std uri template v2 [#166](https://github.com/microsoft/kiota-abstractions-php/issues/166)

## [1.4.0]

### Added

- Add interface for ComposedTypeWrapper for marking composed types.

### Changed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"doctrine/annotations": "^1.13 || ^2.0",
"open-telemetry/sdk": "^1.0.0",
"ramsey/uuid": "^3 || ^4",
"stduritemplate/stduritemplate": "^0.0.53 || ^0.0.54 || ^0.0.55 || ^0.0.56 || ^0.0.57 || ^0.0.59 || ^1.0.0",
"stduritemplate/stduritemplate": "^0.0.53 || ^0.0.54 || ^0.0.55 || ^0.0.56 || ^0.0.57 || ^0.0.59 || ^1.0.0 || ^2.0.0",
"psr/http-message": "^1.1 || ^2.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

final class Constants
{
public const VERSION = '1.4.0';
public const VERSION = '1.4.1';
}
8 changes: 8 additions & 0 deletions src/RequestInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Exception;
use InvalidArgumentException;
use Microsoft\Kiota\Abstractions\Serialization\Parsable;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use OpenTelemetry\API\Trace\StatusCode;
use OpenTelemetry\API\Trace\TracerInterface;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -99,6 +101,12 @@ private function sanitizeValue($value) {
if (is_object($value) && is_a($value, DateTime::class)) {
return $value->format(DateTimeInterface::ATOM);
}
if (is_object($value) && is_a($value, Date::class)) {
return $value->__toString();
}
if (is_object($value) && is_a($value, Time::class)) {
return $value->__toString();
}
if (is_object($value) && is_subclass_of($value, Enum::class)) {
return $value->value();
}
Expand Down
68 changes: 68 additions & 0 deletions tests/RequestInformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Microsoft\Kiota\Abstractions\Enum;
use Microsoft\Kiota\Abstractions\HttpMethod;
use Microsoft\Kiota\Abstractions\RequestInformation;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use PHPUnit\Framework\TestCase;
use Microsoft\Kiota\Abstractions\QueryParameter;

Expand Down Expand Up @@ -90,6 +92,72 @@ public function testPathParametersOfDateTimeOffsetType(): void
$this->assertEquals("https://localhost/getDirectRoutingCalls(fromDateTime='2022-08-01T02%3A33%3A00%2B02%3A00',toDateTime='2022-08-02T10%3A00%3A00-01%3A00')", $uri);
}

/**
* @throws InvalidArgumentException
* @throws Exception
*/
public function testPathParametersOfDateTimeType(): void
{
// Arrange as the request builders would
$requestInfo = new RequestInformation();
$requestInfo->httpMethod = HttpMethod::GET;
$requestInfo->urlTemplate = "https://localhost/getDirectRoutingCalls(fromDateTime='{fromDateTime}',toDateTime='{toDateTime}')";

// Act
$fromDateTime = new DateTime("2022-08-01T2:33");
$toDateTime = new DateTime('2022-08-02T10:00');
$requestInfo->pathParameters["fromDateTime"] = $fromDateTime;
$requestInfo->pathParameters["toDateTime"] = $toDateTime;

// Assert
$uri = $requestInfo->getUri();
$this->assertEquals("https://localhost/getDirectRoutingCalls(fromDateTime='2022-08-01T02%3A33%3A00%2B00%3A00',toDateTime='2022-08-02T10%3A00%3A00%2B00%3A00')", $uri);
}

/**
* @throws InvalidArgumentException
* @throws Exception
*/
public function testPathParametersOfTimeType(): void
{
// Arrange as the request builders would
$requestInfo = new RequestInformation();
$requestInfo->httpMethod = HttpMethod::GET;
$requestInfo->urlTemplate = "https://localhost/getDirectRoutingCalls(fromDateTime='{fromDateTime}',toDateTime='{toDateTime}')";

// Act
$fromDateTime = Time::createFromDateTime(new DateTime("2022-08-01T2:33", new DateTimeZone('+02:00')));
$toDateTime = Time::createFromDateTime(new DateTime('2022-08-02T10:00', new DateTimeZone('-1:00')));
$requestInfo->pathParameters["fromDateTime"] = $fromDateTime;
$requestInfo->pathParameters["toDateTime"] = $toDateTime;

// Assert
$uri = $requestInfo->getUri();
$this->assertEquals("https://localhost/getDirectRoutingCalls(fromDateTime='02%3A33%3A00',toDateTime='10%3A00%3A00')", $uri);
}

/**
* @throws InvalidArgumentException
* @throws Exception
*/
public function testPathParametersOfDateType(): void
{
// Arrange as the request builders would
$requestInfo = new RequestInformation();
$requestInfo->httpMethod = HttpMethod::GET;
$requestInfo->urlTemplate = "https://localhost/getDirectRoutingCalls(fromDateTime='{fromDateTime}',toDateTime='{toDateTime}')";

// Act
$fromDateTime = Date::createFromDateTime(new DateTime("2022-08-01T2:33", new DateTimeZone('+02:00')));
$toDateTime = Date::createFromDateTime(new DateTime('2022-08-02T10:00', new DateTimeZone('-1:00')));
$requestInfo->pathParameters["fromDateTime"] = $fromDateTime;
$requestInfo->pathParameters["toDateTime"] = $toDateTime;

// Assert
$uri = $requestInfo->getUri();
$this->assertEquals("https://localhost/getDirectRoutingCalls(fromDateTime='2022-08-01',toDateTime='2022-08-02')", $uri);
}

public function testCanHandleBooleanTypes(): void {
// Arrange as the request builders would
$requestInfo = new RequestInformation();
Expand Down

0 comments on commit eba7076

Please sign in to comment.