Skip to content

Commit

Permalink
minor #32875 [PhpUnitBridge] Remove @ExpectedException annotation (jd…
Browse files Browse the repository at this point in the history
…erusse)

This PR was squashed before being merged into the 3.4 branch (closes #32875).

Discussion
----------

[PhpUnitBridge] Remove @ExpectedException annotation

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32844
| License       | MIT
| Doc PR        | NA

this PR replaces the deprecated annotation `@expectedException` by calls to the method `expectException`.

To automate the process, I used rector/rector:
```
./vendor/bin/rector process src/Symfony --set phpunit60 -a .phpunit/phpunit-6.5/vendor/autoload.php
```
Which also replace `PHPUnit_Framework_Error_X` by `\PHPUnit\Framework\Error\X`

Commits
-------

a22a9c4 Fix tests
3a626e8 Fix deprecated phpunit annotation
  • Loading branch information
nicolas-grekas committed Aug 2, 2019
2 parents 725187f + a22a9c4 commit 8173daf
Show file tree
Hide file tree
Showing 422 changed files with 2,573 additions and 4,121 deletions.
Expand Up @@ -13,17 +13,18 @@

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class RegisterEventListenersAndSubscribersPassTest extends TestCase
{
/**
* @expectedException \InvalidArgumentException
*/
use ForwardCompatTestTrait;

public function testExceptionOnAbstractTaggedSubscriber()
{
$this->expectException('InvalidArgumentException');
$container = $this->createBuilder();

$abstractDefinition = new Definition('stdClass');
Expand All @@ -35,11 +36,9 @@ public function testExceptionOnAbstractTaggedSubscriber()
$this->process($container);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testExceptionOnAbstractTaggedListener()
{
$this->expectException('InvalidArgumentException');
$container = $this->createBuilder();

$abstractDefinition = new Definition('stdClass');
Expand Down
Expand Up @@ -4,17 +4,18 @@

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

class RegisterMappingsPassTest extends TestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageould Could not find the manager name parameter in the container. Tried the following parameter names: "manager.param.one", "manager.param.two"
*/
use ForwardCompatTestTrait;

public function testNoDriverParmeterException()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Could not find the manager name parameter in the container. Tried the following parameter names: "manager.param.one", "manager.param.two"');
$container = $this->createBuilder();
$this->process($container, [
'manager.param.one',
Expand Down
Expand Up @@ -52,11 +52,9 @@ private function doSetUp()
});
}

/**
* @expectedException \LogicException
*/
public function testFixManagersAutoMappingsWithTwoAutomappings()
{
$this->expectException('LogicException');
$emConfigs = [
'em1' => [
'auto_mapping' => true,
Expand Down Expand Up @@ -241,12 +239,10 @@ public function testServiceCacheDriver()
$this->assertTrue($container->hasAlias('doctrine.orm.default_metadata_cache'));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage "unrecognized_type" is an unrecognized Doctrine cache driver.
*/
public function testUnrecognizedCacheDriverException()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('"unrecognized_type" is an unrecognized Doctrine cache driver.');
$cacheName = 'metadata_cache';
$container = $this->createContainer();
$objectManager = [
Expand Down
Expand Up @@ -65,11 +65,9 @@ public function testTransformNull()
$this->assertSame([], $this->transformer->transform(null));
}

/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testTransformExpectsArrayOrCollection()
{
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
$this->transformer->transform('Foo');
}

Expand Down
16 changes: 4 additions & 12 deletions src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
Expand Up @@ -118,19 +118,15 @@ protected function persist(array $entities)
// be managed!
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
*/
public function testClassOptionIsRequired()
{
$this->expectException('Symfony\Component\OptionsResolver\Exception\MissingOptionsException');
$this->factory->createNamed('name', static::TESTED_TYPE);
}

/**
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
*/
public function testInvalidClassOption()
{
$this->expectException('Symfony\Component\Form\Exception\RuntimeException');
$this->factory->createNamed('name', static::TESTED_TYPE, null, [
'class' => 'foo',
]);
Expand Down Expand Up @@ -190,23 +186,19 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
$this->assertEquals([1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')], $view->vars['choices']);
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
{
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
'query_builder' => new \stdClass(),
]);
}

/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
{
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
Expand Down
Expand Up @@ -83,12 +83,10 @@ public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty
$this->assertSame($user, $provider->loadUserByUsername('user1'));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.
*/
public function testLoadUserByUsernameWithNonUserLoaderRepositoryAndWithoutProperty()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.');
$em = DoctrineTestHelper::createTestEntityManager();
$this->createSchema($em);

Expand Down Expand Up @@ -168,11 +166,9 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
$provider->loadUserByUsername('name');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testLoadUserByUserNameShouldDeclineInvalidInterface()
{
$this->expectException('InvalidArgumentException');
$repository = $this->getMockBuilder('\Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();

$provider = new EntityUserProvider(
Expand Down
Expand Up @@ -278,11 +278,9 @@ public function testValidateUniquenessWithIgnoreNullDisabled()
->assertRaised();
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
*/
public function testAllConfiguredFieldsAreCheckedOfBeingMappedByDoctrineWithIgnoreNullEnabled()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$constraint = new UniqueEntity([
'message' => 'myMessage',
'fields' => ['name', 'name2'],
Expand Down Expand Up @@ -589,12 +587,10 @@ public function testValidateUniquenessWithArrayValue()
->assertRaised();
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
* @expectedExceptionMessage Object manager "foo" does not exist.
*/
public function testDedicatedEntityManagerNullObject()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectExceptionMessage('Object manager "foo" does not exist.');
$constraint = new UniqueEntity([
'message' => 'myMessage',
'fields' => ['name'],
Expand All @@ -611,12 +607,10 @@ public function testDedicatedEntityManagerNullObject()
$this->validator->validate($entity, $constraint);
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
* @expectedExceptionMessage Unable to find the object manager associated with an entity of class "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity"
*/
public function testEntityManagerNullObject()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectExceptionMessage('Unable to find the object manager associated with an entity of class "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity"');
$constraint = new UniqueEntity([
'message' => 'myMessage',
'fields' => ['name'],
Expand Down Expand Up @@ -695,12 +689,10 @@ public function testValidateInheritanceUniqueness()
->assertRaised();
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
* @expectedExceptionMessage The "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity" entity repository does not support the "Symfony\Bridge\Doctrine\Tests\Fixtures\Person" entity. The entity should be an instance of or extend "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity".
*/
public function testInvalidateRepositoryForInheritance()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectExceptionMessage('The "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity" entity repository does not support the "Symfony\Bridge\Doctrine\Tests\Fixtures\Person" entity. The entity should be an instance of or extend "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity".');
$constraint = new UniqueEntity([
'message' => 'myMessage',
'fields' => ['name'],
Expand Down
24 changes: 6 additions & 18 deletions src/Symfony/Bridge/Twig/Tests/AppVariableTest.php
Expand Up @@ -117,51 +117,39 @@ public function testGetUserWithNoToken()
$this->assertNull($this->appVariable->getUser());
}

/**
* @expectedException \RuntimeException
*/
public function testEnvironmentNotSet()
{
$this->expectException('RuntimeException');
$this->appVariable->getEnvironment();
}

/**
* @expectedException \RuntimeException
*/
public function testDebugNotSet()
{
$this->expectException('RuntimeException');
$this->appVariable->getDebug();
}

/**
* @expectedException \RuntimeException
*/
public function testGetTokenWithTokenStorageNotSet()
{
$this->expectException('RuntimeException');
$this->appVariable->getToken();
}

/**
* @expectedException \RuntimeException
*/
public function testGetUserWithTokenStorageNotSet()
{
$this->expectException('RuntimeException');
$this->appVariable->getUser();
}

/**
* @expectedException \RuntimeException
*/
public function testGetRequestWithRequestStackNotSet()
{
$this->expectException('RuntimeException');
$this->appVariable->getRequest();
}

/**
* @expectedException \RuntimeException
*/
public function testGetSessionWithRequestStackNotSet()
{
$this->expectException('RuntimeException');
$this->appVariable->getSession();
}

Expand Down
8 changes: 3 additions & 5 deletions src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php
Expand Up @@ -48,11 +48,9 @@ public function testLintIncorrectFile()
$this->assertRegExp('/ERROR in \S+ \(line /', trim($tester->getDisplay()));
}

/**
* @expectedException \RuntimeException
*/
public function testLintFileNotReadable()
{
$this->expectException('RuntimeException');
$tester = $this->createCommandTester();
$filename = $this->createFile('');
unlink($filename);
Expand All @@ -74,11 +72,11 @@ public function testLintFileCompileTimeException()
/**
* @group legacy
* @expectedDeprecation Passing a command name as the first argument of "Symfony\Bridge\Twig\Command\LintCommand::__construct()" is deprecated since Symfony 3.4 and support for it will be removed in 4.0. If the command was registered by convention, make it a service instead.
* @expectedException \RuntimeException
* @expectedExceptionMessage The Twig environment needs to be set.
*/
public function testLegacyLintCommand()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('The Twig environment needs to be set.');
$command = new LintCommand();

$application = new Application();
Expand Down
Expand Up @@ -25,11 +25,9 @@ class HttpKernelExtensionTest extends TestCase
{
use ForwardCompatTestTrait;

/**
* @expectedException \Twig\Error\RuntimeError
*/
public function testFragmentWithError()
{
$this->expectException('Twig\Error\RuntimeError');
$renderer = $this->getFragmentHandler($this->throwException(new \Exception('foo')));

$this->renderTemplate($renderer);
Expand Down
Expand Up @@ -12,18 +12,19 @@
namespace Symfony\Bridge\Twig\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
use Twig\Environment;
use Twig\Error\RuntimeError;
use Twig\Loader\ArrayLoader;

class StopwatchExtensionTest extends TestCase
{
/**
* @expectedException \Twig\Error\SyntaxError
*/
use ForwardCompatTestTrait;

public function testFailIfStoppingWrongEvent()
{
$this->expectException('Twig\Error\SyntaxError');
$this->testTiming('{% stopwatch "foo" %}{% endstopwatch "bar" %}', []);
}

Expand Down

0 comments on commit 8173daf

Please sign in to comment.