Refactored API tests fixtures to avoid using deprecated methods

This commit is contained in:
Alejandro Celaya 2021-01-31 11:01:38 +01:00
parent 82091c7951
commit 09f25d78b7
2 changed files with 16 additions and 31 deletions

View File

@ -18,18 +18,23 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf
{
public function getDependencies(): array
{
return [ApiKeyFixture::class];
return [ApiKeyFixture::class, TagsFixture::class];
}
public function load(ObjectManager $manager): void
{
$relationResolver = new PersistenceShortUrlRelationResolver($manager);
/** @var ApiKey $authorApiKey */
$authorApiKey = $this->getReference('author_api_key');
$abcShortUrl = $this->setShortUrlDate(
ShortUrl::fromMeta(ShortUrlMeta::fromRawData(
['customSlug' => 'abc123', 'apiKey' => $authorApiKey, 'longUrl' => 'https://shlink.io'],
)),
ShortUrl::fromMeta(ShortUrlMeta::fromRawData([
'customSlug' => 'abc123',
'apiKey' => $authorApiKey,
'longUrl' => 'https://shlink.io',
'tags' => ['foo'],
]), $relationResolver),
'2018-05-01',
);
$manager->persist($abcShortUrl);
@ -40,7 +45,8 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf
'apiKey' => $authorApiKey,
'longUrl' =>
'https://blog.alejandrocelaya.com/2017/12/09/acmailer-7-0-the-most-important-release-in-a-long-time/',
])), '2019-01-01 00:00:10');
'tags' => ['foo', 'bar'],
]), $relationResolver), '2019-01-01 00:00:10');
$manager->persist($defShortUrl);
$customShortUrl = $this->setShortUrlDate(ShortUrl::fromMeta(ShortUrlMeta::fromRawData(
@ -61,7 +67,8 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf
'customSlug' => 'ghi789',
'longUrl' => 'https://blog.alejandrocelaya.com/2019/04/27/considerations-to-properly-use-open-'
. 'source-software-projects/',
]), new PersistenceShortUrlRelationResolver($manager)), '2019-01-01 00:00:30');
'tags' => ['foo'],
]), $relationResolver), '2019-01-01 00:00:30');
$manager->persist($withDomainDuplicatingShortCode);
$withDomainAndSlugShortUrl = $this->setShortUrlDate(ShortUrl::fromMeta(ShortUrlMeta::fromRawData(

View File

@ -4,40 +4,18 @@ declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Fixtures;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Tag;
class TagsFixture extends AbstractFixture implements DependentFixtureInterface
class TagsFixture extends AbstractFixture
{
public function getDependencies(): array
{
return [ShortUrlsFixture::class];
}
public function load(ObjectManager $manager): void
{
$fooTag = new Tag('foo');
$manager->persist($fooTag);
$barTag = new Tag('bar');
$manager->persist($barTag);
$manager->persist(new Tag('foo'));
$manager->persist(new Tag('bar'));
$manager->persist(new Tag('baz'));
/** @var ShortUrl $abcShortUrl */
$abcShortUrl = $this->getReference('abc123_short_url');
$abcShortUrl->setTags(new ArrayCollection([$fooTag]));
/** @var ShortUrl $defShortUrl */
$defShortUrl = $this->getReference('def456_short_url');
$defShortUrl->setTags(new ArrayCollection([$fooTag, $barTag]));
/** @var ShortUrl $exampleShortUrl */
$exampleShortUrl = $this->getReference('example_short_url');
$exampleShortUrl->setTags(new ArrayCollection([$fooTag]));
$manager->flush();
}
}