Skip to content

Commit

Permalink
Fix deprecated phpunit annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Aug 1, 2019
1 parent 61ecb70 commit ce9e68b
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 245 deletions.
64 changes: 23 additions & 41 deletions Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,10 @@ public function testAdd()
$this->assertEquals([$foo, $foo1], [$commands['foo:bar'], $commands['foo:bar1']], '->addCommands() registers an array of commands');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Command class "Foo5Command" is not correctly initialized. You probably forgot to call the parent constructor.
*/
public function testAddCommandWithEmptyConstructor()
{
$this->expectException('LogicException');
$this->expectExceptionMessage('Command class "Foo5Command" is not correctly initialized. You probably forgot to call the parent constructor.');
$application = new Application();
$application->add(new \Foo5Command());
}
Expand Down Expand Up @@ -269,12 +267,10 @@ public function testSilentHelp()
$this->assertEmpty($tester->getDisplay(true));
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage The command "foofoo" does not exist.
*/
public function testGetInvalidCommand()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$this->expectExceptionMessage('The command "foofoo" does not exist.');
$application = new Application();
$application->get('foofoo');
}
Expand Down Expand Up @@ -328,22 +324,18 @@ public function testFindNonAmbiguous()
$this->assertEquals('test-ambiguous', $application->find('test')->getName());
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
*/
public function testFindInvalidNamespace()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$this->expectExceptionMessage('There are no commands defined in the "bar" namespace.');
$application = new Application();
$application->findNamespace('bar');
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage Command "foo1" is not defined
*/
public function testFindUniqueNameButNamespaceName()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$this->expectExceptionMessage('Command "foo1" is not defined');
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo1Command());
Expand Down Expand Up @@ -386,12 +378,10 @@ public function testFindCaseInsensitiveAsFallback()
$this->assertInstanceOf('FooSameCaseLowercaseCommand', $application->find('FoO:BaR'), '->find() will fallback to case insensitivity');
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage Command "FoO:BaR" is ambiguous
*/
public function testFindCaseInsensitiveSuggestions()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$this->expectExceptionMessage('Command "FoO:BaR" is ambiguous');
$application = new Application();
$application->add(new \FooSameCaseLowercaseCommand());
$application->add(new \FooSameCaseUppercaseCommand());
Expand Down Expand Up @@ -479,12 +469,12 @@ public function testFindCommandWithMissingNamespace()
}

/**
* @dataProvider provideInvalidCommandNamesSingle
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage Did you mean this
* @dataProvider provideInvalidCommandNamesSingle
*/
public function testFindAlternativeExceptionMessageSingle($name)
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$this->expectExceptionMessage('Did you mean this');
$application = new Application();
$application->add(new \Foo3Command());
$application->find($name);
Expand Down Expand Up @@ -660,12 +650,10 @@ public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces()
$this->assertEquals('foo:sublong', $application->findNamespace('f:sub'));
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
* @expectedExceptionMessage Command "foo::bar" is not defined.
*/
public function testFindWithDoubleColonInNameThrowsException()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$this->expectExceptionMessage('Command "foo::bar" is not defined.');
$application = new Application();
$application->add(new \FooCommand());
$application->add(new \Foo4Command());
Expand Down Expand Up @@ -1035,12 +1023,10 @@ public function testRunDispatchesExitCodeOneForExceptionCodeZero()
$this->assertTrue($passedRightValue, '-> exit code 1 was passed in the console.terminate event');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage An option with shortcut "e" already exists.
*/
public function testAddingOptionWithDuplicateShortcut()
{
$this->expectException('LogicException');
$this->expectExceptionMessage('An option with shortcut "e" already exists.');
$dispatcher = new EventDispatcher();
$application = new Application();
$application->setAutoExit(false);
Expand All @@ -1063,11 +1049,11 @@ public function testAddingOptionWithDuplicateShortcut()
}

