diff --git a/src/Symfony/Components/Console/Command/Command.php b/src/Symfony/Components/Console/Command/Command.php
index 25b2a0091d..17e7b0a9e0 100644
--- a/src/Symfony/Components/Console/Command/Command.php
+++ b/src/Symfony/Components/Console/Command/Command.php
@@ -294,7 +294,7 @@ class Command
if (!$name)
{
- throw new \InvalidArgumentException('A command name cannot be empty');
+ throw new \InvalidArgumentException('A command name cannot be empty.');
}
$this->namespace = $namespace;
diff --git a/src/Symfony/Components/Console/Input/ArrayInput.php b/src/Symfony/Components/Console/Input/ArrayInput.php
index 71cdefc36f..3af76e3171 100644
--- a/src/Symfony/Components/Console/Input/ArrayInput.php
+++ b/src/Symfony/Components/Console/Input/ArrayInput.php
@@ -124,7 +124,7 @@ class ArrayInput extends Input
{
if (!$this->definition->hasShortcut($shortcut))
{
- throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
+ throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
}
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
@@ -136,13 +136,14 @@ class ArrayInput extends Input
* @param string $name The long option key
* @param mixed $value The value for the option
*
- * @throws \RuntimeException When option given doesn't exist
+ * @throws \InvalidArgumentException When option given doesn't exist
+ * @throws \InvalidArgumentException When a required value is missing
*/
protected function addLongOption($name, $value)
{
if (!$this->definition->hasOption($name))
{
- throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
+ throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
}
$option = $this->definition->getOption($name);
@@ -151,7 +152,7 @@ class ArrayInput extends Input
{
if ($option->isParameterRequired())
{
- throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
+ throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
}
$value = $option->isParameterOptional() ? $option->getDefault() : true;
@@ -166,13 +167,13 @@ class ArrayInput extends Input
* @param string $name The argument name
* @param mixed $value The value for the argument
*
- * @throws \RuntimeException When option given doesn't exist
+ * @throws \InvalidArgumentException When argument given doesn't exist
*/
protected function addArgument($name, $value)
{
if (!$this->definition->hasArgument($name))
{
- throw new \RuntimeException(sprintf('The "%s" argument does not exist.', $name));
+ throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
}
$this->arguments[$name] = $value;
diff --git a/tests/Symfony/Tests/Components/Console/ApplicationTest.php b/tests/Symfony/Tests/Components/Console/ApplicationTest.php
index a78bc7aed7..adf84e9c2f 100644
--- a/tests/Symfony/Tests/Components/Console/ApplicationTest.php
+++ b/tests/Symfony/Tests/Components/Console/ApplicationTest.php
@@ -59,7 +59,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testHelp()
{
$application = new Application();
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_gethelp.txt'), $application->getHelp(), '->setHelp() returns a help message');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $application->getHelp(), '->setHelp() returns a help message');
}
public function testGetCommands()
@@ -97,7 +97,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
{
$application = new Application();
$this->assertTrue($application->hasCommand('list'), '->hasCommand() returns true if a named command is registered');
- $this->assertTrue(!$application->hasCommand('afoobar'), '->hasCommand() returns false if a named command is not registered');
+ $this->assertFalse($application->hasCommand('afoobar'), '->hasCommand() returns false if a named command is not registered');
$application->addCommand($foo = new \FooCommand());
$this->assertTrue($application->hasCommand('afoobar'), '->hasCommand() returns true if an alias is registered');
@@ -109,8 +109,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->getCommand('foofoo');
$this->fail('->getCommand() throws an \InvalidArgumentException if the command does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getCommand() throws an \InvalidArgumentException if the command does not exist');
+ $this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->getCommand() throws an \InvalidArgumentException if the command does not exist');
}
$application = new TestApplication();
@@ -141,8 +143,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->findNamespace('f');
$this->fail('->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
+ $this->assertEquals('The namespace "f" is ambiguous (foo, foo1).', $e->getMessage(), '->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
}
try
@@ -150,8 +154,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->findNamespace('bar');
$this->fail('->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
+ $this->assertEquals('There are no commands defined in the "bar" namespace.', $e->getMessage(), '->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
}
}
@@ -173,8 +179,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->findCommand('f');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
+ $this->assertEquals('Command "f" is not defined.', $e->getMessage(), '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
}
try
@@ -182,8 +190,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->findCommand('a');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
+ $this->assertEquals('Command "a" is ambiguous (afoobar, afoobar1 and 1 more).', $e->getMessage(), '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
}
try
@@ -191,8 +201,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->findCommand('foo:b');
$this->fail('->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
+ $this->assertEquals('Command "foo:b" is ambiguous (foo:bar, foo:bar1).', $e->getMessage(), '->findCommand() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
}
}
@@ -204,7 +216,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->setCatchExceptions(true);
$tester->run(array('command' => 'foo'));
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_renderexception1.txt'), $tester->getDisplay(), '->setCatchExceptions() sets the catch exception flag');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(), '->setCatchExceptions() sets the catch exception flag');
$application->setCatchExceptions(false);
try
@@ -214,6 +226,8 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->setCatchExceptions() sets the catch exception flag');
+ $this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag');
}
}
@@ -221,16 +235,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
{
$application = new Application();
$application->addCommand(new \FooCommand);
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_astext1.txt'), $application->asText(), '->asText() returns a text representation of the application');
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_astext2.txt'), $application->asText('foo'), '->asText() returns a text representation of the application');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $application->asText(), '->asText() returns a text representation of the application');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $application->asText('foo'), '->asText() returns a text representation of the application');
}
public function testAsXml()
{
$application = new Application();
$application->addCommand(new \FooCommand);
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_asxml1.txt'), $application->asXml(), '->asXml() returns an XML representation of the application');
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_asxml2.txt'), $application->asXml('foo'), '->asXml() returns an XML representation of the application');
+ $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
+ $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
}
public function testRenderException()
@@ -240,13 +254,13 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'));
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_renderexception1.txt'), $tester->getDisplay(), '->renderException() renders a pretty exception');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(), '->renderException() renders a pretty exception');
$tester->run(array('command' => 'foo'), array('verbosity' => Output::VERBOSITY_VERBOSE));
$this->assertRegExp('/Exception trace/', $tester->getDisplay(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
$tester->run(array('command' => 'list', '--foo' => true));
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_renderexception2.txt'), $tester->getDisplay(), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getDisplay(), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
}
public function testRun()
@@ -269,17 +283,17 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array());
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_run1.txt'), $tester->getDisplay(), '->run() runs the list command if no argument is passed');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $tester->getDisplay(), '->run() runs the list command if no argument is passed');
$tester->run(array('--help' => true));
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_run2.txt'), $tester->getDisplay(), '->run() runs the help command if --help is passed');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(), '->run() runs the help command if --help is passed');
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'list', '--help' => true));
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_run3.txt'), $tester->getDisplay(), '->run() displays the help if --help is passed');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $tester->getDisplay(), '->run() displays the help if --help is passed');
$application = new Application();
$application->setAutoExit(false);
@@ -293,7 +307,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application->setCatchExceptions(false);
$tester = new ApplicationTester($application);
$tester->run(array('--version' => true));
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/application_run4.txt'), $tester->getDisplay(), '->run() displays the program version if --version is passed');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(), '->run() displays the program version if --version is passed');
$application = new Application();
$application->setAutoExit(false);
diff --git a/tests/Symfony/Tests/Components/Console/Command/CommandTest.php b/tests/Symfony/Tests/Components/Console/Command/CommandTest.php
index fd8706dc21..6fadf49dfb 100644
--- a/tests/Symfony/Tests/Components/Console/Command/CommandTest.php
+++ b/tests/Symfony/Tests/Components/Console/Command/CommandTest.php
@@ -41,8 +41,10 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$command = new Command();
$this->fail('__construct() throws a \LogicException if the name is null');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, '__construct() throws a \LogicException if the name is null');
+ $this->assertEquals('The command name cannot be empty.', $e->getMessage(), '__construct() throws a \LogicException if the name is null');
}
$command = new Command('foo:bar');
$this->assertEquals('foo:bar', $command->getFullName(), '__construct() takes the command name as its first argument');
@@ -107,8 +109,10 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$command->setName('');
$this->fail('->setName() throws an \InvalidArgumentException if the name is empty');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->setName() throws an \InvalidArgumentException if the name is empty');
+ $this->assertEquals('A command name cannot be empty.', $e->getMessage(), '->setName() throws an \InvalidArgumentException if the name is empty');
}
try
@@ -116,8 +120,10 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$command->setName('foo:');
$this->fail('->setName() throws an \InvalidArgumentException if the name is empty');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->setName() throws an \InvalidArgumentException if the name is empty');
+ $this->assertEquals('A command name cannot be empty.', $e->getMessage(), '->setName() throws an \InvalidArgumentException if the name is empty');
}
}
@@ -204,14 +210,16 @@ class CommandTest extends \PHPUnit_Framework_TestCase
try
{
$tester->execute(array('--bar' => true));
- $this->fail('->run() throws a \RuntimeException when the input does not validate the current InputDefinition');
+ $this->fail('->run() throws a \InvalidArgumentException when the input does not validate the current InputDefinition');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->run() throws a \InvalidArgumentException when the input does not validate the current InputDefinition');
+ $this->assertEquals('The "--bar" option does not exist.', $e->getMessage(), '->run() throws a \InvalidArgumentException when the input does not validate the current InputDefinition');
}
- $this->assertEquals("interact called\nexecute called\n", $tester->execute(array(), array('interactive' => true)), '->run() calls the interact() method if the input is interactive');
- $this->assertEquals("execute called\n", $tester->execute(array(), array('interactive' => false)), '->run() does not call the interact() method if the input is not interactive');
+ $this->assertEquals('interact called'.PHP_EOL.'execute called'.PHP_EOL, $tester->execute(array(), array('interactive' => true)), '->run() calls the interact() method if the input is interactive');
+ $this->assertEquals('execute called'.PHP_EOL, $tester->execute(array(), array('interactive' => false)), '->run() does not call the interact() method if the input is not interactive');
$command = new Command('foo');
try
@@ -219,8 +227,10 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$command->run(new StringInput(''), new NullOutput());
$this->fail('->run() throws a \LogicException if the execute() method has not been overriden and no code has been provided');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, '->run() throws a \LogicException if the execute() method has not been overriden and no code has been provided');
+ $this->assertEquals('You must override the execute() method in the concrete command class.', $e->getMessage(), '->run() throws a \LogicException if the execute() method has not been overriden and no code has been provided');
}
}
@@ -236,7 +246,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
$tester = new CommandTester($command);
$tester->execute(array());
- $this->assertEquals("interact called\nfrom the code...\n", $tester->getDisplay());
+ $this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay());
}
public function testAsText()
@@ -245,7 +255,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$command->setApplication(new Application());
$tester = new CommandTester($command);
$tester->execute(array());
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/command_astext.txt'), $command->asText(), '->asText() returns a text representation of the command');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command');
}
public function testAsXml()
@@ -254,6 +264,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$command->setApplication(new Application());
$tester = new CommandTester($command);
$tester->execute(array());
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/command_asxml.txt'), $command->asXml(), '->asXml() returns an XML representation of the command');
+ $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Input/ArgvInputTest.php b/tests/Symfony/Tests/Components/Console/Input/ArgvInputTest.php
index 8f58eb2a74..aea04f2959 100644
--- a/tests/Symfony/Tests/Components/Console/Input/ArgvInputTest.php
+++ b/tests/Symfony/Tests/Components/Console/Input/ArgvInputTest.php
@@ -51,8 +51,10 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->fail('->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
+ $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
}
$input = new TestInput(array('cli.php', '-f'));
@@ -77,8 +79,10 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->fail('->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
+ $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
}
try
@@ -87,8 +91,10 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_NONE))));
$this->fail('->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
+ $this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
}
try
@@ -97,8 +103,10 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input->bind(new InputDefinition());
$this->fail('->parse() throws a \RuntimeException if too many arguments are passed');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->parse() throws a \RuntimeException if too many arguments are passed');
+ $this->assertEquals('Too many arguments.', $e->getMessage(), '->parse() throws a \RuntimeException if too many arguments are passed');
}
try
@@ -107,8 +115,10 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input->bind(new InputDefinition());
$this->fail('->parse() throws a \RuntimeException if an unknown long option is passed');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->parse() throws a \RuntimeException if an unknown long option is passed');
+ $this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if an unknown long option is passed');
}
try
@@ -117,8 +127,10 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input->bind(new InputDefinition());
$this->fail('->parse() throws a \RuntimeException if an unknown short option is passed');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->parse() throws a \RuntimeException if an unknown short option is passed');
+ $this->assertEquals('The "-f" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if an unknown short option is passed');
}
$input = new TestInput(array('cli.php', '-fb'));
@@ -160,7 +172,7 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
$input = new TestInput(array('cli.php', 'foo'));
- $this->assertTrue(!$input->hasParameterOption('--foo'), '->hasParameterOption() returns false if the given short option is not in the raw input');
+ $this->assertFalse($input->hasParameterOption('--foo'), '->hasParameterOption() returns false if the given short option is not in the raw input');
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Input/ArrayInputTest.php b/tests/Symfony/Tests/Components/Console/Input/ArrayInputTest.php
index e4f0b79308..55aaa9e7c8 100644
--- a/tests/Symfony/Tests/Components/Console/Input/ArrayInputTest.php
+++ b/tests/Symfony/Tests/Components/Console/Input/ArrayInputTest.php
@@ -20,7 +20,7 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
public function testGetFirstArgument()
{
$input = new ArrayInput(array());
- $this->assertEquals(null, $input->getFirstArgument(), '->getFirstArgument() returns null if no argument were passed');
+ $this->assertNull($input->getFirstArgument(), '->getFirstArgument() returns null if no argument were passed');
$input = new ArrayInput(array('name' => 'Fabien'));
$this->assertEquals('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
$input = new ArrayInput(array('--foo' => 'bar', 'name' => 'Fabien'));
@@ -31,7 +31,7 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
{
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
- $this->assertTrue(!$input->hasParameterOption('--bar'), '->hasParameterOption() returns false if an option is not present in the passed parameters');
+ $this->assertFalse($input->hasParameterOption('--bar'), '->hasParameterOption() returns false if an option is not present in the passed parameters');
$input = new ArrayInput(array('--foo'));
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
@@ -47,8 +47,10 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
$input = new ArrayInput(array('foo' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
$this->fail('->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
+ $this->assertEquals('The "foo" argument does not exist.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
}
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
@@ -65,8 +67,10 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->fail('->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');
+ $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');
}
try
@@ -74,8 +78,10 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
$input = new ArrayInput(array('--foo' => 'foo'), new InputDefinition());
$this->fail('->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
+ $this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
}
$input = new ArrayInput(array('-f' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f'))));
@@ -86,8 +92,10 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
$input = new ArrayInput(array('-o' => 'foo'), new InputDefinition());
$this->fail('->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
+ $this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
}
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Input/InputArgumentTest.php b/tests/Symfony/Tests/Components/Console/Input/InputArgumentTest.php
index 370e047ca1..d7dc6db055 100644
--- a/tests/Symfony/Tests/Components/Console/Input/InputArgumentTest.php
+++ b/tests/Symfony/Tests/Components/Console/Input/InputArgumentTest.php
@@ -22,16 +22,16 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
// mode argument
$argument = new InputArgument('foo');
- $this->assertEquals(false, $argument->isRequired(), '__construct() gives a "Argument::OPTIONAL" mode by default');
+ $this->assertFalse($argument->isRequired(), '__construct() gives a "Argument::OPTIONAL" mode by default');
$argument = new InputArgument('foo', null);
- $this->assertEquals(false, $argument->isRequired(), '__construct() can take "Argument::OPTIONAL" as its mode');
+ $this->assertFalse($argument->isRequired(), '__construct() can take "Argument::OPTIONAL" as its mode');
$argument = new InputArgument('foo', InputArgument::OPTIONAL);
- $this->assertEquals(false, $argument->isRequired(), '__construct() can take "Argument::PARAMETER_OPTIONAL" as its mode');
+ $this->assertFalse($argument->isRequired(), '__construct() can take "Argument::PARAMETER_OPTIONAL" as its mode');
$argument = new InputArgument('foo', InputArgument::REQUIRED);
- $this->assertEquals(true, $argument->isRequired(), '__construct() can take "Argument::PARAMETER_REQUIRED" as its mode');
+ $this->assertTrue($argument->isRequired(), '__construct() can take "Argument::PARAMETER_REQUIRED" as its mode');
try
{
@@ -40,6 +40,8 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
+ $this->assertEquals('Argument mode "ANOTHER_ONE" is not valid.', $e->getMessage());
}
}
@@ -50,7 +52,7 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
$argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
$this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array');
$argument = new InputArgument('foo', InputArgument::OPTIONAL);
- $this->assertTrue(!$argument->isArray(), '->isArray() returns false if the argument can not be an array');
+ $this->assertFalse($argument->isArray(), '->isArray() returns false if the argument can not be an array');
}
public function testGetDescription()
@@ -69,7 +71,7 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
{
$argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
$argument->setDefault(null);
- $this->assertTrue(is_null($argument->getDefault()), '->setDefault() can reset the default value by passing null');
+ $this->assertNull($argument->getDefault(), '->setDefault() can reset the default value by passing null');
$argument->setDefault('another');
$this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value');
@@ -85,6 +87,8 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
+ $this->assertEquals('Cannot set a default value except for Parameter::OPTIONAL mode.', $e->getMessage());
}
try
@@ -95,6 +99,8 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
+ $this->assertEquals('A default value for an array argument must be an array.', $e->getMessage());
}
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Input/InputDefinitionTest.php b/tests/Symfony/Tests/Components/Console/Input/InputDefinitionTest.php
index 908c1f5fe6..4a2a0d6021 100644
--- a/tests/Symfony/Tests/Components/Console/Input/InputDefinitionTest.php
+++ b/tests/Symfony/Tests/Components/Console/Input/InputDefinitionTest.php
@@ -86,6 +86,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->addArgument() throws a Exception if another argument is already registered with the same name');
+ $this->assertEquals('An argument with name "foo" already exist.', $e->getMessage());
}
// cannot add a parameter after an array parameter
@@ -97,8 +99,11 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->addArgument() throws a Exception if there is an array parameter already registered');
+ $this->assertEquals('Cannot add an argument after an array argument.', $e->getMessage());
}
+
// cannot add a required argument after an optional one
$definition = new InputDefinition();
$definition->addArgument($this->foo);
@@ -109,6 +114,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->addArgument() throws an exception if you try to add a required argument after an optional one');
+ $this->assertEquals('Cannot add a required argument after an optional one.', $e->getMessage());
}
}
@@ -126,6 +133,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->getArgument() throws an exception if the InputArgument name does not exist');
+ $this->assertEquals('The "bar" argument does not exist.', $e->getMessage());
}
}
@@ -135,8 +144,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
$definition = new InputDefinition();
$definition->addArguments(array($this->foo));
- $this->assertEquals(true, $definition->hasArgument('foo'), '->hasArgument() returns true if a InputArgument exists for the given name');
- $this->assertEquals(false, $definition->hasArgument('bar'), '->hasArgument() returns false if a InputArgument exists for the given name');
+ $this->assertTrue($definition->hasArgument('foo'), '->hasArgument() returns true if a InputArgument exists for the given name');
+ $this->assertFalse($definition->hasArgument('bar'), '->hasArgument() returns false if a InputArgument exists for the given name');
}
public function testGetArgumentRequiredCount()
@@ -192,6 +201,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->setOptions() clears all InputOption objects');
+ $this->assertEquals('The "-f" option does not exist.', $e->getMessage());
}
}
@@ -221,6 +232,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same name');
+ $this->assertEquals('An option named "foo" already exist.', $e->getMessage());
}
try
{
@@ -229,6 +242,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same shortcut');
+ $this->assertEquals('An option with shortcut "f" already exist.', $e->getMessage());
}
}
@@ -245,6 +260,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->getOption() throws an exception if the option name does not exist');
+ $this->assertEquals('The "--bar" option does not exist.', $e->getMessage());
}
}
@@ -253,8 +270,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
$this->initializeOptions();
$definition = new InputDefinition(array($this->foo));
- $this->assertEquals(true, $definition->hasOption('foo'), '->hasOption() returns true if a InputOption exists for the given name');
- $this->assertEquals(false, $definition->hasOption('bar'), '->hasOption() returns false if a InputOption exists for the given name');
+ $this->assertTrue($definition->hasOption('foo'), '->hasOption() returns true if a InputOption exists for the given name');
+ $this->assertFalse($definition->hasOption('bar'), '->hasOption() returns false if a InputOption exists for the given name');
}
public function testHasShortcut()
@@ -262,8 +279,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
$this->initializeOptions();
$definition = new InputDefinition(array($this->foo));
- $this->assertEquals(true, $definition->hasShortcut('f'), '->hasShortcut() returns true if a InputOption exists for the given shortcut');
- $this->assertEquals(false, $definition->hasShortcut('b'), '->hasShortcut() returns false if a InputOption exists for the given shortcut');
+ $this->assertTrue($definition->hasShortcut('f'), '->hasShortcut() returns true if a InputOption exists for the given shortcut');
+ $this->assertFalse($definition->hasShortcut('b'), '->hasShortcut() returns false if a InputOption exists for the given shortcut');
}
public function testGetOptionForShortcut()
@@ -279,6 +296,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->getOption() throws an exception if the shortcut does not exist');
+ $this->assertEquals('The "-l" option does not exist.', $e->getMessage());
}
}
@@ -334,7 +353,7 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL, 'The foo option', 'bar'),
));
- $this->assertEquals(file_get_contents(self::$fixtures.'/definition_astext.txt'), $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
+ $this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
}
public function testAsXml()
@@ -345,7 +364,7 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL, 'The foo option', 'bar'),
));
- $this->assertEquals(file_get_contents(self::$fixtures.'/definition_asxml.txt'), $definition->asXml(), '->asText() returns a textual representation of the InputDefinition');
+ $this->assertXmlStringEqualsXmlFile(self::$fixtures.'/definition_asxml.txt', $definition->asXml(), '->asText() returns a textual representation of the InputDefinition');
}
protected function initializeArguments()
diff --git a/tests/Symfony/Tests/Components/Console/Input/InputOptionTest.php b/tests/Symfony/Tests/Components/Console/Input/InputOptionTest.php
index eff2085963..7f2c4b30a1 100644
--- a/tests/Symfony/Tests/Components/Console/Input/InputOptionTest.php
+++ b/tests/Symfony/Tests/Components/Console/Input/InputOptionTest.php
@@ -29,6 +29,8 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->setDefault() throws an Exception if PARAMETER_IS_ARRAY option is used when an option does not accept a value');
+ $this->assertEquals('Impossible to have an option mode PARAMETER_IS_ARRAY if the option does not accept a parameter.', $e->getMessage());
}
// shortcut argument
@@ -39,29 +41,29 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
// mode argument
$option = new InputOption('foo', 'f');
- $this->assertEquals(false, $option->acceptParameter(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
- $this->assertEquals(false, $option->isParameterRequired(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
- $this->assertEquals(false, $option->isParameterOptional(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
+ $this->assertFalse($option->acceptParameter(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
+ $this->assertFalse($option->isParameterRequired(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
+ $this->assertFalse($option->isParameterOptional(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
$option = new InputOption('foo', 'f', null);
- $this->assertEquals(false, $option->acceptParameter(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
- $this->assertEquals(false, $option->isParameterRequired(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
- $this->assertEquals(false, $option->isParameterOptional(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
+ $this->assertFalse($option->acceptParameter(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
+ $this->assertFalse($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
+ $this->assertFalse($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
- $this->assertEquals(false, $option->acceptParameter(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
- $this->assertEquals(false, $option->isParameterRequired(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
- $this->assertEquals(false, $option->isParameterOptional(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
+ $this->assertFalse($option->acceptParameter(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
+ $this->assertFalse($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
+ $this->assertFalse($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$option = new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED);
- $this->assertEquals(true, $option->acceptParameter(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
- $this->assertEquals(true, $option->isParameterRequired(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
- $this->assertEquals(false, $option->isParameterOptional(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
+ $this->assertTrue($option->acceptParameter(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
+ $this->assertTrue($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
+ $this->assertFalse($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
$option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL);
- $this->assertEquals(true, $option->acceptParameter(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
- $this->assertEquals(false, $option->isParameterRequired(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
- $this->assertEquals(true, $option->isParameterOptional(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
+ $this->assertTrue($option->acceptParameter(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
+ $this->assertFalse($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
+ $this->assertTrue($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
try
{
@@ -70,6 +72,8 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
+ $this->assertEquals('Option mode "ANOTHER_ONE" is not valid.', $e->getMessage());
}
}
@@ -78,7 +82,7 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
$option = new InputOption('foo', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
$this->assertTrue($option->isArray(), '->isArray() returns true if the option can be an array');
$option = new InputOption('foo', null, InputOption::PARAMETER_NONE);
- $this->assertTrue(!$option->isArray(), '->isArray() returns false if the option can not be an array');
+ $this->assertFalse($option->isArray(), '->isArray() returns false if the option can not be an array');
}
public function testGetDescription()
@@ -96,20 +100,20 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('default', $option->getDefault(), '->getDefault() returns the default value');
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED);
- $this->assertTrue(is_null($option->getDefault()), '->getDefault() returns null if no default value is configured');
+ $this->assertNull($option->getDefault(), '->getDefault() returns null if no default value is configured');
$option = new InputOption('foo', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
$this->assertEquals(array(), $option->getDefault(), '->getDefault() returns an empty array if option is an array');
$option = new InputOption('foo', null, InputOption::PARAMETER_NONE);
- $this->assertTrue($option->getDefault() === false, '->getDefault() returns false if the option does not take a parameter');
+ $this->assertFalse($option->getDefault(), '->getDefault() returns false if the option does not take a parameter');
}
public function testSetDefault()
{
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED, '', 'default');
$option->setDefault(null);
- $this->assertTrue(is_null($option->getDefault()), '->setDefault() can reset the default value by passing null');
+ $this->assertNull($option->getDefault(), '->setDefault() can reset the default value by passing null');
$option->setDefault('another');
$this->assertEquals('another', $option->getDefault(), '->setDefault() changes the default value');
@@ -125,6 +129,8 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
+ $this->assertEquals('Cannot set a default value when using Option::PARAMETER_NONE mode.', $e->getMessage());
}
$option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
@@ -135,6 +141,8 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
+ $this->assertEquals('A default value for an array option must be an array.', $e->getMessage());
}
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Input/InputTest.php b/tests/Symfony/Tests/Components/Console/Input/InputTest.php
index 726f826ca9..3394a8a626 100644
--- a/tests/Symfony/Tests/Components/Console/Input/InputTest.php
+++ b/tests/Symfony/Tests/Components/Console/Input/InputTest.php
@@ -41,8 +41,10 @@ class InputTest extends \PHPUnit_Framework_TestCase
$input->setOption('foo', 'bar');
$this->fail('->setOption() throws a \InvalidArgumentException if the option does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
+ $this->assertEquals('The "foo" option does not exist.', $e->getMessage());
}
try
@@ -50,8 +52,10 @@ class InputTest extends \PHPUnit_Framework_TestCase
$input->getOption('foo');
$this->fail('->getOption() throws a \InvalidArgumentException if the option does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
+ $this->assertEquals('The "foo" option does not exist.', $e->getMessage());
}
}
@@ -73,8 +77,10 @@ class InputTest extends \PHPUnit_Framework_TestCase
$input->setArgument('foo', 'bar');
$this->fail('->setArgument() throws a \InvalidArgumentException if the argument does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
+ $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
}
try
@@ -82,8 +88,10 @@ class InputTest extends \PHPUnit_Framework_TestCase
$input->getArgument('foo');
$this->fail('->getArgument() throws a \InvalidArgumentException if the argument does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
+ $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
}
}
@@ -97,8 +105,10 @@ class InputTest extends \PHPUnit_Framework_TestCase
$input->validate();
$this->fail('->validate() throws a \RuntimeException if not enough arguments are given');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->validate() throws a \RuntimeException if not enough arguments are given');
+ $this->assertEquals('Not enough arguments.', $e->getMessage());
}
$input = new ArrayInput(array('name' => 'foo'));
@@ -119,6 +129,6 @@ class InputTest extends \PHPUnit_Framework_TestCase
$input = new ArrayInput(array());
$this->assertTrue($input->isInteractive(), '->isInteractive() returns whether the input should be interactive or not');
$input->setInteractive(false);
- $this->assertTrue(!$input->isInteractive(), '->setInteractive() changes the interactive flag');
+ $this->assertFalse($input->isInteractive(), '->setInteractive() changes the interactive flag');
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Output/NullOutputTest.php b/tests/Symfony/Tests/Components/Console/Output/NullOutputTest.php
index c3446faf60..534dc0e6d2 100644
--- a/tests/Symfony/Tests/Components/Console/Output/NullOutputTest.php
+++ b/tests/Symfony/Tests/Components/Console/Output/NullOutputTest.php
@@ -18,6 +18,6 @@ class NullOutputTest extends \PHPUnit_Framework_TestCase
{
$output = new NullOutput();
$output->write('foo');
- $this->assertTrue(true, '->write() does nothing');
+ $this->assertTrue(true, '->write() does nothing'); // FIXME
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Output/OutputTest.php b/tests/Symfony/Tests/Components/Console/Output/OutputTest.php
index 8b9c363b84..9c70b25fc6 100644
--- a/tests/Symfony/Tests/Components/Console/Output/OutputTest.php
+++ b/tests/Symfony/Tests/Components/Console/Output/OutputTest.php
@@ -18,14 +18,14 @@ class OutputTest extends \PHPUnit_Framework_TestCase
{
$output = new TestOutput(Output::VERBOSITY_QUIET, true);
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
- $this->assertEquals(true, $output->isDecorated(), '__construct() takes the decorated flag as its second argument');
+ $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
}
public function testSetIsDecorated()
{
$output = new TestOutput();
$output->setDecorated(true);
- $this->assertEquals(true, 'setDecorated() sets the decorated flag', $output->isDecorated());
+ $this->assertTrue($output->isDecorated(), 'setDecorated() sets the decorated flag');
}
public function testSetGetVerbosity()
@@ -74,8 +74,10 @@ class OutputTest extends \PHPUnit_Framework_TestCase
$output->writeln('foo', 24);
$this->fail('->writeln() throws an \InvalidArgumentException when the type does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->writeln() throws an \InvalidArgumentException when the type does not exist');
+ $this->assertEquals('Unknown output type given (24)', $e->getMessage());
}
try
@@ -83,8 +85,10 @@ class OutputTest extends \PHPUnit_Framework_TestCase
$output->writeln('foo');
$this->fail('->writeln() throws an \InvalidArgumentException when a style does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->writeln() throws an \InvalidArgumentException when a style does not exist');
+ $this->assertEquals('Unknown style "bar".', $e->getMessage());
}
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Output/StreamOutputTest.php b/tests/Symfony/Tests/Components/Console/Output/StreamOutputTest.php
index 3c0a18a105..637a3a3c61 100644
--- a/tests/Symfony/Tests/Components/Console/Output/StreamOutputTest.php
+++ b/tests/Symfony/Tests/Components/Console/Output/StreamOutputTest.php
@@ -29,13 +29,15 @@ class StreamOutputTest extends \PHPUnit_Framework_TestCase
$output = new StreamOutput('foo');
$this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the first argument is not a stream');
+ $this->assertEquals('The StreamOutput class needs a stream as its first argument.', $e->getMessage());
}
$output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
- $this->assertEquals(true, $output->isDecorated(), '__construct() takes the decorated flag as its second argument');
+ $this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
}
public function testGetStream()
@@ -49,6 +51,6 @@ class StreamOutputTest extends \PHPUnit_Framework_TestCase
$output = new StreamOutput($this->stream);
$output->writeln('foo');
rewind($output->getStream());
- $this->assertEquals("foo\n", stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
+ $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Tester/ApplicationTesterTest.php b/tests/Symfony/Tests/Components/Console/Tester/ApplicationTesterTest.php
index d053c19d83..d3e584441d 100644
--- a/tests/Symfony/Tests/Components/Console/Tester/ApplicationTesterTest.php
+++ b/tests/Symfony/Tests/Components/Console/Tester/ApplicationTesterTest.php
@@ -35,8 +35,8 @@ class ApplicationTesterTest extends \PHPUnit_Framework_TestCase
public function testRun()
{
- $this->assertEquals(false, $this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
- $this->assertEquals(false, $this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
+ $this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
+ $this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
$this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
}
@@ -48,11 +48,11 @@ class ApplicationTesterTest extends \PHPUnit_Framework_TestCase
public function testGetOutput()
{
rewind($this->tester->getOutput()->getStream());
- $this->assertEquals("foo\n", stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
+ $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
}
public function testGetDisplay()
{
- $this->assertEquals("foo\n", $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
+ $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
}
}
diff --git a/tests/Symfony/Tests/Components/Console/Tester/CommandTesterTest.php b/tests/Symfony/Tests/Components/Console/Tester/CommandTesterTest.php
index f77c203284..b08003a6b4 100644
--- a/tests/Symfony/Tests/Components/Console/Tester/CommandTesterTest.php
+++ b/tests/Symfony/Tests/Components/Console/Tester/CommandTesterTest.php
@@ -32,8 +32,8 @@ class CommandTesterTest extends \PHPUnit_Framework_TestCase
public function testExecute()
{
- $this->assertEquals(false, $this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
- $this->assertEquals(false, $this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
+ $this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
+ $this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
$this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
}
@@ -45,11 +45,11 @@ class CommandTesterTest extends \PHPUnit_Framework_TestCase
public function testGetOutput()
{
rewind($this->tester->getOutput()->getStream());
- $this->assertEquals("foo\n", stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
+ $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
}
public function testGetDisplay()
{
- $this->assertEquals("foo\n", $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
+ $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
}
}
diff --git a/tests/Symfony/Tests/Components/CssSelector/ParserTest.php b/tests/Symfony/Tests/Components/CssSelector/ParserTest.php
index 08eb645447..7181a97846 100644
--- a/tests/Symfony/Tests/Components/CssSelector/ParserTest.php
+++ b/tests/Symfony/Tests/Components/CssSelector/ParserTest.php
@@ -45,6 +45,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
}
catch (\Exception $e)
{
+ $this->assertType('\Symfony\Components\CssSelector\SyntaxError', $e, '->parse() throws an Exception if the css selector is not valid');
$this->assertEquals("Expected symbol, got '' at h1: -> ", $e->getMessage(), '->parse() throws an Exception if the css selector is not valid');
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/BuilderConfigurationTest.php b/tests/Symfony/Tests/Components/DependencyInjection/BuilderConfigurationTest.php
index 2ac37e7158..8bef486da3 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/BuilderConfigurationTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/BuilderConfigurationTest.php
@@ -110,8 +110,10 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
$configuration->getParameter('baba');
$this->fail('->getParameter() throws an \InvalidArgumentException if the key does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getParameter() throws an \InvalidArgumentException if the key does not exist');
+ $this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->getParameter() throws an \InvalidArgumentException if the key does not exist');
}
}
@@ -120,7 +122,7 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
$configuration = new BuilderConfiguration(array(), array('foo' => 'bar'));
$this->assertTrue($configuration->hasParameter('foo'), '->hasParameter() returns true if a parameter is defined');
$this->assertTrue($configuration->hasParameter('Foo'), '->hasParameter() converts the key to lowercase');
- $this->assertTrue(!$configuration->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined');
+ $this->assertFalse($configuration->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined');
}
public function testAddParameters()
@@ -138,15 +140,17 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
$configuration->setAlias('bar', 'foo');
$this->assertEquals('foo', $configuration->getAlias('bar'), '->setAlias() defines a new alias');
$this->assertTrue($configuration->hasAlias('bar'), '->hasAlias() returns true if the alias is defined');
- $this->assertTrue(!$configuration->hasAlias('baba'), '->hasAlias() returns false if the alias is not defined');
+ $this->assertFalse($configuration->hasAlias('baba'), '->hasAlias() returns false if the alias is not defined');
try
{
$configuration->getAlias('baba');
$this->fail('->getAlias() throws an \InvalidArgumentException if the alias does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getAlias() throws an \InvalidArgumentException if the alias does not exist');
+ $this->assertEquals('The service alias "baba" does not exist.', $e->getMessage(), '->getAlias() throws an \InvalidArgumentException if the alias does not exist');
}
$configuration->setAlias('barbar', 'foofoo');
@@ -166,7 +170,7 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
$configuration->setDefinitions($definitions);
$this->assertEquals($definitions, $configuration->getDefinitions(), '->setDefinitions() sets the service definitions');
$this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
- $this->assertTrue(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
+ $this->assertFalse($configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($foo, $configuration->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
@@ -180,8 +184,10 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
$configuration->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
+ $this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/BuilderTest.php b/tests/Symfony/Tests/Components/DependencyInjection/BuilderTest.php
index cd7164adc2..8da64cb46a 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/BuilderTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/BuilderTest.php
@@ -34,7 +34,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder->setDefinitions($definitions);
$this->assertEquals($definitions, $builder->getDefinitions(), '->setDefinitions() sets the service definitions');
$this->assertTrue($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
- $this->assertTrue(!$builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
+ $this->assertFalse($builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($foo, $builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
@@ -48,8 +48,10 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
+ $this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
}
@@ -58,13 +60,13 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder = new Builder();
$builder->register('foo', 'FooClass');
$this->assertTrue($builder->hasDefinition('foo'), '->register() registers a new service definition');
- $this->assertTrue($builder->getDefinition('foo') instanceof Definition, '->register() returns the newly created Definition instance');
+ $this->assertType('Symfony\Components\DependencyInjection\Definition', $builder->getDefinition('foo'), '->register() returns the newly created Definition instance');
}
public function testHasService()
{
$builder = new Builder();
- $this->assertTrue(!$builder->hasService('foo'), '->hasService() returns false if the service does not exist');
+ $this->assertFalse($builder->hasService('foo'), '->hasService() returns false if the service does not exist');
$builder->register('foo', 'FooClass');
$this->assertTrue($builder->hasService('foo'), '->hasService() returns true if a service definition exists');
$builder->bar = new \stdClass();
@@ -79,11 +81,13 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder->getService('foo');
$this->fail('->getService() throws an InvalidArgumentException if the service does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getService() throws an InvalidArgumentException if the service does not exist');
+ $this->assertEquals('The service definition "foo" does not exist.', $e->getMessage(), '->getService() throws an InvalidArgumentException if the service does not exist');
}
$builder->register('foo', 'stdClass');
- $this->assertTrue(is_object($builder->getService('foo')), '->getService() returns the service definition associated with the id');
+ $this->assertType('object', $builder->getService('foo'), '->getService() returns the service definition associated with the id');
$builder->bar = $bar = new \stdClass();
$this->assertEquals($bar, $builder->getService('bar'), '->getService() returns the service associated with the id');
$builder->register('bar', 'stdClass');
@@ -95,8 +99,10 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
@$builder->getService('baz');
$this->fail('->getService() throws a LogicException if the service has a circular reference to itself');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, '->getService() throws a LogicException if the service has a circular reference to itself');
+ $this->assertEquals('The service "baz" has a circular reference to itself.', $e->getMessage(), '->getService() throws a LogicException if the service has a circular reference to itself');
}
$builder->register('foobar', 'stdClass')->setShared(true);
@@ -118,7 +124,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder->register('foo', 'stdClass');
$builder->setAlias('bar', 'foo');
$this->assertTrue($builder->hasAlias('bar'), '->hasAlias() returns true if the alias exists');
- $this->assertTrue(!$builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
+ $this->assertFalse($builder->hasAlias('foobar'), '->hasAlias() returns false if the alias does not exist');
$this->assertEquals('foo', $builder->getAlias('bar'), '->getAlias() returns the aliased service');
$this->assertTrue($builder->hasService('bar'), '->setAlias() defines a new service');
$this->assertTrue($builder->getService('bar') === $builder->getService('foo'), '->setAlias() creates a service that is an alias to another one');
@@ -128,8 +134,10 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder->getAlias('foobar');
$this->fail('->getAlias() throws an InvalidArgumentException if the alias does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getAlias() throws an InvalidArgumentException if the alias does not exist');
+ $this->assertEquals('The service alias "foobar" does not exist.', $e->getMessage(), '->getAlias() throws an InvalidArgumentException if the alias does not exist');
}
}
@@ -149,10 +157,10 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
{
$builder = new Builder();
$builder->register('foo1', 'FooClass')->setFile(self::$fixturesPath.'/includes/foo.php');
- $this->assertTrue($builder->getService('foo1') instanceof \FooClass, '->createService() requires the file defined by the service definition');
+ $this->assertType('\FooClass', $builder->getService('foo1'), '->createService() requires the file defined by the service definition');
$builder->register('foo2', 'FooClass')->setFile(self::$fixturesPath.'/includes/%file%.php');
$builder->setParameter('file', 'foo');
- $this->assertTrue($builder->getService('foo2') instanceof \FooClass, '->createService() replaces parameters in the file provided by the service definition');
+ $this->assertType('\FooClass', $builder->getService('foo2'), '->createService() replaces parameters in the file provided by the service definition');
}
public function testCreateServiceClass()
@@ -160,7 +168,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder = new Builder();
$builder->register('foo1', '%class%');
$builder->setParameter('class', 'stdClass');
- $this->assertTrue($builder->getService('foo1') instanceof \stdClass, '->createService() replaces parameters in the class provided by the service definition');
+ $this->assertType('\stdClass', $builder->getService('foo1'), '->createService() replaces parameters in the class provided by the service definition');
}
public function testCreateServiceArguments()
@@ -213,8 +221,10 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
$builder->getService('foo4');
$this->fail('->createService() throws an InvalidArgumentException if the configure callable is not a valid callable');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->createService() throws an InvalidArgumentException if the configure callable is not a valid callable');
+ $this->assertEquals('The configure callable for class "FooClass" is not a callable.', $e->getMessage(), '->createService() throws an InvalidArgumentException if the configure callable is not a valid callable');
}
}
@@ -236,8 +246,10 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
Builder::resolveValue('%foobar%', array());
$this->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
+ $this->assertEquals('The parameter "foobar" must be defined.', $e->getMessage(), '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
}
try
@@ -245,8 +257,10 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
Builder::resolveValue('foo %foobar% bar', array());
$this->fail('->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
+ $this->assertEquals('The parameter "foobar" must be defined (used in the following expression: "foo %foobar% bar").', $e->getMessage(), '->resolveValue() throws a RuntimeException if a placeholder references a non-existant parameter');
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php b/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php
index 147a2092bf..7cb6bb845c 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php
@@ -49,7 +49,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo1', $sc['bar1'], '->offsetset() sets the value of a parameter');
unset($sc['bar1']);
- $this->assertTrue(!isset($sc['bar1']), '->offsetUnset() removes a parameter');
+ $this->assertFalse(isset($sc['bar1']), '->offsetUnset() removes a parameter');
$sc->setParameter('foo', 'baz');
$this->assertEquals('baz', $sc->getParameter('foo'), '->setParameter() overrides previously set parameter');
@@ -64,8 +64,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$sc->getParameter('baba');
$this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
+ $this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
}
try
@@ -73,8 +75,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$sc['baba'];
$this->fail('->offsetGet() thrown an \InvalidArgumentException if the key does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->offsetGet() thrown an \InvalidArgumentException if the key does not exist');
+ $this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->offsetGet() thrown an \InvalidArgumentException if the key does not exist');
}
}
@@ -84,9 +88,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($sc->hasParameter('foo'), '->hasParameter() returns true if a parameter is defined');
$this->assertTrue($sc->hasParameter('Foo'), '->hasParameter() converts the key to lowercase');
$this->assertTrue(isset($sc['Foo']), '->offsetExists() converts the key to lowercase');
- $this->assertTrue(!$sc->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined');
+ $this->assertFalse($sc->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined');
$this->assertTrue(isset($sc['foo']), '->offsetExists() returns true if a parameter is defined');
- $this->assertTrue(!isset($sc['bar']), '->offsetExists() returns false if a parameter is not defined');
+ $this->assertFalse(isset($sc['bar']), '->offsetExists() returns false if a parameter is not defined');
}
public function testAddParameters()
@@ -110,8 +114,8 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(spl_object_hash($obj), spl_object_hash($sc->foo), '->__get() gets a service by name');
$this->assertTrue($sc->hasService('foo'), '->hasService() returns true if the service is defined');
$this->assertTrue(isset($sc->foo), '->__isset() returns true if the service is defined');
- $this->assertTrue(!$sc->hasService('bar'), '->hasService() returns false if the service is not defined');
- $this->assertTrue(!isset($sc->bar), '->__isset() returns false if the service is not defined');
+ $this->assertFalse($sc->hasService('bar'), '->hasService() returns false if the service is not defined');
+ $this->assertFalse(isset($sc->bar), '->__isset() returns false if the service is not defined');
}
public function testGetServiceIds()
@@ -133,8 +137,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$sc->getService('baba');
$this->fail('->getService() thrown an \InvalidArgumentException if the service does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getService() thrown an \InvalidArgumentException if the service does not exist');
+ $this->assertEquals('The service "baba" does not exist.', $e->getMessage(), '->getService() thrown an \InvalidArgumentException if the service does not exist');
}
try
@@ -142,8 +148,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$sc->baba;
$this->fail('->__get() thrown an \InvalidArgumentException if the service does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->__get() thrown an \InvalidArgumentException if the service does not exist');
+ $this->assertEquals('The service "baba" does not exist.', $e->getMessage(), '->__get() thrown an \InvalidArgumentException if the service does not exist');
}
try
@@ -151,8 +159,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
unset($sc->baba);
$this->fail('->__unset() thrown an LogicException if you try to remove a service');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, '->__unset() thrown an LogicException if you try to remove a service');
+ $this->assertEquals('You can\'t unset a service.', $e->getMessage(), '->__unset() thrown an LogicException if you try to remove a service');
}
$this->assertEquals(spl_object_hash($sc->__foo_bar), spl_object_hash($sc->getService('foo_bar')), '->getService() camelizes the service id when looking for a method');
@@ -168,10 +178,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
try
{
$sc->getFooBar_Foo();
- $this->fail('__call() throws a \RuntimeException exception if the method is not a service method');
+ $this->fail('__call() throws a \BadMethodCallException exception if the method is not a service method');
}
- catch (\BadMethodCallException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\BadMethodCallException', $e, '__call() throws a \BadMethodCallException exception if the method is not a service method');
+ $this->assertEquals('Call to undefined method Symfony\Components\DependencyInjection\Container::getFooBar_Foo.', $e->getMessage(), '__call() throws a \BadMethodCallException exception if the method is not a service method');
}
}
@@ -184,8 +196,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$sc->getService('');
$this->fail('->getService() throws a \InvalidArgumentException exception if the service is empty');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getService() throws a \InvalidArgumentException exception if the service is empty');
+ $this->assertEquals('The service "" does not exist.', $e->getMessage(), '->getService() throws a \InvalidArgumentException exception if the service is empty');
}
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/DefinitionTest.php b/tests/Symfony/Tests/Components/DependencyInjection/DefinitionTest.php
index 4a5c614556..c899cde32a 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/DefinitionTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/DefinitionTest.php
@@ -65,9 +65,9 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
public function testSetIsShared()
{
$def = new Definition('stdClass');
- $this->assertEquals(true, $def->isShared(), '->isShared() returns true by default');
+ $this->assertTrue($def->isShared(), '->isShared() returns true by default');
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setShared(false)), '->setShared() implements a fluent interface');
- $this->assertEquals(false, $def->isShared(), '->isShared() returns false if the instance must not be shared');
+ $this->assertFalse($def->isShared(), '->isShared() returns false if the instance must not be shared');
}
public function testSetGetConfigurator()
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/DumperTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/DumperTest.php
index f003eaa337..367776eebb 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/DumperTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/DumperTest.php
@@ -24,8 +24,10 @@ class DumperTest extends \PHPUnit_Framework_TestCase
$dumper->dump();
$this->fail('->dump() returns a LogicException if the dump() method has not been overriden by a children class');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, '->dump() returns a LogicException if the dump() method has not been overriden by a children class');
+ $this->assertEquals('You must extend this abstract class and implement the dump() method.', $e->getMessage(), '->dump() returns a LogicException if the dump() method has not been overriden by a children class');
}
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/GraphvizDumperTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/GraphvizDumperTest.php
index 4d17150a18..82708cb221 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/GraphvizDumperTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/GraphvizDumperTest.php
@@ -26,7 +26,7 @@ class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
{
$dumper = new GraphvizDumper($container = new Builder());
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/graphviz/services1.dot'), $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/graphviz/services1.dot', $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
$container = new Builder();
$dumper = new GraphvizDumper($container);
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/PhpDumperTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/PhpDumperTest.php
index 93a52ae5d3..0fd8e53549 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/PhpDumperTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/PhpDumperTest.php
@@ -26,8 +26,8 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
{
$dumper = new PhpDumper($container = new Builder());
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services1.php'), $dumper->dump(), '->dump() dumps an empty container as an empty PHP class');
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services1-1.php'), $dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer')), '->dump() takes a class and a base_class options');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/php/services1.php', $dumper->dump(), '->dump() dumps an empty container as an empty PHP class');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/php/services1-1.php', $dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer')), '->dump() takes a class and a base_class options');
$container = new Builder();
$dumper = new PhpDumper($container);
@@ -37,14 +37,14 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
{
$container = include self::$fixturesPath.'/containers/container8.php';
$dumper = new PhpDumper($container);
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services8.php'), $dumper->dump(), '->dump() dumps parameters');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/php/services8.php', $dumper->dump(), '->dump() dumps parameters');
}
public function testAddService()
{
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new PhpDumper($container);
- $this->assertEquals(str_replace('%path%', self::$fixturesPath.'/includes', file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
+ $this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
$dumper = new PhpDumper($container = new Builder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
@@ -53,8 +53,10 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->dump() returns a LogicException if the dump() method has not been overriden by a children class');
+ $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() returns a LogicException if the dump() method has not been overriden by a children class');
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/XmlDumperTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/XmlDumperTest.php
index e18b87f2a8..dd49d4d85c 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/XmlDumperTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/XmlDumperTest.php
@@ -26,7 +26,7 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
{
$dumper = new XmlDumper($container = new Builder());
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services1.xml'), $dumper->dump(), '->dump() dumps an empty container as an empty XML file');
+ $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services1.xml', $dumper->dump(), '->dump() dumps an empty container as an empty XML file');
$container = new Builder();
$dumper = new XmlDumper($container);
@@ -36,14 +36,14 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
{
$container = include self::$fixturesPath.'//containers/container8.php';
$dumper = new XmlDumper($container);
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services8.xml'), $dumper->dump(), '->dump() dumps parameters');
+ $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/xml/services8.xml', $dumper->dump(), '->dump() dumps parameters');
}
public function testAddService()
{
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new XmlDumper($container);
- $this->assertEquals(str_replace('%path%', self::$fixturesPath.'/includes', file_get_contents(self::$fixturesPath.'/xml/services9.xml')), $dumper->dump(), '->dump() dumps services');
+ $this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/xml/services9.xml')), $dumper->dump(), '->dump() dumps services');
$dumper = new XmlDumper($container = new Builder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
@@ -52,8 +52,10 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
+ $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/YamlDumperTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/YamlDumperTest.php
index 56d7cca19f..f1fb331e90 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Dumper/YamlDumperTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Dumper/YamlDumperTest.php
@@ -26,7 +26,7 @@ class YamlDumperTest extends \PHPUnit_Framework_TestCase
{
$dumper = new YamlDumper($container = new Builder());
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services1.yml'), $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services1.yml', $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
$container = new Builder();
$dumper = new YamlDumper($container);
@@ -36,14 +36,14 @@ class YamlDumperTest extends \PHPUnit_Framework_TestCase
{
$container = include self::$fixturesPath.'/containers/container8.php';
$dumper = new YamlDumper($container);
- $this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services8.yml'), $dumper->dump(), '->dump() dumps parameters');
+ $this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services8.yml', $dumper->dump(), '->dump() dumps parameters');
}
public function testAddService()
{
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new YamlDumper($container);
- $this->assertEquals(str_replace('%path%', self::$fixturesPath.'/includes', file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
+ $this->assertEquals(str_replace('%path%', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services');
$dumper = new YamlDumper($container = new Builder());
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
@@ -52,8 +52,10 @@ class YamlDumperTest extends \PHPUnit_Framework_TestCase
$dumper->dump();
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
- catch (\RuntimeException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
+ $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
}
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/FileResourceTest.php b/tests/Symfony/Tests/Components/DependencyInjection/FileResourceTest.php
index 51d3f82565..84dbda9897 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/FileResourceTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/FileResourceTest.php
@@ -37,9 +37,9 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
public function testIsUptodate()
{
$this->assertTrue($this->resource->isUptodate(time() + 10), '->isUptodate() returns true if the resource has not changed');
- $this->assertTrue(!$this->resource->isUptodate(time() - 86400), '->isUptodate() returns false if the resource has been updated');
+ $this->assertFalse($this->resource->isUptodate(time() - 86400), '->isUptodate() returns false if the resource has been updated');
$resource = new FileResource('/____foo/foobar'.rand(1, 999999));
- $this->assertTrue(!$resource->isUptodate(time()), '->isUptodate() returns false if the resource does not exist');
+ $this->assertFalse($resource->isUptodate(time()), '->isUptodate() returns false if the resource does not exist');
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Loader/FileLoaderTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Loader/FileLoaderTest.php
index 90e31ff80b..2d6ff9f6bc 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Loader/FileLoaderTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Loader/FileLoaderTest.php
@@ -32,9 +32,9 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('c:/foo.xml', $loader->getAbsolutePath('c:/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
$this->assertEquals('\\server\\foo.xml', $loader->getAbsolutePath('\\server\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
- $this->assertEquals(__DIR__.'/FileLoaderTest.php', $loader->getAbsolutePath('FileLoaderTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path');
+ $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'FileLoaderTest.php', $loader->getAbsolutePath('FileLoaderTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path');
- $this->assertEquals(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/containers/container10.php', $loader->getAbsolutePath('container10.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor');
+ $this->assertEquals(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/containers'.DIRECTORY_SEPARATOR.'container10.php', $loader->getAbsolutePath('container10.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor');
$this->assertEquals('foo.xml', $loader->getAbsolutePath('foo.xml', __DIR__), '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths');
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Loader/IniFileLoaderTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Loader/IniFileLoaderTest.php
index 5038512de1..2c18b49025 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Loader/IniFileLoaderTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Loader/IniFileLoaderTest.php
@@ -33,8 +33,10 @@ class IniLoaderTest extends \PHPUnit_Framework_TestCase
$loader->load('foo.ini');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
+ $this->assertStringStartsWith('The file "foo.ini" does not exist (in: ', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
}
try
@@ -42,8 +44,10 @@ class IniLoaderTest extends \PHPUnit_Framework_TestCase
@$loader->load('nonvalid.ini');
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not parseable');
+ $this->assertEquals('The nonvalid.ini file is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not parseable');
}
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Loader/LoaderExtensionTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Loader/LoaderExtensionTest.php
index c28ff06318..08dbf8177b 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Loader/LoaderExtensionTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Loader/LoaderExtensionTest.php
@@ -23,8 +23,10 @@ class LoaderExtensionTest extends \PHPUnit_Framework_TestCase
$extension->load('foo', array());
$this->fail('->load() throws an InvalidArgumentException if the tag does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag does not exist');
+ $this->assertEquals('The tag "foo" is not defined in the "http://www.example.com/schema/project" extension.', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag does not exist');
}
$config = $extension->load('bar', array('foo' => 'bar'));
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php
index 561feb9f41..a7386695f0 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Loader/XmlFileLoaderTest.php
@@ -35,8 +35,10 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->load('foo.xml');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
+ $this->assertStringStartsWith('The file "foo.xml" does not exist (in:', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
}
}
@@ -49,8 +51,10 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->parseFile(self::$fixturesPath.'/ini/parameters.ini');
$this->fail('->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
+ $this->assertStringStartsWith('[ERROR 4] Start tag expected, \'<\' not found (in', $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
}
$loader = new ProjectLoader2(self::$fixturesPath.'/xml');
@@ -60,8 +64,10 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->parseFile(self::$fixturesPath.'/xml/nonvalid.xml');
$this->fail('->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
+ $this->assertStringStartsWith('[ERROR 1845] Element \'nonvalid\': No matching global declaration available for the validation root. (in', $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
}
$xml = $loader->parseFile(self::$fixturesPath.'/xml/services1.xml');
@@ -120,7 +126,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Symfony\\Components\\DependencyInjection\\Definition', get_class($services['foo']), '->load() converts element to Definition instances');
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
$this->assertTrue($services['shared']->isShared(), '->load() parses the shared attribute');
- $this->assertTrue(!$services['non_shared']->isShared(), '->load() parses the shared attribute');
+ $this->assertFalse($services['non_shared']->isShared(), '->load() parses the shared attribute');
$this->assertEquals('getInstance', $services['constructor']->getConstructor(), '->load() parses the constructor attribute');
$this->assertEquals('%path%/foo.php', $services['file']->getFile(), '->load() parses the file tag');
$this->assertEquals(array('foo', new Reference('foo'), array(true, false)), $services['arguments']->getArguments(), '->load() parses the argument tags');
@@ -177,8 +183,10 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$config = $loader->load('services11.xml');
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid');
+ $this->assertStringStartsWith('There is no extension able to load the configuration for "foobar:foobar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
}
try
@@ -186,8 +194,10 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$config = $loader->load('services12.xml');
$this->fail('->load() throws an InvalidArgumentException if an extension is not loaded');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if an extension is not loaded');
+ $this->assertStringStartsWith('The "foobar" tag is not valid (in', $e->getMessage(), '->load() throws an InvalidArgumentException if an extension is not loaded');
}
}
}
diff --git a/tests/Symfony/Tests/Components/DependencyInjection/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Components/DependencyInjection/Loader/YamlFileLoaderTest.php
index a89000c9ed..c90683af94 100644
--- a/tests/Symfony/Tests/Components/DependencyInjection/Loader/YamlFileLoaderTest.php
+++ b/tests/Symfony/Tests/Components/DependencyInjection/Loader/YamlFileLoaderTest.php
@@ -35,8 +35,10 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->loadFile('foo.yml');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
+ $this->assertEquals('The service file "foo.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
}
try
@@ -44,8 +46,10 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->loadFile('parameters.ini');
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
+ $this->assertEquals('The service file "parameters.ini" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
}
$loader = new ProjectLoader3(self::$fixturesPath.'/yaml');
@@ -57,8 +61,10 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$loader->loadFile($fixture.'.yml');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not validate');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not validate');
+ $this->assertStringMatchesFormat('The service file "nonvalid%d.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not validate');
}
}
}
@@ -89,7 +95,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Symfony\\Components\\DependencyInjection\\Definition', get_class($services['foo']), '->load() converts service element to Definition instances');
$this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute');
$this->assertTrue($services['shared']->isShared(), '->load() parses the shared attribute');
- $this->assertTrue(!$services['non_shared']->isShared(), '->load() parses the shared attribute');
+ $this->assertFalse($services['non_shared']->isShared(), '->load() parses the shared attribute');
$this->assertEquals('getInstance', $services['constructor']->getConstructor(), '->load() parses the constructor attribute');
$this->assertEquals('%path%/foo.php', $services['file']->getFile(), '->load() parses the file tag');
$this->assertEquals(array('foo', new Reference('foo'), array(true, false)), $services['arguments']->getArguments(), '->load() parses the argument tags');
@@ -119,8 +125,10 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$config = $loader->load('services11.yml');
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid');
+ $this->assertStringStartsWith('There is no extension able to load the configuration for "foobar.foobar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
}
try
@@ -128,8 +136,10 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$config = $loader->load('services12.yml');
$this->fail('->load() throws an InvalidArgumentException if an extension is not loaded');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if an extension is not loaded');
+ $this->assertStringStartsWith('The "foobar" tag is not valid (in', $e->getMessage(), '->load() throws an InvalidArgumentException if an extension is not loaded');
}
}
}
diff --git a/tests/Symfony/Tests/Components/EventDispatcher/EventDispatcherTest.php b/tests/Symfony/Tests/Components/EventDispatcher/EventDispatcherTest.php
index d671f4aac3..9a5f11ca9b 100644
--- a/tests/Symfony/Tests/Components/EventDispatcher/EventDispatcherTest.php
+++ b/tests/Symfony/Tests/Components/EventDispatcher/EventDispatcherTest.php
@@ -29,18 +29,18 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->disconnect() disconnects a listener for an event name');
$this->assertEquals(array('listenToBarBar'), $dispatcher->getListeners('barbar'), '->disconnect() disconnects a listener for an event name');
- $this->assertTrue($dispatcher->disconnect('foobar', 'listen') === false, '->disconnect() returns false if the listener does not exist');
+ $this->assertFalse($dispatcher->disconnect('foobar', 'listen'), '->disconnect() returns false if the listener does not exist');
}
public function testGetHasListeners()
{
$dispatcher = new EventDispatcher();
- $this->assertEquals(false, $dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
+ $this->assertFalse($dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
$dispatcher->connect('foo', 'listenToFoo');
$this->assertEquals(true, $dispatcher->hasListeners('foo'), '->hasListeners() returns true if the event has some listeners');
$dispatcher->disconnect('foo', 'listenToFoo');
- $this->assertEquals(false, $dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
+ $this->assertFalse($dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
$dispatcher->connect('bar', 'listenToBar');
$this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->getListeners() returns an array of listeners connected to the given event name');
diff --git a/tests/Symfony/Tests/Components/EventDispatcher/EventTest.php b/tests/Symfony/Tests/Components/EventDispatcher/EventTest.php
index bfe2d1ebdf..944cb06da6 100644
--- a/tests/Symfony/Tests/Components/EventDispatcher/EventTest.php
+++ b/tests/Symfony/Tests/Components/EventDispatcher/EventTest.php
@@ -38,15 +38,17 @@ class EventTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $event->getParameter('foo'), '->setParameter() changes the value of a parameter');
$this->assertTrue($event->hasParameter('foo'), '->hasParameter() returns true if the parameter is defined');
unset($event['foo']);
- $this->assertTrue(!$event->hasParameter('foo'), '->hasParameter() returns false if the parameter is not defined');
+ $this->assertFalse($event->hasParameter('foo'), '->hasParameter() returns false if the parameter is not defined');
try
{
$event->getParameter('foobar');
$this->fail('->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist');
+ $this->assertEquals('The event "name" has no "foobar" parameter.', $e->getMessage(), '->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist');
}
$event = new Event($this->subject, 'name', $this->parameters);
}
@@ -62,9 +64,9 @@ class EventTest extends \PHPUnit_Framework_TestCase
{
$event = $this->createEvent();
$event->setProcessed(true);
- $this->assertEquals(true, $event->isProcessed(), '->isProcessed() returns true if the event has been processed');
+ $this->assertTrue($event->isProcessed(), '->isProcessed() returns true if the event has been processed');
$event->setProcessed(false);
- $this->assertEquals(false, $event->isProcessed(), '->setProcessed() changes the processed status');
+ $this->assertFalse($event->isProcessed(), '->setProcessed() changes the processed status');
}
public function testArrayAccessInterface()
@@ -80,13 +82,15 @@ class EventTest extends \PHPUnit_Framework_TestCase
$event['foobar'];
$this->fail('::offsetGet() throws an \InvalidArgumentException exception when the parameter does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '::offsetGet() throws an \InvalidArgumentException exception when the parameter does not exist');
+ $this->assertEquals('The event "name" has no "foobar" parameter.', $e->getMessage(), '::offsetGet() throws an \InvalidArgumentException exception when the parameter does not exist');
}
$this->assertTrue(isset($event['foo']), 'Event implements the ArrayAccess interface');
unset($event['foo']);
- $this->assertTrue(!isset($event['foo']), 'Event implements the ArrayAccess interface');
+ $this->assertFalse(isset($event['foo']), 'Event implements the ArrayAccess interface');
}
protected function createEvent()
diff --git a/tests/Symfony/Tests/Components/OutputEscaper/ArrayDecoratorTest.php b/tests/Symfony/Tests/Components/OutputEscaper/ArrayDecoratorTest.php
index 3dac6aed5b..6a9a765ef6 100644
--- a/tests/Symfony/Tests/Components/OutputEscaper/ArrayDecoratorTest.php
+++ b/tests/Symfony/Tests/Components/OutputEscaper/ArrayDecoratorTest.php
@@ -32,7 +32,7 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
public function testArrayAccessInterface()
{
$this->assertEquals('<strong>escaped!</strong>', self::$escaped[0], 'The escaped object behaves like an array');
- $this->assertEquals(null, self::$escaped[2], 'The escaped object behaves like an array');
+ $this->assertNull(self::$escaped[2], 'The escaped object behaves like an array');
$this->assertEquals('<strong>escaped!</strong>', self::$escaped[3][1], 'The escaped object behaves like an array');
$this->assertTrue(isset(self::$escaped[1]), 'The escaped object behaves like an array (isset)');
@@ -43,8 +43,10 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
$this->fail('The escaped object is read only (unset)');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, 'The escaped object is read only (unset)');
+ $this->assertEquals('Cannot unset values.', $e->getMessage(), 'The escaped object is read only (unset)');
}
try
@@ -53,8 +55,10 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
$this->fail('The escaped object is read only (set)');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, 'The escaped object is read only (set)');
+ $this->assertEquals('Cannot set values.', $e->getMessage(), 'The escaped object is read only (set)');
}
}
@@ -71,7 +75,7 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(1, $value, 'The escaped object behaves like an array');
break;
case 2:
- $this->assertEquals(null, $value, 'The escaped object behaves like an array');
+ $this->assertNull($value, 'The escaped object behaves like an array');
break;
case 3:
break;
diff --git a/tests/Symfony/Tests/Components/OutputEscaper/EscaperTest.php b/tests/Symfony/Tests/Components/OutputEscaper/EscaperTest.php
index 1e228d9de3..0a853e5e95 100644
--- a/tests/Symfony/Tests/Components/OutputEscaper/EscaperTest.php
+++ b/tests/Symfony/Tests/Components/OutputEscaper/EscaperTest.php
@@ -21,9 +21,9 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
{
public function testEscapeDoesNotEscapeSpecialValues()
{
- $this->assertSame(Escaper::escape('entities', null), null, '::escape() returns null if the value to escape is null');
- $this->assertSame(Escaper::escape('entities', false), false, '::escape() returns false if the value to escape is false');
- $this->assertSame(Escaper::escape('entities', true), true, '::escape() returns true if the value to escape is true');
+ $this->assertNull(Escaper::escape('entities', null), '::escape() returns null if the value to escape is null');
+ $this->assertFalse(Escaper::escape('entities', false), '::escape() returns false if the value to escape is false');
+ $this->assertTrue(Escaper::escape('entities', true), '::escape() returns true if the value to escape is true');
}
public function testEscapeDoesNotEscapeAValueWhenEscapingMethodIsRAW()
@@ -44,7 +44,7 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
'bar' => array('foo' => 'escaped!'),
);
$output = Escaper::escape('entities', $input);
- $this->assertTrue($output instanceof ArrayDecorator, '::escape() returns a ArrayDecorator object if the value to escape is an array');
+ $this->assertType('Symfony\Components\OutputEscaper\ArrayDecorator', $output, '::escape() returns a ArrayDecorator object if the value to escape is an array');
$this->assertEquals('<strong>escaped!</strong>', $output['foo'], '::escape() escapes all elements of the original array');
$this->assertEquals('<strong>escaped!</strong>', $output['bar']['foo'], '::escape() is recursive');
$this->assertEquals($input, $output->getRawValue(), '->getRawValue() returns the unescaped value');
@@ -54,23 +54,23 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
{
$input = new OutputEscaperTestClass();
$output = Escaper::escape('entities', $input);
- $this->assertTrue($output instanceof ObjectDecorator, '::escape() returns a ObjectDecorator object if the value to escape is an object');
+ $this->assertType('Symfony\Components\OutputEscaper\ObjectDecorator', $output, '::escape() returns a ObjectDecorator object if the value to escape is an object');
$this->assertEquals('<strong>escaped!</strong>', $output->getTitle(), '::escape() escapes all methods of the original object');
$this->assertEquals('<strong>escaped!</strong>', $output->title, '::escape() escapes all properties of the original object');
$this->assertEquals('<strong>escaped!</strong>', $output->getTitleTitle(), '::escape() is recursive');
$this->assertEquals($input, $output->getRawValue(), '->getRawValue() returns the unescaped value');
$this->assertEquals('<strong>escaped!</strong>', Escaper::escape('entities', $output)->getTitle(), '::escape() does not double escape an object');
- $this->assertTrue(Escaper::escape('entities', new \DirectoryIterator('.')) instanceof IteratorDecorator, '::escape() returns a IteratorDecorator object if the value to escape is an object that implements the ArrayAccess interface');
+ $this->assertType('Symfony\Components\OutputEscaper\IteratorDecorator', Escaper::escape('entities', new \DirectoryIterator('.')), '::escape() returns a IteratorDecorator object if the value to escape is an object that implements the ArrayAccess interface');
}
public function testEscapeDoesNotEscapeObjectMarkedAsBeingSafe()
{
- $this->assertTrue(Escaper::escape('entities', new SafeDecorator(new OutputEscaperTestClass())) instanceof OutputEscaperTestClass, '::escape() returns the original value if it is marked as being safe');
+ $this->assertType('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass', Escaper::escape('entities', new SafeDecorator(new OutputEscaperTestClass())), '::escape() returns the original value if it is marked as being safe');
Escaper::markClassAsSafe('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass');
- $this->assertTrue(Escaper::escape('entities', new OutputEscaperTestClass()) instanceof OutputEscaperTestClass, '::escape() returns the original value if the object class is marked as being safe');
- $this->assertTrue(Escaper::escape('entities', new OutputEscaperTestClassChild()) instanceof OutputEscaperTestClassChild, '::escape() returns the original value if one of the object parent class is marked as being safe');
+ $this->assertType('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass', Escaper::escape('entities', new OutputEscaperTestClass()), '::escape() returns the original value if the object class is marked as being safe');
+ $this->assertType('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass', Escaper::escape('entities', new OutputEscaperTestClassChild()), '::escape() returns the original value if one of the object parent class is marked as being safe');
}
public function testEscapeCannotEscapeResources()
@@ -90,9 +90,9 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
public function testUnescapeDoesNotUnescapeSpecialValues()
{
- $this->assertTrue(Escaper::unescape(null) === null, '::unescape() returns null if the value to unescape is null');
- $this->assertTrue(Escaper::unescape(false) === false, '::unescape() returns false if the value to unescape is false');
- $this->assertTrue(Escaper::unescape(true) === true, '::unescape() returns true if the value to unescape is true');
+ $this->assertNull(Escaper::unescape(null), '::unescape() returns null if the value to unescape is null');
+ $this->assertFalse(Escaper::unescape(false), '::unescape() returns false if the value to unescape is false');
+ $this->assertTrue(Escaper::unescape(true), '::unescape() returns true if the value to unescape is true');
}
public function testUnescapeUnescapesStrings()
@@ -108,7 +108,7 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
'bar' => array('foo' => 'escaped!'),
));
$output = Escaper::unescape($input);
- $this->assertTrue(is_array($output), '::unescape() returns an array if the input is a ArrayDecorator object');
+ $this->assertType('array', $output, '::unescape() returns an array if the input is a ArrayDecorator object');
$this->assertEquals('escaped!', $output['foo'], '::unescape() unescapes all elements of the original array');
$this->assertEquals('escaped!', $output['bar']['foo'], '::unescape() is recursive');
}
@@ -118,21 +118,21 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
$object = new OutputEscaperTestClass();
$input = Escaper::escape('entities', $object);
$output = Escaper::unescape($input);
- $this->assertTrue($output instanceof OutputEscaperTestClass, '::unescape() returns the original object when a ObjectDecorator object is passed');
+ $this->assertType('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass', $output, '::unescape() returns the original object when a ObjectDecorator object is passed');
$this->assertEquals('escaped!', $output->getTitle(), '::unescape() unescapes all methods of the original object');
$this->assertEquals('escaped!', $output->title, '::unescape() unescapes all properties of the original object');
$this->assertEquals('escaped!', $output->getTitleTitle(), '::unescape() is recursive');
- $this->assertTrue(IteratorDecorator::unescape(Escaper::escape('entities', new \DirectoryIterator('.'))) instanceof \DirectoryIterator, '::unescape() unescapes IteratorDecorator objects');
+ $this->assertType('\DirectoryIterator', IteratorDecorator::unescape(Escaper::escape('entities', new \DirectoryIterator('.'))), '::unescape() unescapes IteratorDecorator objects');
}
public function testUnescapeDoesNotUnescapeObjectMarkedAsBeingSafe()
{
- $this->assertTrue(Escaper::unescape(Escaper::escape('entities', new SafeDecorator(new OutputEscaperTestClass()))) instanceof OutputEscaperTestClass, '::unescape() returns the original value if it is marked as being safe');
+ $this->assertType('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass', Escaper::unescape(Escaper::escape('entities', new SafeDecorator(new OutputEscaperTestClass()))), '::unescape() returns the original value if it is marked as being safe');
Escaper::markClassAsSafe('OutputEscaperTestClass');
- $this->assertTrue(Escaper::unescape(Escaper::escape('entities', new OutputEscaperTestClass())) instanceof OutputEscaperTestClass, '::unescape() returns the original value if the object class is marked as being safe');
- $this->assertTrue(Escaper::unescape(Escaper::escape('entities', new OutputEscaperTestClassChild())) instanceof OutputEscaperTestClassChild, '::unescape() returns the original value if one of the object parent class is marked as being safe');
+ $this->assertType('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass', Escaper::unescape(Escaper::escape('entities', new OutputEscaperTestClass())), '::unescape() returns the original value if the object class is marked as being safe');
+ $this->assertType('Symfony\Tests\Components\OutputEscaper\OutputEscaperTestClass', Escaper::unescape(Escaper::escape('entities', new OutputEscaperTestClassChild())), '::unescape() returns the original value if one of the object parent class is marked as being safe');
}
public function testUnescapeDoesNothingToResources()
diff --git a/tests/Symfony/Tests/Components/OutputEscaper/SafeDecoratorTest.php b/tests/Symfony/Tests/Components/OutputEscaper/SafeDecoratorTest.php
index 32a5391bab..ce5b6ec9a5 100644
--- a/tests/Symfony/Tests/Components/OutputEscaper/SafeDecoratorTest.php
+++ b/tests/Symfony/Tests/Components/OutputEscaper/SafeDecoratorTest.php
@@ -41,12 +41,12 @@ class SafeDecoratorTest extends \PHPUnit_Framework_TestCase
{
$safe = new SafeDecorator(new TestClass3());
- $this->assertEquals(true, isset($safe->boolValue), '->__isset() returns true if the property is not null');
- $this->assertEquals(false, isset($safe->nullValue), '->__isset() returns false if the property is null');
- $this->assertEquals(false, isset($safe->undefinedValue), '->__isset() returns false if the property does not exist');
+ $this->assertTrue(isset($safe->boolValue), '->__isset() returns true if the property is not null');
+ $this->assertFalse(isset($safe->nullValue), '->__isset() returns false if the property is null');
+ $this->assertFalse(isset($safe->undefinedValue), '->__isset() returns false if the property does not exist');
unset($safe->boolValue);
- $this->assertEquals(false, isset($safe->boolValue), '->__unset() unsets the embedded property');
+ $this->assertFalse(isset($safe->boolValue), '->__unset() unsets the embedded property');
}
public function testIteratorInterface()
@@ -69,9 +69,9 @@ class SafeDecoratorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar', $safe['foo'], '"ArrayAccess" implementation returns a value from the embedded array');
$safe['foo'] = 'baz';
$this->assertEquals('baz', $safe['foo'], '"ArrayAccess" implementation sets a value on the embedded array');
- $this->assertEquals(true, isset($safe['foo']), '"ArrayAccess" checks if a value is set on the embedded array');
+ $this->assertTrue(isset($safe['foo']), '"ArrayAccess" checks if a value is set on the embedded array');
unset($safe['foo']);
- $this->assertEquals(false, isset($safe['foo']), '"ArrayAccess" unsets a value on the embedded array');
+ $this->assertFalse(isset($safe['foo']), '"ArrayAccess" unsets a value on the embedded array');
}
}
diff --git a/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php b/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php
index fc8b012e50..25919970b5 100644
--- a/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php
+++ b/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php
@@ -71,8 +71,8 @@ class RequestTest extends \PHPUnit_Framework_TestCase
{
$request = new Request();
- $this->assertEquals(null, $request->getFormat(null), '->getFormat() returns null when mime-type is null');
- $this->assertEquals(null, $request->getFormat('unexistant-mime-type'), '->getFormat() returns null when mime-type is unknown');
+ $this->assertNull($request->getFormat(null), '->getFormat() returns null when mime-type is null');
+ $this->assertNull($request->getFormat('unexistant-mime-type'), '->getFormat() returns null when mime-type is unknown');
$this->assertEquals('txt', $request->getFormat('text/plain'), '->getFormat() returns correct format when mime-type have one format only');
$this->assertEquals('js', $request->getFormat('application/javascript'), '->getFormat() returns correct format when format have multiple mime-type (first)');
$this->assertEquals('js', $request->getFormat('application/x-javascript'), '->getFormat() returns correct format when format have multiple mime-type');
diff --git a/tests/Symfony/Tests/Components/Templating/EngineTest.php b/tests/Symfony/Tests/Components/Templating/EngineTest.php
index 2fac620557..500adb15f5 100644
--- a/tests/Symfony/Tests/Components/Templating/EngineTest.php
+++ b/tests/Symfony/Tests/Components/Templating/EngineTest.php
@@ -57,8 +57,10 @@ class EngineTest extends \PHPUnit_Framework_TestCase
$engine->bar;
$this->fail('->__get() throws an InvalidArgumentException if the helper is not defined');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->__get() throws an InvalidArgumentException if the helper is not defined');
+ $this->assertEquals('The helper "bar" is not defined.', $e->getMessage(), '->__get() throws an InvalidArgumentException if the helper is not defined');
}
}
@@ -77,12 +79,14 @@ class EngineTest extends \PHPUnit_Framework_TestCase
$engine->get('foobar');
$this->fail('->get() throws an InvalidArgumentException if the helper is not defined');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->get() throws an InvalidArgumentException if the helper is not defined');
+ $this->assertEquals('The helper "foobar" is not defined.', $e->getMessage(), '->get() throws an InvalidArgumentException if the helper is not defined');
}
$this->assertTrue($engine->has('foo'), '->has() returns true if the helper exists');
- $this->assertTrue(!$engine->has('foobar'), '->has() returns false if the helper does not exist');
+ $this->assertFalse($engine->has('foobar'), '->has() returns false if the helper does not exist');
}
public function testExtendRender()
@@ -93,8 +97,10 @@ class EngineTest extends \PHPUnit_Framework_TestCase
$engine->render('name');
$this->fail('->render() throws an InvalidArgumentException if the template does not exist');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->render() throws an InvalidArgumentException if the template does not exist');
+ $this->assertEquals('The template "name" does not exist (renderer: php).', $e->getMessage(), '->render() throws an InvalidArgumentException if the template does not exist');
}
try
@@ -103,8 +109,10 @@ class EngineTest extends \PHPUnit_Framework_TestCase
$engine->render('foo:name');
$this->fail('->render() throws an InvalidArgumentException if no renderer is registered for the given renderer');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\InvalidArgumentException', $e, '->render() throws an InvalidArgumentException if no renderer is registered for the given renderer');
+ $this->assertEquals('The template "foo" does not exist (renderer: name).', $e->getMessage(), '->render() throws an InvalidArgumentException if no renderer is registered for the given renderer');
}
$engine = new ProjectTemplateEngine(self::$loader, array(), array(new SlotsHelper()));
diff --git a/tests/Symfony/Tests/Components/Templating/Helper/SlotsHelperTest.php b/tests/Symfony/Tests/Components/Templating/Helper/SlotsHelperTest.php
index 849d64c207..5d69cbe175 100644
--- a/tests/Symfony/Tests/Components/Templating/Helper/SlotsHelperTest.php
+++ b/tests/Symfony/Tests/Components/Templating/Helper/SlotsHelperTest.php
@@ -23,7 +23,7 @@ class SlotsHelperTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar', $helper->get('bar', 'bar'), '->get() takes a default value to return if the slot does not exist');
$this->assertTrue($helper->has('foo'), '->has() returns true if the slot exists');
- $this->assertTrue(!$helper->has('bar'), '->has() returns false if the slot does not exist');
+ $this->assertFalse($helper->has('bar'), '->has() returns false if the slot does not exist');
}
public function testOutput()
@@ -34,19 +34,19 @@ class SlotsHelperTest extends \PHPUnit_Framework_TestCase
$ret = $helper->output('foo');
$output = ob_get_clean();
$this->assertEquals('bar', $output, '->output() outputs the content of a slot');
- $this->assertEquals(true, $ret, '->output() returns true if the slot exists');
+ $this->assertTrue($ret, '->output() returns true if the slot exists');
ob_start();
$ret = $helper->output('bar', 'bar');
$output = ob_get_clean();
$this->assertEquals('bar', $output, '->output() takes a default value to return if the slot does not exist');
- $this->assertEquals(true, $ret, '->output() returns true if the slot does not exist but a default value is provided');
+ $this->assertTrue($ret, '->output() returns true if the slot does not exist but a default value is provided');
ob_start();
$ret = $helper->output('bar');
$output = ob_get_clean();
$this->assertEquals('', $output, '->output() outputs nothing if the slot does not exist');
- $this->assertEquals(false, $ret, '->output() returns false if the slot does not exist');
+ $this->assertFalse($ret, '->output() returns false if the slot does not exist');
}
public function testStartStop()
@@ -65,9 +65,11 @@ class SlotsHelperTest extends \PHPUnit_Framework_TestCase
$helper->stop();
$this->fail('->start() throws an InvalidArgumentException if a slot with the same name is already started');
}
- catch (\InvalidArgumentException $e)
+ catch (\Exception $e)
{
$helper->stop();
+ $this->assertType('\InvalidArgumentException', $e, '->start() throws an InvalidArgumentException if a slot with the same name is already started');
+ $this->assertEquals('A slot named "bar" is already started.', $e->getMessage(), '->start() throws an InvalidArgumentException if a slot with the same name is already started');
}
try
@@ -75,8 +77,10 @@ class SlotsHelperTest extends \PHPUnit_Framework_TestCase
$helper->stop();
$this->fail('->stop() throws an LogicException if no slot is started');
}
- catch (\LogicException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\LogicException', $e, '->stop() throws an LogicException if no slot is started');
+ $this->assertEquals('No slot started.', $e->getMessage(), '->stop() throws an LogicException if no slot is started');
}
}
}
diff --git a/tests/Symfony/Tests/Components/Templating/Loader/CacheLoaderTest.php b/tests/Symfony/Tests/Components/Templating/Loader/CacheLoaderTest.php
index def8c3822b..4ab8282188 100644
--- a/tests/Symfony/Tests/Components/Templating/Loader/CacheLoaderTest.php
+++ b/tests/Symfony/Tests/Components/Templating/Loader/CacheLoaderTest.php
@@ -34,7 +34,7 @@ class CacheLoaderTest extends \PHPUnit_Framework_TestCase
$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), $dir);
$loader->setDebugger($debugger = new \ProjectTemplateDebugger());
- $this->assertTrue($loader->load('foo') === false, '->load() returns false if the embed loader is not able to load the template');
+ $this->assertFalse($loader->load('foo'), '->load() returns false if the embed loader is not able to load the template');
$loader->load('index');
$this->assertTrue($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
$loader->load('index');
diff --git a/tests/Symfony/Tests/Components/Templating/Loader/ChainLoaderTest.php b/tests/Symfony/Tests/Components/Templating/Loader/ChainLoaderTest.php
index e3b1760813..5a872c577a 100644
--- a/tests/Symfony/Tests/Components/Templating/Loader/ChainLoaderTest.php
+++ b/tests/Symfony/Tests/Components/Templating/Loader/ChainLoaderTest.php
@@ -44,9 +44,9 @@ class ChainLoaderTest extends \PHPUnit_Framework_TestCase
public function testLoad()
{
$loader = new ProjectTemplateLoader1(array(self::$loader1, self::$loader2));
- $this->assertTrue($loader->load('bar') === false, '->load() returns false if the template is not found');
- $this->assertTrue($loader->load('foo', array('renderer' => 'xml')) === false, '->load() returns false if the template does not exists for the given renderer');
- $this->assertTrue($loader->load('foo') instanceof FileStorage, '->load() returns a FileStorage if the template exists');
+ $this->assertFalse($loader->load('bar'), '->load() returns false if the template is not found');
+ $this->assertFalse($loader->load('foo', array('renderer' => 'xml')), '->load() returns false if the template does not exists for the given renderer');
+ $this->assertType('Symfony\Components\Templating\Storage\FileStorage', $loader->load('foo'), '->load() returns a FileStorage if the template exists');
}
}
diff --git a/tests/Symfony/Tests/Components/Templating/Loader/FilesystemLoaderTest.php b/tests/Symfony/Tests/Components/Templating/Loader/FilesystemLoaderTest.php
index 1b358af09c..384da9c759 100644
--- a/tests/Symfony/Tests/Components/Templating/Loader/FilesystemLoaderTest.php
+++ b/tests/Symfony/Tests/Components/Templating/Loader/FilesystemLoaderTest.php
@@ -49,18 +49,18 @@ class FilesystemLoaderTest extends \PHPUnit_Framework_TestCase
$path = self::$fixturesPath.'/templates';
$loader = new ProjectTemplateLoader2($pathPattern);
$storage = $loader->load($path.'/foo.php');
- $this->assertTrue($storage instanceof FileStorage, '->load() returns a FileStorage if you pass an absolute path');
+ $this->assertType('Symfony\Components\Templating\Storage\FileStorage', $storage, '->load() returns a FileStorage if you pass an absolute path');
$this->assertEquals($path.'/foo.php', (string) $storage, '->load() returns a FileStorage pointing to the passed absolute path');
- $this->assertTrue($loader->load('bar') === false, '->load() returns false if the template is not found');
+ $this->assertFalse($loader->load('bar'), '->load() returns false if the template is not found');
$storage = $loader->load('foo');
- $this->assertTrue($storage instanceof FileStorage, '->load() returns a FileStorage if you pass a relative template that exists');
+ $this->assertType('Symfony\Components\Templating\Storage\FileStorage', $storage, '->load() returns a FileStorage if you pass a relative template that exists');
$this->assertEquals($path.'/foo.php', (string) $storage, '->load() returns a FileStorage pointing to the absolute path of the template');
$loader = new ProjectTemplateLoader2($pathPattern);
$loader->setDebugger($debugger = new \ProjectTemplateDebugger());
- $this->assertTrue($loader->load('foo', array('renderer' => 'xml')) === false, '->load() returns false if the template does not exists for the given renderer');
+ $this->assertFalse($loader->load('foo', array('renderer' => 'xml')), '->load() returns false if the template does not exists for the given renderer');
$this->assertTrue($debugger->hasMessage('Failed loading template'), '->load() logs a "Failed loading template" message if the template is not found');
$loader = new ProjectTemplateLoader2(array(self::$fixturesPath.'/null/%name%', $pathPattern));
diff --git a/tests/Symfony/Tests/Components/Templating/Storage/FileStorageTest.php b/tests/Symfony/Tests/Components/Templating/Storage/FileStorageTest.php
index 650b676274..515fedb341 100644
--- a/tests/Symfony/Tests/Components/Templating/Storage/FileStorageTest.php
+++ b/tests/Symfony/Tests/Components/Templating/Storage/FileStorageTest.php
@@ -19,7 +19,7 @@ class FileStorageTest extends \PHPUnit_Framework_TestCase
public function testGetContent()
{
$storage = new FileStorage('foo');
- $this->assertTrue($storage instanceof Storage, 'FileStorage is an instance of Storage');
+ $this->assertType('Symfony\Components\Templating\Storage\Storage', $storage, 'FileStorage is an instance of Storage');
$storage = new FileStorage(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/templates/foo.php');
$this->assertEquals('', $storage->getContent(), '->getContent() returns the content of the template');
}
diff --git a/tests/Symfony/Tests/Components/Templating/Storage/StringStorageTest.php b/tests/Symfony/Tests/Components/Templating/Storage/StringStorageTest.php
index 656295fea6..96e1a4d8b9 100644
--- a/tests/Symfony/Tests/Components/Templating/Storage/StringStorageTest.php
+++ b/tests/Symfony/Tests/Components/Templating/Storage/StringStorageTest.php
@@ -19,7 +19,7 @@ class StringStorageTest extends \PHPUnit_Framework_TestCase
public function testGetContent()
{
$storage = new StringStorage('foo');
- $this->assertTrue($storage instanceof Storage, 'StringStorage is an instance of Storage');
+ $this->assertType('Symfony\Components\Templating\Storage\Storage', $storage, 'StringStorage is an instance of Storage');
$storage = new StringStorage('foo');
$this->assertEquals('foo', $storage->getContent(), '->getContent() returns the content of the template');
}
diff --git a/tests/Symfony/Tests/Components/Yaml/ParserTest.php b/tests/Symfony/Tests/Components/Yaml/ParserTest.php
index 916a1f641b..3fbb1880be 100644
--- a/tests/Symfony/Tests/Components/Yaml/ParserTest.php
+++ b/tests/Symfony/Tests/Components/Yaml/ParserTest.php
@@ -78,8 +78,10 @@ class ParserTest extends \PHPUnit_Framework_TestCase
$this->fail('YAML files must not contain tabs');
}
- catch (ParserException $e)
+ catch (\Exception $e)
{
+ $this->assertType('\Exception', $e, 'YAML files must not contain tabs');
+ $this->assertEquals('A YAML file cannot contain tabs as indentation at line 2 ('.strpbrk($yaml, "\t").').', $e->getMessage(), 'YAML files must not contain tabs');
}
}
}
diff --git a/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt b/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt
index e884d9022f..78acf10170 100644
--- a/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt
+++ b/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt
@@ -1,7 +1,7 @@
- [RuntimeException]
+ [InvalidArgumentException]
The "--foo" option does not exist.
diff --git a/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php b/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
index 8fbdf8cf00..c00f155d63 100644
--- a/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
+++ b/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
@@ -38,7 +38,7 @@ class ProjectServiceContainer extends Container
*/
protected function getFooService()
{
- require_once '%path%/foo.php';
+ require_once '%path%foo.php';
$instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $this->getFoo_BazService(), array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo'), 'bar' => $this->getParameter('foo')), true, $this);
$instance->setBar('bar');
@@ -153,11 +153,11 @@ class ProjectServiceContainer extends Container
public function findAnnotatedServiceIds($name)
{
static $annotations = array (
- 'foo' =>
+ 'foo' =>
array (
- 'foo' =>
+ 'foo' =>
array (
- 0 =>
+ 0 =>
array (
'foo' => 'foo',
),
diff --git a/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml b/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml
index a89e56f50b..f0a62ec37c 100644
--- a/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml
+++ b/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml
@@ -12,7 +12,7 @@
- %path%/foo.php
+ %path%foo.php
foo
diff --git a/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml b/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml
index cfa08a3017..79d414db58 100644
--- a/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml
+++ b/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml
@@ -9,7 +9,7 @@ services:
annotations:
- { name: foo, foo: foo }
- { name: foo, bar: bar }
- file: %path%/foo.php
+ file: %path%foo.php
constructor: getInstance
arguments: [foo, '@foo.baz', { '%foo%': 'foo is %foo%', bar: '%foo%' }, true, '@service_container']
calls: