Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #37 from archdevil666pl/master
Browse files Browse the repository at this point in the history
Test bugfix, fixes #35
  • Loading branch information
arius86 committed Jan 5, 2015
2 parents df5f349 + 77197cb commit 9673a18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Util/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function isValid($value)
return true;
try {
new static($value);
return true;
return !is_null($value);
} catch (\Exception $e) {
return false;
}
Expand Down
11 changes: 8 additions & 3 deletions tests/Db/MappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,14 @@ public function testShouldResolveDateTime()
$this->assertSame($fake->createdAt, $fake->readMapped('createdAt')->format('m/d/Y'));

$fake->createdAt = $now->format('d/m/Y');
$this->assertNotInstanceOf('\Vegas\Util\DateTime', $fake->readMapped('createdAt'));
$this->assertEquals($now->format('d/m/Y'), $fake->readMapped('createdAt'));
$this->assertInternalType('string', $fake->readMapped('createdAt'));
if ($now->format('j') > 12) {
$this->assertNotInstanceOf('\Vegas\Util\DateTime', $fake->readMapped('createdAt'));
$this->assertEquals($now->format('d/m/Y'), $fake->readMapped('createdAt'));
$this->assertInternalType('string', $fake->readMapped('createdAt'));
} else {
$this->assertInstanceOf('\Vegas\Util\DateTime', $fake->readMapped('createdAt'));
$this->assertNotEquals($now->format('d/m/Y'), $fake->readMapped('createdAt')->format('d/m/Y'));
}
}

public function testShouldResolveMultipleMappersForOneField()
Expand Down
12 changes: 9 additions & 3 deletions tests/Util/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ public function testShouldValidateGivenDateString()
{
$this->assertFalse(\Vegas\Util\DateTime::isValid('Invalid date'));
$this->assertFalse(\Vegas\Util\DateTime::isValid(time()));
$this->assertFalse(\Vegas\Util\DateTime::isValid((new \DateTime())->format('d/m/Y')));
$this->assertTrue(\Vegas\Util\DateTime::isValid((new \DateTime())->format('Y-m-d H:i:s')));
$this->assertTrue(\Vegas\Util\DateTime::isValid((new \DateTime())->format('m/d/Y')));
$this->assertFalse(\Vegas\Util\DateTime::isValid(null));

$date = new \DateTime();
// @see http://php.net/manual/en/datetime.formats.date.php
$this->assertTrue($date->format('j') <= 12 && \Vegas\Util\DateTime::isValid($date->format('d/m/Y')));
$this->assertFalse($date->format('j') > 12 && \Vegas\Util\DateTime::isValid($date->format('d/m/Y')));

$this->assertTrue(\Vegas\Util\DateTime::isValid($date->format('Y-m-d H:i:s')));
$this->assertTrue(\Vegas\Util\DateTime::isValid($date->format('m/d/Y')));
}

public function testShouldSerializeDateTimeObjectToJson()
Expand Down

0 comments on commit 9673a18

Please sign in to comment.