1
0
mirror of synced 2025-02-09 00:39:25 +03:00

Make test suite compatible with PHPUnit 5.4.

* Use createMock() and getMockBuilder() instead of getMock()
* Use expectException() and expectExceptionMessage() instead of setExpectedException()
This commit is contained in:
Sebastian Bergmann 2016-06-18 13:01:59 +02:00
parent d3f6c5ec70
commit 9da83cfae8
55 changed files with 443 additions and 262 deletions

View File

@ -25,7 +25,7 @@
}, },
"require-dev": { "require-dev": {
"symfony/yaml": "~2.3|~3.0", "symfony/yaml": "~2.3|~3.0",
"phpunit/phpunit": "~4.0" "phpunit/phpunit": "^5.4"
}, },
"suggest": { "suggest": {
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver" "symfony/yaml": "If you want to use YAML Metadata Mapping Driver"

View File

@ -2,8 +2,11 @@
namespace Doctrine\Tests\ORM\Cache; namespace Doctrine\Tests\ORM\Cache;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\ORM\Cache\CacheConfiguration; use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Cache\CacheFactory;
use Doctrine\ORM\Cache\QueryCacheValidator;
use Doctrine\ORM\Cache\Logging\CacheLogger;
use Doctrine\Tests\DoctrineTestCase;
/** /**
* @group DDC-2183 * @group DDC-2183
@ -42,7 +45,7 @@ class CacheConfigTest extends DoctrineTestCase
public function testSetGetCacheLogger() public function testSetGetCacheLogger()
{ {
$logger = $this->getMock('Doctrine\ORM\Cache\Logging\CacheLogger'); $logger = $this->createMock(CacheLogger::class);
$this->assertNull($this->config->getCacheLogger()); $this->assertNull($this->config->getCacheLogger());
@ -53,7 +56,7 @@ class CacheConfigTest extends DoctrineTestCase
public function testSetGetCacheFactory() public function testSetGetCacheFactory()
{ {
$factory = $this->getMock('Doctrine\ORM\Cache\CacheFactory'); $factory = $this->createMock(CacheFactory::class);
$this->assertNull($this->config->getCacheFactory()); $this->assertNull($this->config->getCacheFactory());
@ -64,7 +67,7 @@ class CacheConfigTest extends DoctrineTestCase
public function testSetGetQueryValidator() public function testSetGetQueryValidator()
{ {
$validator = $this->getMock('Doctrine\ORM\Cache\QueryCacheValidator'); $validator = $this->createMock(QueryCacheValidator::class);
$this->assertInstanceOf('Doctrine\ORM\Cache\TimestampQueryCacheValidator', $this->config->getQueryValidator()); $this->assertInstanceOf('Doctrine\ORM\Cache\TimestampQueryCacheValidator', $this->config->getQueryValidator());

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Cache; namespace Doctrine\Tests\ORM\Cache;
use Doctrine\ORM\Cache\Logging\CacheLogger;
use Doctrine\ORM\Cache\Logging\CacheLoggerChain; use Doctrine\ORM\Cache\Logging\CacheLoggerChain;
use Doctrine\ORM\Cache\CollectionCacheKey; use Doctrine\ORM\Cache\CollectionCacheKey;
use Doctrine\ORM\Cache\EntityCacheKey; use Doctrine\ORM\Cache\EntityCacheKey;
@ -29,7 +30,7 @@ class CacheLoggerChainTest extends DoctrineTestCase
parent::setUp(); parent::setUp();
$this->logger = new CacheLoggerChain(); $this->logger = new CacheLoggerChain();
$this->mock = $this->getMock('Doctrine\ORM\Cache\Logging\CacheLogger'); $this->mock = $this->createMock(CacheLogger::class);
} }
public function testGetAndSetLogger() public function testGetAndSetLogger()

View File

@ -2,6 +2,8 @@
namespace Doctrine\Tests\ORM\Cache; namespace Doctrine\Tests\ORM\Cache;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\CacheProvider;
use \Doctrine\Tests\OrmTestCase; use \Doctrine\Tests\OrmTestCase;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Cache\DefaultCacheFactory; use Doctrine\ORM\Cache\DefaultCacheFactory;
@ -39,9 +41,10 @@ class DefaultCacheFactoryTest extends OrmTestCase
$this->em = $this->_getTestEntityManager(); $this->em = $this->_getTestEntityManager();
$this->regionsConfig = new RegionsConfiguration; $this->regionsConfig = new RegionsConfiguration;
$arguments = array($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); $arguments = array($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl());
$this->factory = $this->getMock('\Doctrine\ORM\Cache\DefaultCacheFactory', array( $this->factory = $this->getMockBuilder(DefaultCacheFactory::class)
'getRegion' ->setMethods(array('getRegion'))
), $arguments); ->setConstructorArgs($arguments)
->getMock();
} }
public function testImplementsCacheFactory() public function testImplementsCacheFactory()
@ -284,7 +287,7 @@ class DefaultCacheFactoryTest extends OrmTestCase
public function testBuildsDefaultCacheRegionFromGenericCacheRegion() public function testBuildsDefaultCacheRegionFromGenericCacheRegion()
{ {
/* @var $cache \Doctrine\Common\Cache\Cache */ /* @var $cache \Doctrine\Common\Cache\Cache */
$cache = $this->getMock('Doctrine\Common\Cache\Cache'); $cache = $this->createMock(Cache::class);
$factory = new DefaultCacheFactory($this->regionsConfig, $cache); $factory = new DefaultCacheFactory($this->regionsConfig, $cache);
@ -300,7 +303,7 @@ class DefaultCacheFactoryTest extends OrmTestCase
public function testBuildsMultiGetCacheRegionFromGenericCacheRegion() public function testBuildsMultiGetCacheRegionFromGenericCacheRegion()
{ {
/* @var $cache \Doctrine\Common\Cache\CacheProvider */ /* @var $cache \Doctrine\Common\Cache\CacheProvider */
$cache = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider'); $cache = $this->getMockForAbstractClass(CacheProvider::class);
$factory = new DefaultCacheFactory($this->regionsConfig, $cache); $factory = new DefaultCacheFactory($this->regionsConfig, $cache);

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Cache;
use Doctrine\Common\Cache\ApcCache; use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;
use Doctrine\ORM\Cache\CollectionCacheEntry; use Doctrine\ORM\Cache\CollectionCacheEntry;
use Doctrine\ORM\Cache\Region\DefaultRegion; use Doctrine\ORM\Cache\Region\DefaultRegion;
use Doctrine\Tests\Mocks\CacheEntryMock; use Doctrine\Tests\Mocks\CacheEntryMock;
@ -66,11 +67,11 @@ class DefaultRegionTest extends AbstractRegionTest
public function testEvictAllWithGenericCacheThrowsUnsupportedException() public function testEvictAllWithGenericCacheThrowsUnsupportedException()
{ {
/* @var $cache \Doctrine\Common\Cache\Cache */ /* @var $cache \Doctrine\Common\Cache\Cache */
$cache = $this->getMock('Doctrine\Common\Cache\Cache'); $cache = $this->createMock(Cache::class);
$region = new DefaultRegion('foo', $cache); $region = new DefaultRegion('foo', $cache);
$this->setExpectedException('BadMethodCallException'); $this->expectException(\BadMethodCallException::class);
$region->evictAll(); $region->evictAll();
} }

View File

@ -80,10 +80,9 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase
$this->em = $this->_getTestEntityManager(); $this->em = $this->_getTestEntityManager();
$this->region = $this->createRegion(); $this->region = $this->createRegion();
$this->collectionPersister = $this->getMock( $this->collectionPersister = $this->getMockBuilder(CollectionPersister::class)
'Doctrine\ORM\Persisters\Collection\CollectionPersister', ->setMethods($this->collectionPersisterMockMethods)
$this->collectionPersisterMockMethods ->getMock();
);
} }
/** /**
@ -91,7 +90,9 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase
*/ */
protected function createRegion() protected function createRegion()
{ {
return $this->getMock('Doctrine\ORM\Cache\Region', $this->regionMockMethods); return $this->getMockBuilder(Region::class)
->setMethods($this->regionMockMethods)
->getMock();
} }
/** /**

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Cache\Persister\Collection; namespace Doctrine\Tests\ORM\Cache\Persister\Collection;
use Doctrine\ORM\Cache\ConcurrentRegion;
use Doctrine\ORM\Cache\Lock; use Doctrine\ORM\Cache\Lock;
use Doctrine\ORM\Cache\Region; use Doctrine\ORM\Cache\Region;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
@ -40,7 +41,9 @@ class ReadWriteCachedCollectionPersisterTest extends AbstractCollectionPersister
*/ */
protected function createRegion() protected function createRegion()
{ {
return $this->getMock('Doctrine\ORM\Cache\ConcurrentRegion', $this->regionMockMethods); return $this->getMockBuilder(ConcurrentRegion::class)
->setMethods($this->regionMockMethods)
->getMock();
} }
public function testDeleteShouldLockItem() public function testDeleteShouldLockItem()

View File

@ -99,10 +99,9 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase
$this->em = $this->_getTestEntityManager(); $this->em = $this->_getTestEntityManager();
$this->region = $this->createRegion(); $this->region = $this->createRegion();
$this->entityPersister = $this->getMock( $this->entityPersister = $this->getMockBuilder(EntityPersister::class)
'Doctrine\ORM\Persisters\Entity\EntityPersister', ->setMethods($this->entityPersisterMockMethods)
$this->entityPersisterMockMethods ->getMock();
);
} }
/** /**
@ -110,7 +109,9 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase
*/ */
protected function createRegion() protected function createRegion()
{ {
return $this->getMock('Doctrine\ORM\Cache\Region', $this->regionMockMethods); return $this->getMockBuilder(Region::class)
->setMethods($this->regionMockMethods)
->getMock();
} }
/** /**

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Cache\Persister\Entity; namespace Doctrine\Tests\ORM\Cache\Persister\Entity;
use Doctrine\ORM\Cache\ConcurrentRegion;
use Doctrine\ORM\Cache\Region; use Doctrine\ORM\Cache\Region;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Cache\Lock; use Doctrine\ORM\Cache\Lock;
@ -41,7 +42,9 @@ class ReadWriteCachedEntityPersisterTest extends AbstractEntityPersisterTest
*/ */
protected function createRegion() protected function createRegion()
{ {
return $this->getMock('Doctrine\ORM\Cache\ConcurrentRegion', $this->regionMockMethods); return $this->getMockBuilder(ConcurrentRegion::class)
->setConstructorArgs($this->regionMockMethods)
->getMock();
} }
public function testDeleteShouldLockItem() public function testDeleteShouldLockItem()

View File

