Skip to content

Commit

Permalink
Address deprecation about PHPUnit annotations
Browse files Browse the repository at this point in the history
These changes have been done using Rector, this might not result in the
best placement for method calls, but it is not worse than the current
situation.

I used the configuration documented at
https://github.com/rectorphp/rector/blob/b398e8740c3619525061350d4d4e1bca20dabea9/docs/HowItWorks.md#221-order-of-rectors

Fixes doctrine#8069
  • Loading branch information
greg0ire committed Mar 15, 2020
1 parent 1da002c commit e613844
Show file tree
Hide file tree
Showing 24 changed files with 97 additions and 182 deletions.
18 changes: 6 additions & 12 deletions tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php
Expand Up @@ -640,12 +640,10 @@ public function testGetAssociationValue()
$this->assertCount(1, $attractions[1]);
}

/**
* @expectedException Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second level cache does not support scalar results.
*/
public function testScalarResultException()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Second level cache does not support scalar results.');
$result = [];
$key = new QueryCacheKey('query.key1', 0);
$rsm = new ResultSetMappingBuilder($this->em);
Expand All @@ -655,12 +653,10 @@ public function testScalarResultException()
$this->queryCache->put($key, $rsm, $result);
}

/**
* @expectedException Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second level cache does not support multiple root entities.
*/
public function testSupportMultipleRootEntitiesException()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Second level cache does not support multiple root entities.');
$result = [];
$key = new QueryCacheKey('query.key1', 0);
$rsm = new ResultSetMappingBuilder($this->em);
Expand All @@ -671,12 +667,10 @@ public function testSupportMultipleRootEntitiesException()
$this->queryCache->put($key, $rsm, $result);
}

/**
* @expectedException Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Entity "Doctrine\Tests\Models\Generic\BooleanModel" not configured as part of the second-level cache.
*/
public function testNotCacheableEntityException()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Entity "Doctrine\Tests\Models\Generic\BooleanModel" not configured as part of the second-level cache.');
$result = [];
$key = new QueryCacheKey('query.key1', 0);
$rsm = new ResultSetMappingBuilder($this->em);
Expand Down
Expand Up @@ -22,12 +22,10 @@ protected function createPersister(EntityManager $em, EntityPersister $persister
return new ReadOnlyCachedEntityPersister($persister, $region, $em, $metadata);
}

/**
* @expectedException Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Cannot update a readonly entity "Doctrine\Tests\Models\Cache\Country"
*/
public function testInvokeUpdate()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Cannot update a readonly entity "Doctrine\Tests\Models\Cache\Country"');
$persister = $this->createPersisterDefault();
$entity = new Country("Foo");

Expand Down
17 changes: 6 additions & 11 deletions tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php
Expand Up @@ -306,18 +306,14 @@ public function testCountBy()
$this->assertSame(2, $userCount);
}

/**
* @expectedException \Doctrine\ORM\ORMException
*/
public function testExceptionIsThrownWhenCallingFindByWithoutParameter() {
$this->expectException('Doctrine\ORM\ORMException');
$this->_em->getRepository(CmsUser::class)
->findByStatus();
}

/**
* @expectedException \Doctrine\ORM\ORMException
*/
public function testExceptionIsThrownWhenUsingInvalidFieldName() {
$this->expectException('Doctrine\ORM\ORMException');
$this->_em->getRepository(CmsUser::class)
->findByThisFieldDoesNotExist('testvalue');
}
Expand Down Expand Up @@ -645,11 +641,11 @@ public function testDefaultRepositoryClassName()

/**
* @group DDC-753
* @expectedException Doctrine\ORM\ORMException
* @expectedExceptionMessage Invalid repository class 'Doctrine\Tests\Models\DDC753\DDC753InvalidRepository'. It must be a Doctrine\Common\Persistence\ObjectRepository.
*/
public function testSetDefaultRepositoryInvalidClassError()
{
$this->expectException('Doctrine\ORM\ORMException');
$this->expectExceptionMessage('Invalid repository class \'Doctrine\Tests\Models\DDC753\DDC753InvalidRepository\'. It must be a Doctrine\Common\Persistence\ObjectRepository.');
$this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), EntityRepository::class);
$this->_em->getConfiguration()->setDefaultRepositoryClassName(DDC753InvalidRepository::class);
}
Expand Down Expand Up @@ -683,12 +679,11 @@ public function testCanRetrieveRepositoryFromClassNameWithLeadingBackslash()

