2019-01-27 14:14:18 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2019-01-27 14:14:18 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Fixtures;
|
|
|
|
|
|
|
|
use Cake\Chronos\Chronos;
|
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture;
|
2021-01-10 10:40:18 +03:00
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
2019-12-16 23:46:27 +03:00
|
|
|
use Doctrine\Persistence\ObjectManager;
|
2019-01-27 14:35:00 +03:00
|
|
|
use ReflectionObject;
|
2019-01-27 14:14:18 +03:00
|
|
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
|
|
|
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
|
2021-01-10 10:40:18 +03:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Resolver\PersistenceShortUrlRelationResolver;
|
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
2019-01-27 14:14:18 +03:00
|
|
|
|
2021-01-10 10:40:18 +03:00
|
|
|
class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterface
|
2019-01-27 14:14:18 +03:00
|
|
|
{
|
2021-01-10 10:40:18 +03:00
|
|
|
public function getDependencies(): array
|
|
|
|
{
|
|
|
|
return [ApiKeyFixture::class];
|
|
|
|
}
|
|
|
|
|
2019-01-27 14:14:18 +03:00
|
|
|
public function load(ObjectManager $manager): void
|
|
|
|
{
|
2021-01-10 10:40:18 +03:00
|
|
|
/** @var ApiKey $authorApiKey */
|
|
|
|
$authorApiKey = $this->getReference('author_api_key');
|
|
|
|
|
2019-10-11 10:14:25 +03:00
|
|
|
$abcShortUrl = $this->setShortUrlDate(
|
2021-01-10 10:40:18 +03:00
|
|
|
new ShortUrl('https://shlink.io', ShortUrlMeta::fromRawData(
|
|
|
|
['customSlug' => 'abc123', 'apiKey' => $authorApiKey],
|
|
|
|
)),
|
2020-01-01 22:48:31 +03:00
|
|
|
'2018-05-01',
|
2019-10-11 10:14:25 +03:00
|
|
|
);
|
2019-01-27 14:14:18 +03:00
|
|
|
$manager->persist($abcShortUrl);
|
|
|
|
|
2019-01-27 14:35:00 +03:00
|
|
|
$defShortUrl = $this->setShortUrlDate(new ShortUrl(
|
|
|
|
'https://blog.alejandrocelaya.com/2017/12/09/acmailer-7-0-the-most-important-release-in-a-long-time/',
|
2021-01-10 10:40:18 +03:00
|
|
|
ShortUrlMeta::fromRawData(
|
|
|
|
['validSince' => Chronos::parse('2020-05-01'), 'customSlug' => 'def456', 'apiKey' => $authorApiKey],
|
|
|
|
),
|
2019-12-18 17:26:23 +03:00
|
|
|
), '2019-01-01 00:00:10');
|
2019-01-27 14:14:18 +03:00
|
|
|
$manager->persist($defShortUrl);
|
|
|
|
|
2019-01-27 14:35:00 +03:00
|
|
|
$customShortUrl = $this->setShortUrlDate(new ShortUrl(
|
2019-01-27 14:14:18 +03:00
|
|
|
'https://shlink.io',
|
2021-01-10 10:40:18 +03:00
|
|
|
ShortUrlMeta::fromRawData(['customSlug' => 'custom', 'maxVisits' => 2, 'apiKey' => $authorApiKey]),
|
2019-12-18 17:26:23 +03:00
|
|
|
), '2019-01-01 00:00:20');
|
2019-01-27 14:14:18 +03:00
|
|
|
$manager->persist($customShortUrl);
|
|
|
|
|
2020-02-02 11:51:17 +03:00
|
|
|
$ghiShortUrl = $this->setShortUrlDate(
|
|
|
|
new ShortUrl('https://shlink.io/documentation/', ShortUrlMeta::fromRawData(['customSlug' => 'ghi789'])),
|
|
|
|
'2018-05-01',
|
|
|
|
);
|
|
|
|
$manager->persist($ghiShortUrl);
|
|
|
|
|
|
|
|
$withDomainDuplicatingShortCode = $this->setShortUrlDate(new ShortUrl(
|
2019-10-01 21:24:11 +03:00
|
|
|
'https://blog.alejandrocelaya.com/2019/04/27/considerations-to-properly-use-open-source-software-projects/',
|
2020-01-26 10:42:51 +03:00
|
|
|
ShortUrlMeta::fromRawData(['domain' => 'example.com', 'customSlug' => 'ghi789']),
|
2021-01-10 10:40:18 +03:00
|
|
|
new PersistenceShortUrlRelationResolver($manager),
|
2019-12-18 17:26:23 +03:00
|
|
|
), '2019-01-01 00:00:30');
|
2020-02-02 11:51:17 +03:00
|
|
|
$manager->persist($withDomainDuplicatingShortCode);
|
2019-10-01 21:24:11 +03:00
|
|
|
|
2019-10-02 21:13:25 +03:00
|
|
|
$withDomainAndSlugShortUrl = $this->setShortUrlDate(new ShortUrl(
|
|
|
|
'https://google.com',
|
2020-01-26 10:42:51 +03:00
|
|
|
ShortUrlMeta::fromRawData(['domain' => 'some-domain.com', 'customSlug' => 'custom-with-domain']),
|
2019-12-18 17:26:23 +03:00
|
|
|
), '2018-10-20');
|
2019-10-02 21:13:25 +03:00
|
|
|
$manager->persist($withDomainAndSlugShortUrl);
|
|
|
|
|
2019-01-27 14:14:18 +03:00
|
|
|
$manager->flush();
|
|
|
|
|
|
|
|
$this->addReference('abc123_short_url', $abcShortUrl);
|
|
|
|
$this->addReference('def456_short_url', $defShortUrl);
|
2020-02-02 12:46:38 +03:00
|
|
|
$this->addReference('ghi789_short_url', $ghiShortUrl);
|
2019-01-27 14:14:18 +03:00
|
|
|
}
|
2019-01-27 14:35:00 +03:00
|
|
|
|
2019-12-18 17:26:23 +03:00
|
|
|
private function setShortUrlDate(ShortUrl $shortUrl, string $date): ShortUrl
|
2019-01-27 14:35:00 +03:00
|
|
|
{
|
|
|
|
$ref = new ReflectionObject($shortUrl);
|
|
|
|
$dateProp = $ref->getProperty('dateCreated');
|
|
|
|
$dateProp->setAccessible(true);
|
2019-12-18 17:26:23 +03:00
|
|
|
$dateProp->setValue($shortUrl, Chronos::parse($date));
|
2019-01-27 14:35:00 +03:00
|
|
|
|
|
|
|
return $shortUrl;
|
|
|
|
}
|
2019-01-27 14:14:18 +03:00
|
|
|
}
|