Migrated from standard datetime objects to chronos objects

This commit is contained in:
Alejandro Celaya
2018-09-29 12:52:32 +02:00
parent 9a2ca35e6e
commit 0183c8a4b7
31 changed files with 271 additions and 198 deletions

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Model;
use Cake\Chronos\Chronos;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\ValidationException;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
@@ -42,10 +43,10 @@ class ShortUrlMetaTest extends TestCase
*/
public function properlyCreatedInstanceReturnsValues()
{
$meta = ShortUrlMeta::createFromParams((new \DateTime('2015-01-01'))->format(\DateTime::ATOM), null, 'foobar');
$meta = ShortUrlMeta::createFromParams(Chronos::parse('2015-01-01')->toAtomString(), null, 'foobar');
$this->assertTrue($meta->hasValidSince());
$this->assertEquals(new \DateTime('2015-01-01'), $meta->getValidSince());
$this->assertEquals(Chronos::parse('2015-01-01'), $meta->getValidSince());
$this->assertFalse($meta->hasValidUntil());
$this->assertNull($meta->getValidUntil());

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Service;
use Cake\Chronos\Chronos;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use PHPUnit\Framework\TestCase;
@@ -104,15 +105,15 @@ class ShortUrlServiceTest extends TestCase
$flush = $this->em->flush($shortUrl)->willReturn(null);
$result = $this->service->updateMetadataByShortCode('abc123', ShortUrlMeta::createFromParams(
(new \DateTime('2017-01-01 00:00:00'))->format(\DateTime::ATOM),
(new \DateTime('2017-01-05 00:00:00'))->format(\DateTime::ATOM),
Chronos::parse('2017-01-01 00:00:00')->toAtomString(),
Chronos::parse('2017-01-05 00:00:00')->toAtomString(),
null,
5
));
$this->assertSame($shortUrl, $result);
$this->assertEquals(new \DateTime('2017-01-01 00:00:00'), $shortUrl->getValidSince());
$this->assertEquals(new \DateTime('2017-01-05 00:00:00'), $shortUrl->getValidUntil());
$this->assertEquals(Chronos::parse('2017-01-01 00:00:00'), $shortUrl->getValidSince());
$this->assertEquals(Chronos::parse('2017-01-05 00:00:00'), $shortUrl->getValidUntil());
$this->assertEquals(5, $shortUrl->getMaxVisits());
$findShortUrl->shouldHaveBeenCalled();
$getRepo->shouldHaveBeenCalled();