/**
* @group DDC-1376
*
* @expectedException Doctrine\ORM\ORMException
* @expectedExceptionMessage You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association.
*/
public function testInvalidOrderByAssociation()
{
$this->expectException('Doctrine\ORM\ORMException');
$this->expectExceptionMessage('You cannot search for the association field \'Doctrine\Tests\Models\CMS\CmsUser#address\', because it is the inverse side of an association.');
$this->_em->getRepository(CmsUser::class)
->findBy(['status' => 'test'], ['address' => 'ASC']);
}
Expand Down
4 changes: 1 addition & 3 deletions tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php
Expand Up @@ -341,11 +341,9 @@ public function testAbstractClassInSingleTableInheritanceSchemaWithRSMBuilderThr
$rsm->addRootEntityFromClassMetadata(CompanyContract::class, 'c');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testRSMBuilderThrowsExceptionOnColumnConflict()
{
$this->expectException('InvalidArgumentException');
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u');
$rsm->addJoinedEntityFromClassMetadata(CmsAddress::class, 'a', 'u', 'address');
Expand Down
24 changes: 8 additions & 16 deletions tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php
Expand Up @@ -1047,42 +1047,34 @@ public function testShouldSupportMultipleNewOperatorsAndMultipleScalarsWithAndWi
$this->assertEquals($this->fixtures[2]->username,$result[2]['cmsUserUsername']);
}

/**
* @expectedException Doctrine\ORM\Query\QueryException
* @expectedExceptionMessage [Semantical Error] line 0, col 11 near '\InvalidClass(u.name)': Error: Class "\InvalidClass" is not defined.
*/
public function testInvalidClassException()
{
$this->expectException('Doctrine\ORM\Query\QueryException');
$this->expectExceptionMessage('[Semantical Error] line 0, col 11 near \'\InvalidClass(u.name)\': Error: Class "\InvalidClass" is not defined.');
$dql = "SELECT new \InvalidClass(u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u";
$this->_em->createQuery($dql)->getResult();
}

/**
* @expectedException Doctrine\ORM\Query\QueryException
* @expectedExceptionMessage [Semantical Error] line 0, col 11 near '\stdClass(u.name)': Error: Class "\stdClass" has not a valid constructor.
*/
public function testInvalidClassConstructorException()
{
$this->expectException('Doctrine\ORM\Query\QueryException');
$this->expectExceptionMessage('[Semantical Error] line 0, col 11 near \'\stdClass(u.name)\': Error: Class "\stdClass" has not a valid constructor.');
$dql = "SELECT new \stdClass(u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u";
$this->_em->createQuery($dql)->getResult();
}

/**
* @expectedException Doctrine\ORM\Query\QueryException
* @expectedExceptionMessage [Semantical Error] line 0, col 11 near 'Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs(u.name)': Error: Number of arguments does not match with "Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs" constructor declaration.
*/
public function testInvalidClassWithoutConstructorException()
{
$this->expectException('Doctrine\ORM\Query\QueryException');
$this->expectExceptionMessage('[Semantical Error] line 0, col 11 near \'Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs(u.name)\': Error: Number of arguments does not match with "Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs" constructor declaration.');
$dql = "SELECT new Doctrine\Tests\ORM\Functional\ClassWithTooMuchArgs(u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u";
$this->_em->createQuery($dql)->getResult();
}

/**
* @expectedException Doctrine\ORM\Query\QueryException
* @expectedExceptionMessage [Semantical Error] line 0, col 11 near 'Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor(u.name)': Error: Class "Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor" can not be instantiated.
*/
public function testClassCantBeInstantiatedException()
{
$this->expectException('Doctrine\ORM\Query\QueryException');
$this->expectExceptionMessage('[Semantical Error] line 0, col 11 near \'Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor(u.name)\': Error: Class "Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor" can not be instantiated.');
$dql = "SELECT new Doctrine\Tests\ORM\Functional\ClassWithPrivateConstructor(u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u";
$this->_em->createQuery($dql)->getResult();
}
Expand Down
16 changes: 4 additions & 12 deletions tests/Doctrine/Tests/ORM/Functional/QueryTest.php
Expand Up @@ -315,38 +315,30 @@ public function testIterateResultClearEveryCycle()
$this->_em->flush();
}

