Merge pull request #553 from acelaya-forks/feature/doctrine-2.7

Updated to latest doctrine versions, solving deprecations
This commit is contained in:
Alejandro Celaya 2019-11-20 20:12:02 +01:00 committed by GitHub
commit a7d308c585
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 30 additions and 38 deletions

View file

@ -19,10 +19,10 @@
"akrabat/ip-address-middleware": "^1.0", "akrabat/ip-address-middleware": "^1.0",
"cakephp/chronos": "^1.2", "cakephp/chronos": "^1.2",
"cocur/slugify": "^3.0", "cocur/slugify": "^3.0",
"doctrine/cache": "^1.6", "doctrine/cache": "^1.9",
"doctrine/dbal": "^2.9", "doctrine/dbal": "^2.10",
"doctrine/migrations": "^2.0", "doctrine/migrations": "^2.2",
"doctrine/orm": "^2.5", "doctrine/orm": "^2.7",
"endroid/qr-code": "^3.6", "endroid/qr-code": "^3.6",
"firebase/php-jwt": "^4.0", "firebase/php-jwt": "^4.0",
"geoip2/geoip2": "^2.9", "geoip2/geoip2": "^2.9",

View file

@ -82,6 +82,6 @@ class LocateShortUrlVisit
} }
$visit->locate(new VisitLocation($location)); $visit->locate(new VisitLocation($location));
$this->em->flush($visit); $this->em->flush();
} }
} }

View file

@ -64,9 +64,7 @@ class ShortUrlService implements ShortUrlServiceInterface
$shortUrl = $this->findByShortCode($this->em, $shortCode); $shortUrl = $this->findByShortCode($this->em, $shortCode);
$shortUrl->updateMeta($shortUrlMeta); $shortUrl->updateMeta($shortUrlMeta);
/** @var ORM\EntityManager $em */ $this->em->flush();
$em = $this->em;
$em->flush($shortUrl);
return $shortUrl; return $shortUrl;
} }

View file

@ -77,9 +77,7 @@ class TagService implements TagServiceInterface
$tag->rename($newName); $tag->rename($newName);
/** @var ORM\EntityManager $em */ $this->em->flush();
$em = $this->em;
$em->flush($tag);
return $tag; return $tag;
} }

View file

@ -43,10 +43,8 @@ class VisitsTracker implements VisitsTrackerInterface
$visit = new Visit($shortUrl, $visitor); $visit = new Visit($shortUrl, $visitor);
/** @var ORM\EntityManager $em */ $this->em->persist($visit);
$em = $this->em; $this->em->flush();
$em->persist($visit);
$em->flush($visit);
$this->eventDispatcher->dispatch(new ShortUrlVisited($visit->getId())); $this->eventDispatcher->dispatch(new ShortUrlVisited($visit->getId()));
} }

View file