@ -2,10 +2,18 @@
namespace Doctrine\Tests\ORM; namespace Doctrine\Tests\ORM;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Mapping as AnnotationNamespace; use Doctrine\ORM\Mapping as AnnotationNamespace;
use Doctrine\ORM\Configuration; use Doctrine\ORM\Configuration;
use Doctrine\ORM\Mapping\EntityListenerResolver;
use Doctrine\ORM\Mapping\NamingStrategy;
use Doctrine\ORM\Mapping\QuoteStrategy;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Query\ResultSetMapping;
use ReflectionClass; use ReflectionClass;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
@ -60,7 +68,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->assertSame(null, $this->configuration->getMetadataDriverImpl()); // defaults $this->assertSame(null, $this->configuration->getMetadataDriverImpl()); // defaults
$metadataDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $metadataDriver = $this->createMock(MappingDriver::class);
$this->configuration->setMetadataDriverImpl($metadataDriver); $this->configuration->setMetadataDriverImpl($metadataDriver);
$this->assertSame($metadataDriver, $this->configuration->getMetadataDriverImpl()); $this->assertSame($metadataDriver, $this->configuration->getMetadataDriverImpl());
} }
@ -94,14 +102,14 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$namespaces = array('OtherNamespace' => __NAMESPACE__); $namespaces = array('OtherNamespace' => __NAMESPACE__);
$this->configuration->setEntityNamespaces($namespaces); $this->configuration->setEntityNamespaces($namespaces);
$this->assertSame($namespaces, $this->configuration->getEntityNamespaces()); $this->assertSame($namespaces, $this->configuration->getEntityNamespaces());
$this->setExpectedException('Doctrine\ORM\ORMException'); $this->expectException(\Doctrine\ORM\ORMException::class);
$this->configuration->getEntityNamespace('NonExistingNamespace'); $this->configuration->getEntityNamespace('NonExistingNamespace');
} }
public function testSetGetQueryCacheImpl() public function testSetGetQueryCacheImpl()
{ {
$this->assertSame(null, $this->configuration->getQueryCacheImpl()); // defaults $this->assertSame(null, $this->configuration->getQueryCacheImpl()); // defaults
$queryCacheImpl = $this->getMock('Doctrine\Common\Cache\Cache'); $queryCacheImpl = $this->createMock(Cache::class);
$this->configuration->setQueryCacheImpl($queryCacheImpl); $this->configuration->setQueryCacheImpl($queryCacheImpl);
$this->assertSame($queryCacheImpl, $this->configuration->getQueryCacheImpl()); $this->assertSame($queryCacheImpl, $this->configuration->getQueryCacheImpl());
} }
@ -109,7 +117,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
public function testSetGetHydrationCacheImpl() public function testSetGetHydrationCacheImpl()
{ {
$this->assertSame(null, $this->configuration->getHydrationCacheImpl()); // defaults $this->assertSame(null, $this->configuration->getHydrationCacheImpl()); // defaults
$queryCacheImpl = $this->getMock('Doctrine\Common\Cache\Cache'); $queryCacheImpl = $this->createMock(Cache::class);
$this->configuration->setHydrationCacheImpl($queryCacheImpl); $this->configuration->setHydrationCacheImpl($queryCacheImpl);
$this->assertSame($queryCacheImpl, $this->configuration->getHydrationCacheImpl()); $this->assertSame($queryCacheImpl, $this->configuration->getHydrationCacheImpl());
} }
@ -117,7 +125,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
public function testSetGetMetadataCacheImpl() public function testSetGetMetadataCacheImpl()
{ {
$this->assertSame(null, $this->configuration->getMetadataCacheImpl()); // defaults $this->assertSame(null, $this->configuration->getMetadataCacheImpl()); // defaults
$queryCacheImpl = $this->getMock('Doctrine\Common\Cache\Cache'); $queryCacheImpl = $this->createMock(Cache::class);
$this->configuration->setMetadataCacheImpl($queryCacheImpl); $this->configuration->setMetadataCacheImpl($queryCacheImpl);
$this->assertSame($queryCacheImpl, $this->configuration->getMetadataCacheImpl()); $this->assertSame($queryCacheImpl, $this->configuration->getMetadataCacheImpl());
} }
@ -127,19 +135,19 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$dql = 'SELECT u FROM User u'; $dql = 'SELECT u FROM User u';
$this->configuration->addNamedQuery('QueryName', $dql); $this->configuration->addNamedQuery('QueryName', $dql);
$this->assertSame($dql, $this->configuration->getNamedQuery('QueryName')); $this->assertSame($dql, $this->configuration->getNamedQuery('QueryName'));
$this->setExpectedException('Doctrine\ORM\ORMException'); $this->expectException(\Doctrine\ORM\ORMException::class);
$this->configuration->getNamedQuery('NonExistingQuery'); $this->configuration->getNamedQuery('NonExistingQuery');
} }
public function testAddGetNamedNativeQuery() public function testAddGetNamedNativeQuery()
{ {
$sql = 'SELECT * FROM user'; $sql = 'SELECT * FROM user';
$rsm = $this->getMock('Doctrine\ORM\Query\ResultSetMapping'); $rsm = $this->createMock(ResultSetMapping::class);
$this->configuration->addNamedNativeQuery('QueryName', $sql, $rsm); $this->configuration->addNamedNativeQuery('QueryName', $sql, $rsm);
$fetched = $this->configuration->getNamedNativeQuery('QueryName'); $fetched = $this->configuration->getNamedNativeQuery('QueryName');
$this->assertSame($sql, $fetched[0]); $this->assertSame($sql, $fetched[0]);
$this->assertSame($rsm, $fetched[1]); $this->assertSame($rsm, $fetched[1]);
$this->setExpectedException('Doctrine\ORM\ORMException'); $this->expectException(\Doctrine\ORM\ORMException::class);
$this->configuration->getNamedQuery('NonExistingQuery'); $this->configuration->getNamedQuery('NonExistingQuery');
} }
@ -152,7 +160,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_NEVER); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_NEVER);
$cache = $this->getMock('Doctrine\Common\Cache\Cache'); $cache = $this->createMock(Cache::class);
if ('query' !== $skipCache) { if ('query' !== $skipCache) {
$this->configuration->setQueryCacheImpl($cache); $this->configuration->setQueryCacheImpl($cache);
@ -172,14 +180,20 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
public function testEnsureProductionSettingsQueryCache() public function testEnsureProductionSettingsQueryCache()
{ {
$this->setProductionSettings('query'); $this->setProductionSettings('query');
$this->setExpectedException('Doctrine\ORM\ORMException', 'Query Cache is not configured.');
$this->expectException(ORMException::class);
$this->expectExceptionMessage('Query Cache is not configured.');
$this->configuration->ensureProductionSettings(); $this->configuration->ensureProductionSettings();
} }
public function testEnsureProductionSettingsMetadataCache() public function testEnsureProductionSettingsMetadataCache()
{ {
$this->setProductionSettings('metadata'); $this->setProductionSettings('metadata');
$this->setExpectedException('Doctrine\ORM\ORMException', 'Metadata Cache is not configured.');
$this->expectException(ORMException::class);
$this->expectExceptionMessage('Metadata Cache is not configured.');
$this->configuration->ensureProductionSettings(); $this->configuration->ensureProductionSettings();
} }
@ -187,9 +201,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->setProductionSettings(); $this->setProductionSettings();
$this->configuration->setQueryCacheImpl(new ArrayCache()); $this->configuration->setQueryCacheImpl(new ArrayCache());
$this->setExpectedException(
'Doctrine\ORM\ORMException', $this->expectException(ORMException::class);
'Query Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.'); $this->expectExceptionMessage('Query Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.');
$this->configuration->ensureProductionSettings(); $this->configuration->ensureProductionSettings();
} }
@ -197,9 +212,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->setProductionSettings(); $this->setProductionSettings();
$this->configuration->setMetadataCacheImpl(new ArrayCache()); $this->configuration->setMetadataCacheImpl(new ArrayCache());
$this->setExpectedException(
'Doctrine\ORM\ORMException', $this->expectException(ORMException::class);
'Metadata Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.'); $this->expectExceptionMessage('Metadata Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.');
$this->configuration->ensureProductionSettings(); $this->configuration->ensureProductionSettings();
} }
@ -207,7 +223,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->setProductionSettings(); $this->setProductionSettings();
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_ALWAYS); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_ALWAYS);
$this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.');
$this->expectException(ORMException::class);
$this->expectExceptionMessage('Proxy Classes are always regenerating.');
$this->configuration->ensureProductionSettings(); $this->configuration->ensureProductionSettings();
} }
@ -215,7 +234,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->setProductionSettings(); $this->setProductionSettings();
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS);
$this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.');
$this->expectException(ORMException::class);
$this->expectExceptionMessage('Proxy Classes are always regenerating.');
$this->configuration->ensureProductionSettings(); $this->configuration->ensureProductionSettings();
} }
@ -223,7 +245,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->setProductionSettings(); $this->setProductionSettings();
$this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_EVAL); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_EVAL);
$this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.');
$this->expectException(ORMException::class);
$this->expectExceptionMessage('Proxy Classes are always regenerating.');
$this->configuration->ensureProductionSettings(); $this->configuration->ensureProductionSettings();
} }
@ -234,7 +259,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$this->assertSame(null, $this->configuration->getCustomStringFunction('NonExistingFunction')); $this->assertSame(null, $this->configuration->getCustomStringFunction('NonExistingFunction'));
$this->configuration->setCustomStringFunctions(array('OtherFunctionName' => __CLASS__)); $this->configuration->setCustomStringFunctions(array('OtherFunctionName' => __CLASS__));
$this->assertSame(__CLASS__, $this->configuration->getCustomStringFunction('OtherFunctionName')); $this->assertSame(__CLASS__, $this->configuration->getCustomStringFunction('OtherFunctionName'));
$this->setExpectedException('Doctrine\ORM\ORMException'); $this->expectException(\Doctrine\ORM\ORMException::class);
$this->configuration->addCustomStringFunction('concat', __CLASS__); $this->configuration->addCustomStringFunction('concat', __CLASS__);
} }
@ -245,7 +270,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$this->assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction')); $this->assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction'));
$this->configuration->setCustomNumericFunctions(array('OtherFunctionName' => __CLASS__)); $this->configuration->setCustomNumericFunctions(array('OtherFunctionName' => __CLASS__));
$this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('OtherFunctionName')); $this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('OtherFunctionName'));
$this->setExpectedException('Doctrine\ORM\ORMException'); $this->expectException(\Doctrine\ORM\ORMException::class);
$this->configuration->addCustomNumericFunction('abs', __CLASS__); $this->configuration->addCustomNumericFunction('abs', __CLASS__);
} }
@ -256,7 +281,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$this->assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction')); $this->assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction'));
$this->configuration->setCustomDatetimeFunctions(array('OtherFunctionName' => __CLASS__)); $this->configuration->setCustomDatetimeFunctions(array('OtherFunctionName' => __CLASS__));
$this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('OtherFunctionName')); $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('OtherFunctionName'));
$this->setExpectedException('Doctrine\ORM\ORMException'); $this->expectException(\Doctrine\ORM\ORMException::class);
$this->configuration->addCustomDatetimeFunction('date_add', __CLASS__); $this->configuration->addCustomDatetimeFunction('date_add', __CLASS__);
} }
@ -302,14 +327,14 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
$repositoryClass = 'Doctrine\Tests\Models\DDC753\DDC753CustomRepository'; $repositoryClass = 'Doctrine\Tests\Models\DDC753\DDC753CustomRepository';
$this->configuration->setDefaultRepositoryClassName($repositoryClass); $this->configuration->setDefaultRepositoryClassName($repositoryClass);
$this->assertSame($repositoryClass, $this->configuration->getDefaultRepositoryClassName()); $this->assertSame($repositoryClass, $this->configuration->getDefaultRepositoryClassName());
$this->setExpectedException('Doctrine\ORM\ORMException'); $this->expectException(\Doctrine\ORM\ORMException::class);
$this->configuration->setDefaultRepositoryClassName(__CLASS__); $this->configuration->setDefaultRepositoryClassName(__CLASS__);
} }
public function testSetGetNamingStrategy() public function testSetGetNamingStrategy()
{ {
$this->assertInstanceOf('Doctrine\ORM\Mapping\NamingStrategy', $this->configuration->getNamingStrategy()); $this->assertInstanceOf('Doctrine\ORM\Mapping\NamingStrategy', $this->configuration->getNamingStrategy());
$namingStrategy = $this->getMock('Doctrine\ORM\Mapping\NamingStrategy'); $namingStrategy = $this->createMock(NamingStrategy::class);
$this->configuration->setNamingStrategy($namingStrategy); $this->configuration->setNamingStrategy($namingStrategy);
$this->assertSame($namingStrategy, $this->configuration->getNamingStrategy()); $this->assertSame($namingStrategy, $this->configuration->getNamingStrategy());
} }
@ -317,7 +342,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
public function testSetGetQuoteStrategy() public function testSetGetQuoteStrategy()
{ {
$this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $this->configuration->getQuoteStrategy()); $this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $this->configuration->getQuoteStrategy());
$quoteStrategy = $this->getMock('Doctrine\ORM\Mapping\QuoteStrategy'); $quoteStrategy = $this->createMock(QuoteStrategy::class);
$this->configuration->setQuoteStrategy($quoteStrategy); $this->configuration->setQuoteStrategy($quoteStrategy);
$this->assertSame($quoteStrategy, $this->configuration->getQuoteStrategy()); $this->assertSame($quoteStrategy, $this->configuration->getQuoteStrategy());
} }
@ -329,7 +354,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
{ {
$this->assertInstanceOf('Doctrine\ORM\Mapping\EntityListenerResolver', $this->configuration->getEntityListenerResolver()); $this->assertInstanceOf('Doctrine\ORM\Mapping\EntityListenerResolver', $this->configuration->getEntityListenerResolver());
$this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultEntityListenerResolver', $this->configuration->getEntityListenerResolver()); $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultEntityListenerResolver', $this->configuration->getEntityListenerResolver());
$resolver = $this->getMock('Doctrine\ORM\Mapping\EntityListenerResolver'); $resolver = $this->createMock(EntityListenerResolver::class);
$this->configuration->setEntityListenerResolver($resolver); $this->configuration->setEntityListenerResolver($resolver);
$this->assertSame($resolver, $this->configuration->getEntityListenerResolver()); $this->assertSame($resolver, $this->configuration->getEntityListenerResolver());
} }
@ -339,7 +364,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
*/ */
public function testSetGetSecondLevelCacheConfig() public function testSetGetSecondLevelCacheConfig()
{ {
$mockClass = $this->getMock('Doctrine\ORM\Cache\CacheConfiguration'); $mockClass = $this->createMock(CacheConfiguration::class);
$this->assertNull($this->configuration->getSecondLevelCacheConfiguration()); $this->assertNull($this->configuration->getSecondLevelCacheConfiguration());
$this->configuration->setSecondLevelCacheConfiguration($mockClass); $this->configuration->setSecondLevelCacheConfiguration($mockClass);

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Decorator; namespace Doctrine\Tests\ORM\Decorator;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMapping;
class EntityManagerDecoratorTest extends \PHPUnit_Framework_TestCase class EntityManagerDecoratorTest extends \PHPUnit_Framework_TestCase
@ -11,7 +12,7 @@ class EntityManagerDecoratorTest extends \PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
$this->wrapped = $this->getMock('Doctrine\ORM\EntityManagerInterface'); $this->wrapped = $this->createMock(EntityManagerInterface::class);
$this->decorator = $this->getMockBuilder('Doctrine\ORM\Decorator\EntityManagerDecorator') $this->decorator = $this->getMockBuilder('Doctrine\ORM\Decorator\EntityManagerDecorator')
->setConstructorArgs(array($this->wrapped)) ->setConstructorArgs(array($this->wrapped))
->setMethods(null) ->setMethods(null)

View File

@ -2,6 +2,8 @@
namespace Doctrine\Tests\ORM; namespace Doctrine\Tests\ORM;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\OrmTestCase;
@ -142,8 +144,9 @@ class EntityManagerTest extends OrmTestCase
* @dataProvider dataMethodsAffectedByNoObjectArguments * @dataProvider dataMethodsAffectedByNoObjectArguments
*/ */
public function testThrowsExceptionOnNonObjectValues($methodName) { public function testThrowsExceptionOnNonObjectValues($methodName) {
$this->setExpectedException('Doctrine\ORM\ORMInvalidArgumentException', $this->expectException(ORMInvalidArgumentException::class);
'EntityManager#'.$methodName.'() expects parameter 1 to be an entity object, NULL given.'); $this->expectExceptionMessage('EntityManager#' . $methodName . '() expects parameter 1 to be an entity object, NULL given.');
$this->_em->$methodName(null); $this->_em->$methodName(null);
} }
@ -164,7 +167,8 @@ class EntityManagerTest extends OrmTestCase
*/ */
public function testAffectedByErrorIfClosedException($methodName) public function testAffectedByErrorIfClosedException($methodName)
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', 'closed'); $this->expectException(ORMException::class);
$this->expectExceptionMessage('closed');
$this->_em->close(); $this->_em->close();
$this->_em->$methodName(new \stdClass()); $this->_em->$methodName(new \stdClass());
@ -189,7 +193,9 @@ class EntityManagerTest extends OrmTestCase
public function testTransactionalThrowsInvalidArgumentExceptionIfNonCallablePassed() public function testTransactionalThrowsInvalidArgumentExceptionIfNonCallablePassed()
{ {
$this->setExpectedException('InvalidArgumentException', 'Expected argument of type "callable", got "object"'); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected argument of type "callable", got "object"');
$this->_em->transactional($this); $this->_em->transactional($this);
} }

View File

@ -2,6 +2,8 @@
namespace Doctrine\Tests\ORM; namespace Doctrine\Tests\ORM;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
@ -15,7 +17,7 @@ class OnClassMetadataNotFoundEventArgsTest extends PHPUnit_Framework_TestCase
public function testEventArgsMutability() public function testEventArgsMutability()
{ {
/* @var $objectManager \Doctrine\Common\Persistence\ObjectManager */ /* @var $objectManager \Doctrine\Common\Persistence\ObjectManager */
$objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); $objectManager = $this->createMock(ObjectManager::class);
$args = new OnClassMetadataNotFoundEventArgs('foo', $objectManager); $args = new OnClassMetadataNotFoundEventArgs('foo', $objectManager);
@ -25,7 +27,7 @@ class OnClassMetadataNotFoundEventArgsTest extends PHPUnit_Framework_TestCase
$this->assertNull($args->getFoundMetadata()); $this->assertNull($args->getFoundMetadata());
/* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata */ /* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata */
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); $metadata = $this->createMock(ClassMetadata::class);
$args->setFoundMetadata($metadata); $args->setFoundMetadata($metadata);

View File

@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork; use Doctrine\ORM\UnitOfWork;
use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsUser;
@ -1118,7 +1119,9 @@ class BasicFunctionalTest extends OrmFunctionalTestCase
$user->username = 'domnikl'; $user->username = 'domnikl';
$user->status = 'developer'; $user->status = 'developer';
$this->setExpectedException('InvalidArgumentException', 'Entity has to be managed or scheduled for removal for single computation'); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Entity has to be managed or scheduled for removal for single computation');
$this->_em->flush($user); $this->_em->flush($user);
} }
@ -1195,7 +1198,9 @@ class BasicFunctionalTest extends OrmFunctionalTestCase
$article1->author = $user; $article1->author = $user;
$user->articles[] = $article1; $user->articles[] = $article1;
$this->setExpectedException('InvalidArgumentException', "A new entity was found through the relationship 'Doctrine\Tests\Models\CMS\CmsUser#articles'"); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("A new entity was found through the relationship 'Doctrine\Tests\Models\CMS\CmsUser#articles'");
$this->_em->flush($user); $this->_em->flush($user);
} }
@ -1291,10 +1296,10 @@ class BasicFunctionalTest extends OrmFunctionalTestCase
$user->status = 'developer'; $user->status = 'developer';
$user->address = $user; $user->address = $user;
$this->setExpectedException( $this->expectException(ORMInvalidArgumentException::class);
'Doctrine\ORM\ORMInvalidArgumentException', $this->expectExceptionMessage(
'Expected value of type "Doctrine\Tests\Models\CMS\CmsAddress" for association field ' 'Expected value of type "Doctrine\Tests\Models\CMS\CmsAddress" for association field ' .
. '"Doctrine\Tests\Models\CMS\CmsUser#$address", got "Doctrine\Tests\Models\CMS\CmsUser" instead.' '"Doctrine\Tests\Models\CMS\CmsUser#$address", got "Doctrine\Tests\Models\CMS\CmsUser" instead.'
); );
$this->_em->persist($user); $this->_em->persist($user);

