Skip to content

Commit

Permalink
add DateRange & DateProp Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
irfan-dahir committed Sep 25, 2018
1 parent cc0a152 commit 09f8c34
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/JikanTest/Helper/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PHPUnit\Framework\TestCase;

/**
* Class AnimeParserTest
* Class ParserTest
*/
class ParserTest extends TestCase
{
Expand Down
34 changes: 34 additions & 0 deletions test/JikanTest/Model/Common/DatePropTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace JikanTest\Model\Common;

use Jikan\Model\Common\DateProp;
use PHPUnit\Framework\TestCase;

/**
* Class DatePropTest
*/
class DatePropTest extends TestCase
{
/**
* @test
*/
public function it_gets_date_props()
{
$date = DateProp::fromFactory(null, null, null);
self::assertInstanceOf(DateProp::class, $date);
self::assertEquals(null, $date->getDay());

$date = new DateProp('Dec 1, 2004');
self::assertInstanceOf(DateProp::class, $date);
self::assertEquals(1, $date->getDay());
self::assertEquals(12, $date->getMonth());
self::assertEquals(2004, $date->getYear());

$date = new DateProp('Dec, 2004');
self::assertInstanceOf(DateProp::class, $date);
self::assertEquals(null, $date->getDay());
self::assertEquals(12, $date->getMonth());
self::assertEquals(2004, $date->getYear());
}
}
72 changes: 72 additions & 0 deletions test/JikanTest/Model/Common/DateRangeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace JikanTest\Model\Common;

use Jikan\Model\Common\DateProp;
use Jikan\Model\Common\DateRange;
use PHPUnit\Framework\TestCase;

/**
* Class DateRangeTest
*/
class DateRangeTest extends TestCase
{
/**
* @test
*/
public function it_gets_date()
{
$date = new DateRange('Sep 15, 2018 to Sep, 2019');
self::assertInstanceOf(\DateTimeImmutable::class, $date->getFrom());
self::assertInstanceOf(\DateTimeImmutable::class, $date->getUntil());

$date = new DateRange('Sep 15, 2018 to ?');
self::assertInstanceOf(\DateTimeImmutable::class, $date->getFrom());
self::assertEquals(null, $date->getUntil());

$date = new DateRange('?');
self::assertEquals(null, $date->getFrom());
self::assertEquals(null, $date->getUntil());
}

/**
* @test
*/
public function it_gets_date_props()
{
$date = new DateRange('Sep 15, 2018 to Oct, 2019');

self::assertInstanceOf(DateProp::class, $date->getFromProp());
self::assertInstanceOf(DateProp::class, $date->getUntilProp());

self::assertEquals(15, $date->getFromProp()->getDay());
self::assertEquals(9, $date->getFromProp()->getMonth());
self::assertEquals(2018, $date->getFromProp()->getYear());
self::assertEquals(null, $date->getUntilProp()->getDay());
self::assertEquals(10, $date->getUntilProp()->getMonth());
self::assertEquals(2019, $date->getUntilProp()->getYear());

$date = new DateRange('Jan, 2018 to ?');
self::assertEquals(null, $date->getFromProp()->getDay());
self::assertEquals(1, $date->getFromProp()->getMonth());
self::assertEquals(2018, $date->getFromProp()->getYear());
self::assertEquals(null, $date->getUntilProp()->getDay());
self::assertEquals(null, $date->getUntilProp()->getMonth());
self::assertEquals(null, $date->getUntilProp()->getYear());

$date = new DateRange('?');
self::assertEquals(null, $date->getFromProp()->getDay());
self::assertEquals(null, $date->getFromProp()->getMonth());
self::assertEquals(null, $date->getFromProp()->getYear());
self::assertEquals(null, $date->getUntilProp()->getDay());
self::assertEquals(null, $date->getUntilProp()->getMonth());
self::assertEquals(null, $date->getUntilProp()->getYear());

$date = new DateRange('Jan 3, 2015 to 2016');
self::assertEquals(null, $date->getUntilProp()->getDay());
self::assertEquals(null, $date->getUntilProp()->getMonth());
self::assertEquals(2016, $date->getUntilProp()->getYear());


}
}

0 comments on commit 09f8c34

Please sign in to comment.