/**
* @expectedException \LogicException
* @dataProvider getAddingAlreadySetDefinitionElementData
*/
public function testAddingAlreadySetDefinitionElementData($def)
{
$this->expectException('LogicException');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
Expand Down Expand Up @@ -1216,12 +1202,10 @@ public function testRunWithDispatcher()
$this->assertEquals('before.foo.after.'.PHP_EOL, $tester->getDisplay());
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage error
*/
public function testRunWithExceptionAndDispatcher()
{
$this->expectException('LogicException');
$this->expectExceptionMessage('error');
$application = new Application();
$application->setDispatcher($this->getDispatcher());
$application->setAutoExit(false);
Expand Down Expand Up @@ -1396,11 +1380,11 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()

/**
* @requires PHP 7
* @expectedException \LogicException
* @expectedExceptionMessage error
*/
public function testRunWithErrorAndDispatcher()
{
$this->expectException('LogicException');
$this->expectExceptionMessage('error');
$application = new Application();
$application->setDispatcher($this->getDispatcher());
$application->setAutoExit(false);
Expand Down Expand Up @@ -1650,11 +1634,9 @@ public function testRunLazyCommandService()
$this->assertSame(['lazy:alias', 'lazy:alias2'], $command->getAliases());
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
*/
public function testGetDisabledLazyCommand()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
$application = new Application();
$application->setCommandLoader(new FactoryCommandLoader(['disabled' => function () { return new DisabledCommand(); }]));
$application->get('disabled');
Expand Down
24 changes: 8 additions & 16 deletions Tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ public function testConstructor()
$this->assertEquals('foo:bar', $command->getName(), '__construct() takes the command name as its first argument');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage The command defined in "Symfony\Component\Console\Command\Command" cannot have an empty name.
*/
public function testCommandNameCannotBeEmpty()
{
$this->expectException('LogicException');
$this->expectExceptionMessage('The command defined in "Symfony\Component\Console\Command\Command" cannot have an empty name.');
(new Application())->add(new Command());
}

Expand Down Expand Up @@ -217,12 +215,10 @@ public function testGetHelper()
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->getHelper() returns the correct helper');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Cannot retrieve helper "formatter" because there is no HelperSet defined.
*/
public function testGetHelperWithoutHelperSet()
{
$this->expectException('LogicException');
$this->expectExceptionMessage('Cannot retrieve helper "formatter" because there is no HelperSet defined.');
$command = new \TestCommand();
$command->getHelper('formatter');
}
Expand Down Expand Up @@ -290,22 +286,18 @@ public function testRunNonInteractive()
$this->assertEquals('execute called'.PHP_EOL, $tester->getDisplay(), '->run() does not call the interact() method if the input is not interactive');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage You must override the execute() method in the concrete command class.
*/
public function testExecuteMethodNeedsToBeOverridden()
{
$this->expectException('LogicException');
$this->expectExceptionMessage('You must override the execute() method in the concrete command class.');
$command = new Command('foo');
$command->run(new StringInput(''), new NullOutput());
}

/**
* @expectedException \Symfony\Component\Console\Exception\InvalidOptionException
* @expectedExceptionMessage The "--bar" option does not exist.
*/
public function testRunWithInvalidOption()
{
$this->expectException('Symfony\Component\Console\Exception\InvalidOptionException');
$this->expectExceptionMessage('The "--bar" option does not exist.');
$command = new \TestCommand();
$tester = new CommandTester($command);
$tester->execute(['--bar' => true]);
Expand Down
7 changes: 4 additions & 3 deletions Tests/CommandLoader/ContainerCommandLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
namespace Symfony\Component\Console\Tests\CommandLoader;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
use Symfony\Component\DependencyInjection\ServiceLocator;

class ContainerCommandLoaderTest extends TestCase
{
use ForwardCompatTestTrait;

public function testHas()
{
$loader = new ContainerCommandLoader(new ServiceLocator([
Expand All @@ -41,11 +44,9 @@ public function testGet()
$this->assertInstanceOf(Command::class, $loader->get('bar'));
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
*/
public function testGetUnknownCommandThrows()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
(new ContainerCommandLoader(new ServiceLocator([]), []))->get('unknown');
}

Expand Down
7 changes: 4 additions & 3 deletions Tests/CommandLoader/FactoryCommandLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
namespace Symfony\Component\Console\Tests\CommandLoader;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;

class FactoryCommandLoaderTest extends TestCase
{
use ForwardCompatTestTrait;

public function testHas()
{
$loader = new FactoryCommandLoader([
Expand All @@ -40,11 +43,9 @@ public function testGet()
$this->assertInstanceOf(Command::class, $loader->get('bar'));
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
*/
public function testGetUnknownCommandThrows()
{
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
(new FactoryCommandLoader([]))->get('unknown');
}

Expand Down
21 changes: 9 additions & 12 deletions Tests/DependencyInjection/AddConsoleCommandPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Console\Tests\DependencyInjection;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
Expand All @@ -24,6 +25,8 @@

class AddConsoleCommandPassTest extends TestCase
{
use ForwardCompatTestTrait;

/**
* @dataProvider visibilityProvider
*/
Expand Down Expand Up @@ -121,12 +124,10 @@ public function visibilityProvider()
];
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
*/
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('The service "my-command" tagged "console.command" must not be abstract.');
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
Expand All @@ -139,12 +140,10 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
$container->compile();
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".
*/
public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".');
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
Expand Down Expand Up @@ -227,12 +226,10 @@ public function testProcessOnChildDefinitionWithParentClass()
$this->assertInstanceOf($className, $command);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage The definition for "my-child-command" has no class.
*/
public function testProcessOnChildDefinitionWithoutClass()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('The definition for "my-child-command" has no class.');
$container = new ContainerBuilder();
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);

Expand Down
7 changes: 4 additions & 3 deletions Tests/Formatter/OutputFormatterStyleStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
namespace Symfony\Component\Console\Tests\Formatter;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Formatter\OutputFormatterStyleStack;

class OutputFormatterStyleStackTest extends TestCase
{
use ForwardCompatTestTrait;

public function testPush()
{
$stack = new OutputFormatterStyleStack();
Expand Down Expand Up @@ -59,11 +62,9 @@ public function testPopNotLast()
$this->assertEquals($s1, $stack->pop());
}

/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidPop()
{
$this->expectException('InvalidArgumentException');
$stack = new OutputFormatterStyleStack();
$stack->push(new OutputFormatterStyle('white', 'black'));
$stack->pop(new OutputFormatterStyle('yellow', 'blue'));
Expand Down
Loading

0 comments on commit ce9e68b

Please sign in to comment.