Programming Language PHP

Namespace Oro\Component\TestUtils\ORM\Mocks

Class EntityManagerMock

Total Examples 2

2 code examples of PHP Oro\Component\TestUtils\ORM\Mocks\EntityManagerMock extracted from open source projects

Was this example useful?
0
                                                    /**
     * Creates an EntityManager for testing purposes.
     *
     * NOTE: The created EntityManager will have its dependant DBAL parts completely
     * mocked out using a DriverMock, ConnectionMock, etc. These mocks can then
     * be configured in the tests to simulate the DBAL behavior that is desired
     * for a particular test.
     */
    protected function getTestEntityManager(
        mixed $conn = null,
        EventManager $eventManager = null,
        bool $withSharedMetadata = true
    ): EntityManagerMock {
        $config = new \Doctrine\ORM\Configuration();
        $config->setMetadataCache($this->getMetadataCacheImpl($withSharedMetadata));
        $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([], true));
        $config->setQueryCache($this->getQueryCacheImpl());
        $config->setProxyDir($this->getProxyDir());
        $config->setProxyNamespace('Doctrine\Tests\Proxies');

        // The namespace of custom functions is hardcoded in \Oro\ORM\Query\AST\FunctionFactory::create, so we are
        // making our mock of 'CAST' available in Oro\ORM\Query\AST\Platform\Functions\Mock\ namespace:
        if (!class_exists('Oro\ORM\Query\AST\Platform\Functions\Mock\Cast', false)) {
            class_alias(
                \Oro\Component\TestUtils\ORM\Mocks\Cast::class,
                'Oro\ORM\Query\AST\Platform\Functions\Mock\Cast'
            );
        }
        $config->setCustomStringFunctions(['cast' => 'Oro\ORM\Query\AST\Functions\Cast']);

        if (null === $conn) {
            $conn = [
                'driverClass'  => DriverMock::class,
                'wrapperClass' => ConnectionMock::class,
                'user'         => 'john',
                'password'     => 'wayne',
            ];
        }

        if (is_array($conn)) {
            $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
        }

        return EntityManagerMock::create($conn, $config, $eventManager);
    }
                                            
Was this example useful?
0
                                                    private function getEntityManager(): EntityManagerInterface
    {
        $config = new Configuration();
        $config->setMetadataDriverImpl(new AnnotationDriver(
            new AnnotationReader(),
            'Oro\Bundle\ReportBundle\Tests\Unit\Entity'
        ));
        $config->setProxyDir($this->getTempDir('test_orm_proxies'));
        $config->setProxyNamespace('Doctrine\Tests\Proxies');
        $eventManager = $this->createMock(EventManager::class);
        $connection = $this->createMock(Connection::class);
        $connection->expects(self::any())
            ->method('getEventManager')
            ->willReturn($eventManager);

        return EntityManagerMock::create($connection, $config, $eventManager);
    }
                                            
EntityManagerMock's Other Methods
EntityManagerMock's Other Methods