View File

@ -1,6 +1,8 @@
<?php <?php
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Tests\Models\Navigation\NavCountry; use Doctrine\Tests\Models\Navigation\NavCountry;
use Doctrine\Tests\Models\Navigation\NavPointOfInterest; use Doctrine\Tests\Models\Navigation\NavPointOfInterest;
use Doctrine\Tests\Models\Navigation\NavTour; use Doctrine\Tests\Models\Navigation\NavTour;
@ -67,7 +69,9 @@ class CompositePrimaryKeyTest extends OrmFunctionalTestCase
$dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavPhotos t WHERE t.poi = ?1'; $dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavPhotos t WHERE t.poi = ?1';
$this->setExpectedException('Doctrine\ORM\Query\QueryException', 'A single-valued association path expression to an entity with a composite primary key is not supported.'); $this->expectException(QueryException::class);
$this->expectExceptionMessage('A single-valued association path expression to an entity with a composite primary key is not supported.');
$sql = $this->_em->createQuery($dql)->getSQL(); $sql = $this->_em->createQuery($dql)->getSQL();
} }
@ -133,13 +137,17 @@ class CompositePrimaryKeyTest extends OrmFunctionalTestCase
public function testSpecifyUnknownIdentifierPrimaryKeyFails() public function testSpecifyUnknownIdentifierPrimaryKeyFails()
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', 'The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest'); $this->expectException(ORMException::class);
$this->expectExceptionMessage('The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest');
$poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100)); $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100));
} }
public function testUnrecognizedIdentifierFieldsOnGetReference() public function testUnrecognizedIdentifierFieldsOnGetReference()
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', "Unrecognized identifier fields: 'key1'"); $this->expectException(ORMException::class);
$this->expectExceptionMessage("Unrecognized identifier fields: 'key1'");
$poi = $this->_em->getReference('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 10, 'long' => 20, 'key1' => 100)); $poi = $this->_em->getReference('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 10, 'long' => 20, 'key1' => 100));
} }

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsPhonenumber;
use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsAddress;
@ -217,7 +218,9 @@ class DetachedEntityTest extends OrmFunctionalTestCase
$sql = "UPDATE cms_articles SET version = version+1 WHERE id = " . $article->id; $sql = "UPDATE cms_articles SET version = version+1 WHERE id = " . $article->id;
$this->_em->getConnection()->executeUpdate($sql); $this->_em->getConnection()->executeUpdate($sql);
$this->setExpectedException('Doctrine\ORM\OptimisticLockException', 'The optimistic lock failed, version 1 was expected, but is actually 2'); $this->expectException(OptimisticLockException::class);
$this->expectExceptionMessage('The optimistic lock failed, version 1 was expected, but is actually 2');
$this->_em->merge($article); $this->_em->merge($article);
} }
} }

View File

