From 09f25d78b783fd29fae3859b3d983c9b4565c461 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 31 Jan 2021 11:01:38 +0100 Subject: [PATCH] Refactored API tests fixtures to avoid using deprecated methods --- .../test-api/Fixtures/ShortUrlsFixture.php | 19 +++++++++---- module/Rest/test-api/Fixtures/TagsFixture.php | 28 ++----------------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php index 390a2144..93defe90 100644 --- a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php +++ b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php @@ -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( diff --git a/module/Rest/test-api/Fixtures/TagsFixture.php b/module/Rest/test-api/Fixtures/TagsFixture.php index bf16104e..a28357a1 100644 --- a/module/Rest/test-api/Fixtures/TagsFixture.php +++ b/module/Rest/test-api/Fixtures/TagsFixture.php @@ -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(); } }