shlink/module/Rest/test-api/Fixtures/ShortUrlsFixture.php

59 lines
2.0 KiB
PHP
Raw Normal View History

2019-01-27 05:14:18 -06:00
<?php
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Fixtures;
use Cake\Chronos\Chronos;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
2019-01-27 05:35:00 -06:00
use ReflectionObject;
2019-01-27 05:14:18 -06:00
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
class ShortUrlsFixture extends AbstractFixture
{
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager): void
{
2019-01-27 05:35:00 -06:00
$abcShortUrl = $this->setShortUrlDate(new ShortUrl('https://shlink.io'))->setShortCode('abc123');
2019-01-27 05:14:18 -06:00
$manager->persist($abcShortUrl);
2019-01-27 05:35:00 -06:00
$defShortUrl = $this->setShortUrlDate(new ShortUrl(
'https://blog.alejandrocelaya.com/2017/12/09/acmailer-7-0-the-most-important-release-in-a-long-time/',
ShortUrlMeta::createFromParams(Chronos::parse('2020-05-01'))
2019-01-27 05:14:18 -06:00
))->setShortCode('def456');
$manager->persist($defShortUrl);
2019-01-27 05:35:00 -06:00
$customShortUrl = $this->setShortUrlDate(new ShortUrl(
2019-01-27 05:14:18 -06:00
'https://shlink.io',
ShortUrlMeta::createFromParams(null, null, 'custom', 2)
2019-01-27 05:35:00 -06:00
));
2019-01-27 05:14:18 -06:00
$manager->persist($customShortUrl);
$withDomainShortUrl = $this->setShortUrlDate(new ShortUrl(
'https://blog.alejandrocelaya.com/2019/04/27/considerations-to-properly-use-open-source-software-projects/',
ShortUrlMeta::createFromRawData(['domain' => 'example.com'])
))->setShortCode('ghi789');
$manager->persist($withDomainShortUrl);
2019-01-27 05:14:18 -06:00
$manager->flush();
$this->addReference('abc123_short_url', $abcShortUrl);
$this->addReference('def456_short_url', $defShortUrl);
}
2019-01-27 05:35:00 -06:00
private function setShortUrlDate(ShortUrl $shortUrl): ShortUrl
{
$ref = new ReflectionObject($shortUrl);
$dateProp = $ref->getProperty('dateCreated');
$dateProp->setAccessible(true);
$dateProp->setValue($shortUrl, Chronos::create(2019, 1, 1, 0, 0, 0));
return $shortUrl;
}
2019-01-27 05:14:18 -06:00
}