@ -4,6 +4,9 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode; use Doctrine\DBAL\LockMode;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\TransactionRequiredException;
use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\Tests\Models\CMS\CmsEmail;
use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsAddress;
@ -291,7 +294,7 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testPessimisticReadLockWithoutTransaction_ThrowsException() public function testPessimisticReadLockWithoutTransaction_ThrowsException()
{ {
$this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); $this->expectException(TransactionRequiredException::class);
$this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')
->find(1, LockMode::PESSIMISTIC_READ); ->find(1, LockMode::PESSIMISTIC_READ);
@ -303,7 +306,7 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testPessimisticWriteLockWithoutTransaction_ThrowsException() public function testPessimisticWriteLockWithoutTransaction_ThrowsException()
{ {
$this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); $this->expectException(TransactionRequiredException::class);
$this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')
->find(1, LockMode::PESSIMISTIC_WRITE); ->find(1, LockMode::PESSIMISTIC_WRITE);
@ -315,7 +318,7 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testOptimisticLockUnversionedEntity_ThrowsException() public function testOptimisticLockUnversionedEntity_ThrowsException()
{ {
$this->setExpectedException('Doctrine\ORM\OptimisticLockException'); $this->expectException(OptimisticLockException::class);
$this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')
->find(1, LockMode::OPTIMISTIC); ->find(1, LockMode::OPTIMISTIC);
@ -338,7 +341,8 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
$this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId);
$this->setExpectedException('Doctrine\ORM\OptimisticLockException'); $this->expectException(OptimisticLockException::class);
$this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId, LockMode::OPTIMISTIC); $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId, LockMode::OPTIMISTIC);
} }
@ -360,7 +364,7 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testInvalidMagicCall() public function testInvalidMagicCall()
{ {
$this->setExpectedException('BadMethodCallException'); $this->expectException(\BadMethodCallException::class);
$repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$repos->foo(); $repos->foo();
@ -374,7 +378,9 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
list($userId, $addressId) = $this->loadAssociatedFixture(); list($userId, $addressId) = $this->loadAssociatedFixture();
$repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$this->setExpectedException('Doctrine\ORM\ORMException', "You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association. Find methods only work on owning side associations."); $this->expectException(ORMException::class);
$this->expectExceptionMessage("You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association. Find methods only work on owning side associations.");
$user = $repos->findBy(array('address' => $addressId)); $user = $repos->findBy(array('address' => $addressId));
} }
@ -460,7 +466,7 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
{ {
$repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$repos->createNamedQuery('invalidNamedQuery'); $repos->createNamedQuery('invalidNamedQuery');
} }
@ -658,7 +664,8 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testInvalidOrientation() public function testInvalidOrientation()
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', 'Invalid order by orientation specified for Doctrine\Tests\Models\CMS\CmsUser#username'); $this->expectException(ORMException::class);
$this->expectExceptionMessage('Invalid order by orientation specified for Doctrine\Tests\Models\CMS\CmsUser#username');
$repo = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repo = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$repo->findBy(array('status' => 'test'), array('username' => 'INVALID')); $repo->findBy(array('status' => 'test'), array('username' => 'INVALID'));
@ -918,7 +925,8 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testFindByFieldInjectionPrevented() public function testFindByFieldInjectionPrevented()
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized field: '); $this->expectException(ORMException::class);
$this->expectExceptionMessage('Unrecognized field: ');
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$repository->findBy(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test')); $repository->findBy(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test'));
@ -929,7 +937,8 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testFindOneByFieldInjectionPrevented() public function testFindOneByFieldInjectionPrevented()
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized field: '); $this->expectException(ORMException::class);
$this->expectExceptionMessage('Unrecognized field: ');
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$repository->findOneBy(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test')); $repository->findOneBy(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test'));
@ -940,7 +949,8 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testMatchingInjectionPrevented() public function testMatchingInjectionPrevented()
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized field: '); $this->expectException(ORMException::class);
$this->expectExceptionMessage('Unrecognized field: ');
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$result = $repository->matching(new Criteria( $result = $repository->matching(new Criteria(
@ -956,7 +966,8 @@ class EntityRepositoryTest extends OrmFunctionalTestCase
*/ */
public function testFindInjectionPrevented() public function testFindInjectionPrevented()
{ {
$this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized identifier fields: '); $this->expectException(ORMException::class);
$this->expectExceptionMessage('Unrecognized identifier fields: ');
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$repository->find(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test', 'id' => 1)); $repository->find(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test', 'id' => 1));

View File

@ -3,7 +3,9 @@
namespace Doctrine\Tests\ORM\Functional\Locking; namespace Doctrine\Tests\ORM\Functional\Locking;
use Doctrine\DBAL\LockMode; use Doctrine\DBAL\LockMode;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\TransactionRequiredException;
use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\Tests\OrmFunctionalTestCase;
@ -47,7 +49,8 @@ class LockTest extends OrmFunctionalTestCase
$this->_em->persist($article); $this->_em->persist($article);
$this->_em->flush(); $this->_em->flush();
$this->setExpectedException('Doctrine\ORM\OptimisticLockException'); $this->expectException(OptimisticLockException::class);
$this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1); $this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1);
} }
@ -64,7 +67,8 @@ class LockTest extends OrmFunctionalTestCase
$this->_em->persist($user); $this->_em->persist($user);
$this->_em->flush(); $this->_em->flush();
$this->setExpectedException('Doctrine\ORM\OptimisticLockException'); $this->expectException(OptimisticLockException::class);
$this->_em->lock($user, LockMode::OPTIMISTIC); $this->_em->lock($user, LockMode::OPTIMISTIC);
} }
@ -75,7 +79,9 @@ class LockTest extends OrmFunctionalTestCase
public function testLockUnmanagedEntity_ThrowsException() { public function testLockUnmanagedEntity_ThrowsException() {
$article = new CmsArticle(); $article = new CmsArticle();
$this->setExpectedException('InvalidArgumentException', 'Entity Doctrine\Tests\Models\CMS\CmsArticle'); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Entity Doctrine\Tests\Models\CMS\CmsArticle');
$this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1); $this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1);
} }
@ -91,7 +97,8 @@ class LockTest extends OrmFunctionalTestCase
$this->_em->persist($article); $this->_em->persist($article);
$this->_em->flush(); $this->_em->flush();
$this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); $this->expectException(TransactionRequiredException::class);
$this->_em->lock($article, LockMode::PESSIMISTIC_READ); $this->_em->lock($article, LockMode::PESSIMISTIC_READ);
} }
@ -107,7 +114,8 @@ class LockTest extends OrmFunctionalTestCase
$this->_em->persist($article); $this->_em->persist($article);
$this->_em->flush(); $this->_em->flush();
$this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); $this->expectException(TransactionRequiredException::class);
$this->_em->lock($article, LockMode::PESSIMISTIC_WRITE); $this->_em->lock($article, LockMode::PESSIMISTIC_WRITE);
} }
@ -181,7 +189,9 @@ class LockTest extends OrmFunctionalTestCase
{ {
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'"; $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'";
$this->setExpectedException('Doctrine\ORM\OptimisticLockException', 'The optimistic lock on an entity failed.'); $this->expectException(OptimisticLockException::class);
$this->expectExceptionMessage('The optimistic lock on an entity failed.');
$sql = $this->_em->createQuery($dql)->setHint( $sql = $this->_em->createQuery($dql)->setHint(
Query::HINT_LOCK_MODE, LockMode::OPTIMISTIC Query::HINT_LOCK_MODE, LockMode::OPTIMISTIC
)->getSQL(); )->getSQL();

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Internal\Hydration\HydrationException;
use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\Parameter;
@ -324,7 +325,9 @@ class NativeQueryTest extends OrmFunctionalTestCase
*/ */
public function testAbstractClassInSingleTableInheritanceSchemaWithRSMBuilderThrowsException() public function testAbstractClassInSingleTableInheritanceSchemaWithRSMBuilderThrowsException()
{ {
$this->setExpectedException('\InvalidArgumentException', 'ResultSetMapping builder does not currently support your inheritance scheme.'); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('ResultSetMapping builder does not currently support your inheritance scheme.');
$rsm = new ResultSetMappingBuilder($this->_em); $rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\Company\CompanyContract', 'c'); $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\Company\CompanyContract', 'c');
} }
@ -351,10 +354,9 @@ class NativeQueryTest extends OrmFunctionalTestCase
$query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm); $query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm);
$query->setParameter(1, 'romanb'); $query->setParameter(1, 'romanb');
$this->setExpectedException( $this->expectException(HydrationException::class);
"Doctrine\ORM\Internal\Hydration\HydrationException", $this->expectExceptionMessage("The parent object of entity result with alias 'a' was not found. The parent alias is 'un'.");
"The parent object of entity result with alias 'a' was not found. The parent alias is 'un'."
);
$users = $query->getResult(); $users = $query->getResult();
} }

View File

