Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Also upgrade to doctrine 3
  • Loading branch information
usox committed Mar 17, 2024
1 parent f1f7c12 commit 24b8bcb
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 613 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
"require": {
"php": "^8.2",
"php": "~8.2 || ~8.3",
"ext-gd": "*",
"ext-iconv": "*",
"ext-readline": "*",
Expand All @@ -18,7 +18,7 @@
"caseyamcl/configula": "^4.2",
"cube43/slim-jwt-auth": "^6.0",
"doctrine/annotations": "^1||^2",
"doctrine/orm": "^2.9",
"doctrine/orm": "^3.1",
"guzzlehttp/psr7": "^2.4",
"james-heinrich/getid3": "^1.9",
"jetbrains/phpstorm-attributes": "^1.0",
Expand Down
968 changes: 404 additions & 564 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/Bootstrap/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use DateTimeInterface;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\ResolveTargetEntityListener;
use getID3;
Expand Down Expand Up @@ -105,6 +107,10 @@
$ormConfig->setQueryCache($cacheProvider->getOrmQueryCache());
$ormConfig->setResultCache($cacheProvider->getOrmResultCache());

$ormConfig->setIdentityGenerationPreferences([
PostgreSQLPlatform::class => ClassMetadata::GENERATOR_TYPE_SEQUENCE,
]);

return new EntityManager(
DriverManager::getConnection(
[
Expand Down
10 changes: 6 additions & 4 deletions src/Orm/Repository/AlbumRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Uxmp\Core\Orm\Repository;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\Query\Parameter;
use Generator;
use Uxmp\Core\Orm\Model\Album;
use Uxmp\Core\Orm\Model\AlbumInterface;
Expand Down Expand Up @@ -117,8 +119,8 @@ public function getFavorites(
?int $offset = null
): iterable {
$parameter = [
'user' => $user,
'type' => FavoriteItemTypeEnum::ALBUM,
new Parameter('user', $user),
new Parameter('type', FavoriteItemTypeEnum::ALBUM),
];

$qb = $this
Expand All @@ -137,7 +139,7 @@ public function getFavorites(
if ($catalog !== null) {
$andExpression->add($expressionBuilder->eq('a.catalog', ':catalog'));

$parameter['catalog'] = $catalog;
$parameter[] = new Parameter('catalog', $catalog);
}

$qb
Expand All @@ -153,7 +155,7 @@ public function getFavorites(
->getDQL()
)
)
->setParameters($parameter)
->setParameters(new ArrayCollection($parameter))
->orderBy('a.title', 'ASC')
->setMaxResults($limit)
->setFirstResult($offset);
Expand Down
10 changes: 6 additions & 4 deletions src/Orm/Repository/GenreMapRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Uxmp\Core\Orm\Repository;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Parameter;
use Uxmp\Core\Orm\Model\AlbumInterface;
use Uxmp\Core\Orm\Model\GenreMap;
use Uxmp\Core\Orm\Model\GenreMapEnum;
Expand Down Expand Up @@ -53,10 +55,10 @@ public function deleteByAlbum(AlbumInterface $album): void
->delete(GenreMap::class, 'gm')
->where('gm.mapped_item_type = :itemType')
->andWhere('gm.mapped_item_id = :itemId')
->setParameters([
'itemType' => GenreMapEnum::ALBUM,
'itemId' => $album->getId(),
])
->setParameters(new ArrayCollection([
new Parameter('itemType', GenreMapEnum::ALBUM),
new Parameter('itemId', $album->getId()),
]))
->getQuery()
->execute();
}
Expand Down
10 changes: 6 additions & 4 deletions src/Orm/Repository/GenreRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Uxmp\Core\Orm\Repository;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\Query\Parameter;
use Generator;
use Uxmp\Core\Orm\Model\Genre;
use Uxmp\Core\Orm\Model\GenreInterface;
Expand Down Expand Up @@ -69,10 +71,10 @@ public function getGenreStatistics(): Generator
Join::WITH,
'c.genre_id = a.id AND c.mapped_item_type = :song_index_name'
)
->setParameters([
'album_index_name' => GenreMapEnum::ALBUM,
'song_index_name' => GenreMapEnum::SONG,
])
->setParameters(new ArrayCollection([
new Parameter('album_index_name', GenreMapEnum::ALBUM),
new Parameter('song_index_name', GenreMapEnum::SONG),
]))
->groupBy('a.title')
->groupBy('a.id')
->having('COUNT(b.id) > 0')
Expand Down
10 changes: 6 additions & 4 deletions src/Orm/Repository/SongRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Uxmp\Core\Orm\Repository;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Parameter;
use Traversable;
use Uxmp\Core\Orm\Model\ArtistInterface;
use Uxmp\Core\Orm\Model\CatalogInterface;
Expand Down Expand Up @@ -61,8 +63,8 @@ public function findFavorites(
?CatalogInterface $catalog = null
): iterable {
$parameter = [
'user' => $user,
'type' => FavoriteItemTypeEnum::SONG,
new Parameter('user', $user),
new Parameter('type', FavoriteItemTypeEnum::SONG),
];

$qb = $this->createQueryBuilder('a');
Expand All @@ -77,7 +79,7 @@ public function findFavorites(
if ($catalog !== null) {
$andExpression->add($expressionBuilder->eq('a.catalog', ':catalog'));

$parameter['catalog'] = $catalog;
$parameter[] = new Parameter('catalog', $catalog);
}

$qb
Expand All @@ -91,7 +93,7 @@ public function findFavorites(
->getDQL()
)
)
->setParameters($parameter)
->setParameters(new ArrayCollection($parameter))
;

return $qb->getQuery()->getResult();
Expand Down
28 changes: 28 additions & 0 deletions tests/DoctrineTestHelperTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Uxmp\Core;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Query\Parameter;
use Mockery;
use Mockery\Matcher\Closure;

trait DoctrineTestHelperTrait
{
/**
* @param list<Parameter> $expectedData
*/
private function withOrmParams(array $expectedData): Closure
{
return Mockery::on(function (ArrayCollection $collection) use ($expectedData): bool {
$params = [];
foreach ($collection as $param) {
$params[$param->getName()] = $param->getValue();
}

return $params === $expectedData;
});
}
}
21 changes: 12 additions & 9 deletions tests/Orm/Repository/AlbumRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Uxmp\Core\Orm\Repository;

use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\Query\Expr\Comparison;
Expand All @@ -19,6 +19,7 @@
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\MockInterface;
use Uxmp\Core\DoctrineTestHelperTrait;
use Uxmp\Core\Orm\Model\Album;
use Uxmp\Core\Orm\Model\AlbumInterface;
use Uxmp\Core\Orm\Model\Artist;
Expand All @@ -33,6 +34,8 @@

class AlbumRepositoryTest extends MockeryTestCase
{
use DoctrineTestHelperTrait;

private EntityManagerInterface&MockInterface $entityManager;

private ClassMetadata&MockInterface $classMetaData;
Expand Down Expand Up @@ -120,7 +123,7 @@ public function testDeleteDeletes(): void
public function testFindEmptyAlbumsReturnsResult(): void
{
$catalog = Mockery::mock(CatalogInterface::class);
$query = Mockery::mock(AbstractQuery::class);
$query = Mockery::mock(Query::class);

$catalogId = 666;
$result = [Mockery::mock(AlbumInterface::class)];
Expand Down Expand Up @@ -163,14 +166,14 @@ public function testGetFavoritesReturnsData(): void
$qb = Mockery::mock(QueryBuilder::class);
$qbSub = Mockery::mock(QueryBuilder::class);
$expressionBuilder = Mockery::mock(Expr::class);
$query = Mockery::mock(AbstractQuery::class);
$query = Mockery::mock(Query::class);
$andExpression = Mockery::mock(Andx::class);
$comparisonExpression = Mockery::mock(Comparison::class);
$catalog = Mockery::mock(CatalogInterface::class);
$inExpression = $this->createMock(Func::class);

$result = ['some-result'];
$qbSubDql = 'some-dql';
$inExpression = 'some-in-expression';
$limit = 666;
$offset = 42;

Expand Down Expand Up @@ -254,11 +257,11 @@ public function testGetFavoritesReturnsData(): void
->once()
->andReturnSelf();
$qb->shouldReceive('setParameters')
->with([
->with($this->withOrmParams([
'user' => $user,
'type' => FavoriteItemTypeEnum::ALBUM,
'catalog' => $catalog,
])
]))
->once()
->andReturnSelf();
$qb->shouldReceive('getQuery')
Expand Down Expand Up @@ -287,7 +290,7 @@ public function testFindByGenreReturnsData(): void
$equalExpression = Mockery::mock(Comparison::class);
$inExpression = Mockery::mock(Func::class);
$album = Mockery::mock(AlbumInterface::class);
$query = Mockery::mock(AbstractQuery::class);
$query = Mockery::mock(Query::class);

$subQueryBuilderDQL = 'some-dql';
$limit = 666;
Expand Down Expand Up @@ -405,7 +408,7 @@ public function testGetListOrderedByArtistReturnsData(): void

$album = Mockery::mock(AlbumInterface::class);
$qb = Mockery::mock(QueryBuilder::class);
$query = Mockery::mock(AbstractQuery::class);
$query = Mockery::mock(Query::class);

$this->entityManager->shouldReceive('createQueryBuilder')
->withNoArgs()
Expand Down Expand Up @@ -476,7 +479,7 @@ public function testSearchReturnsData(): void

$album = $this->createMock(AlbumInterface::class);
$qb = $this->createMock(QueryBuilder::class);
$query = $this->createMock(AbstractQuery::class);
$query = $this->createMock(Query::class);
$expression = $this->createMock(Expr::class);
$comparison = $this->createMock(Comparison::class);

Expand Down
6 changes: 3 additions & 3 deletions tests/Orm/Repository/ArtistRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Uxmp\Core\Orm\Repository;

use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Comparison;
use Doctrine\ORM\QueryBuilder;
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testFindByMbIdReturnsValue(): void

public function testGetAllHavingNoRelationsReturnsArtists(): void
{
$query = Mockery::mock(AbstractQuery::class);
$query = Mockery::mock(Query::class);
$artist = Mockery::mock(ArtistInterface::class);

$this->entityManager->shouldReceive('createQuery')
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testSearchReturnsData(): void

$artist = $this->createMock(ArtistInterface::class);
$qb = $this->createMock(QueryBuilder::class);
$query = $this->createMock(AbstractQuery::class);
$query = $this->createMock(Query::class);
$expression = $this->createMock(Expr::class);
$comparison = $this->createMock(Comparison::class);

Expand Down
4 changes: 2 additions & 2 deletions tests/Orm/Repository/DiscRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Uxmp\Core\Orm\Repository;

use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
Expand Down Expand Up @@ -118,7 +118,7 @@ public function testFindUniqDiscReturnsValue(): void

public function testFindEmptyDiscsReturnsData(): void
{
$query = Mockery::mock(AbstractQuery::class);
$query = Mockery::mock(Query::class);
$result = [Mockery::mock(DiscInterface::class)];
$catalog = Mockery::mock(CatalogInterface::class);

Expand Down
11 changes: 7 additions & 4 deletions tests/Orm/Repository/GenreMapRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@

namespace Uxmp\Core\Orm\Repository;

use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\UnitOfWork;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\MockInterface;
use Uxmp\Core\DoctrineTestHelperTrait;
use Uxmp\Core\Orm\Model\AlbumInterface;
use Uxmp\Core\Orm\Model\GenreMap;
use Uxmp\Core\Orm\Model\GenreMapEnum;
use Uxmp\Core\Orm\Model\GenreMapInterface;

class GenreMapRepositoryTest extends MockeryTestCase
{
use DoctrineTestHelperTrait;

private EntityManagerInterface&MockInterface $entityManager;

private ClassMetadata&MockInterface $classMetaData;
Expand Down Expand Up @@ -122,7 +125,7 @@ public function testDeleteByAlbumDeletes(): void
{
$queryBuilder = Mockery::mock(QueryBuilder::class);
$album = Mockery::mock(AlbumInterface::class);
$query = Mockery::mock(AbstractQuery::class);
$query = Mockery::mock(Query::class);

$albumId = 666;

Expand All @@ -149,10 +152,10 @@ public function testDeleteByAlbumDeletes(): void
->once()
->andReturnSelf();
$queryBuilder->shouldReceive('setParameters')
->with([
->with($this->withOrmParams([
'itemType' => GenreMapEnum::ALBUM,
'itemId' => $albumId,
])
]))
->once()
->andReturnSelf();
$queryBuilder->shouldReceive('getQuery')
Expand Down
Loading

0 comments on commit 24b8bcb

Please sign in to comment.