File tree Expand file tree Collapse file tree 5 files changed +30
-8
lines changed
Expand file tree Collapse file tree 5 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 2222 php-version : ${{ matrix.php-version }}
2323 tools : composer
2424 coverage : none
25- - run : composer install --no-interaction --prefer-dist ${{ matrix.php-version == '8.3' && '--ignore-platform-req=php' || '' }}
25+ - run : composer install --no-interaction --prefer-dist
2626 - run : composer ${{ matrix.command }}
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ All notable changes to this project will be documented in this file.
44
55The format is based on [ Keep a Changelog] ( https://keepachangelog.com ) , and this project adheres to [ Semantic Versioning] ( https://semver.org ) .
66
7- ## [ Unreleased ]
7+ ## [ 4.2.0 ] - 2024-11-09
88### Added
9- * * Nothing *
9+ * Add new ` DatabaseTestCase::createRepository() ` protected method to create default or custom repositories without duplicating code.
1010
1111### Changed
1212* Update shlinkio coding standard to v2.4
Original file line number Diff line number Diff line change 1313 ],
1414 "require" : {
1515 "php" : " ^8.2" ,
16- "doctrine/data-fixtures" : " ^1.7 " ,
16+ "doctrine/data-fixtures" : " ^1.8 " ,
1717 "doctrine/orm" : " ^3.3" ,
1818 "fig/http-message-util" : " ^1.1" ,
19- "guzzlehttp/guzzle" : " ^7.8 " ,
19+ "guzzlehttp/guzzle" : " ^7.9 " ,
2020 "phpunit/php-code-coverage" : " ^11.0" ,
2121 "phpunit/phpunit" : " ^11.4" ,
2222 "psr/container" : " ^2.0 || ^1.0" ,
2323 "psr/http-server-middleware" : " ^1.0" ,
24- "shlinkio/shlink-json" : " ^1.0 " ,
24+ "shlinkio/shlink-json" : " ^1.2 " ,
2525 "symfony/console" : " ^7.1" ,
2626 "symfony/event-dispatcher" : " ^7.1" ,
2727 "symfony/process" : " ^7.1"
2828 },
2929 "require-dev" : {
30- "phpstan/phpstan" : " ^1.10 " ,
30+ "phpstan/phpstan" : " ^1.12 " ,
3131 "roave/security-advisories" : " dev-master" ,
3232 "shlinkio/php-coding-standard" : " ~2.4.0"
3333 },
Original file line number Diff line number Diff line change 11parameters :
2- checkMissingIterableValueType : false
2+ ignoreErrors :
3+ - identifier : missingType.iterableValue
Original file line number Diff line number Diff line change 55namespace Shlinkio \Shlink \TestUtils \DbTest ;
66
77use Doctrine \ORM \EntityManagerInterface ;
8+ use Doctrine \Persistence \ObjectRepository ;
89use PHPUnit \Framework \Attributes \After ;
910use PHPUnit \Framework \Attributes \Before ;
1011use PHPUnit \Framework \TestCase ;
@@ -28,6 +29,26 @@ final protected function getEntityManager(): EntityManagerInterface
2829 return self ::$ em ;
2930 }
3031
32+ /**
33+ * Create a repository instance for provided empty.
34+ * If $repositoryName is not provided, default repository will be returned via $em->getRepository($entityName)
35+ *
36+ * @template TEntity of object
37+ * @template TRepo of ObjectRepository<TEntity>
38+ * @param class-string<TEntity> $entityName
39+ * @param class-string<TRepo>|null $repositoryName
40+ * @return ($repositoryName is null ? ObjectRepository<TEntity> : TRepo)
41+ */
42+ final protected function createRepository (string $ entityName , string |null $ repositoryName = null ): ObjectRepository
43+ {
44+ $ em = $ this ->getEntityManager ();
45+ if ($ repositoryName === null ) {
46+ return $ em ->getRepository ($ entityName );
47+ }
48+
49+ return new $ repositoryName ($ em , $ em ->getClassMetadata ($ entityName ));
50+ }
51+
3152 #[Before]
3253 final public function beginTransaction (): void
3354 {
You can’t perform that action at this time.
0 commit comments