@ -74,10 +74,9 @@ class PaginationTest extends OrmFunctionalTestCase
$paginator = new Paginator($query); $paginator = new Paginator($query);
$paginator->setUseOutputWalkers(false); $paginator->setUseOutputWalkers(false);
$this->setExpectedException( $this->expectException(\RuntimeException::class);
'RuntimeException', $this->expectExceptionMessage('Cannot count query that uses a HAVING clause. Use the output walkers for pagination');
'Cannot count query that uses a HAVING clause. Use the output walkers for pagination'
);
$this->assertCount(3, $paginator); $this->assertCount(3, $paginator);
} }
@ -495,7 +494,9 @@ class PaginationTest extends OrmFunctionalTestCase
public function testIterateWithFetchJoinOneToManyWithOrderByColumnFromBothWithLimitWithoutOutputWalker() public function testIterateWithFetchJoinOneToManyWithOrderByColumnFromBothWithLimitWithoutOutputWalker()
{ {
$this->setExpectedException("RuntimeException", "Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers."); $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers.');
$dql = 'SELECT c, d FROM Doctrine\Tests\Models\Pagination\Company c JOIN c.departments d ORDER BY c.name'; $dql = 'SELECT c, d FROM Doctrine\Tests\Models\Pagination\Company c JOIN c.departments d ORDER BY c.name';
$dqlAsc = $dql . " ASC, d.name"; $dqlAsc = $dql . " ASC, d.name";
$dqlDesc = $dql . " DESC, d.name"; $dqlDesc = $dql . " DESC, d.name";
@ -552,7 +553,9 @@ class PaginationTest extends OrmFunctionalTestCase
public function testIterateWithFetchJoinOneToManyWithOrderByColumnFromJoinedWithLimitWithoutOutputWalker() public function testIterateWithFetchJoinOneToManyWithOrderByColumnFromJoinedWithLimitWithoutOutputWalker()
{ {
$this->setExpectedException("RuntimeException", "Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers."); $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers.');
$dql = 'SELECT c, d FROM Doctrine\Tests\Models\Pagination\Company c JOIN c.departments d ORDER BY d.name'; $dql = 'SELECT c, d FROM Doctrine\Tests\Models\Pagination\Company c JOIN c.departments d ORDER BY d.name';
$this->iterateWithOrderAscWithLimit(false, true, $dql, "name"); $this->iterateWithOrderAscWithLimit(false, true, $dql, "name");
@ -595,10 +598,8 @@ class PaginationTest extends OrmFunctionalTestCase
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker'); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker');
$paginator = new Paginator($query); $paginator = new Paginator($query);
$this->setExpectedException( $this->expectException(\RuntimeException::class);
'RuntimeException', $this->expectExceptionMessage('Cannot count query that uses a HAVING clause. Use the output walkers for pagination');
'Cannot count query that uses a HAVING clause. Use the output walkers for pagination'
);
count($paginator); count($paginator);
} }

View File

@ -36,7 +36,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
public function testLoadedEntityUsingFindShouldTriggerEvent() public function testLoadedEntityUsingFindShouldTriggerEvent()
{ {
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
// CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser // CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser
$mockListener $mockListener
@ -53,7 +53,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
public function testLoadedEntityUsingQueryShouldTriggerEvent() public function testLoadedEntityUsingQueryShouldTriggerEvent()
{ {
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
// CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser // CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser
$mockListener $mockListener
@ -73,7 +73,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
public function testLoadedAssociationToOneShouldTriggerEvent() public function testLoadedAssociationToOneShouldTriggerEvent()
{ {
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
// CmsUser (root), CmsAddress (ToOne inverse side), CmsEmail (joined association) // CmsUser (root), CmsAddress (ToOne inverse side), CmsEmail (joined association)
$mockListener $mockListener
@ -93,7 +93,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
public function testLoadedAssociationToManyShouldTriggerEvent() public function testLoadedAssociationToManyShouldTriggerEvent()
{ {
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
// CmsUser (root), CmsAddress (ToOne inverse side), 2 CmsPhonenumber (joined association) // CmsUser (root), CmsAddress (ToOne inverse side), 2 CmsPhonenumber (joined association)
$mockListener $mockListener
@ -116,7 +116,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
$eventManager = $this->_em->getEventManager(); $eventManager = $this->_em->getEventManager();
// Should not be invoked during getReference call // Should not be invoked during getReference call
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
$mockListener $mockListener
->expects($this->never()) ->expects($this->never())
@ -130,7 +130,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
// Now deactivate original listener and attach new one // Now deactivate original listener and attach new one
$eventManager->removeEventListener(array(Events::postLoad), $mockListener); $eventManager->removeEventListener(array(Events::postLoad), $mockListener);
$mockListener2 = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener2 = $this->createMock(PostLoadListener::class);
$mockListener2 $mockListener2
->expects($this->exactly(2)) ->expects($this->exactly(2))
@ -147,7 +147,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
$eventManager = $this->_em->getEventManager(); $eventManager = $this->_em->getEventManager();
// Should not be invoked during getReference call // Should not be invoked during getReference call
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
// CmsUser (partially loaded), CmsAddress (inverse ToOne), 2 CmsPhonenumber // CmsUser (partially loaded), CmsAddress (inverse ToOne), 2 CmsPhonenumber
$mockListener $mockListener
@ -167,7 +167,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
{ {
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
// CmsEmail (proxy) // CmsEmail (proxy)
$mockListener $mockListener
@ -188,7 +188,7 @@ class PostLoadEventTest extends OrmFunctionalTestCase
{ {
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
$mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); $mockListener = $this->createMock(PostLoadListener::class);
// 2 CmsPhonenumber (proxy) // 2 CmsPhonenumber (proxy)
$mockListener $mockListener

View File

@ -3,6 +3,10 @@
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\ParserResult;
use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\Tests\OrmFunctionalTestCase;
/** /**
@ -105,7 +109,7 @@ class QueryCacheTest extends OrmFunctionalTestCase
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$cache = $this->getMock('Doctrine\Common\Cache\Cache'); $cache = $this->createMock(Cache::class);
$query->setQueryCacheDriver($cache); $query->setQueryCacheDriver($cache);
@ -123,18 +127,23 @@ class QueryCacheTest extends OrmFunctionalTestCase
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$sqlExecMock = $this->getMock('Doctrine\ORM\Query\Exec\AbstractSqlExecutor', array('execute')); $sqlExecMock = $this->getMockBuilder(AbstractSqlExecutor::class)
->setMethods(array('execute'))
->getMock();
$sqlExecMock->expects($this->once()) $sqlExecMock->expects($this->once())
->method('execute') ->method('execute')
->will($this->returnValue( 10 )); ->will($this->returnValue( 10 ));
$parserResultMock = $this->getMock('Doctrine\ORM\Query\ParserResult'); $parserResultMock = $this->createMock(ParserResult::class);
$parserResultMock->expects($this->once()) $parserResultMock->expects($this->once())
->method('getSqlExecutor') ->method('getSqlExecutor')
->will($this->returnValue($sqlExecMock)); ->will($this->returnValue($sqlExecMock));
$cache = $this->getMock('Doctrine\Common\Cache\CacheProvider', $cache = $this->getMockBuilder(CacheProvider::class)
array('doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush', 'doGetStats')); ->setMethods(array('doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush', 'doGetStats'))
->getMock();
$cache->expects($this->at(0))->method('doFetch')->will($this->returnValue(1)); $cache->expects($this->at(0))->method('doFetch')->will($this->returnValue(1));
$cache->expects($this->at(1)) $cache->expects($this->at(1))
->method('doFetch') ->method('doFetch')

View File

@ -4,6 +4,8 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\UnexpectedResultException; use Doctrine\ORM\UnexpectedResultException;
use Doctrine\Tests\Models\CMS\CmsUser, use Doctrine\Tests\Models\CMS\CmsUser,
Doctrine\Tests\Models\CMS\CmsArticle, Doctrine\Tests\Models\CMS\CmsArticle,
@ -118,10 +120,8 @@ class QueryTest extends OrmFunctionalTestCase
public function testUsingUnknownQueryParameterShouldThrowException() public function testUsingUnknownQueryParameterShouldThrowException()
{ {
$this->setExpectedException( $this->expectException(QueryException::class);
"Doctrine\ORM\Query\QueryException", $this->expectExceptionMessage('Invalid parameter: token 2 is not defined in the query.');
"Invalid parameter: token 2 is not defined in the query."
);
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1'); $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1');
$q->setParameter(2, 'jwage'); $q->setParameter(2, 'jwage');
@ -130,10 +130,8 @@ class QueryTest extends OrmFunctionalTestCase
public function testTooManyParametersShouldThrowException() public function testTooManyParametersShouldThrowException()
{ {
$this->setExpectedException( $this->expectException(QueryException::class);
"Doctrine\ORM\Query\QueryException", $this->expectExceptionMessage('Too many parameters: the query defines 1 parameters and you bound 2');
"Too many parameters: the query defines 1 parameters and you bound 2"
);
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1'); $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1');
$q->setParameter(1, 'jwage'); $q->setParameter(1, 'jwage');
@ -144,10 +142,8 @@ class QueryTest extends OrmFunctionalTestCase
public function testTooFewParametersShouldThrowException() public function testTooFewParametersShouldThrowException()
{ {
$this->setExpectedException( $this->expectException(QueryException::class);
"Doctrine\ORM\Query\QueryException", $this->expectExceptionMessage('Too few parameters: the query defines 1 parameters but you only bound 0');
"Too few parameters: the query defines 1 parameters but you only bound 0"
);
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1'); $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1');
@ -156,7 +152,7 @@ class QueryTest extends OrmFunctionalTestCase
public function testInvalidInputParameterThrowsException() public function testInvalidInputParameterThrowsException()
{ {
$this->setExpectedException("Doctrine\ORM\Query\QueryException"); $this->expectException(QueryException::class);
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?'); $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?');
$q->setParameter(1, 'jwage'); $q->setParameter(1, 'jwage');
@ -505,7 +501,8 @@ class QueryTest extends OrmFunctionalTestCase
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u"); $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u");
$this->setExpectedException('Doctrine\ORM\NonUniqueResultException'); $this->expectException(NonUniqueResultException::class);
$fetchedUser = $query->getOneOrNullResult(); $fetchedUser = $query->getOneOrNullResult();
} }

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Persisters\PersisterException;
use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyEmployee;
use Doctrine\Tests\Models\Company\CompanyFixContract; use Doctrine\Tests\Models\Company\CompanyFixContract;
use Doctrine\Tests\Models\Company\CompanyFlexContract; use Doctrine\Tests\Models\Company\CompanyFlexContract;
@ -371,7 +372,9 @@ class SingleTableInheritanceTest extends OrmFunctionalTestCase
$repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract"); $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract");
$this->setExpectedException('Doctrine\ORM\Persisters\PersisterException', 'annot match on Doctrine\Tests\Models\Company\CompanyContract::salesPerson with a non-object value.'); $this->expectException(PersisterException::class);
$this->expectExceptionMessage('annot match on Doctrine\Tests\Models\Company\CompanyContract::salesPerson with a non-object value.');
$contracts = $repository->matching(new Criteria( $contracts = $repository->matching(new Criteria(
Criteria::expr()->eq('salesPerson', $this->salesPerson->getId()) Criteria::expr()->eq('salesPerson', $this->salesPerson->getId())
)); ));

View File

@ -55,7 +55,9 @@ class DDC1685Test extends \Doctrine\Tests\OrmFunctionalTestCase
{ {
$this->paginator->setUseOutputWalkers(false); $this->paginator->setUseOutputWalkers(false);
$this->setExpectedException('RuntimeException', 'Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.'); $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.');
foreach ($this->paginator as $ad) { foreach ($this->paginator as $ad) {
$this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $ad); $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $ad);
} }

View File

@ -1,6 +1,13 @@
<?php <?php
namespace Doctrine\Tests\ORM\Functional\Ticket; namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\EventManager;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
/** /**
* @group DDC-2359 * @group DDC-2359
@ -14,18 +21,20 @@ class DDC2359Test extends \PHPUnit_Framework_TestCase
*/ */
public function testIssue() public function testIssue()
{ {
$mockDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver'); $mockDriver = $this->createMock(MappingDriver::class);
$mockMetadata = $this->getMock('Doctrine\\ORM\\Mapping\\ClassMetadata', array(), array(), '', false); $mockMetadata = $this->createMock(ClassMetadata::class);
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManager', array(), array(), '', false); $entityManager = $this->createMock(EntityManager::class);
/* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */ /* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */
$metadataFactory = $this->getMock( $metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class)
'Doctrine\\ORM\\Mapping\\ClassMetadataFactory', ->setMethods(array('newClassMetadataInstance', 'wakeupReflection'))
array('newClassMetadataInstance', 'wakeupReflection') ->getMock();
);
$configuration = $this->getMockBuilder(Configuration::class)
$configuration = $this->getMock('Doctrine\\ORM\\Configuration', array('getMetadataDriverImpl')); ->setMethods(array('getMetadataDriverImpl'))
$connection = $this->getMock('Doctrine\\DBAL\\Connection', array(), array(), '', false); ->getMock();
$connection = $this->createMock(Connection::class);
$configuration $configuration
->expects($this->any()) ->expects($this->any())
@ -37,7 +46,7 @@ class DDC2359Test extends \PHPUnit_Framework_TestCase
$entityManager $entityManager
->expects($this->any()) ->expects($this->any())
->method('getEventManager') ->method('getEventManager')
->will($this->returnValue($this->getMock('Doctrine\\Common\\EventManager'))); ->will($this->returnValue($this->createMock(EventManager::class)));
$metadataFactory->expects($this->any())->method('newClassMetadataInstance')->will($this->returnValue($mockMetadata)); $metadataFactory->expects($this->any())->method('newClassMetadataInstance')->will($this->returnValue($mockMetadata));
$metadataFactory->expects($this->once())->method('wakeupReflection'); $metadataFactory->expects($this->once())->method('wakeupReflection');

View File

@ -29,7 +29,10 @@ class DDC2692Test extends \Doctrine\Tests\OrmFunctionalTestCase
public function testIsListenerCalledOnlyOnceOnPreFlush() public function testIsListenerCalledOnlyOnceOnPreFlush()
{ {
$listener = $this->getMock('Doctrine\Tests\ORM\Functional\Ticket\DDC2692Listener', array('preFlush')); $listener = $this->getMockBuilder(DDC2692Listener::class)
->setMethods(array('preFlush'))
->getMock();
$listener->expects($this->once())->method('preFlush'); $listener->expects($this->once())->method('preFlush');
$this->_em->getEventManager()->addEventSubscriber($listener); $this->_em->getEventManager()->addEventSubscriber($listener);

View File

@ -28,7 +28,9 @@ class DDC3123Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->persist($user); $this->_em->persist($user);
$uow->scheduleExtraUpdate($user, array('name' => 'changed name')); $uow->scheduleExtraUpdate($user, array('name' => 'changed name'));
$listener = $this->getMock('stdClass', array(Events::postFlush)); $listener = $this->getMockBuilder(\stdClass::class)
->setMethods(array(Events::postFlush))
->getMock();
$listener $listener
->expects($this->once()) ->expects($this->once())

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\Tests\OrmFunctionalTestCase;
@ -22,7 +23,9 @@ class UnitOfWorkLifecycleTest extends OrmFunctionalTestCase
$this->_em->persist($user); $this->_em->persist($user);
$this->_em->flush(); $this->_em->flush();
$this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "A managed+dirty entity Doctrine\Tests\Models\CMS\CmsUser"); $this->expectException(ORMInvalidArgumentException::class);
$this->expectExceptionMessage('A managed+dirty entity Doctrine\Tests\Models\CMS\CmsUser');
$this->_em->getUnitOfWork()->scheduleForInsert($user); $this->_em->getUnitOfWork()->scheduleForInsert($user);
} }
@ -37,7 +40,9 @@ class UnitOfWorkLifecycleTest extends OrmFunctionalTestCase
$this->_em->remove($user); $this->_em->remove($user);
$this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "Removed entity Doctrine\Tests\Models\CMS\CmsUser"); $this->expectException(ORMInvalidArgumentException::class);
$this->expectExceptionMessage('Removed entity Doctrine\Tests\Models\CMS\CmsUser');
$this->_em->getUnitOfWork()->scheduleForInsert($user); $this->_em->getUnitOfWork()->scheduleForInsert($user);
} }
@ -50,7 +55,9 @@ class UnitOfWorkLifecycleTest extends OrmFunctionalTestCase
$this->_em->getUnitOfWork()->scheduleForInsert($user); $this->_em->getUnitOfWork()->scheduleForInsert($user);
$this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "Entity Doctrine\Tests\Models\CMS\CmsUser"); $this->expectException(ORMInvalidArgumentException::class);
$this->expectExceptionMessage('Entity Doctrine\Tests\Models\CMS\CmsUser');
$this->_em->getUnitOfWork()->scheduleForInsert($user); $this->_em->getUnitOfWork()->scheduleForInsert($user);
} }
@ -58,7 +65,9 @@ class UnitOfWorkLifecycleTest extends OrmFunctionalTestCase
{ {
$user = new CmsUser(); $user = new CmsUser();
$this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "The given entity of type 'Doctrine\Tests\Models\CMS\CmsUser' (Doctrine\Tests\Models\CMS\CmsUser@"); $this->expectException(ORMInvalidArgumentException::class);
$this->expectExceptionMessage("The given entity of type 'Doctrine\Tests\Models\CMS\CmsUser' (Doctrine\Tests\Models\CMS\CmsUser@");
$this->_em->getUnitOfWork()->registerManaged($user, array(), array()); $this->_em->getUnitOfWork()->registerManaged($user, array(), array());
} }
@ -66,7 +75,9 @@ class UnitOfWorkLifecycleTest extends OrmFunctionalTestCase
{ {
$user = new CmsUser(); $user = new CmsUser();
$this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "Only managed entities can be marked or checked as read only. But Doctrine\Tests\Models\CMS\CmsUser@"); $this->expectException(ORMInvalidArgumentException::class);
$this->expectExceptionMessage('Only managed entities can be marked or checked as read only. But Doctrine\Tests\Models\CMS\CmsUser@');
$this->_em->getUnitOfWork()->markReadOnly($user); $this->_em->getUnitOfWork()->markReadOnly($user);
} }
} }

View File

@ -1,6 +1,8 @@
<?php <?php
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\Tests\OrmFunctionalTestCase;
/** /**
@ -228,7 +230,8 @@ class ValueObjectsTest extends OrmFunctionalTestCase
public function testDqlWithNonExistentEmbeddableField() public function testDqlWithNonExistentEmbeddableField()
{ {
$this->setExpectedException('Doctrine\ORM\Query\QueryException', 'no field or association named address.asdfasdf'); $this->expectException(QueryException::class);
$this->expectExceptionMessage('no field or association named address.asdfasdf');
$this->_em->createQuery("SELECT p FROM " . __NAMESPACE__ . "\\DDC93Person p WHERE p.address.asdfasdf IS NULL") $this->_em->createQuery("SELECT p FROM " . __NAMESPACE__ . "\\DDC93Person p WHERE p.address.asdfasdf IS NULL")
->execute(); ->execute();
@ -236,8 +239,9 @@ class ValueObjectsTest extends OrmFunctionalTestCase
public function testPartialDqlWithNonExistentEmbeddableField() public function testPartialDqlWithNonExistentEmbeddableField()
{ {
$this->setExpectedException('Doctrine\ORM\Query\QueryException', "no mapped field named 'address.asdfasdf'"); $this->expectException(QueryException::class);
$this->expectExceptionMessage("no mapped field named 'address.asdfasdf'");
$this->_em->createQuery("SELECT PARTIAL p.{id,address.asdfasdf} FROM " . __NAMESPACE__ . "\\DDC93Person p") $this->_em->createQuery("SELECT PARTIAL p.{id,address.asdfasdf} FROM " . __NAMESPACE__ . "\\DDC93Person p")
->execute(); ->execute();
} }
@ -297,8 +301,8 @@ class ValueObjectsTest extends OrmFunctionalTestCase
*/ */
public function testThrowsExceptionOnInfiniteEmbeddableNesting($embeddableClassName, $declaredEmbeddableClassName) public function testThrowsExceptionOnInfiniteEmbeddableNesting($embeddableClassName, $declaredEmbeddableClassName)
{ {
$this->setExpectedException( $this->expectException(MappingException::class);
'Doctrine\ORM\Mapping\MappingException', $this->expectExceptionMessage(
sprintf( sprintf(
'Infinite nesting detected for embedded property %s::nested. ' . 'Infinite nesting detected for embedded property %s::nested. ' .
'You cannot embed an embeddable from the same type inside an embeddable.', 'You cannot embed an embeddable from the same type inside an embeddable.',

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Hydration; namespace Doctrine\Tests\ORM\Hydration;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\Tests\Mocks\HydratorMockStatement;
use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
@ -1004,7 +1005,11 @@ class ObjectHydratorTest extends HydrationTestCase
$proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping(); $proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping();
// mocking the proxy factory // mocking the proxy factory
$proxyFactory = $this->getMock('Doctrine\ORM\Proxy\ProxyFactory', array('getProxy'), array(), '', false, false, false); $proxyFactory = $this->getMockBuilder(ProxyFactory::class)
->setMethods(array('getProxy'))
->disableOriginalConstructor()
->getMock();
$proxyFactory->expects($this->once()) $proxyFactory->expects($this->once())
->method('getProxy') ->method('getProxy')
->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42)) ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42))
@ -1049,7 +1054,11 @@ class ObjectHydratorTest extends HydrationTestCase
$proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping(); $proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping();
// mocking the proxy factory // mocking the proxy factory
$proxyFactory = $this->getMock('Doctrine\ORM\Proxy\ProxyFactory', array('getProxy'), array(), '', false, false, false); $proxyFactory = $this->getMockBuilder(ProxyFactory::class)
->setMethods(array('getProxy'))
->disableOriginalConstructor()
->getMock();
$proxyFactory->expects($this->once()) $proxyFactory->expects($this->once())
->method('getProxy') ->method('getProxy')
->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42)) ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42))