@ -61,7 +61,7 @@ class LocateShortUrlVisitTest extends TestCase
($this->locateVisit)($event); ($this->locateVisit)($event);
$findVisit->shouldHaveBeenCalledOnce(); $findVisit->shouldHaveBeenCalledOnce();
$this->em->flush(Argument::cetera())->shouldNotHaveBeenCalled(); $this->em->flush()->shouldNotHaveBeenCalled();
$this->ipLocationResolver->resolveIpLocation(Argument::cetera())->shouldNotHaveBeenCalled(); $this->ipLocationResolver->resolveIpLocation(Argument::cetera())->shouldNotHaveBeenCalled();
$logWarning->shouldHaveBeenCalled(); $logWarning->shouldHaveBeenCalled();
} }
@ -86,7 +86,7 @@ class LocateShortUrlVisitTest extends TestCase
$findVisit->shouldHaveBeenCalledOnce(); $findVisit->shouldHaveBeenCalledOnce();
$resolveLocation->shouldHaveBeenCalledOnce(); $resolveLocation->shouldHaveBeenCalledOnce();
$logWarning->shouldHaveBeenCalled(); $logWarning->shouldHaveBeenCalled();
$this->em->flush(Argument::cetera())->shouldNotHaveBeenCalled(); $this->em->flush()->shouldNotHaveBeenCalled();
} }
/** /**
@ -97,7 +97,7 @@ class LocateShortUrlVisitTest extends TestCase
{ {
$event = new ShortUrlVisited('123'); $event = new ShortUrlVisited('123');
$findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit);
$flush = $this->em->flush($visit)->will(function () { $flush = $this->em->flush()->will(function () {
}); });
$resolveIp = $this->ipLocationResolver->resolveIpLocation(Argument::any()); $resolveIp = $this->ipLocationResolver->resolveIpLocation(Argument::any());
@ -128,7 +128,7 @@ class LocateShortUrlVisitTest extends TestCase
$event = new ShortUrlVisited('123'); $event = new ShortUrlVisited('123');
$findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit);
$flush = $this->em->flush($visit)->will(function () { $flush = $this->em->flush()->will(function () {
}); });
$resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location); $resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location);
@ -151,7 +151,7 @@ class LocateShortUrlVisitTest extends TestCase
$event = new ShortUrlVisited('123'); $event = new ShortUrlVisited('123');
$findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit);
$flush = $this->em->flush($visit)->will(function () { $flush = $this->em->flush()->will(function () {
}); });
$resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location); $resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location);
$checkUpdateDb = $this->dbUpdater->checkDbUpdate(Argument::cetera())->willThrow($e); $checkUpdateDb = $this->dbUpdater->checkDbUpdate(Argument::cetera())->willThrow($e);
@ -179,7 +179,7 @@ class LocateShortUrlVisitTest extends TestCase
$event = new ShortUrlVisited('123'); $event = new ShortUrlVisited('123');
$findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit);
$flush = $this->em->flush($visit)->will(function () { $flush = $this->em->flush()->will(function () {
}); });
$resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location); $resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location);
$checkUpdateDb = $this->dbUpdater->checkDbUpdate(Argument::cetera())->willThrow($e); $checkUpdateDb = $this->dbUpdater->checkDbUpdate(Argument::cetera())->willThrow($e);

View file

@ -35,7 +35,7 @@ class ShortUrlServiceTest extends TestCase
} }
/** @test */ /** @test */
public function listedUrlsAreReturnedFromEntityManager() public function listedUrlsAreReturnedFromEntityManager(): void
{ {
$list = [ $list = [
new ShortUrl(''), new ShortUrl(''),
@ -54,7 +54,7 @@ class ShortUrlServiceTest extends TestCase
} }
/** @test */ /** @test */
public function exceptionIsThrownWhenSettingTagsOnInvalidShortcode() public function exceptionIsThrownWhenSettingTagsOnInvalidShortcode(): void
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
$repo = $this->prophesize(ShortUrlRepository::class); $repo = $this->prophesize(ShortUrlRepository::class);
@ -67,7 +67,7 @@ class ShortUrlServiceTest extends TestCase
} }
/** @test */ /** @test */
public function providedTagsAreGetFromRepoAndSetToTheShortUrl() public function providedTagsAreGetFromRepoAndSetToTheShortUrl(): void
{ {
$shortUrl = $this->prophesize(ShortUrl::class); $shortUrl = $this->prophesize(ShortUrl::class);
$shortUrl->setTags(Argument::any())->shouldBeCalledOnce(); $shortUrl->setTags(Argument::any())->shouldBeCalledOnce();
@ -86,14 +86,14 @@ class ShortUrlServiceTest extends TestCase
} }
/** @test */ /** @test */
public function updateMetadataByShortCodeUpdatesProvidedData() public function updateMetadataByShortCodeUpdatesProvidedData(): void
{ {
$shortUrl = new ShortUrl(''); $shortUrl = new ShortUrl('');
$repo = $this->prophesize(ShortUrlRepository::class); $repo = $this->prophesize(ShortUrlRepository::class);
$findShortUrl = $repo->findOneBy(['shortCode' => 'abc123'])->willReturn($shortUrl); $findShortUrl = $repo->findOneBy(['shortCode' => 'abc123'])->willReturn($shortUrl);
$getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal());
$flush = $this->em->flush($shortUrl)->willReturn(null); $flush = $this->em->flush()->willReturn(null);
$result = $this->service->updateMetadataByShortCode('abc123', ShortUrlMeta::createFromParams( $result = $this->service->updateMetadataByShortCode('abc123', ShortUrlMeta::createFromParams(
Chronos::parse('2017-01-01 00:00:00')->toAtomString(), Chronos::parse('2017-01-01 00:00:00')->toAtomString(),

View file

@ -28,7 +28,7 @@ class TagServiceTest extends TestCase
} }
/** @test */ /** @test */
public function listTagsDelegatesOnRepository() public function listTagsDelegatesOnRepository(): void
{ {
$expected = [new Tag('foo'), new Tag('bar')]; $expected = [new Tag('foo'), new Tag('bar')];
@ -44,7 +44,7 @@ class TagServiceTest extends TestCase
} }
/** @test */ /** @test */
public function deleteTagsDelegatesOnRepository() public function deleteTagsDelegatesOnRepository(): void
{ {
$repo = $this->prophesize(TagRepository::class); $repo = $this->prophesize(TagRepository::class);
$delete = $repo->deleteByName(['foo', 'bar'])->willReturn(4); $delete = $repo->deleteByName(['foo', 'bar'])->willReturn(4);
@ -57,7 +57,7 @@ class TagServiceTest extends TestCase
} }
/** @test */ /** @test */
public function createTagsPersistsEntities() public function createTagsPersistsEntities(): void
{ {
$repo = $this->prophesize(TagRepository::class); $repo = $this->prophesize(TagRepository::class);
$find = $repo->findOneBy(Argument::cetera())->willReturn(new Tag('foo')); $find = $repo->findOneBy(Argument::cetera())->willReturn(new Tag('foo'));
@ -75,7 +75,7 @@ class TagServiceTest extends TestCase
} }
/** @test */ /** @test */
public function renameInvalidTagThrowsException() public function renameInvalidTagThrowsException(): void
{ {
$repo = $this->prophesize(TagRepository::class); $repo = $this->prophesize(TagRepository::class);
$find = $repo->findOneBy(Argument::cetera())->willReturn(null); $find = $repo->findOneBy(Argument::cetera())->willReturn(null);
@ -89,14 +89,14 @@ class TagServiceTest extends TestCase
} }
/** @test */ /** @test */
public function renameValidTagChangesItsName() public function renameValidTagChangesItsName(): void
{ {
$expected = new Tag('foo'); $expected = new Tag('foo');
$repo = $this->prophesize(TagRepository::class); $repo = $this->prophesize(TagRepository::class);
$find = $repo->findOneBy(Argument::cetera())->willReturn($expected); $find = $repo->findOneBy(Argument::cetera())->willReturn($expected);
$getRepo = $this->em->getRepository(Tag::class)->willReturn($repo->reveal()); $getRepo = $this->em->getRepository(Tag::class)->willReturn($repo->reveal());
$flush = $this->em->flush($expected)->willReturn(null); $flush = $this->em->flush()->willReturn(null);
$tag = $this->service->renameTag('foo', 'bar'); $tag = $this->service->renameTag('foo', 'bar');

View file

@ -46,11 +46,11 @@ class VisitsTrackerTest extends TestCase
$repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl('')); $repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl(''));
$this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce(); $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce();
$this->em->persist(Argument::any())->shouldBeCalledOnce(); $this->em->persist(Argument::that(function (Visit $visit) {
$this->em->flush(Argument::that(function (Visit $visit) {
$visit->setId('1'); $visit->setId('1');
return $visit; return $visit;
}))->shouldBeCalledOnce(); }))->shouldBeCalledOnce();
$this->em->flush()->shouldBeCalledOnce();
$this->visitsTracker->track($shortCode, Visitor::emptyInstance()); $this->visitsTracker->track($shortCode, Visitor::emptyInstance());
@ -69,11 +69,10 @@ class VisitsTrackerTest extends TestCase
/** @var Visit $visit */ /** @var Visit $visit */
$visit = $args[0]; $visit = $args[0];
Assert::assertEquals('4.3.2.0', $visit->getRemoteAddr()); Assert::assertEquals('4.3.2.0', $visit->getRemoteAddr());
})->shouldBeCalledOnce();
$this->em->flush(Argument::that(function (Visit $visit) {
$visit->setId('1'); $visit->setId('1');
return $visit; return $visit;
}))->shouldBeCalledOnce(); })->shouldBeCalledOnce();
$this->em->flush()->shouldBeCalledOnce();
$this->visitsTracker->track($shortCode, new Visitor('', '', '4.3.2.1')); $this->visitsTracker->track($shortCode, new Visitor('', '', '4.3.2.1'));

View file

@ -1,7 +1,6 @@
parameters: parameters:
ignoreErrors: ignoreErrors:
- '#is not subtype of Throwable#' - '#is not subtype of Throwable#'
- '#ObjectManager::flush()#'
- '#Undefined variable: \$metadata#' - '#Undefined variable: \$metadata#'
- '#AbstractQuery::setParameters()#' - '#AbstractQuery::setParameters()#'
- '#mustRun()#' - '#mustRun()#'