Skip to content

Commit

Permalink
Added custom Date and Time tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Jan 27, 2022
1 parent 70733bb commit a50de02
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
2 changes: 1 addition & 1 deletion abstractions/php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"autoload-dev": {
"psr-4": {
"Microsoft\\Kiota\\Abstractions\\": "./src",
"Microsoft\\Kiota\\Tests\\": "./tests"
"Microsoft\\Kiota\\Abstractions\\Tests": "./tests"
}
},
"require": {
Expand Down
2 changes: 1 addition & 1 deletion abstractions/php/src/Types/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Time
* The final string representation of the Time
* @var string $value
*/
private $value;
private string $value;

/**
* @param string $timeString The time value in string format HH:MM:SS
Expand Down
2 changes: 1 addition & 1 deletion abstractions/php/tests/HttpMethodTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Microsoft\Kiota\Tests;
namespace Microsoft\Kiota\Abstractions\Tests;

use InvalidArgumentException;
use Microsoft\Kiota\Abstractions\HttpMethod;
Expand Down
12 changes: 0 additions & 12 deletions abstractions/php/tests/Microsoft/Kiota/Tests/SampleTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion abstractions/php/tests/RequestInformationTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Microsoft\Kiota\Tests;
namespace Microsoft\Kiota\Abstractions\Tests;
use DateTime;
use Microsoft\Kiota\Abstractions\RequestInformation;
use PHPUnit\Framework\TestCase;
Expand Down
35 changes: 35 additions & 0 deletions abstractions/php/tests/Types/DateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Microsoft\Kiota\Abstractions\Tests\Types;

use Microsoft\Kiota\Abstractions\Types\Date;
use PHPUnit\Framework\TestCase;

class DateTest extends TestCase
{
public function testConstructWithDateString(): void
{
$dateString = "2022-01-27";
$date = new Date($dateString);
$this->assertInstanceOf(Date::class, $date);
$this->assertEquals($dateString, strval($date));
}

public function testConstructorWithInvalidDateStringThrowsException(): void
{
$this->expectException(\Exception::class);
$date = new Date("invalid string");
}

public function testCreateFromDateTime(): void
{
$date = Date::createFromDateTime(new \DateTime("2022-01-2700:00:00"));
$this->assertEquals("2022-01-27", strval($date));
}

public function testCreateFrom(): void
{
$date = Date::createFrom(2022, 01, 27);
$this->assertEquals("2022-01-27", strval($date));
}
}
35 changes: 35 additions & 0 deletions abstractions/php/tests/Types/TimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Microsoft\Kiota\Abstractions\Tests\Types;

use Microsoft\Kiota\Abstractions\Types\Time;
use PHPUnit\Framework\TestCase;

class TimeTest extends TestCase
{
public function testConstructorWithValidTimeString(): void
{
$time = new Time("19:25:00");
$this->assertInstanceOf(Time::class, $time);
}

public function testConstructorWithInvalidTimeString(): void
{
$this->expectException(\Exception::class);
$time = new Time("invalid string");
}

public function testCreateFromDateTime(): void
{
$time = Time::createFromDateTime(new \DateTime("2022-01-2719:25:00"));
$this->assertInstanceOf(Time::class, $time);
$this->assertEquals("19:25:00", strval($time));
}

public function testCreateFrom(): void
{
$time = Time::createFrom(19, 25, 0);
$this->assertInstanceOf(Time::class, $time);
$this->assertEquals("19:25:00", strval($time));
}
}

0 comments on commit a50de02

Please sign in to comment.