View File

@ -20,9 +20,11 @@
namespace Doctrine\Tests\ORM\Internal; namespace Doctrine\Tests\ORM\Internal;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\ListenersInvoker; use Doctrine\ORM\Event\ListenersInvoker;
use Doctrine\ORM\Events; use Doctrine\ORM\Events;
use Doctrine\ORM\Internal\HydrationCompleteHandler; use Doctrine\ORM\Internal\HydrationCompleteHandler;
use Doctrine\ORM\Mapping\ClassMetadata;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
use stdClass; use stdClass;
@ -53,8 +55,8 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase
*/ */
protected function setUp() protected function setUp()
{ {
$this->listenersInvoker = $this->getMock('Doctrine\ORM\Event\ListenersInvoker', array(), array(), '', false); $this->listenersInvoker = $this->createMock(ListenersInvoker::class);
$this->entityManager = $this->getMock('Doctrine\ORM\EntityManagerInterface'); $this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->handler = new HydrationCompleteHandler($this->listenersInvoker, $this->entityManager); $this->handler = new HydrationCompleteHandler($this->listenersInvoker, $this->entityManager);
} }
@ -66,7 +68,7 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase
public function testDefersPostLoadOfEntity($listenersFlag) public function testDefersPostLoadOfEntity($listenersFlag)
{ {
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
$metadata = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); $metadata = $this->createMock(ClassMetadata::class);
$entity = new stdClass(); $entity = new stdClass();
$entityManager = $this->entityManager; $entityManager = $this->entityManager;
@ -104,7 +106,7 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase
public function testDefersPostLoadOfEntityOnlyOnce($listenersFlag) public function testDefersPostLoadOfEntityOnlyOnce($listenersFlag)
{ {
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
$metadata = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); $metadata = $this->createMock(ClassMetadata::class);
$entity = new stdClass(); $entity = new stdClass();
$this $this
@ -131,8 +133,8 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase
{ {
/* @var $metadata1 \Doctrine\ORM\Mapping\ClassMetadata */ /* @var $metadata1 \Doctrine\ORM\Mapping\ClassMetadata */
/* @var $metadata2 \Doctrine\ORM\Mapping\ClassMetadata */ /* @var $metadata2 \Doctrine\ORM\Mapping\ClassMetadata */
$metadata1 = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); $metadata1 = $this->createMock(ClassMetadata::class);
$metadata2 = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); $metadata2 = $this->createMock(ClassMetadata::class);
$entity1 = new stdClass(); $entity1 = new stdClass();
$entity2 = new stdClass(); $entity2 = new stdClass();
$entityManager = $this->entityManager; $entityManager = $this->entityManager;
@ -168,7 +170,7 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase
public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners() public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners()
{ {
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
$metadata = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); $metadata = $this->createMock(ClassMetadata::class);
$entity = new stdClass(); $entity = new stdClass();
$this $this

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM;
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\LazyCriteriaCollection; use Doctrine\ORM\LazyCriteriaCollection;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use stdClass; use stdClass;
/** /**
@ -33,7 +34,7 @@ class LazyCriteriaCollectionTest extends \PHPUnit_Framework_TestCase
*/ */
protected function setUp() protected function setUp()
{ {
$this->persister = $this->getMock('Doctrine\ORM\Persisters\Entity\EntityPersister'); $this->persister = $this->createMock(EntityPersister::class);
$this->criteria = new Criteria(); $this->criteria = new Criteria();
$this->lazyCriteriaCollection = new LazyCriteriaCollection($this->persister, $this->criteria); $this->lazyCriteriaCollection = new LazyCriteriaCollection($this->persister, $this->criteria);
} }

View File

@ -8,6 +8,7 @@ use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\DiscriminatorColumn; use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy; use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Doctrine\Tests\Models\Cache\City; use Doctrine\Tests\Models\Cache\City;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
@ -520,7 +521,8 @@ abstract class AbstractMappingDriverTest extends OrmTestCase
*/ */
public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses() public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
{ {
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.'); $this->expectException(MappingException::class);
$this->expectExceptionMessage('Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.');
$this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class');
} }
@ -532,7 +534,9 @@ abstract class AbstractMappingDriverTest extends OrmTestCase
{ {
$factory = $this->createClassMetadataFactory(); $factory = $this->createClassMetadataFactory();
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.'); $this->expectException(MappingException::class);
$this->expectExceptionMessage('No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.');
$factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity'); $factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity');
} }

View File

@ -2,11 +2,13 @@
namespace Doctrine\Tests\ORM\Mapping; namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\MappingException;
class AnnotationDriverTest extends AbstractMappingDriverTest class AnnotationDriverTest extends AbstractMappingDriverTest
{ {
@ -20,7 +22,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$reader = new AnnotationReader(); $reader = new AnnotationReader();
$annotationDriver = new AnnotationDriver($reader); $annotationDriver = new AnnotationDriver($reader);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$annotationDriver->loadMetadataForClass('stdClass', $cm); $annotationDriver->loadMetadataForClass('stdClass', $cm);
} }
@ -157,9 +159,12 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$factory = new ClassMetadataFactory(); $factory = new ClassMetadataFactory();
$factory->setEntityManager($em); $factory->setEntityManager($em);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', $this->expectException(MappingException::class);
"It is illegal to put an inverse side one-to-many or many-to-many association on ". $this->expectExceptionMessage(
"mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'"); "It is illegal to put an inverse side one-to-many or many-to-many association on " .
"mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'"
);
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass'); $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass');
} }
@ -175,9 +180,12 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$factory = new ClassMetadataFactory(); $factory = new ClassMetadataFactory();
$factory->setEntityManager($em); $factory->setEntityManager($em);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', $this->expectException(MappingException::class);
"It is not supported to define inheritance information on a mapped ". $this->expectExceptionMessage(
"superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'."); "It is not supported to define inheritance information on a mapped " .
"superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'."
);
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'); $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence');
} }
@ -224,8 +232,9 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$factory = new ClassMetadataFactory(); $factory = new ClassMetadataFactory();
$factory->setEntityManager($em); $factory->setEntityManager($em);
$this->setExpectedException('Doctrine\Common\Annotations\AnnotationException', $this->expectException(AnnotationException::class);
'[Enum Error] Attribute "fetch" of @Doctrine\ORM\Mapping\OneToMany declared on property Doctrine\Tests\ORM\Mapping\InvalidFetchOption::$collection accept only [LAZY, EAGER, EXTRA_LAZY], but got eager.'); $this->expectExceptionMessage('[Enum Error] Attribute "fetch" of @Doctrine\ORM\Mapping\OneToMany declared on property Doctrine\Tests\ORM\Mapping\InvalidFetchOption::$collection accept only [LAZY, EAGER, EXTRA_LAZY], but got eager.');
$factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\InvalidFetchOption'); $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\InvalidFetchOption');
} }

View File

@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Tests\Models\DDC869\DDC869Payment; use Doctrine\Tests\Models\DDC869\DDC869Payment;
use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\OrmTestCase;
@ -26,7 +27,7 @@ class BasicInheritanceMappingTest extends OrmTestCase
public function testGetMetadataForTransientClassThrowsException() public function testGetMetadataForTransientClassThrowsException()
{ {
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass'); $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass');
} }
@ -122,12 +123,13 @@ class BasicInheritanceMappingTest extends OrmTestCase
*/ */
public function testUnmappedEntityInHierarchy() public function testUnmappedEntityInHierarchy()
{ {
$this->setExpectedException( $this->expectException(MappingException::class);
'Doctrine\ORM\Mapping\MappingException', $this->expectExceptionMessage(
'Entity \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' has to be part of the discriminator map' 'Entity \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' has to be part of the discriminator map'
. ' of \'Doctrine\Tests\ORM\Mapping\HierarchyBase\' to be properly mapped in the inheritance hierarchy.' . ' of \'Doctrine\Tests\ORM\Mapping\HierarchyBase\' to be properly mapped in the inheritance hierarchy.'
. ' Alternatively you can make \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' an abstract class to' . ' Alternatively you can make \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' an abstract class to'
. ' avoid this exception from occurring.'); . ' avoid this exception from occurring.'
);
$this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyE');
} }

View File