/**
* @expectedException \Doctrine\ORM\Query\QueryException
*/
public function testIterateResult_FetchJoinedCollection_ThrowsException()
{
$this->expectException('Doctrine\ORM\Query\QueryException');
$query = $this->_em->createQuery("SELECT u, a FROM ' . CmsUser::class . ' u JOIN u.articles a");
$articles = $query->iterate();
}

/**
* @expectedException Doctrine\ORM\NoResultException
*/
public function testGetSingleResultThrowsExceptionOnNoResult()
{
$this->expectException('Doctrine\ORM\NoResultException');
$this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a")
->getSingleResult();
}

/**
* @expectedException Doctrine\ORM\NoResultException
*/
public function testGetSingleScalarResultThrowsExceptionOnNoResult()
{
$this->expectException('Doctrine\ORM\NoResultException');
$this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a")
->getSingleScalarResult();
}

/**
* @expectedException Doctrine\ORM\NonUniqueResultException
*/
public function testGetSingleScalarResultThrowsExceptionOnNonUniqueResult()
{
$this->expectException('Doctrine\ORM\NonUniqueResultException');
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
Expand Down
Expand Up @@ -186,12 +186,10 @@ public function testStoreManyToManyAssociationWhitCascade()
$this->assertEquals($queryCount1, $this->getCurrentQueryCount());
}

/**
* @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Cannot update a readonly collection "Doctrine\Tests\Models\Cache\Travel#visitedCities
*/
public function testReadOnlyCollection()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Cannot update a readonly collection "Doctrine\Tests\Models\Cache\Travel#visitedCities');
$this->evictRegions();

$this->loadFixturesCountries();
Expand Down
Expand Up @@ -1085,12 +1085,10 @@ public function testHintClearEntityRegionDeleteStatement()
$this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId()));
}

/**
* @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second level cache does not support partial entities.
*/
public function testCacheablePartialQueryException()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Second level cache does not support partial entities.');
$this->evictRegions();
$this->loadFixturesCountries();

Expand All @@ -1100,23 +1098,19 @@ public function testCacheablePartialQueryException()
->getResult();
}

/**
* @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second-level cache query supports only select statements.
*/
public function testNonCacheableQueryDeleteStatementException()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Second-level cache query supports only select statements.');
$this->_em->createQuery("DELETE Doctrine\Tests\Models\Cache\Country u WHERE u.id = 4")
->setCacheable(true)
->getResult();
}

/**
* @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second-level cache query supports only select statements.
*/
public function testNonCacheableQueryUpdateStatementException()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Second-level cache query supports only select statements.');
$this->_em->createQuery("UPDATE Doctrine\Tests\Models\Cache\Country u SET u.name = 'foo' WHERE u.id = 4")
->setCacheable(true)
->getResult();
Expand Down
6 changes: 2 additions & 4 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php
Expand Up @@ -49,12 +49,10 @@ public function testIssue()
$this->assertEquals('Foo', $e->getMyEntity2()->getValue());
}

/**
* @expectedException \Doctrine\ORM\ORMInvalidArgumentException
* @expectedExceptionMessage Binding entities to query parameters only allowed for entities that have an identifier.
*/
public function testinvalidIdentifierBindingEntityException()
{
$this->expectException('Doctrine\ORM\ORMInvalidArgumentException');
$this->expectExceptionMessage('Binding entities to query parameters only allowed for entities that have an identifier.');
$this->_em->find(__NAMESPACE__ . '\DDC2084\MyEntity1', new DDC2084\MyEntity2('Foo'));
}
}
Expand Down
15 changes: 6 additions & 9 deletions tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php
Expand Up @@ -1822,12 +1822,11 @@ public function testIndexByScalarsOnly($userEntityKey)

