mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
Improved API tests by adding fixtures
This commit is contained in:
41
module/Rest/test-api/Fixtures/ShortUrlsFixture.php
Normal file
41
module/Rest/test-api/Fixtures/ShortUrlsFixture.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioApiTest\Shlink\Rest\Fixtures;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
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
|
||||
{
|
||||
$abcShortUrl = (new ShortUrl('https://shlink.io'))->setShortCode('abc123');
|
||||
$manager->persist($abcShortUrl);
|
||||
|
||||
$defShortUrl = (new ShortUrl(
|
||||
'https://shlink.io',
|
||||
ShortUrlMeta::createFromParams(Chronos::now()->addDays(3))
|
||||
))->setShortCode('def456');
|
||||
$manager->persist($defShortUrl);
|
||||
|
||||
$customShortUrl = new ShortUrl(
|
||||
'https://shlink.io',
|
||||
ShortUrlMeta::createFromParams(null, null, 'custom', 2)
|
||||
);
|
||||
$manager->persist($customShortUrl);
|
||||
|
||||
$manager->flush();
|
||||
|
||||
$this->addReference('abc123_short_url', $abcShortUrl);
|
||||
$this->addReference('def456_short_url', $defShortUrl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user