@ -528,7 +528,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
public function testThrowsExceptionOnCreateOneToOneWithIdentityOnInverseSide() public function testThrowsExceptionOnCreateOneToOneWithIdentityOnInverseSide()
{ {
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$this $this
->builder ->builder
@ -624,7 +624,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
public function testThrowsExceptionOnCreateManyToManyWithIdentity() public function testThrowsExceptionOnCreateManyToManyWithIdentity()
{ {
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$this->builder->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') $this->builder->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup')
->makePrimaryKey() ->makePrimaryKey()
@ -677,7 +677,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
public function testThrowsExceptionOnCreateOneToManyWithIdentity() public function testThrowsExceptionOnCreateOneToManyWithIdentity()
{ {
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup')
->makePrimaryKey() ->makePrimaryKey()
@ -775,7 +775,7 @@ class ClassMetadataBuilderTest extends OrmTestCase
public function testExceptionOnOrphanRemovalOnManyToOne() public function testExceptionOnOrphanRemovalOnManyToOne()
{ {
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$this->builder $this->builder
->createManyToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') ->createManyToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup')

View File

@ -3,14 +3,19 @@
namespace Doctrine\Tests\ORM\Mapping; namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration; use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs;
use Doctrine\ORM\Events; use Doctrine\ORM\Events;
use Doctrine\ORM\Id\AbstractIdGenerator; use Doctrine\ORM\Id\AbstractIdGenerator;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\ORMException;
use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\DriverMock;
use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\EntityManagerMock;
@ -78,7 +83,7 @@ class ClassMetadataFactoryTest extends OrmTestCase
$cm1->customGeneratorDefinition = array("class" => "NotExistingGenerator"); $cm1->customGeneratorDefinition = array("class" => "NotExistingGenerator");
$cmf = $this->_createTestFactory(); $cmf = $this->_createTestFactory();
$cmf->setMetadataForClass($cm1->name, $cm1); $cmf->setMetadataForClass($cm1->name, $cm1);
$this->setExpectedException("Doctrine\ORM\ORMException"); $this->expectException(ORMException::class);
$actual = $cmf->getMetadataFor($cm1->name); $actual = $cmf->getMetadataFor($cm1->name);
} }
@ -89,7 +94,7 @@ class ClassMetadataFactoryTest extends OrmTestCase
$cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM);
$cmf = $this->_createTestFactory(); $cmf = $this->_createTestFactory();
$cmf->setMetadataForClass($cm1->name, $cm1); $cmf->setMetadataForClass($cm1->name, $cm1);
$this->setExpectedException("Doctrine\ORM\ORMException"); $this->expectException(ORMException::class);
$actual = $cmf->getMetadataFor($cm1->name); $actual = $cmf->getMetadataFor($cm1->name);
} }
@ -119,7 +124,7 @@ class ClassMetadataFactoryTest extends OrmTestCase
public function testIsTransient() public function testIsTransient()
{ {
$cmf = new ClassMetadataFactory(); $cmf = new ClassMetadataFactory();
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver = $this->createMock(MappingDriver::class);
$driver->expects($this->at(0)) $driver->expects($this->at(0))
->method('isTransient') ->method('isTransient')
->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser'))
@ -141,7 +146,7 @@ class ClassMetadataFactoryTest extends OrmTestCase
public function testIsTransientEntityNamespace() public function testIsTransientEntityNamespace()
{ {
$cmf = new ClassMetadataFactory(); $cmf = new ClassMetadataFactory();
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); $driver = $this->createMock(MappingDriver::class);
$driver->expects($this->at(0)) $driver->expects($this->at(0))
->method('isTransient') ->method('isTransient')
->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser'))
@ -189,7 +194,7 @@ class ClassMetadataFactoryTest extends OrmTestCase
// ClassMetadataFactory::addDefaultDiscriminatorMap shouldn't be called again, because the // ClassMetadataFactory::addDefaultDiscriminatorMap shouldn't be called again, because the
// discriminator map is already cached // discriminator map is already cached
$cmf = $this->getMock('Doctrine\ORM\Mapping\ClassMetadataFactory', array('addDefaultDiscriminatorMap')); $cmf = $this->getMockBuilder(ClassMetadataFactory::class)->setMethods(array('addDefaultDiscriminatorMap'))->getMock();
$cmf->setEntityManager($em); $cmf->setEntityManager($em);
$cmf->expects($this->never()) $cmf->expects($this->never())
->method('addDefaultDiscriminatorMap'); ->method('addDefaultDiscriminatorMap');
@ -200,9 +205,7 @@ class ClassMetadataFactoryTest extends OrmTestCase
public function testGetAllMetadataWorksWithBadConnection() public function testGetAllMetadataWorksWithBadConnection()
{ {
// DDC-3551 // DDC-3551
$conn = $this->getMockBuilder('Doctrine\DBAL\Connection') $conn = $this->createMock(Connection::class);
->disableOriginalConstructor()
->getMock();
$mockDriver = new MetadataDriverMock(); $mockDriver = new MetadataDriverMock();
$em = $this->_createEntityManager($mockDriver, $conn); $em = $this->_createEntityManager($mockDriver, $conn);
@ -361,11 +364,11 @@ class ClassMetadataFactoryTest extends OrmTestCase
{ {
$test = $this; $test = $this;
/* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata */ /* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata */
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); $metadata = $this->createMock(ClassMetadata::class);
$cmf = new ClassMetadataFactory(); $cmf = new ClassMetadataFactory();
$mockDriver = new MetadataDriverMock(); $mockDriver = new MetadataDriverMock();
$em = $this->_createEntityManager($mockDriver); $em = $this->_createEntityManager($mockDriver);
$listener = $this->getMock('stdClass', array('onClassMetadataNotFound')); $listener = $this->getMockBuilder(\stdClass::class)->setMethods(array('onClassMetadataNotFound'))->getMock();
$eventManager = $em->getEventManager(); $eventManager = $em->getEventManager();
$cmf->setEntityManager($em); $cmf->setEntityManager($em);
@ -394,7 +397,7 @@ class ClassMetadataFactoryTest extends OrmTestCase
$classMetadataFactory = new ClassMetadataFactory(); $classMetadataFactory = new ClassMetadataFactory();
/* @var $entityManager EntityManager */ /* @var $entityManager EntityManager */
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface'); $entityManager = $this->createMock(EntityManagerInterface::class);
$classMetadataFactory->setEntityManager($entityManager); $classMetadataFactory->setEntityManager($entityManager);
@ -419,10 +422,8 @@ class ClassMetadataFactoryTest extends OrmTestCase
$cmf->setMetadataForClass($metadata->name, $metadata); $cmf->setMetadataForClass($metadata->name, $metadata);
$this->setExpectedException( $this->expectException(MappingException::class);
'Doctrine\ORM\Mapping\MappingException', $this->expectExceptionMessage('The embed mapping \'embedded\' misses the \'class\' attribute.');
'The embed mapping \'embedded\' misses the \'class\' attribute.'
);
$cmf->getMetadataFor($metadata->name); $cmf->getMetadataFor($metadata->name);
} }

View File

@ -7,6 +7,7 @@ use Doctrine\Common\Persistence\Mapping\StaticReflectionService;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Events; use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\DefaultNamingStrategy;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy; use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\OrmTestCase;
use Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser;
@ -182,7 +183,7 @@ class ClassMetadataTest extends OrmTestCase
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->setVersionMapping($field); $cm->setVersionMapping($field);
} }
@ -192,7 +193,7 @@ class ClassMetadataTest extends OrmTestCase
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$cm->isIdentifierComposite = true; $cm->isIdentifierComposite = true;
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->getSingleIdentifierFieldName(); $cm->getSingleIdentifierFieldName();
} }
@ -205,7 +206,7 @@ class ClassMetadataTest extends OrmTestCase
$a2 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); $a2 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo');
$cm->addInheritedAssociationMapping($a1); $cm->addInheritedAssociationMapping($a1);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->addInheritedAssociationMapping($a2); $cm->addInheritedAssociationMapping($a2);
} }
@ -216,7 +217,7 @@ class ClassMetadataTest extends OrmTestCase
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->mapField(array('fieldName' => 'username', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'username', 'columnName' => 'name'));
} }
@ -227,7 +228,7 @@ class ClassMetadataTest extends OrmTestCase
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->setDiscriminatorColumn(array('name' => 'name')); $cm->setDiscriminatorColumn(array('name' => 'name'));
} }
@ -238,7 +239,7 @@ class ClassMetadataTest extends OrmTestCase
$cm->setDiscriminatorColumn(array('name' => 'name')); $cm->setDiscriminatorColumn(array('name' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
} }
@ -249,7 +250,7 @@ class ClassMetadataTest extends OrmTestCase
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser'));
} }
@ -260,7 +261,7 @@ class ClassMetadataTest extends OrmTestCase
$cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser'));
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
} }
@ -395,7 +396,9 @@ class ClassMetadataTest extends OrmTestCase
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'."); $this->expectException(MappingException::class);
$this->expectExceptionMessage("No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'.");
$cm->getFieldMapping('foo'); $cm->getFieldMapping('foo');
} }
@ -439,7 +442,9 @@ class ClassMetadataTest extends OrmTestCase
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'The orphan removal option is not allowed on an association that'); $this->expectException(MappingException::class);
$this->expectExceptionMessage('The orphan removal option is not allowed on an association that');
$cm->mapOneToOne(array( $cm->mapOneToOne(array(
'fieldName' => 'article', 'fieldName' => 'article',
'id' => true, 'id' => true,
@ -457,8 +462,9 @@ class ClassMetadataTest extends OrmTestCase
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$this->expectException(MappingException::class);
$this->expectExceptionMessage('An inverse association is not allowed to be identifier in');
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'An inverse association is not allowed to be identifier in');
$cm->mapOneToOne(array( $cm->mapOneToOne(array(
'fieldName' => 'article', 'fieldName' => 'article',
'id' => true, 'id' => true,
@ -476,8 +482,9 @@ class ClassMetadataTest extends OrmTestCase
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$this->expectException(MappingException::class);
$this->expectExceptionMessage('Many-to-many or one-to-many associations are not allowed to be identifier in');
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Many-to-many or one-to-many associations are not allowed to be identifier in');
$cm->mapManyToMany(array( $cm->mapManyToMany(array(
'fieldName' => 'article', 'fieldName' => 'article',
'id' => true, 'id' => true,
@ -491,8 +498,9 @@ class ClassMetadataTest extends OrmTestCase
*/ */
public function testEmptyFieldNameThrowsException() public function testEmptyFieldNameThrowsException()
{ {
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', $this->expectException(MappingException::class);
"The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'."); $this->expectExceptionMessage("The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'.");
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
@ -833,7 +841,9 @@ class ClassMetadataTest extends OrmTestCase
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$cm->addLifecycleCallback('notfound', 'postLoad'); $cm->addLifecycleCallback('notfound', 'postLoad');
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); $this->expectException(MappingException::class);
$this->expectExceptionMessage("Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback.");
$cm->validateLifecycleCallbacks(new RuntimeReflectionService()); $cm->validateLifecycleCallbacks(new RuntimeReflectionService());
} }
@ -846,7 +856,9 @@ class ClassMetadataTest extends OrmTestCase
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass')); $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass'));
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'."); $this->expectException(MappingException::class);
$this->expectExceptionMessage("The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'.");
$cm->validateAssociations(); $cm->validateAssociations();
} }
@ -972,8 +984,8 @@ class ClassMetadataTest extends OrmTestCase
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "You have specified invalid cascade options for Doctrine\Tests\Models\CMS\CmsUser::\$address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'"); $this->expectException(MappingException::class);
$this->expectExceptionMessage("You have specified invalid cascade options for Doctrine\Tests\Models\CMS\CmsUser::\$address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'");
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => array('invalid'))); $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => array('invalid')));
} }
@ -1080,7 +1092,7 @@ class ClassMetadataTest extends OrmTestCase
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new RuntimeReflectionService()); $cm->initializeReflection(new RuntimeReflectionService());
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class);
$cm->setSequenceGeneratorDefinition(array()); $cm->setSequenceGeneratorDefinition(array());
} }

View File