/**
* @group DDC-1470
*
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
* @expectedExceptionMessage The meta mapping for the discriminator column "c_discr" is missing for "Doctrine\Tests\Models\Company\CompanyFixContract" using the DQL alias "c".
*/
public function testMissingMetaMappingException()
{
$this->expectException('Doctrine\ORM\Internal\Hydration\HydrationException');
$this->expectExceptionMessage('The meta mapping for the discriminator column "c_discr" is missing for "Doctrine\Tests\Models\Company\CompanyFixContract" using the DQL alias "c".');
$rsm = new ResultSetMapping;

$rsm->addEntityResult(CompanyFixContract::class, 'c');
Expand All @@ -1849,12 +1848,11 @@ public function testMissingMetaMappingException()

/**
* @group DDC-1470
*
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
* @expectedExceptionMessage The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyEmployee" using the DQL alias "e".
*/
public function testMissingDiscriminatorColumnException()
{
$this->expectException('Doctrine\ORM\Internal\Hydration\HydrationException');
$this->expectExceptionMessage('The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyEmployee" using the DQL alias "e".');
$rsm = new ResultSetMapping;

$rsm->addEntityResult(CompanyFixContract::class, 'c');
Expand Down Expand Up @@ -1883,12 +1881,11 @@ public function testMissingDiscriminatorColumnException()

/**
* @group DDC-3076
*
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
* @expectedExceptionMessage The discriminator value "subworker" is invalid. It must be one of "person", "manager", "employee".
*/
public function testInvalidDiscriminatorValueException()
{
$this->expectException('Doctrine\ORM\Internal\Hydration\HydrationException');
$this->expectExceptionMessage('The discriminator value "subworker" is invalid. It must be one of "person", "manager", "employee".');
$rsm = new ResultSetMapping;

$rsm->addEntityResult(CompanyPerson::class, 'p');
Expand Down
10 changes: 4 additions & 6 deletions tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php
Expand Up @@ -14,12 +14,11 @@ class SimpleObjectHydratorTest extends HydrationTestCase
{
/**
* @group DDC-1470
*
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
* @expectedExceptionMessage The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyPerson" using the DQL alias "p".
*/
public function testMissingDiscriminatorColumnException()
{
$this->expectException('Doctrine\ORM\Internal\Hydration\HydrationException');
$this->expectExceptionMessage('The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyPerson" using the DQL alias "p".');
$rsm = new ResultSetMapping;
$rsm->addEntityResult(CompanyPerson::class, 'p');
$rsm->addFieldResult('p', 'p__id', 'id');
Expand Down Expand Up @@ -64,12 +63,11 @@ public function testExtraFieldInResultSetShouldBeIgnore()

/**
* @group DDC-3076
*
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
* @expectedExceptionMessage The discriminator value "subworker" is invalid. It must be one of "person", "manager", "employee".
*/
public function testInvalidDiscriminatorValueException()
{
$this->expectException('Doctrine\ORM\Internal\Hydration\HydrationException');
$this->expectExceptionMessage('The discriminator value "subworker" is invalid. It must be one of "person", "manager", "employee".');
$rsm = new ResultSetMapping;

$rsm->addEntityResult(CompanyPerson::class, 'p');
Expand Down
6 changes: 2 additions & 4 deletions tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php
Expand Up @@ -33,12 +33,10 @@ public function testLoadMetadataForNonEntityThrowsException()
$annotationDriver->loadMetadataForClass('stdClass', $cm);
}

/**
* @expectedException Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Entity association field "Doctrine\Tests\ORM\Mapping\AnnotationSLC#foo" not configured as part of the second-level cache.
*/
public function testFailingSecondLevelCacheAssociation()
{
$this->expectException('Doctrine\ORM\Cache\CacheException');
$this->expectExceptionMessage('Entity association field "Doctrine\Tests\ORM\Mapping\AnnotationSLC#foo" not configured as part of the second-level cache.');
$mappingDriver = $this->_loadDriver();

$class = new ClassMetadata(AnnotationSLC::class);
Expand Down

0 comments on commit e613844

Please sign in to comment.