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;
|
2022-09-23 20:03:32 +03:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
2022-09-23 19:05:17 +03:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
|
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
|
|
|
|
{
|
2021-01-31 13:01:38 +03:00
|
|
|
return [ApiKeyFixture::class, TagsFixture::class];
|
2021-01-10 10:40:18 +03:00
|
|
|
}
|
|
|
|
|
2019-01-27 14:14:18 +03:00
|
|
|
public function load(ObjectManager $manager): void
|
|
|
|
{
|
2022-10-24 21:25:06 +03:00
|
|
|
$relationResolver = new PersistenceShortUrlRelationResolver($manager); // @phpstan-ignore-line
|
2021-01-31 13:01:38 +03:00
|
|
|
|
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(
|
2022-12-11 20:24:47 +03:00
|
|
|
ShortUrl::create(ShortUrlCreation::fromRawData([
|
2021-01-31 13:01:38 +03:00
|
|
|
'customSlug' => 'abc123',
|
|
|
|
'apiKey' => $authorApiKey,
|
|
|
|
'longUrl' => 'https://shlink.io',
|
|
|
|
'tags' => ['foo'],
|
2021-02-04 23:27:16 +03:00
|
|
|
'title' => 'My cool title',
|
2021-05-22 08:35:47 +03:00
|
|
|
'crawlable' => true,
|
2022-12-11 15:38:11 +03:00
|
|
|
'maxVisits' => 2,
|
2021-01-31 13:01:38 +03:00
|
|
|
]), $relationResolver),
|
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);
|
|
|
|
|
2022-12-11 20:24:47 +03:00
|
|
|
$defShortUrl = $this->setShortUrlDate(ShortUrl::create(ShortUrlCreation::fromRawData([
|
2021-01-30 16:18:44 +03:00
|
|
|
'validSince' => Chronos::parse('2020-05-01'),
|
|
|
|
'customSlug' => 'def456',
|
|
|
|
'apiKey' => $authorApiKey,
|
|
|
|
'longUrl' =>
|
|
|
|
'https://blog.alejandrocelaya.com/2017/12/09/acmailer-7-0-the-most-important-release-in-a-long-time/',
|
2021-01-31 13:01:38 +03:00
|
|
|
'tags' => ['foo', 'bar'],
|
|
|
|
]), $relationResolver), '2019-01-01 00:00:10');
|
2019-01-27 14:14:18 +03:00
|
|
|
$manager->persist($defShortUrl);
|
|
|
|
|
2022-12-11 20:24:47 +03:00
|
|
|
$customShortUrl = $this->setShortUrlDate(ShortUrl::create(ShortUrlCreation::fromRawData([
|
2021-10-02 11:31:23 +03:00
|
|
|
'customSlug' => 'custom',
|
|
|
|
'maxVisits' => 2,
|
|
|
|
'apiKey' => $authorApiKey,
|
|
|
|
'longUrl' => 'https://shlink.io',
|
|
|
|
'forwardQuery' => false,
|
|
|
|
])), '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(
|
2022-12-11 20:24:47 +03:00
|
|
|
ShortUrl::create(ShortUrlCreation::fromRawData([
|
2022-12-11 15:38:11 +03:00
|
|
|
'customSlug' => 'ghi789',
|
|
|
|
'longUrl' => 'https://shlink.io/documentation/',
|
|
|
|
'validUntil' => Chronos::parse('2020-05-01'), // In the past
|
|
|
|
])),
|
2020-02-02 11:51:17 +03:00
|
|
|
'2018-05-01',
|
|
|
|
);
|
|
|
|
$manager->persist($ghiShortUrl);
|
|
|
|
|
2022-12-11 20:24:47 +03:00
|
|
|
$withDomainDuplicatingShortCode = $this->setShortUrlDate(ShortUrl::create(ShortUrlCreation::fromRawData([
|
2021-01-30 16:18:44 +03:00
|
|
|
'domain' => 'example.com',
|
|
|
|
'customSlug' => 'ghi789',
|
|
|
|
'longUrl' => 'https://blog.alejandrocelaya.com/2019/04/27/considerations-to-properly-use-open-'
|
|
|
|
. 'source-software-projects/',
|
2021-01-31 13:01:38 +03:00
|
|
|
'tags' => ['foo'],
|
|
|
|
]), $relationResolver), '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
|
|
|
|
2022-12-11 20:24:47 +03:00
|
|
|
$withDomainAndSlugShortUrl = $this->setShortUrlDate(ShortUrl::create(ShortUrlCreation::fromRawData(
|
2021-01-30 16:18:44 +03:00
|
|
|
['domain' => 'some-domain.com', 'customSlug' => 'custom-with-domain', 'longUrl' => 'https://google.com'],
|
|
|
|
)), '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);
|
2021-01-10 11:54:19 +03:00
|
|
|
$this->addReference('example_short_url', $withDomainDuplicatingShortCode);
|
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
|
|
|
}
|