@ -90,7 +90,7 @@ class ReflectionPropertiesGetterTest extends PHPUnit_Framework_TestCase
public function testPropertyGetterWillSkipPropertiesNotRetrievedByTheRuntimeReflectionService() public function testPropertyGetterWillSkipPropertiesNotRetrievedByTheRuntimeReflectionService()
{ {
/* @var $reflectionService ReflectionService|\PHPUnit_Framework_MockObject_MockObject */ /* @var $reflectionService ReflectionService|\PHPUnit_Framework_MockObject_MockObject */
$reflectionService = $this->getMock('Doctrine\Common\Persistence\Mapping\ReflectionService'); $reflectionService = $this->createMock(ReflectionService::class);
$reflectionService $reflectionService
->expects($this->exactly(2)) ->expects($this->exactly(2))
@ -113,7 +113,7 @@ class ReflectionPropertiesGetterTest extends PHPUnit_Framework_TestCase
public function testPropertyGetterWillSkipClassesNotRetrievedByTheRuntimeReflectionService() public function testPropertyGetterWillSkipClassesNotRetrievedByTheRuntimeReflectionService()
{ {
/* @var $reflectionService ReflectionService|\PHPUnit_Framework_MockObject_MockObject */ /* @var $reflectionService ReflectionService|\PHPUnit_Framework_MockObject_MockObject */
$reflectionService = $this->getMock('Doctrine\Common\Persistence\Mapping\ReflectionService'); $reflectionService = $this->createMock(ReflectionService::class);
$reflectionService $reflectionService
->expects($this->once()) ->expects($this->once())

View File

@ -18,6 +18,7 @@
*/ */
namespace Doctrine\Tests\ORM\Mapping\Symfony; namespace Doctrine\Tests\ORM\Mapping\Symfony;
use Doctrine\Common\Persistence\Mapping\MappingException;
/** /**
* @group DDC-1418 * @group DDC-1418
@ -47,10 +48,8 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
public function testFindMappingFileNamespacedFoundFileNotFound() public function testFindMappingFileNamespacedFoundFileNotFound()
{ {
$this->setExpectedException( $this->expectException(MappingException::class);
'Doctrine\Common\Persistence\Mapping\MappingException', $this->expectExceptionMessage('No mapping file found named');
"No mapping file found named"
);
$driver = $this->getDriver(array( $driver = $this->getDriver(array(
'MyNamespace\MySubnamespace\Entity' => $this->dir, 'MyNamespace\MySubnamespace\Entity' => $this->dir,
@ -61,10 +60,8 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
public function testFindMappingNamespaceNotFound() public function testFindMappingNamespaceNotFound()
{ {
$this->setExpectedException( $this->expectException(MappingException::class);
'Doctrine\Common\Persistence\Mapping\MappingException', $this->expectExceptionMessage("No mapping file found named 'Foo" . $this->getFileExtension() . "' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'.");
"No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."
);
$driver = $this->getDriver(array( $driver = $this->getDriver(array(
'MyNamespace\MySubnamespace\Entity' => $this->dir, 'MyNamespace\MySubnamespace\Entity' => $this->dir,

View File

@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Proxy;
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\EntityManagerMock;
@ -56,7 +57,8 @@ class ProxyFactoryTest extends OrmTestCase
{ {
$identifier = array('id' => 42); $identifier = array('id' => 42);
$proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature'; $proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature';
$persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load'), array(), '', false); $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock();
$this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
$proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $identifier); $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $identifier);
@ -89,7 +91,7 @@ class ProxyFactoryTest extends OrmTestCase
*/ */
public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized() public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized()
{ {
$persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load'), array(), '', false); $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock();
$this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
/* @var $proxy \Doctrine\Common\Proxy\Proxy */ /* @var $proxy \Doctrine\Common\Proxy\Proxy */
@ -116,7 +118,7 @@ class ProxyFactoryTest extends OrmTestCase
*/ */
public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized() public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized()
{ {
$persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load'), array(), '', false); $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock();
$this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
/* @var $proxy \Doctrine\Common\Proxy\Proxy */ /* @var $proxy \Doctrine\Common\Proxy\Proxy */

View File

@ -20,6 +20,7 @@
namespace Doctrine\Tests\ORM\Functional; namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\OrmTestCase;
/** /**
@ -90,7 +91,9 @@ class CustomTreeWalkersTest extends OrmTestCase
public function testSetUnknownQueryComponentThrowsException() public function testSetUnknownQueryComponentThrowsException()
{ {
$this->setExpectedException("Doctrine\ORM\Query\QueryException", "Invalid query component given for DQL alias 'x', requires 'metadata', 'parent', 'relation', 'map', 'nestingLevel' and 'token' keys."); $this->expectException(QueryException::class);
$this->expectExceptionMessage("Invalid query component given for DQL alias 'x', requires 'metadata', 'parent', 'relation', 'map', 'nestingLevel' and 'token' keys.");
$this->generateSql( $this->generateSql(
'select u from Doctrine\Tests\Models\CMS\CmsUser u', 'select u from Doctrine\Tests\Models\CMS\CmsUser u',
array(), array(),

View File

@ -84,7 +84,7 @@ class LanguageRecognitionTest extends OrmTestCase
*/ */
public function testRejectsInvalidDQL($dql) public function testRejectsInvalidDQL($dql)
{ {
$this->setExpectedException('\Doctrine\ORM\Query\QueryException'); $this->expectException(QueryException::class);
$this->_em->getConfiguration()->setEntityNamespaces(array( $this->_em->getConfiguration()->setEntityNamespaces(array(
'Unknown' => 'Unknown', 'Unknown' => 'Unknown',

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Query; namespace Doctrine\Tests\ORM\Query;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\ParserResult; use Doctrine\ORM\Query\ParserResult;
class ParserResultTest extends \PHPUnit_Framework_TestCase class ParserResultTest extends \PHPUnit_Framework_TestCase
@ -25,7 +26,7 @@ class ParserResultTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertNull($this->parserResult->getSqlExecutor()); $this->assertNull($this->parserResult->getSqlExecutor());
$executor = $this->getMock('Doctrine\ORM\Query\Exec\AbstractSqlExecutor', array('execute')); $executor = $this->getMockBuilder(AbstractSqlExecutor::class)->setMethods(array('execute'))->getMock();
$this->parserResult->setSqlExecutor($executor); $this->parserResult->setSqlExecutor($executor);
$this->assertSame($executor, $this->parserResult->getSqlExecutor()); $this->assertSame($executor, $this->parserResult->getSqlExecutor());
} }

View File

@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Query;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\OrmTestCase;
class ParserTest extends OrmTestCase class ParserTest extends OrmTestCase
@ -90,7 +91,7 @@ class ParserTest extends OrmTestCase
*/ */
public function testMatchFailure($expectedToken, $inputString) public function testMatchFailure($expectedToken, $inputString)
{ {
$this->setExpectedException('\Doctrine\ORM\Query\QueryException'); $this->expectException(QueryException::class);
$parser = $this->createParser($inputString); $parser = $this->createParser($inputString);

View File

@ -13,6 +13,7 @@ use Doctrine\ORM\Query as ORMQuery;
use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker; use Doctrine\ORM\Query\SqlWalker;
use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsGroup;
use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsPhonenumber;
@ -76,7 +77,7 @@ class SelectSqlGenerationTest extends OrmTestCase
*/ */
public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = array(), array $queryParams = array()) public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = array(), array $queryParams = array())
{ {
$this->setExpectedException($expectedException); $this->expectException($expectedException);
$query = $this->_em->createQuery($dqlToBeTested); $query = $this->_em->createQuery($dqlToBeTested);
@ -429,7 +430,7 @@ class SelectSqlGenerationTest extends OrmTestCase
*/ */
public function testJoinOnClause_NotYetSupported_ThrowsException() public function testJoinOnClause_NotYetSupported_ThrowsException()
{ {
$this->setExpectedException('Doctrine\ORM\Query\QueryException'); $this->expectException(QueryException::class);
$sql = $this->_em->createQuery( $sql = $this->_em->createQuery(
"SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a ON a.topic LIKE '%foo%'" "SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a ON a.topic LIKE '%foo%'"

View File

@ -1083,7 +1083,8 @@ class QueryBuilderTest extends OrmTestCase
*/ */
public function testWhereAppend() public function testWhereAppend()
{ {
$this->setExpectedException('InvalidArgumentException', "Using \$append = true does not have an effect with 'where' or 'having' parts. See QueryBuilder#andWhere() for an example for correct usage."); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("Using \$append = true does not have an effect with 'where' or 'having' parts. See QueryBuilder#andWhere() for an example for correct usage.");
$qb = $this->_em->createQueryBuilder() $qb = $this->_em->createQueryBuilder()
->add('where', 'u.foo = ?1') ->add('where', 'u.foo = ?1')

View File

@ -2,6 +2,9 @@
namespace Doctrine\Tests\ORM\Repository; namespace Doctrine\Tests\ORM\Repository;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Repository\DefaultRepositoryFactory; use Doctrine\ORM\Repository\DefaultRepositoryFactory;
use PHPUnit_Framework_TestCase; use PHPUnit_Framework_TestCase;
@ -32,7 +35,7 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase
*/ */
protected function setUp() protected function setUp()
{ {
$this->configuration = $this->getMock('Doctrine\\ORM\\Configuration'); $this->configuration = $this->createMock(Configuration::class);
$this->entityManager = $this->createEntityManager(); $this->entityManager = $this->createEntityManager();
$this->repositoryFactory = new DefaultRepositoryFactory(); $this->repositoryFactory = new DefaultRepositoryFactory();
@ -122,10 +125,7 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase
public function buildClassMetadata($className) public function buildClassMetadata($className)
{ {
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */ /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */
$metadata = $this $metadata = $this->createMock(ClassMetadata::class);
->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')
->disableOriginalConstructor()
->getMock();
$metadata->expects($this->any())->method('getName')->will($this->returnValue($className)); $metadata->expects($this->any())->method('getName')->will($this->returnValue($className));
@ -139,7 +139,7 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase
*/ */
private function createEntityManager() private function createEntityManager()
{ {
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface'); $entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager $entityManager
->expects($this->any()) ->expects($this->any())

View File

@ -3,17 +3,19 @@
namespace Doctrine\Tests\ORM\Tools\Console\Command; namespace Doctrine\Tests\ORM\Tools\Console\Command;
use Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand; use Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand;
use Doctrine\ORM\Tools\EntityGenerator;
use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\OrmTestCase;
use Symfony\Component\Console\Output\OutputInterface;
class ConvertDoctrine1SchemaCommandTest extends OrmTestCase class ConvertDoctrine1SchemaCommandTest extends OrmTestCase
{ {
public function testExecution() public function testExecution()
{ {
$entityGenerator = $this->getMock('Doctrine\ORM\Tools\EntityGenerator'); $entityGenerator = $this->createMock(EntityGenerator::class);
$command = new ConvertDoctrine1SchemaCommand(); $command = new ConvertDoctrine1SchemaCommand();
$command->setEntityGenerator($entityGenerator); $command->setEntityGenerator($entityGenerator);
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); $output = $this->createMock(OutputInterface::class);
$output->expects($this->once()) $output->expects($this->once())
->method('writeln') ->method('writeln')
->with($this->equalTo('No Metadata Classes to process.')); ->with($this->equalTo('No Metadata Classes to process.'));

View File

@ -613,7 +613,9 @@ class EntityGeneratorTest extends OrmTestCase
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
$this->setExpectedException('\InvalidArgumentException', 'Invalid provided InheritanceType: INVALID'); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid provided InheritanceType: INVALID');
$method->invoke($this->_generator, 'INVALID'); $method->invoke($this->_generator, 'INVALID');
} }
@ -640,7 +642,9 @@ class EntityGeneratorTest extends OrmTestCase
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
$this->setExpectedException('\InvalidArgumentException', 'Invalid provided ChangeTrackingPolicy: INVALID'); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid provided ChangeTrackingPolicy: INVALID');
$method->invoke($this->_generator, 'INVALID'); $method->invoke($this->_generator, 'INVALID');
} }
@ -667,7 +671,9 @@ class EntityGeneratorTest extends OrmTestCase
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
$this->setExpectedException('\InvalidArgumentException', 'Invalid provided IdGeneratorType: INVALID'); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid provided IdGeneratorType: INVALID');
$method->invoke($this->_generator, 'INVALID'); $method->invoke($this->_generator, 'INVALID');
} }

View File

@ -83,10 +83,8 @@ class CountWalkerTest extends PaginationTestCase
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker'));
$query->setFirstResult(null)->setMaxResults(null); $query->setFirstResult(null)->setMaxResults(null);
$this->setExpectedException( $this->expectException(\RuntimeException::class);
'RuntimeException', $this->expectExceptionMessage('Cannot count query that uses a HAVING clause. Use the output walkers for pagination');
'Cannot count query that uses a HAVING clause. Use the output walkers for pagination'
);
$query->getSQL(); $query->getSQL();
} }

View File

@ -3,6 +3,7 @@
namespace Doctrine\Tests\ORM\Tools; namespace Doctrine\Tests\ORM\Tools;
use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\Tools\Setup;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\ORM\Version; use Doctrine\ORM\Version;
use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\OrmTestCase;
@ -97,9 +98,7 @@ class SetupTest extends OrmTestCase
*/ */
public function testConfigureCacheCustomInstance() public function testConfigureCacheCustomInstance()
{ {
$cache = $this->getMock('Doctrine\Common\Cache\Cache'); $cache = $this->createMock(Cache::class);
$cache->expects($this->never())->method('setNamespace');
$config = Setup::createConfiguration(array(), true, $cache); $config = Setup::createConfiguration(array(), true, $cache);
$this->assertSame($cache, $config->getResultCacheImpl()); $this->assertSame($cache, $config->getResultCacheImpl());

View File

@ -248,7 +248,7 @@ class UnitOfWorkTest extends OrmTestCase
*/ */
public function testLockWithoutEntityThrowsException() public function testLockWithoutEntityThrowsException()
{ {
$this->setExpectedException('InvalidArgumentException'); $this->expectException(\InvalidArgumentException::class);
$this->_unitOfWork->lock(null, null, null); $this->_unitOfWork->lock(null, null, null);
} }
@ -273,7 +273,7 @@ class UnitOfWorkTest extends OrmTestCase
$user->username = 'John'; $user->username = 'John';
$user->avatar = $invalidValue; $user->avatar = $invalidValue;
$this->setExpectedException('Doctrine\ORM\ORMInvalidArgumentException'); $this->expectException(\Doctrine\ORM\ORMInvalidArgumentException::class);
$this->_unitOfWork->persist($user); $this->_unitOfWork->persist($user);
} }
@ -301,7 +301,7 @@ class UnitOfWorkTest extends OrmTestCase
$user->username = 'John'; $user->username = 'John';
$user->avatar = $invalidValue; $user->avatar = $invalidValue;
$this->setExpectedException('Doctrine\ORM\ORMInvalidArgumentException'); $this->expectException(\Doctrine\ORM\ORMInvalidArgumentException::class);
$this->_unitOfWork->computeChangeSet($metadata, $user); $this->_unitOfWork->computeChangeSet($metadata, $user);
} }

View File

@ -742,7 +742,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
* *
* @throws \Exception * @throws \Exception
*/ */
protected function onNotSuccessfulTest(\Exception $e) protected function onNotSuccessfulTest($e)
{ {
if ($e instanceof \PHPUnit_Framework_AssertionFailedError) { if ($e instanceof \PHPUnit_Framework_AssertionFailedError) {
throw $e; throw $e;