sonata-project /
SonataTranslationBundle
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of the Sonata Project package. |
||
| 7 | * |
||
| 8 | * (c) Thomas Rabaix <[email protected]> |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Sonata\TranslationBundle\Test; |
||
| 15 | |||
| 16 | use Doctrine\Common\Annotations\AnnotationReader; |
||
| 17 | use Doctrine\Common\EventManager; |
||
| 18 | use Doctrine\ORM\Configuration; |
||
| 19 | use Doctrine\ORM\EntityManager; |
||
| 20 | use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
||
| 21 | use Doctrine\ORM\Tools\SchemaTool; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Base test case contains common mock objects |
||
| 25 | * and functionality among all tests using |
||
| 26 | * ORM entity manager. |
||
| 27 | * |
||
| 28 | * @author Dariusz Markowicz <[email protected]> |
||
| 29 | * |
||
| 30 | * Inspired by BaseTestCaseORM |
||
| 31 | * @author Gediminas Morkevicius <[email protected]> |
||
| 32 | */ |
||
| 33 | abstract class DoctrineOrmTestCase extends \PHPUnit\Framework\TestCase |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var EntityManager |
||
| 37 | */ |
||
| 38 | protected $em; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * EntityManager mock object together with |
||
| 42 | * annotation mapping driver and pdo_sqlite |
||
| 43 | * database in memory. |
||
| 44 | * |
||
| 45 | * @param EventManager $evm |
||
| 46 | * @param Configuration $config |
||
| 47 | * |
||
| 48 | * @return EntityManager |
||
| 49 | */ |
||
| 50 | final protected function getMockSqliteEntityManager(EventManager $evm = null, Configuration $config = null) |
||
| 51 | { |
||
| 52 | $conn = [ |
||
| 53 | 'driver' => 'pdo_sqlite', |
||
| 54 | 'memory' => true, |
||
| 55 | ]; |
||
| 56 | |||
| 57 | $em = EntityManager::create($conn, $config ?: $this->getMockAnnotatedConfig(), $evm ?: new EventManager()); |
||
| 58 | |||
| 59 | $schema = array_map(static function ($class) use ($em) { |
||
| 60 | return $em->getClassMetadata($class); |
||
| 61 | }, (array) $this->getUsedEntityFixtures()); |
||
| 62 | |||
| 63 | $schemaTool = new SchemaTool($em); |
||
| 64 | $schemaTool->dropSchema([]); |
||
| 65 | $schemaTool->createSchema($schema); |
||
| 66 | |||
| 67 | return $this->em = $em; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Creates default mapping driver. |
||
| 72 | * |
||
| 73 | * @return AnnotationDriver |
||
| 74 | */ |
||
| 75 | final protected function getMetadataDriverImplementation() |
||
| 76 | { |
||
| 77 | return new AnnotationDriver(new AnnotationReader()); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Get a list of used fixture classes. |
||
| 82 | * |
||
| 83 | * @return array |
||
| 84 | */ |
||
| 85 | abstract protected function getUsedEntityFixtures(); |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Get annotation mapping configuration. |
||
| 89 | * |
||
| 90 | * @return Configuration |
||
| 91 | */ |
||
| 92 | final protected function getMockAnnotatedConfig() |
||
| 93 | { |
||
| 94 | $config = new Configuration(); |
||
| 95 | $config->setProxyDir(sys_get_temp_dir().'/sonata-translation-bundle'); |
||
| 96 | $config->setProxyNamespace('Proxy'); |
||
| 97 | $config->setMetadataDriverImpl($this->getMetadataDriverImplementation()); |
||
|
0 ignored issues
–
show
|
|||
| 98 | |||
| 99 | return $config; |
||
| 100 | } |
||
| 101 | } |
||
| 102 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: