fixed assertEquals() calls arguments order
The conversion has been done automatically with the following command: perl -p -i -e 's#this\->assertEquals\((.+?), (.+?)(, '\''(\-|\:|_)|\);)#this->assertEquals($2, $1$3#g' tests/Symfony/Tests/*/*.php tests/Symfony/Tests/*/*/*.php tests/Symfony/Tests/*/*/*.php ... and with some manual tweaking after that
This commit is contained in:
parent
39aa067c21
commit
2dc36191d1
@ -33,53 +33,53 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$application = new Application('foo', 'bar');
|
||||
$this->assertEquals($application->getName(), 'foo', '__construct() takes the application name as its first argument');
|
||||
$this->assertEquals($application->getVersion(), 'bar', '__construct() takes the application version as its first argument');
|
||||
$this->assertEquals(array_keys($application->getCommands()), array('help', 'list'), '__construct() registered the help and list commands by default');
|
||||
$this->assertEquals('foo', $application->getName(), '__construct() takes the application name as its first argument');
|
||||
$this->assertEquals('bar', $application->getVersion(), '__construct() takes the application version as its first argument');
|
||||
$this->assertEquals(array('help', 'list'), array_keys($application->getCommands()), '__construct() registered the help and list commands by default');
|
||||
}
|
||||
|
||||
public function testSetGetName()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setName('foo');
|
||||
$this->assertEquals($application->getName(), 'foo', '->setName() sets the name of the application');
|
||||
$this->assertEquals('foo', $application->getName(), '->setName() sets the name of the application');
|
||||
}
|
||||
|
||||
public function testSetGetVersion()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setVersion('bar');
|
||||
$this->assertEquals($application->getVersion(), 'bar', '->setVersion() sets the version of the application');
|
||||
$this->assertEquals('bar', $application->getVersion(), '->setVersion() sets the version of the application');
|
||||
}
|
||||
|
||||
public function testGetLongVersion()
|
||||
{
|
||||
$application = new Application('foo', 'bar');
|
||||
$this->assertEquals($application->getLongVersion(), '<info>foo</info> version <comment>bar</comment>', '->getLongVersion() returns the long version of the application');
|
||||
$this->assertEquals('<info>foo</info> version <comment>bar</comment>', $application->getLongVersion(), '->getLongVersion() returns the long version of the application');
|
||||
}
|
||||
|
||||
public function testHelp()
|
||||
{
|
||||
$application = new Application();
|
||||
$this->assertEquals($application->getHelp(), file_get_contents(self::$fixturesPath.'/application_gethelp.txt'), '->setHelp() returns a help message');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/application_gethelp.txt'), $application->getHelp(), '->setHelp() returns a help message');
|
||||
}
|
||||
|
||||
public function testGetCommands()
|
||||
{
|
||||
$application = new Application();
|
||||
$commands = $application->getCommands();
|
||||
$this->assertEquals(get_class($commands['help']), 'Symfony\\Components\\Console\\Command\\HelpCommand', '->getCommands() returns the registered commands');
|
||||
$this->assertEquals('Symfony\\Components\\Console\\Command\\HelpCommand', get_class($commands['help']), '->getCommands() returns the registered commands');
|
||||
|
||||
$application->addCommand(new \FooCommand());
|
||||
$commands = $application->getCommands('foo');
|
||||
$this->assertEquals(count($commands), 1, '->getCommands() takes a namespace as its first argument');
|
||||
$this->assertEquals(1, count($commands), '->getCommands() takes a namespace as its first argument');
|
||||
}
|
||||
|
||||
public function testRegister()
|
||||
{
|
||||
$application = new Application();
|
||||
$command = $application->register('foo');
|
||||
$this->assertEquals($command->getName(), 'foo', '->register() regiters a new command');
|
||||
$this->assertEquals('foo', $command->getName(), '->register() regiters a new command');
|
||||
}
|
||||
|
||||
public function testAddCommand()
|
||||
@ -87,12 +87,12 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$application = new Application();
|
||||
$application->addCommand($foo = new \FooCommand());
|
||||
$commands = $application->getCommands();
|
||||
$this->assertEquals($commands['foo:bar'], $foo, '->addCommand() registers a command');
|
||||
$this->assertEquals($foo, $commands['foo:bar'], '->addCommand() registers a command');
|
||||
|
||||
$application = new Application();
|
||||
$application->addCommands(array($foo = new \FooCommand(), $foo1 = new \Foo1Command()));
|
||||
$commands = $application->getCommands();
|
||||
$this->assertEquals(array($commands['foo:bar'], $commands['foo:bar1']), array($foo, $foo1), '->addCommands() registers an array of commands');
|
||||
$this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
|
||||
}
|
||||
|
||||
public function testHasGetCommand()
|
||||
@ -103,8 +103,8 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$application->addCommand($foo = new \FooCommand());
|
||||
$this->assertTrue($application->hasCommand('afoobar'), '->hasCommand() returns true if an alias is registered');
|
||||
$this->assertEquals($application->getCommand('foo:bar'), $foo, '->getCommand() returns a command by name');
|
||||
$this->assertEquals($application->getCommand('afoobar'), $foo, '->getCommand() returns a command by alias');
|
||||
$this->assertEquals($foo, $application->getCommand('foo:bar'), '->getCommand() returns a command by name');
|
||||
$this->assertEquals($foo, $application->getCommand('afoobar'), '->getCommand() returns a command by alias');
|
||||
|
||||
try
|
||||
{
|
||||
@ -119,7 +119,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$application->addCommand($foo = new \FooCommand());
|
||||
$application->setWantHelps();
|
||||
$command = $application->getCommand('foo:bar');
|
||||
$this->assertEquals(get_class($command), 'Symfony\Components\Console\Command\HelpCommand', '->getCommand() returns the help command if --help is provided as the input');
|
||||
$this->assertEquals('Symfony\Components\Console\Command\HelpCommand', get_class($command), '->getCommand() returns the help command if --help is provided as the input');
|
||||
}
|
||||
|
||||
public function testGetNamespaces()
|
||||
@ -127,17 +127,17 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$application = new TestApplication();
|
||||
$application->addCommand(new \FooCommand());
|
||||
$application->addCommand(new \Foo1Command());
|
||||
$this->assertEquals($application->getNamespaces(), array('foo'), '->getNamespaces() returns an array of unique used namespaces');
|
||||
$this->assertEquals(array('foo'), $application->getNamespaces(), '->getNamespaces() returns an array of unique used namespaces');
|
||||
}
|
||||
|
||||
public function testFindNamespace()
|
||||
{
|
||||
$application = new TestApplication();
|
||||
$application->addCommand(new \FooCommand());
|
||||
$this->assertEquals($application->findNamespace('foo'), 'foo', '->findNamespace() returns the given namespace if it exists');
|
||||
$this->assertEquals($application->findNamespace('f'), 'foo', '->findNamespace() finds a namespace given an abbreviation');
|
||||
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
|
||||
$this->assertEquals('foo', $application->findNamespace('f'), '->findNamespace() finds a namespace given an abbreviation');
|
||||
$application->addCommand(new \Foo2Command());
|
||||
$this->assertEquals($application->findNamespace('foo'), 'foo', '->findNamespace() returns the given namespace if it exists');
|
||||
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
|
||||
try
|
||||
{
|
||||
$application->findNamespace('f');
|
||||
@ -161,11 +161,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$application = new TestApplication();
|
||||
$application->addCommand(new \FooCommand());
|
||||
$this->assertEquals(get_class($application->findCommand('foo:bar')), 'FooCommand', '->findCommand() returns a command if its name exists');
|
||||
$this->assertEquals(get_class($application->findCommand('h')), 'Symfony\Components\Console\Command\HelpCommand', '->findCommand() returns a command if its name exists');
|
||||
$this->assertEquals(get_class($application->findCommand('f:bar')), 'FooCommand', '->findCommand() returns a command if the abbreviation for the namespace exists');
|
||||
$this->assertEquals(get_class($application->findCommand('f:b')), 'FooCommand', '->findCommand() returns a command if the abbreviation for the namespace and the command name exist');
|
||||
$this->assertEquals(get_class($application->findCommand('a')), 'FooCommand', '->findCommand() returns a command if the abbreviation exists for an alias');
|
||||
$this->assertEquals('FooCommand', get_class($application->findCommand('foo:bar')), '->findCommand() returns a command if its name exists');
|
||||
$this->assertEquals('Symfony\Components\Console\Command\HelpCommand', get_class($application->findCommand('h')), '->findCommand() returns a command if its name exists');
|
||||
$this->assertEquals('FooCommand', get_class($application->findCommand('f:bar')), '->findCommand() returns a command if the abbreviation for the namespace exists');
|
||||
$this->assertEquals('FooCommand', get_class($application->findCommand('f:b')), '->findCommand() returns a command if the abbreviation for the namespace and the command name exist');
|
||||
$this->assertEquals('FooCommand', get_class($application->findCommand('a')), '->findCommand() returns a command if the abbreviation exists for an alias');
|
||||
|
||||
$application->addCommand(new \Foo1Command());
|
||||
$application->addCommand(new \Foo2Command());
|
||||
@ -206,7 +206,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$application->setCatchExceptions(true);
|
||||
$tester->run(array('command' => 'foo'));
|
||||
$this->assertEquals($tester->getDisplay(), file_get_contents(self::$fixturesPath.'/application_renderexception1.txt'), '->setCatchExceptions() sets the catch exception flag');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/application_renderexception1.txt'), $tester->getDisplay(), '->setCatchExceptions() sets the catch exception flag');
|
||||
|
||||
$application->setCatchExceptions(false);
|
||||
try
|
||||
@ -223,16 +223,16 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$application = new Application();
|
||||
$application->addCommand(new \FooCommand);
|
||||
$this->assertEquals($application->asText(), file_get_contents(self::$fixturesPath.'/application_astext1.txt'), '->asText() returns a text representation of the application');
|
||||
$this->assertEquals($application->asText('foo'), file_get_contents(self::$fixturesPath.'/application_astext2.txt'), '->asText() returns a text representation of the application');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testAsXml()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->addCommand(new \FooCommand);
|
||||
$this->assertEquals($application->asXml(), file_get_contents(self::$fixturesPath.'/application_asxml1.txt'), '->asXml() returns an XML representation of the application');
|
||||
$this->assertEquals($application->asXml('foo'), file_get_contents(self::$fixturesPath.'/application_asxml2.txt'), '->asXml() returns an XML representation of the application');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testRenderException()
|
||||
@ -242,13 +242,13 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo'));
|
||||
$this->assertEquals($tester->getDisplay(), file_get_contents(self::$fixturesPath.'/application_renderexception1.txt'), '->renderException() renders a pretty exception');
|
||||
$this->assertEquals(file_get_contents(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($tester->getDisplay(), file_get_contents(self::$fixturesPath.'/application_renderexception2.txt'), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
@ -263,25 +263,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$application->run();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertEquals(get_class($command->input), 'Symfony\Components\Console\Input\ArgvInput', '->run() creates an ArgvInput by default if none is given');
|
||||
$this->assertEquals(get_class($command->output), 'Symfony\Components\Console\Output\ConsoleOutput', '->run() creates a ConsoleOutput by default if none is given');
|
||||
$this->assertEquals('Symfony\Components\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
|
||||
$this->assertEquals('Symfony\Components\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array());
|
||||
$this->assertEquals($tester->getDisplay(), file_get_contents(self::$fixturesPath.'/application_run1.txt'), '->run() runs the list command if no argument is passed');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/application_run1.txt'), $tester->getDisplay(), '->run() runs the list command if no argument is passed');
|
||||
|
||||
$tester->run(array('--help' => true));
|
||||
$this->assertEquals($tester->getDisplay(), file_get_contents(self::$fixturesPath.'/application_run2.txt'), '->run() runs the help command if --help is passed');
|
||||
$this->assertEquals(file_get_contents(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($tester->getDisplay(), file_get_contents(self::$fixturesPath.'/application_run3.txt'), '->run() displays the help if --help is passed');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/application_run3.txt'), $tester->getDisplay(), '->run() displays the help if --help is passed');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
@ -295,21 +295,21 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$application->setCatchExceptions(false);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('--version' => true));
|
||||
$this->assertEquals($tester->getDisplay(), file_get_contents(self::$fixturesPath.'/application_run4.txt'), '->run() displays the program version if --version is passed');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/application_run4.txt'), $tester->getDisplay(), '->run() displays the program version if --version is passed');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'list', '--quiet' => true));
|
||||
$this->assertEquals($tester->getDisplay(), '', '->run() removes all output if --quiet is passed');
|
||||
$this->assertEquals('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'list', '--verbose' => true));
|
||||
$this->assertEquals($tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->run() sets the output to verbose is --verbose is passed');
|
||||
$this->assertEquals(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose is --verbose is passed');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
@ -317,7 +317,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$application->addCommand(new \FooCommand());
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'foo:bar', '--no-interaction' => true));
|
||||
$this->assertEquals($tester->getDisplay(), "called\n", '->run() does not called interact() if --no-interaction is passed');
|
||||
$this->assertEquals("called\n", $tester->getDisplay(), '->run() does not called interact() if --no-interaction is passed');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
||||
$command = new Command('foo:bar');
|
||||
$this->assertEquals($command->getFullName(), 'foo:bar', '__construct() takes the command name as its first argument');
|
||||
$this->assertEquals('foo:bar', $command->getFullName(), '__construct() takes the command name as its first argument');
|
||||
}
|
||||
|
||||
public function testSetApplication()
|
||||
@ -54,15 +54,15 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
$application = new Application();
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication($application);
|
||||
$this->assertEquals($command->getApplication(), $application, '->setApplication() sets the current application');
|
||||
$this->assertEquals($application, $command->getApplication(), '->setApplication() sets the current application');
|
||||
}
|
||||
|
||||
public function testSetGetDefinition()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$ret = $command->setDefinition($definition = new InputDefinition());
|
||||
$this->assertEquals($ret, $command, '->setDefinition() implements a fluent interface');
|
||||
$this->assertEquals($command->getDefinition(), $definition, '->setDefinition() sets the current InputDefinition instance');
|
||||
$this->assertEquals($command, $ret, '->setDefinition() implements a fluent interface');
|
||||
$this->assertEquals($definition, $command->getDefinition(), '->setDefinition() sets the current InputDefinition instance');
|
||||
$command->setDefinition(array(new InputArgument('foo'), new InputOption('bar')));
|
||||
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument');
|
||||
$this->assertTrue($command->getDefinition()->hasOption('bar'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument');
|
||||
@ -73,7 +73,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$ret = $command->addArgument('foo');
|
||||
$this->assertEquals($ret, $command, '->addArgument() implements a fluent interface');
|
||||
$this->assertEquals($command, $ret, '->addArgument() implements a fluent interface');
|
||||
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->addArgument() adds an argument to the command');
|
||||
}
|
||||
|
||||
@ -81,27 +81,27 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$ret = $command->addOption('foo');
|
||||
$this->assertEquals($ret, $command, '->addOption() implements a fluent interface');
|
||||
$this->assertEquals($command, $ret, '->addOption() implements a fluent interface');
|
||||
$this->assertTrue($command->getDefinition()->hasOption('foo'), '->addOption() adds an option to the command');
|
||||
}
|
||||
|
||||
public function testgetNamespaceGetNameGetFullNameSetName()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals($command->getNamespace(), 'namespace', '->getNamespace() returns the command namespace');
|
||||
$this->assertEquals($command->getName(), 'name', '->getName() returns the command name');
|
||||
$this->assertEquals($command->getFullName(), 'namespace:name', '->getNamespace() returns the full command name');
|
||||
$this->assertEquals('namespace', $command->getNamespace(), '->getNamespace() returns the command namespace');
|
||||
$this->assertEquals('name', $command->getName(), '->getName() returns the command name');
|
||||
$this->assertEquals('namespace:name', $command->getFullName(), '->getNamespace() returns the full command name');
|
||||
$command->setName('foo');
|
||||
$this->assertEquals($command->getName(), 'foo', '->setName() sets the command name');
|
||||
$this->assertEquals('foo', $command->getName(), '->setName() sets the command name');
|
||||
|
||||
$command->setName(':bar');
|
||||
$this->assertEquals($command->getName(), 'bar', '->setName() sets the command name');
|
||||
$this->assertEquals($command->getNamespace(), '', '->setName() can set the command namespace');
|
||||
$this->assertEquals('bar', $command->getName(), '->setName() sets the command name');
|
||||
$this->assertEquals('', $command->getNamespace(), '->setName() can set the command namespace');
|
||||
|
||||
$ret = $command->setName('foobar:bar');
|
||||
$this->assertEquals($ret, $command, '->setName() implements a fluent interface');
|
||||
$this->assertEquals($command->getName(), 'bar', '->setName() sets the command name');
|
||||
$this->assertEquals($command->getNamespace(), 'foobar', '->setName() can set the command namespace');
|
||||
$this->assertEquals($command, $ret, '->setName() implements a fluent interface');
|
||||
$this->assertEquals('bar', $command->getName(), '->setName() sets the command name');
|
||||
$this->assertEquals('foobar', $command->getNamespace(), '->setName() can set the command namespace');
|
||||
|
||||
try
|
||||
{
|
||||
@ -125,28 +125,28 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetSetDescription()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals($command->getDescription(), 'description', '->getDescription() returns the description');
|
||||
$this->assertEquals('description', $command->getDescription(), '->getDescription() returns the description');
|
||||
$ret = $command->setDescription('description1');
|
||||
$this->assertEquals($ret, $command, '->setDescription() implements a fluent interface');
|
||||
$this->assertEquals($command->getDescription(), 'description1', '->setDescription() sets the description');
|
||||
$this->assertEquals($command, $ret, '->setDescription() implements a fluent interface');
|
||||
$this->assertEquals('description1', $command->getDescription(), '->setDescription() sets the description');
|
||||
}
|
||||
|
||||
public function testGetSetHelp()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals($command->getHelp(), 'help', '->getHelp() returns the help');
|
||||
$this->assertEquals('help', $command->getHelp(), '->getHelp() returns the help');
|
||||
$ret = $command->setHelp('help1');
|
||||
$this->assertEquals($ret, $command, '->setHelp() implements a fluent interface');
|
||||
$this->assertEquals($command->getHelp(), 'help1', '->setHelp() sets the help');
|
||||
$this->assertEquals($command, $ret, '->setHelp() implements a fluent interface');
|
||||
$this->assertEquals('help1', $command->getHelp(), '->setHelp() sets the help');
|
||||
}
|
||||
|
||||
public function testGetSetAliases()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals($command->getAliases(), array('name'), '->getAliases() returns the aliases');
|
||||
$this->assertEquals(array('name'), $command->getAliases(), '->getAliases() returns the aliases');
|
||||
$ret = $command->setAliases(array('name1'));
|
||||
$this->assertEquals($ret, $command, '->setAliases() implements a fluent interface');
|
||||
$this->assertEquals($command->getAliases(), array('name1'), '->setAliases() sets the aliases');
|
||||
$this->assertEquals($command, $ret, '->setAliases() implements a fluent interface');
|
||||
$this->assertEquals(array('name1'), $command->getAliases(), '->setAliases() sets the aliases');
|
||||
}
|
||||
|
||||
public function testGetSynopsis()
|
||||
@ -154,7 +154,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
$command = new \TestCommand();
|
||||
$command->addOption('foo');
|
||||
$command->addArgument('foo');
|
||||
$this->assertEquals($command->getSynopsis(), 'namespace:name [--foo] [foo]', '->getSynopsis() returns the synopsis');
|
||||
$this->assertEquals('namespace:name [--foo] [foo]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
|
||||
}
|
||||
|
||||
public function testMergeApplicationDefinition()
|
||||
@ -172,7 +172,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition() merges the application options and the command options');
|
||||
|
||||
$command->mergeApplicationDefinition();
|
||||
$this->assertEquals($command->getDefinition()->getArgumentCount(), 3, '->mergeApplicationDefinition() does not try to merge twice the application arguments and options');
|
||||
$this->assertEquals(3, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments and options');
|
||||
|
||||
$command = new \TestCommand();
|
||||
$command->mergeApplicationDefinition();
|
||||
@ -193,8 +193,8 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
||||
|
||||
$this->assertEquals($tester->execute(array(), array('interactive' => true)), "interact called\nexecute called\n", '->run() calls the interact() method if the input is interactive');
|
||||
$this->assertEquals($tester->execute(array(), array('interactive' => false)), "execute called\n", '->run() does not call the interact() method if the input is not interactive');
|
||||
$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');
|
||||
|
||||
$command = new Command('foo');
|
||||
try
|
||||
@ -216,10 +216,10 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$output->writeln('from the code...');
|
||||
});
|
||||
$this->assertEquals($ret, $command, '->setCode() implements a fluent interface');
|
||||
$this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array());
|
||||
$this->assertEquals($tester->getDisplay(), "interact called\nfrom the code...\n");
|
||||
$this->assertEquals("interact called\nfrom the code...\n", $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testAsText()
|
||||
@ -228,7 +228,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
$command->setApplication(new Application());
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array());
|
||||
$this->assertEquals($command->asText(), file_get_contents(self::$fixturesPath.'/command_astext.txt'), '->asText() returns a text representation of the command');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/command_astext.txt'), $command->asText(), '->asText() returns a text representation of the command');
|
||||
}
|
||||
|
||||
public function testAsXml()
|
||||
@ -237,6 +237,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
$command->setApplication(new Application());
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array());
|
||||
$this->assertEquals($command->asXml(), file_get_contents(self::$fixturesPath.'/command_asxml.txt'), '->asXml() returns an XML representation of the command');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/command_asxml.txt'), $command->asXml(), '->asXml() returns an XML representation of the command');
|
||||
}
|
||||
}
|
||||
|
@ -20,16 +20,16 @@ class FormatterHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals($formatter->formatSection('cli', 'Some text to display'), '<info>[cli]</info> Some text to display', '::formatSection() formats a message in a section');
|
||||
$this->assertEquals('<info>[cli]</info> Some text to display', $formatter->formatSection('cli', 'Some text to display'), '::formatSection() formats a message in a section');
|
||||
}
|
||||
|
||||
public function testFormatBlock()
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals($formatter->formatBlock('Some text to display', 'error'), '<error> Some text to display </error>', '::formatBlock() formats a message in a block');
|
||||
$this->assertEquals($formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'), "<error> Some text to display </error>\n<error> foo bar </error>", '::formatBlock() formats a message in a block');
|
||||
$this->assertEquals('<error> Some text to display </error>', $formatter->formatBlock('Some text to display', 'error'), '::formatBlock() formats a message in a block');
|
||||
$this->assertEquals("<error> Some text to display </error>\n<error> foo bar </error>", $formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'), '::formatBlock() formats a message in a block');
|
||||
|
||||
$this->assertEquals($formatter->formatBlock('Some text to display', 'error', true), "<error> </error>\n<error> Some text to display </error>\n<error> </error>", '::formatBlock() formats a message in a block');
|
||||
$this->assertEquals("<error> </error>\n<error> Some text to display </error>\n<error> </error>", $formatter->formatBlock('Some text to display', 'error', true), '::formatBlock() formats a message in a block');
|
||||
}
|
||||
}
|
||||
|
@ -23,29 +23,29 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$_SERVER['argv'] = array('cli.php', 'foo');
|
||||
$input = new TestInput();
|
||||
$this->assertEquals($input->getTokens(), array('foo'), '__construct() automatically get its input from the argv server variable');
|
||||
$this->assertEquals(array('foo'), $input->getTokens(), '__construct() automatically get its input from the argv server variable');
|
||||
}
|
||||
|
||||
public function testParser()
|
||||
{
|
||||
$input = new TestInput(array('cli.php', 'foo'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments');
|
||||
$this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
|
||||
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals($input->getArguments(), array('name' => 'foo'), '->parse() is stateless');
|
||||
$this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() is stateless');
|
||||
|
||||
$input = new TestInput(array('cli.php', '--foo'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => true), '->parse() parses long options without parameter');
|
||||
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses long options without parameter');
|
||||
|
||||
$input = new TestInput(array('cli.php', '--foo=bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a required parameter (with a = separator)');
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required parameter (with a = separator)');
|
||||
|
||||
$input = new TestInput(array('cli.php', '--foo', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a required parameter (with a space separator)');
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required parameter (with a space separator)');
|
||||
|
||||
try
|
||||
{
|
||||
@ -59,19 +59,19 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$input = new TestInput(array('cli.php', '-f'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => true), '->parse() parses short options without parameter');
|
||||
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses short options without parameter');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-fbar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses short options with a required parameter (with no separator)');
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required parameter (with no separator)');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-f', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses short options with a required parameter (with a space separator)');
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required parameter (with a space separator)');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-f', '-b', 'foo'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL), new InputOption('bar', 'b'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => null, 'bar' => true), '->parse() parses short options with an optional parameter which is not present');
|
||||
$this->assertEquals(array('foo' => null, 'bar' => true), $input->getOptions(), '->parse() parses short options with an optional parameter which is not present');
|
||||
|
||||
try
|
||||
{
|
||||
@ -125,32 +125,32 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$input = new TestInput(array('cli.php', '-fb'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => true, 'bar' => true), '->parse() parses short options when they are aggregated as a single one');
|
||||
$this->assertEquals(array('foo' => true, 'bar' => true), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-fb', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::PARAMETER_REQUIRED))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => true, 'bar' => 'bar'), '->parse() parses short options when they are aggregated as a single one and the last one has a required parameter');
|
||||
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has a required parameter');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-fb', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => true, 'bar' => 'bar'), '->parse() parses short options when they are aggregated as a single one and the last one has an optional parameter');
|
||||
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional parameter');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-fbbar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => true, 'bar' => 'bar'), '->parse() parses short options when they are aggregated as a single one and the last one has an optional parameter with no separator');
|
||||
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional parameter with no separator');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-fbbar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL), new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bbar', 'bar' => null), '->parse() parses short options when they are aggregated as a single one and one of them takes a parameter');
|
||||
$this->assertEquals(array('foo' => 'bbar', 'bar' => null), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and one of them takes a parameter');
|
||||
}
|
||||
|
||||
public function testGetFirstArgument()
|
||||
{
|
||||
$input = new TestInput(array('cli.php', '-fbbar'));
|
||||
$this->assertEquals($input->getFirstArgument(), '', '->getFirstArgument() returns the first argument from the raw input');
|
||||
$this->assertEquals('', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');
|
||||
|
||||
$input = new TestInput(array('cli.php', '-fbbar', 'foo'));
|
||||
$this->assertEquals($input->getFirstArgument(), 'foo', '->getFirstArgument() returns the first argument from the raw input');
|
||||
$this->assertEquals('foo', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');
|
||||
}
|
||||
|
||||
public function testHasParameterOption()
|
||||
|
@ -22,11 +22,11 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetFirstArgument()
|
||||
{
|
||||
$input = new ArrayInput(array());
|
||||
$this->assertEquals($input->getFirstArgument(), null, '->getFirstArgument() returns null if no argument were passed');
|
||||
$this->assertEquals(null, $input->getFirstArgument(), '->getFirstArgument() returns null if no argument were passed');
|
||||
$input = new ArrayInput(array('name' => 'Fabien'));
|
||||
$this->assertEquals($input->getFirstArgument(), 'Fabien', '->getFirstArgument() returns the first passed argument');
|
||||
$this->assertEquals('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
|
||||
$input = new ArrayInput(array('--foo' => 'bar', 'name' => 'Fabien'));
|
||||
$this->assertEquals($input->getFirstArgument(), 'Fabien', '->getFirstArgument() returns the first passed argument');
|
||||
$this->assertEquals('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
|
||||
}
|
||||
|
||||
public function testHasParameterOption()
|
||||
@ -42,7 +42,7 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
|
||||
public function testParse()
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals($input->getArguments(), array('name' => 'foo'), '->parse() parses required arguments');
|
||||
$this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
|
||||
|
||||
try
|
||||
{
|
||||
@ -54,13 +54,13 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options');
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options');
|
||||
|
||||
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses long options with a default value');
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a default value');
|
||||
|
||||
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'default'), '->parse() parses long options with a default value');
|
||||
$this->assertEquals(array('foo' => 'default'), $input->getOptions(), '->parse() parses long options with a default value');
|
||||
|
||||
try
|
||||
{
|
||||
@ -81,7 +81,7 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$input = new ArrayInput(array('-f' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f'))));
|
||||
$this->assertEquals($input->getOptions(), array('foo' => 'bar'), '->parse() parses short options');
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options');
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -20,20 +20,20 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$argument = new InputArgument('foo');
|
||||
$this->assertEquals($argument->getName(), 'foo', '__construct() takes a name as its first argument');
|
||||
$this->assertEquals('foo', $argument->getName(), '__construct() takes a name as its first argument');
|
||||
|
||||
// mode argument
|
||||
$argument = new InputArgument('foo');
|
||||
$this->assertEquals($argument->isRequired(), false, '__construct() gives a "Argument::OPTIONAL" mode by default');
|
||||
$this->assertEquals(false, $argument->isRequired(), '__construct() gives a "Argument::OPTIONAL" mode by default');
|
||||
|
||||
$argument = new InputArgument('foo', null);
|
||||
$this->assertEquals($argument->isRequired(), false, '__construct() can take "Argument::OPTIONAL" as its mode');
|
||||
$this->assertEquals(false, $argument->isRequired(), '__construct() can take "Argument::OPTIONAL" as its mode');
|
||||
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL);
|
||||
$this->assertEquals($argument->isRequired(), false, '__construct() can take "Argument::PARAMETER_OPTIONAL" as its mode');
|
||||
$this->assertEquals(false, $argument->isRequired(), '__construct() can take "Argument::PARAMETER_OPTIONAL" as its mode');
|
||||
|
||||
$argument = new InputArgument('foo', InputArgument::REQUIRED);
|
||||
$this->assertEquals($argument->isRequired(), true, '__construct() can take "Argument::PARAMETER_REQUIRED" as its mode');
|
||||
$this->assertEquals(true, $argument->isRequired(), '__construct() can take "Argument::PARAMETER_REQUIRED" as its mode');
|
||||
|
||||
try
|
||||
{
|
||||
@ -58,13 +58,13 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetDescription()
|
||||
{
|
||||
$argument = new InputArgument('foo', null, 'Some description');
|
||||
$this->assertEquals($argument->getDescription(), 'Some description', '->getDescription() return the message description');
|
||||
$this->assertEquals('Some description', $argument->getDescription(), '->getDescription() return the message description');
|
||||
}
|
||||
|
||||
public function testGetDefault()
|
||||
{
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
|
||||
$this->assertEquals($argument->getDefault(), 'default', '->getDefault() return the default value');
|
||||
$this->assertEquals('default', $argument->getDefault(), '->getDefault() return the default value');
|
||||
}
|
||||
|
||||
public function testSetDefault()
|
||||
@ -73,11 +73,11 @@ class InputArgumentTest extends \PHPUnit_Framework_TestCase
|
||||
$argument->setDefault(null);
|
||||
$this->assertTrue(is_null($argument->getDefault()), '->setDefault() can reset the default value by passing null');
|
||||
$argument->setDefault('another');
|
||||
$this->assertEquals($argument->getDefault(), 'another', '->setDefault() changes the default value');
|
||||
$this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
|
||||
$argument->setDefault(array(1, 2));
|
||||
$this->assertEquals($argument->getDefault(), array(1, 2), '->setDefault() changes the default value');
|
||||
$this->assertEquals(array(1, 2), $argument->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -33,18 +33,18 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$this->assertEquals($definition->getArguments(), array(), '__construct() creates a new InputDefinition object');
|
||||
$this->assertEquals(array(), $definition->getArguments(), '__construct() creates a new InputDefinition object');
|
||||
|
||||
$definition = new InputDefinition(array($this->foo, $this->bar));
|
||||
$this->assertEquals($definition->getArguments(), array('foo' => $this->foo, 'bar' => $this->bar), '__construct() takes an array of InputArgument objects as its first argument');
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '__construct() takes an array of InputArgument objects as its first argument');
|
||||
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$this->assertEquals($definition->getOptions(), array(), '__construct() creates a new InputDefinition object');
|
||||
$this->assertEquals(array(), $definition->getOptions(), '__construct() creates a new InputDefinition object');
|
||||
|
||||
$definition = new InputDefinition(array($this->foo, $this->bar));
|
||||
$this->assertEquals($definition->getOptions(), array('foo' => $this->foo, 'bar' => $this->bar), '__construct() takes an array of InputOption objects as its first argument');
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '__construct() takes an array of InputOption objects as its first argument');
|
||||
}
|
||||
|
||||
public function testSetArguments()
|
||||
@ -53,10 +53,10 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->setArguments(array($this->foo));
|
||||
$this->assertEquals($definition->getArguments(), array('foo' => $this->foo), '->setArguments() sets the array of InputArgument objects');
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->setArguments() sets the array of InputArgument objects');
|
||||
$definition->setArguments(array($this->bar));
|
||||
|
||||
$this->assertEquals($definition->getArguments(), array('bar' => $this->bar), '->setArguments() clears all InputArgument objects');
|
||||
$this->assertEquals(array('bar' => $this->bar), $definition->getArguments(), '->setArguments() clears all InputArgument objects');
|
||||
}
|
||||
|
||||
public function testAddArguments()
|
||||
@ -65,9 +65,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArguments(array($this->foo));
|
||||
$this->assertEquals($definition->getArguments(), array('foo' => $this->foo), '->addArguments() adds an array of InputArgument objects');
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArguments() adds an array of InputArgument objects');
|
||||
$definition->addArguments(array($this->bar));
|
||||
$this->assertEquals($definition->getArguments(), array('foo' => $this->foo, 'bar' => $this->bar), '->addArguments() does not clear existing InputArgument objects');
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '->addArguments() does not clear existing InputArgument objects');
|
||||
}
|
||||
|
||||
public function testAddArgument()
|
||||
@ -76,9 +76,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArgument($this->foo);
|
||||
$this->assertEquals($definition->getArguments(), array('foo' => $this->foo), '->addArgument() adds a InputArgument object');
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArgument() adds a InputArgument object');
|
||||
$definition->addArgument($this->bar);
|
||||
$this->assertEquals($definition->getArguments(), array('foo' => $this->foo, 'bar' => $this->bar), '->addArgument() adds a InputArgument object');
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '->addArgument() adds a InputArgument object');
|
||||
|
||||
// arguments must have different names
|
||||
try
|
||||
@ -120,7 +120,7 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArguments(array($this->foo));
|
||||
$this->assertEquals($definition->getArgument('foo'), $this->foo, '->getArgument() returns a InputArgument by its name');
|
||||
$this->assertEquals($this->foo, $definition->getArgument('foo'), '->getArgument() returns a InputArgument by its name');
|
||||
try
|
||||
{
|
||||
$definition->getArgument('bar');
|
||||
@ -137,8 +137,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArguments(array($this->foo));
|
||||
$this->assertEquals($definition->hasArgument('foo'), true, '->hasArgument() returns true if a InputArgument exists for the given name');
|
||||
$this->assertEquals($definition->hasArgument('bar'), false, '->hasArgument() returns false if a InputArgument exists for the given name');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testGetArgumentRequiredCount()
|
||||
@ -147,9 +147,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArgument($this->foo2);
|
||||
$this->assertEquals($definition->getArgumentRequiredCount(), 1, '->getArgumentRequiredCount() returns the number of required arguments');
|
||||
$this->assertEquals(1, $definition->getArgumentRequiredCount(), '->getArgumentRequiredCount() returns the number of required arguments');
|
||||
$definition->addArgument($this->foo);
|
||||
$this->assertEquals($definition->getArgumentRequiredCount(), 1, '->getArgumentRequiredCount() returns the number of required arguments');
|
||||
$this->assertEquals(1, $definition->getArgumentRequiredCount(), '->getArgumentRequiredCount() returns the number of required arguments');
|
||||
}
|
||||
|
||||
public function testGetArgumentCount()
|
||||
@ -158,9 +158,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArgument($this->foo2);
|
||||
$this->assertEquals($definition->getArgumentCount(), 1, '->getArgumentCount() returns the number of arguments');
|
||||
$this->assertEquals(1, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
|
||||
$definition->addArgument($this->foo);
|
||||
$this->assertEquals($definition->getArgumentCount(), 2, '->getArgumentCount() returns the number of arguments');
|
||||
$this->assertEquals(2, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
|
||||
}
|
||||
|
||||
public function testGetArgumentDefaults()
|
||||
@ -171,12 +171,12 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
new InputArgument('foo3', InputArgument::OPTIONAL | InputArgument::IS_ARRAY),
|
||||
// new InputArgument('foo4', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, '', array(1, 2)),
|
||||
));
|
||||
$this->assertEquals($definition->getArgumentDefaults(), array('foo1' => null, 'foo2' => 'default', 'foo3' => array()), '->getArgumentDefaults() return the default values for each argument');
|
||||
$this->assertEquals(array('foo1' => null, 'foo2' => 'default', 'foo3' => array()), $definition->getArgumentDefaults(), '->getArgumentDefaults() return the default values for each argument');
|
||||
|
||||
$definition = new InputDefinition(array(
|
||||
new InputArgument('foo4', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, '', array(1, 2)),
|
||||
));
|
||||
$this->assertEquals($definition->getArgumentDefaults(), array('foo4' => array(1, 2)), '->getArgumentDefaults() return the default values for each argument');
|
||||
$this->assertEquals(array('foo4' => array(1, 2)), $definition->getArgumentDefaults(), '->getArgumentDefaults() return the default values for each argument');
|
||||
}
|
||||
|
||||
public function testSetOptions()
|
||||
@ -184,9 +184,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($definition->getOptions(), array('foo' => $this->foo), '->setOptions() sets the array of InputOption objects');
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->setOptions() sets the array of InputOption objects');
|
||||
$definition->setOptions(array($this->bar));
|
||||
$this->assertEquals($definition->getOptions(), array('bar' => $this->bar), '->setOptions() clears all InputOption objects');
|
||||
$this->assertEquals(array('bar' => $this->bar), $definition->getOptions(), '->setOptions() clears all InputOption objects');
|
||||
try
|
||||
{
|
||||
$definition->getOptionForShortcut('f');
|
||||
@ -202,9 +202,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($definition->getOptions(), array('foo' => $this->foo), '->addOptions() adds an array of InputOption objects');
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOptions() adds an array of InputOption objects');
|
||||
$definition->addOptions(array($this->bar));
|
||||
$this->assertEquals($definition->getOptions(), array('foo' => $this->foo, 'bar' => $this->bar), '->addOptions() does not clear existing InputOption objects');
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOptions() does not clear existing InputOption objects');
|
||||
}
|
||||
|
||||
public function testAddOption()
|
||||
@ -213,9 +213,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addOption($this->foo);
|
||||
$this->assertEquals($definition->getOptions(), array('foo' => $this->foo), '->addOption() adds a InputOption object');
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOption() adds a InputOption object');
|
||||
$definition->addOption($this->bar);
|
||||
$this->assertEquals($definition->getOptions(), array('foo' => $this->foo, 'bar' => $this->bar), '->addOption() adds a InputOption object');
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOption() adds a InputOption object');
|
||||
try
|
||||
{
|
||||
$definition->addOption($this->foo2);
|
||||
@ -239,7 +239,7 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($definition->getOption('foo'), $this->foo, '->getOption() returns a InputOption by its name');
|
||||
$this->assertEquals($this->foo, $definition->getOption('foo'), '->getOption() returns a InputOption by its name');
|
||||
try
|
||||
{
|
||||
$definition->getOption('bar');
|
||||
@ -255,8 +255,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($definition->hasOption('foo'), true, '->hasOption() returns true if a InputOption exists for the given name');
|
||||
$this->assertEquals($definition->hasOption('bar'), false, '->hasOption() returns false if a InputOption exists for the given name');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testHasShortcut()
|
||||
@ -264,8 +264,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($definition->hasShortcut('f'), true, '->hasShortcut() returns true if a InputOption exists for the given shortcut');
|
||||
$this->assertEquals($definition->hasShortcut('b'), false, '->hasShortcut() returns false if a InputOption exists for the given shortcut');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testGetOptionForShortcut()
|
||||
@ -273,7 +273,7 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($definition->getOptionForShortcut('f'), $this->foo, '->getOptionForShortcut() returns a InputOption by its shortcut');
|
||||
$this->assertEquals($this->foo, $definition->getOptionForShortcut('f'), '->getOptionForShortcut() returns a InputOption by its shortcut');
|
||||
try
|
||||
{
|
||||
$definition->getOptionForShortcut('l');
|
||||
@ -304,28 +304,28 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
'foo6' => array(),
|
||||
'foo7' => array(1, 2),
|
||||
);
|
||||
$this->assertEquals($definition->getOptionDefaults(), $defaults, '->getOptionDefaults() returns the default values for all options');
|
||||
$this->assertEquals($defaults, $definition->getOptionDefaults(), '->getOptionDefaults() returns the default values for all options');
|
||||
}
|
||||
|
||||
public function testGetSynopsis()
|
||||
{
|
||||
$definition = new InputDefinition(array(new InputOption('foo')));
|
||||
$this->assertEquals($definition->getSynopsis(), '[--foo]', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('[--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputOption('foo', 'f')));
|
||||
$this->assertEquals($definition->getSynopsis(), '[-f|--foo]', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('[-f|--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED)));
|
||||
$this->assertEquals($definition->getSynopsis(), '[-f|--foo="..."]', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('[-f|--foo="..."]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL)));
|
||||
$this->assertEquals($definition->getSynopsis(), '[-f|--foo[="..."]]', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('[-f|--foo[="..."]]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
|
||||
$definition = new InputDefinition(array(new InputArgument('foo')));
|
||||
$this->assertEquals($definition->getSynopsis(), '[foo]', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('[foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED)));
|
||||
$this->assertEquals($definition->getSynopsis(), 'foo', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('foo', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY)));
|
||||
$this->assertEquals($definition->getSynopsis(), '[foo1] ... [fooN]', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('[foo1] ... [fooN]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY)));
|
||||
$this->assertEquals($definition->getSynopsis(), 'foo1 ... [fooN]', '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$this->assertEquals('foo1 ... [fooN]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
}
|
||||
|
||||
public function testAsText()
|
||||
@ -336,7 +336,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($definition->asText(), file_get_contents(self::$fixtures.'/definition_astext.txt'), '->asText() returns a textual representation of the InputDefinition');
|
||||
$this->assertEquals(file_get_contents(self::$fixtures.'/definition_astext.txt'), $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
|
||||
}
|
||||
|
||||
public function testAsXml()
|
||||
@ -347,7 +347,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($definition->asXml(), file_get_contents(self::$fixtures.'/definition_asxml.txt'), '->asText() returns a textual representation of the InputDefinition');
|
||||
$this->assertEquals(file_get_contents(self::$fixtures.'/definition_asxml.txt'), $definition->asXml(), '->asText() returns a textual representation of the InputDefinition');
|
||||
}
|
||||
|
||||
protected function initializeArguments()
|
||||
|
@ -20,9 +20,9 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$option = new InputOption('foo');
|
||||
$this->assertEquals($option->getName(), 'foo', '__construct() takes a name as its first argument');
|
||||
$this->assertEquals('foo', $option->getName(), '__construct() takes a name as its first argument');
|
||||
$option = new InputOption('--foo');
|
||||
$this->assertEquals($option->getName(), 'foo', '__construct() removes the leading -- of the option name');
|
||||
$this->assertEquals('foo', $option->getName(), '__construct() removes the leading -- of the option name');
|
||||
|
||||
try
|
||||
{
|
||||
@ -35,35 +35,35 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// shortcut argument
|
||||
$option = new InputOption('foo', 'f');
|
||||
$this->assertEquals($option->getShortcut(), 'f', '__construct() can take a shortcut as its second argument');
|
||||
$this->assertEquals('f', $option->getShortcut(), '__construct() can take a shortcut as its second argument');
|
||||
$option = new InputOption('foo', '-f');
|
||||
$this->assertEquals($option->getShortcut(), 'f', '__construct() removes the leading - of the shortcut');
|
||||
$this->assertEquals('f', $option->getShortcut(), '__construct() removes the leading - of the shortcut');
|
||||
|
||||
// mode argument
|
||||
$option = new InputOption('foo', 'f');
|
||||
$this->assertEquals($option->acceptParameter(), false, '__construct() gives a "Option::PARAMETER_NONE" mode by default');
|
||||
$this->assertEquals($option->isParameterRequired(), false, '__construct() gives a "Option::PARAMETER_NONE" mode by default');
|
||||
$this->assertEquals($option->isParameterOptional(), false, '__construct() gives a "Option::PARAMETER_NONE" mode by default');
|
||||
$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');
|
||||
|
||||
$option = new InputOption('foo', 'f', null);
|
||||
$this->assertEquals($option->acceptParameter(), false, '__construct() can take "Option::PARAMETER_NONE" as its mode');
|
||||
$this->assertEquals($option->isParameterRequired(), false, '__construct() can take "Option::PARAMETER_NONE" as its mode');
|
||||
$this->assertEquals($option->isParameterOptional(), false, '__construct() can take "Option::PARAMETER_NONE" as its mode');
|
||||
$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');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
|
||||
$this->assertEquals($option->acceptParameter(), false, '__construct() can take "Option::PARAMETER_NONE" as its mode');
|
||||
$this->assertEquals($option->isParameterRequired(), false, '__construct() can take "Option::PARAMETER_NONE" as its mode');
|
||||
$this->assertEquals($option->isParameterOptional(), false, '__construct() can take "Option::PARAMETER_NONE" as its mode');
|
||||
$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');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED);
|
||||
$this->assertEquals($option->acceptParameter(), true, '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
|
||||
$this->assertEquals($option->isParameterRequired(), true, '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
|
||||
$this->assertEquals($option->isParameterOptional(), false, '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
|
||||
$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');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL);
|
||||
$this->assertEquals($option->acceptParameter(), true, '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
|
||||
$this->assertEquals($option->isParameterRequired(), false, '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
|
||||
$this->assertEquals($option->isParameterOptional(), true, '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
|
||||
$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');
|
||||
|
||||
try
|
||||
{
|
||||
@ -86,22 +86,22 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetDescription()
|
||||
{
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$this->assertEquals($option->getDescription(), 'Some description', '->getDescription() returns the description message');
|
||||
$this->assertEquals('Some description', $option->getDescription(), '->getDescription() returns the description message');
|
||||
}
|
||||
|
||||
public function testGetDefault()
|
||||
{
|
||||
$option = new InputOption('foo', null, InputOption::PARAMETER_OPTIONAL, '', 'default');
|
||||
$this->assertEquals($option->getDefault(), 'default', '->getDefault() returns the default value');
|
||||
$this->assertEquals('default', $option->getDefault(), '->getDefault() returns the default value');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED, '', 'default');
|
||||
$this->assertEquals($option->getDefault(), 'default', '->getDefault() returns the default value');
|
||||
$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');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
|
||||
$this->assertEquals($option->getDefault(), array(), '->getDefault() returns an empty array if option is an 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');
|
||||
@ -113,11 +113,11 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
|
||||
$option->setDefault(null);
|
||||
$this->assertTrue(is_null($option->getDefault()), '->setDefault() can reset the default value by passing null');
|
||||
$option->setDefault('another');
|
||||
$this->assertEquals($option->getDefault(), 'another', '->setDefault() changes the default value');
|
||||
$this->assertEquals('another', $option->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY);
|
||||
$option->setDefault(array(1, 2));
|
||||
$this->assertEquals($option->getDefault(), array(1, 2), '->setDefault() changes the default value');
|
||||
$this->assertEquals(array(1, 2), $option->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
|
||||
try
|
||||
|
@ -22,21 +22,21 @@ class InputTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals($input->getArgument('name'), 'foo', '->__construct() takes a InputDefinition as an argument');
|
||||
$this->assertEquals('foo', $input->getArgument('name'), '->__construct() takes a InputDefinition as an argument');
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'))));
|
||||
$this->assertEquals($input->getOption('name'), 'foo', '->getOption() returns the value for the given option');
|
||||
$this->assertEquals('foo', $input->getOption('name'), '->getOption() returns the value for the given option');
|
||||
|
||||
$input->setOption('name', 'bar');
|
||||
$this->assertEquals($input->getOption('name'), 'bar', '->setOption() sets the value for a given option');
|
||||
$this->assertEquals($input->getOptions(), array('name' => 'bar'), '->getOptions() returns all option values');
|
||||
$this->assertEquals('bar', $input->getOption('name'), '->setOption() sets the value for a given option');
|
||||
$this->assertEquals(array('name' => 'bar'), $input->getOptions(), '->getOptions() returns all option values');
|
||||
|
||||
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals($input->getOption('bar'), 'default', '->getOption() returns the default value for optional options');
|
||||
$this->assertEquals($input->getOptions(), array('name' => 'foo', 'bar' => 'default'), '->getOptions() returns all option values, even optional ones');
|
||||
$this->assertEquals('default', $input->getOption('bar'), '->getOption() returns the default value for optional options');
|
||||
$this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getOptions(), '->getOptions() returns all option values, even optional ones');
|
||||
|
||||
try
|
||||
{
|
||||
@ -60,15 +60,15 @@ class InputTest extends \PHPUnit_Framework_TestCase
|
||||
public function testArguments()
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals($input->getArgument('name'), 'foo', '->getArgument() returns the value for the given argument');
|
||||
$this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
|
||||
|
||||
$input->setArgument('name', 'bar');
|
||||
$this->assertEquals($input->getArgument('name'), 'bar', '->setArgument() sets the value for a given argument');
|
||||
$this->assertEquals($input->getArguments(), array('name' => 'bar'), '->getArguments() returns all argument values');
|
||||
$this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
|
||||
$this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->getArguments() returns all argument values');
|
||||
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals($input->getArgument('bar'), 'default', '->getArgument() returns the default value for optional arguments');
|
||||
$this->assertEquals($input->getArguments(), array('name' => 'foo', 'bar' => 'default'), '->getArguments() returns all argument values, even optional ones');
|
||||
$this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
|
||||
$this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -19,73 +19,73 @@ class StringInputTest extends \PHPUnit_Framework_TestCase
|
||||
public function testTokenize()
|
||||
{
|
||||
$input = new TestInput1('');
|
||||
$this->assertEquals($input->getTokens(), array(), '->tokenize() parses an empty string');
|
||||
$this->assertEquals(array(), $input->getTokens(), '->tokenize() parses an empty string');
|
||||
|
||||
$input = new TestInput1('foo');
|
||||
$this->assertEquals($input->getTokens(), array('foo'), '->tokenize() parses arguments');
|
||||
$this->assertEquals(array('foo'), $input->getTokens(), '->tokenize() parses arguments');
|
||||
|
||||
$input = new TestInput1(' foo bar ');
|
||||
$this->assertEquals($input->getTokens(), array('foo', 'bar'), '->tokenize() ignores whitespaces between arguments');
|
||||
$this->assertEquals(array('foo', 'bar'), $input->getTokens(), '->tokenize() ignores whitespaces between arguments');
|
||||
|
||||
$input = new TestInput1('"quoted"');
|
||||
$this->assertEquals($input->getTokens(), array('quoted'), '->tokenize() parses quoted arguments');
|
||||
$this->assertEquals(array('quoted'), $input->getTokens(), '->tokenize() parses quoted arguments');
|
||||
|
||||
$input = new TestInput1("'quoted'");
|
||||
$this->assertEquals($input->getTokens(), array('quoted'), '->tokenize() parses quoted arguments');
|
||||
$this->assertEquals(array('quoted'), $input->getTokens(), '->tokenize() parses quoted arguments');
|
||||
|
||||
$input = new TestInput1('\"quoted\"');
|
||||
$this->assertEquals($input->getTokens(), array('"quoted"'), '->tokenize() parses escaped-quoted arguments');
|
||||
$this->assertEquals(array('"quoted"'), $input->getTokens(), '->tokenize() parses escaped-quoted arguments');
|
||||
|
||||
$input = new TestInput1("\'quoted\'");
|
||||
$this->assertEquals($input->getTokens(), array('\'quoted\''), '->tokenize() parses escaped-quoted arguments');
|
||||
$this->assertEquals(array('\'quoted\''), $input->getTokens(), '->tokenize() parses escaped-quoted arguments');
|
||||
|
||||
$input = new TestInput1('-a');
|
||||
$this->assertEquals($input->getTokens(), array('-a'), '->tokenize() parses short options');
|
||||
$this->assertEquals(array('-a'), $input->getTokens(), '->tokenize() parses short options');
|
||||
|
||||
$input = new TestInput1('-azc');
|
||||
$this->assertEquals($input->getTokens(), array('-azc'), '->tokenize() parses aggregated short options');
|
||||
$this->assertEquals(array('-azc'), $input->getTokens(), '->tokenize() parses aggregated short options');
|
||||
|
||||
$input = new TestInput1('-awithavalue');
|
||||
$this->assertEquals($input->getTokens(), array('-awithavalue'), '->tokenize() parses short options with a value');
|
||||
$this->assertEquals(array('-awithavalue'), $input->getTokens(), '->tokenize() parses short options with a value');
|
||||
|
||||
$input = new TestInput1('-a"foo bar"');
|
||||
$this->assertEquals($input->getTokens(), array('-afoo bar'), '->tokenize() parses short options with a value');
|
||||
$this->assertEquals(array('-afoo bar'), $input->getTokens(), '->tokenize() parses short options with a value');
|
||||
|
||||
$input = new TestInput1('-a"foo bar""foo bar"');
|
||||
$this->assertEquals($input->getTokens(), array('-afoo barfoo bar'), '->tokenize() parses short options with a value');
|
||||
$this->assertEquals(array('-afoo barfoo bar'), $input->getTokens(), '->tokenize() parses short options with a value');
|
||||
|
||||
$input = new TestInput1('-a\'foo bar\'');
|
||||
$this->assertEquals($input->getTokens(), array('-afoo bar'), '->tokenize() parses short options with a value');
|
||||
$this->assertEquals(array('-afoo bar'), $input->getTokens(), '->tokenize() parses short options with a value');
|
||||
|
||||
$input = new TestInput1('-a\'foo bar\'\'foo bar\'');
|
||||
$this->assertEquals($input->getTokens(), array('-afoo barfoo bar'), '->tokenize() parses short options with a value');
|
||||
$this->assertEquals(array('-afoo barfoo bar'), $input->getTokens(), '->tokenize() parses short options with a value');
|
||||
|
||||
$input = new TestInput1('-a\'foo bar\'"foo bar"');
|
||||
$this->assertEquals($input->getTokens(), array('-afoo barfoo bar'), '->tokenize() parses short options with a value');
|
||||
$this->assertEquals(array('-afoo barfoo bar'), $input->getTokens(), '->tokenize() parses short options with a value');
|
||||
|
||||
$input = new TestInput1('--long-option');
|
||||
$this->assertEquals($input->getTokens(), array('--long-option'), '->tokenize() parses long options');
|
||||
$this->assertEquals(array('--long-option'), $input->getTokens(), '->tokenize() parses long options');
|
||||
|
||||
$input = new TestInput1('--long-option=foo');
|
||||
$this->assertEquals($input->getTokens(), array('--long-option=foo'), '->tokenize() parses long options with a value');
|
||||
$this->assertEquals(array('--long-option=foo'), $input->getTokens(), '->tokenize() parses long options with a value');
|
||||
|
||||
$input = new TestInput1('--long-option="foo bar"');
|
||||
$this->assertEquals($input->getTokens(), array('--long-option=foo bar'), '->tokenize() parses long options with a value');
|
||||
$this->assertEquals(array('--long-option=foo bar'), $input->getTokens(), '->tokenize() parses long options with a value');
|
||||
|
||||
$input = new TestInput1('--long-option="foo bar""another"');
|
||||
$this->assertEquals($input->getTokens(), array('--long-option=foo baranother'), '->tokenize() parses long options with a value');
|
||||
$this->assertEquals(array('--long-option=foo baranother'), $input->getTokens(), '->tokenize() parses long options with a value');
|
||||
|
||||
$input = new TestInput1('--long-option=\'foo bar\'');
|
||||
$this->assertEquals($input->getTokens(), array('--long-option=foo bar'), '->tokenize() parses long options with a value');
|
||||
$this->assertEquals(array('--long-option=foo bar'), $input->getTokens(), '->tokenize() parses long options with a value');
|
||||
|
||||
$input = new TestInput1("--long-option='foo bar''another'");
|
||||
$this->assertEquals($input->getTokens(), array("--long-option=foo baranother"), '->tokenize() parses long options with a value');
|
||||
$this->assertEquals(array("--long-option=foo baranother"), $input->getTokens(), '->tokenize() parses long options with a value');
|
||||
|
||||
$input = new TestInput1("--long-option='foo bar'\"another\"");
|
||||
$this->assertEquals($input->getTokens(), array("--long-option=foo baranother"), '->tokenize() parses long options with a value');
|
||||
$this->assertEquals(array("--long-option=foo baranother"), $input->getTokens(), '->tokenize() parses long options with a value');
|
||||
|
||||
$input = new TestInput1('foo -a -ffoo --long bar');
|
||||
$this->assertEquals($input->getTokens(), array('foo', '-a', '-ffoo', '--long', 'bar'), '->tokenize() parses when several arguments and options');
|
||||
$this->assertEquals(array('foo', '-a', '-ffoo', '--long', 'bar'), $input->getTokens(), '->tokenize() parses when several arguments and options');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,6 @@ class ConsoleOutputTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);
|
||||
$this->assertEquals($output->getVerbosity(), Output::VERBOSITY_QUIET, '__construct() takes the verbosity as its first argument');
|
||||
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
|
||||
}
|
||||
}
|
||||
|
@ -19,57 +19,57 @@ class OutputTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$output = new TestOutput(Output::VERBOSITY_QUIET, true);
|
||||
$this->assertEquals($output->getVerbosity(), Output::VERBOSITY_QUIET, '__construct() takes the verbosity as its first argument');
|
||||
$this->assertEquals($output->isDecorated(), true, '__construct() takes the decorated flag as its second argument');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testSetIsDecorated()
|
||||
{
|
||||
$output = new TestOutput();
|
||||
$output->setDecorated(true);
|
||||
$this->assertEquals($output->isDecorated(), true, 'setDecorated() sets the decorated flag');
|
||||
$this->assertEquals(true, 'setDecorated() sets the decorated flag', $output->isDecorated());
|
||||
}
|
||||
|
||||
public function testSetGetVerbosity()
|
||||
{
|
||||
$output = new TestOutput();
|
||||
$output->setVerbosity(Output::VERBOSITY_QUIET);
|
||||
$this->assertEquals($output->getVerbosity(), Output::VERBOSITY_QUIET, '->setVerbosity() sets the verbosity');
|
||||
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '->setVerbosity() sets the verbosity');
|
||||
}
|
||||
|
||||
public function testSetStyle()
|
||||
{
|
||||
Output::setStyle('FOO', array('bg' => 'red', 'fg' => 'yellow', 'blink' => true));
|
||||
$this->assertEquals(TestOutput::getStyle('foo'), array('bg' => 'red', 'fg' => 'yellow', 'blink' => true), '::setStyle() sets a new style');
|
||||
$this->assertEquals(array('bg' => 'red', 'fg' => 'yellow', 'blink' => true), TestOutput::getStyle('foo'), '::setStyle() sets a new style');
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$output = new TestOutput(Output::VERBOSITY_QUIET);
|
||||
$output->writeln('foo');
|
||||
$this->assertEquals($output->output, '', '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET');
|
||||
$this->assertEquals('', $output->output, '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->writeln(array('foo', 'bar'));
|
||||
$this->assertEquals($output->output, "foo\nbar\n", '->writeln() can take an array of messages to output');
|
||||
$this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an array of messages to output');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->writeln('<info>foo</info>', Output::OUTPUT_RAW);
|
||||
$this->assertEquals($output->output, "<info>foo</info>\n", '->writeln() outputs the raw message if OUTPUT_RAW is specified');
|
||||
$this->assertEquals("<info>foo</info>\n", $output->output, '->writeln() outputs the raw message if OUTPUT_RAW is specified');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->writeln('<info>foo</info>', Output::OUTPUT_PLAIN);
|
||||
$this->assertEquals($output->output, "foo\n", '->writeln() strips decoration tags if OUTPUT_PLAIN is specified');
|
||||
$this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if OUTPUT_PLAIN is specified');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->setDecorated(false);
|
||||
$output->writeln('<info>foo</info>');
|
||||
$this->assertEquals($output->output, "foo\n", '->writeln() strips decoration tags if decoration is set to false');
|
||||
$this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if decoration is set to false');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->setDecorated(true);
|
||||
$output->writeln('<foo>foo</foo>');
|
||||
$this->assertEquals($output->output, "\033[33;41;5mfoo\033[0m\n", '->writeln() decorates the output');
|
||||
$this->assertEquals("\033[33;41;5mfoo\033[0m\n", $output->output, '->writeln() decorates the output');
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -36,14 +36,14 @@ class StreamOutputTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
|
||||
$this->assertEquals($output->getVerbosity(), Output::VERBOSITY_QUIET, '__construct() takes the verbosity as its first argument');
|
||||
$this->assertEquals($output->isDecorated(), true, '__construct() takes the decorated flag as its second argument');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testGetStream()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$this->assertEquals($output->getStream(), $this->stream, '->getStream() returns the current stream');
|
||||
$this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
|
||||
}
|
||||
|
||||
public function testDoWrite()
|
||||
@ -51,6 +51,6 @@ class StreamOutputTest extends \PHPUnit_Framework_TestCase
|
||||
$output = new StreamOutput($this->stream);
|
||||
$output->writeln('foo');
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(stream_get_contents($output->getStream()), "foo\n", '->doWrite() writes to the stream');
|
||||
$this->assertEquals("foo\n", stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
|
||||
}
|
||||
}
|
||||
|
@ -37,24 +37,24 @@ class ApplicationTesterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
$this->assertEquals($this->tester->getInput()->isInteractive(), false, '->execute() takes an interactive option');
|
||||
$this->assertEquals($this->tester->getOutput()->isDecorated(), false, '->execute() takes a decorated option');
|
||||
$this->assertEquals($this->tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->execute() takes a verbosity option');
|
||||
$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->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
|
||||
}
|
||||
|
||||
public function testGetInput()
|
||||
{
|
||||
$this->assertEquals($this->tester->getInput()->getArgument('foo'), 'bar', '->getInput() returns the current input instance');
|
||||
$this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
|
||||
}
|
||||
|
||||
public function testGetOutput()
|
||||
{
|
||||
rewind($this->tester->getOutput()->getStream());
|
||||
$this->assertEquals(stream_get_contents($this->tester->getOutput()->getStream()), "foo\n", '->getOutput() returns the current output instance');
|
||||
$this->assertEquals("foo\n", stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
|
||||
}
|
||||
|
||||
public function testGetDisplay()
|
||||
{
|
||||
$this->assertEquals($this->tester->getDisplay(), "foo\n", '->getDisplay() returns the display of the last execution');
|
||||
$this->assertEquals("foo\n", $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
|
||||
}
|
||||
}
|
||||
|
@ -34,24 +34,24 @@ class CommandTesterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$this->assertEquals($this->tester->getInput()->isInteractive(), false, '->execute() takes an interactive option');
|
||||
$this->assertEquals($this->tester->getOutput()->isDecorated(), false, '->execute() takes a decorated option');
|
||||
$this->assertEquals($this->tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->execute() takes a verbosity option');
|
||||
$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->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
|
||||
}
|
||||
|
||||
public function testGetInput()
|
||||
{
|
||||
$this->assertEquals($this->tester->getInput()->getArgument('foo'), 'bar', '->getInput() returns the current input instance');
|
||||
$this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
|
||||
}
|
||||
|
||||
public function testGetOutput()
|
||||
{
|
||||
rewind($this->tester->getOutput()->getStream());
|
||||
$this->assertEquals(stream_get_contents($this->tester->getOutput()->getStream()), "foo\n", '->getOutput() returns the current output instance');
|
||||
$this->assertEquals("foo\n", stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
|
||||
}
|
||||
|
||||
public function testGetDisplay()
|
||||
{
|
||||
$this->assertEquals($this->tester->getDisplay(), "foo\n", '->getDisplay() returns the display of the last execution');
|
||||
$this->assertEquals("foo\n", $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
|
||||
}
|
||||
}
|
||||
|
@ -38,74 +38,74 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
'bar' => 'bar',
|
||||
);
|
||||
$configuration = new BuilderConfiguration($definitions, $parameters);
|
||||
$this->assertEquals($configuration->getDefinitions(), $definitions, '__construct() takes an array of definitions as its first argument');
|
||||
$this->assertEquals($configuration->getParameters(), $parameters, '__construct() takes an array of parameters as its second argument');
|
||||
$this->assertEquals($definitions, $configuration->getDefinitions(), '__construct() takes an array of definitions as its first argument');
|
||||
$this->assertEquals($parameters, $configuration->getParameters(), '__construct() takes an array of parameters as its second argument');
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
{
|
||||
$configuration = new BuilderConfiguration();
|
||||
$configuration->merge(null);
|
||||
$this->assertEquals($configuration->getParameters(), array(), '->merge() accepts null as an argument');
|
||||
$this->assertEquals($configuration->getDefinitions(), array(), '->merge() accepts null as an argument');
|
||||
$this->assertEquals(array(), $configuration->getParameters(), '->merge() accepts null as an argument');
|
||||
$this->assertEquals(array(), $configuration->getDefinitions(), '->merge() accepts null as an argument');
|
||||
|
||||
$configuration = new BuilderConfiguration(array(), array('bar' => 'foo'));
|
||||
$configuration1 = new BuilderConfiguration(array(), array('foo' => 'bar'));
|
||||
$configuration->merge($configuration1);
|
||||
$this->assertEquals($configuration->getParameters(), array('bar' => 'foo', 'foo' => 'bar'), '->merge() merges current parameters with the loaded ones');
|
||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $configuration->getParameters(), '->merge() merges current parameters with the loaded ones');
|
||||
|
||||
$configuration = new BuilderConfiguration(array(), array('bar' => 'foo', 'foo' => 'baz'));
|
||||
$config = new BuilderConfiguration(array(), array('foo' => 'bar'));
|
||||
$configuration->merge($config);
|
||||
$this->assertEquals($configuration->getParameters(), array('bar' => 'foo', 'foo' => 'bar'), '->merge() overrides existing parameters');
|
||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $configuration->getParameters(), '->merge() overrides existing parameters');
|
||||
|
||||
$configuration = new BuilderConfiguration(array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass')));
|
||||
$config = new BuilderConfiguration(array('baz' => new Definition('BazClass')));
|
||||
$config->setAlias('alias_for_foo', 'foo');
|
||||
$configuration->merge($config);
|
||||
$this->assertEquals(array_keys($configuration->getDefinitions()), array('foo', 'bar', 'baz'), '->merge() merges definitions already defined ones');
|
||||
$this->assertEquals($configuration->getAliases(), array('alias_for_foo' => 'foo'), '->merge() registers defined aliases');
|
||||
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($configuration->getDefinitions()), '->merge() merges definitions already defined ones');
|
||||
$this->assertEquals(array('alias_for_foo' => 'foo'), $configuration->getAliases(), '->merge() registers defined aliases');
|
||||
|
||||
$configuration = new BuilderConfiguration(array('foo' => new Definition('FooClass')));
|
||||
$config->setDefinition('foo', new Definition('BazClass'));
|
||||
$configuration->merge($config);
|
||||
$this->assertEquals($configuration->getDefinition('foo')->getClass(), 'BazClass', '->merge() overrides already defined services');
|
||||
$this->assertEquals('BazClass', $configuration->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
|
||||
|
||||
$configuration = new BuilderConfiguration();
|
||||
$configuration->addResource($a = new FileResource('foo.xml'));
|
||||
$config = new BuilderConfiguration();
|
||||
$config->addResource($b = new FileResource('foo.yml'));
|
||||
$configuration->merge($config);
|
||||
$this->assertEquals($configuration->getResources(), array($a, $b), '->merge() merges resources');
|
||||
$this->assertEquals(array($a, $b), $configuration->getResources(), '->merge() merges resources');
|
||||
}
|
||||
|
||||
public function testSetGetParameters()
|
||||
{
|
||||
$configuration = new BuilderConfiguration();
|
||||
$this->assertEquals($configuration->getParameters(), array(), '->getParameters() returns an empty array if no parameter has been defined');
|
||||
$this->assertEquals(array(), $configuration->getParameters(), '->getParameters() returns an empty array if no parameter has been defined');
|
||||
|
||||
$configuration->setParameters(array('foo' => 'bar'));
|
||||
$this->assertEquals($configuration->getParameters(), array('foo' => 'bar'), '->setParameters() sets the parameters');
|
||||
$this->assertEquals(array('foo' => 'bar'), $configuration->getParameters(), '->setParameters() sets the parameters');
|
||||
|
||||
$configuration->setParameters(array('bar' => 'foo'));
|
||||
$this->assertEquals($configuration->getParameters(), array('bar' => 'foo'), '->setParameters() overrides the previous defined parameters');
|
||||
$this->assertEquals(array('bar' => 'foo'), $configuration->getParameters(), '->setParameters() overrides the previous defined parameters');
|
||||
|
||||
$configuration->setParameters(array('Bar' => 'foo'));
|
||||
$this->assertEquals($configuration->getParameters(), array('bar' => 'foo'), '->setParameters() converts the key to lowercase');
|
||||
$this->assertEquals(array('bar' => 'foo'), $configuration->getParameters(), '->setParameters() converts the key to lowercase');
|
||||
}
|
||||
|
||||
public function testSetGetParameter()
|
||||
{
|
||||
$configuration = new BuilderConfiguration(array(), array('foo' => 'bar'));
|
||||
$configuration->setParameter('bar', 'foo');
|
||||
$this->assertEquals($configuration->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter');
|
||||
$this->assertEquals('foo', $configuration->getParameter('bar'), '->setParameter() sets the value of a new parameter');
|
||||
|
||||
$configuration->setParameter('foo', 'baz');
|
||||
$this->assertEquals($configuration->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter');
|
||||
$this->assertEquals('baz', $configuration->getParameter('foo'), '->setParameter() overrides previously set parameter');
|
||||
|
||||
$configuration->setParameter('Foo', 'baz1');
|
||||
$this->assertEquals($configuration->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase');
|
||||
$this->assertEquals($configuration->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase');
|
||||
$this->assertEquals('baz1', $configuration->getParameter('foo'), '->setParameter() converts the key to lowercase');
|
||||
$this->assertEquals('baz1', $configuration->getParameter('FOO'), '->getParameter() converts the key to lowercase');
|
||||
|
||||
try
|
||||
{
|
||||
@ -129,16 +129,16 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$configuration = new BuilderConfiguration(array(), array('foo' => 'bar'));
|
||||
$configuration->addParameters(array('bar' => 'foo'));
|
||||
$this->assertEquals($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->addParameters() adds parameters to the existing ones');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo'), $configuration->getParameters(), '->addParameters() adds parameters to the existing ones');
|
||||
$configuration->addParameters(array('Bar' => 'fooz'));
|
||||
$this->assertEquals($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'fooz'), '->addParameters() converts keys to lowercase');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'fooz'), $configuration->getParameters(), '->addParameters() converts keys to lowercase');
|
||||
}
|
||||
|
||||
public function testAliases()
|
||||
{
|
||||
$configuration = new BuilderConfiguration();
|
||||
$configuration->setAlias('bar', 'foo');
|
||||
$this->assertEquals($configuration->getAlias('bar'), 'foo', '->setAlias() defines a new alias');
|
||||
$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');
|
||||
|
||||
@ -152,10 +152,10 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$configuration->setAlias('barbar', 'foofoo');
|
||||
$this->assertEquals($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo'), '->getAliases() returns an array of all defined aliases');
|
||||
$this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo'), $configuration->getAliases(), '->getAliases() returns an array of all defined aliases');
|
||||
|
||||
$configuration->addAliases(array('foo' => 'bar'));
|
||||
$this->assertEquals($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), '->addAliases() adds some aliases');
|
||||
$this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), $configuration->getAliases(), '->addAliases() adds some aliases');
|
||||
}
|
||||
|
||||
public function testDefinitions()
|
||||
@ -166,16 +166,16 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
'bar' => new Definition('BarClass'),
|
||||
);
|
||||
$configuration->setDefinitions($definitions);
|
||||
$this->assertEquals($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service 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');
|
||||
|
||||
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
|
||||
$this->assertEquals($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
|
||||
$this->assertEquals($foo, $configuration->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
|
||||
$this->assertTrue($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
|
||||
|
||||
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
|
||||
$this->assertEquals($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
|
||||
$this->assertEquals(array_merge($definitions, $defs), $configuration->getDefinitions(), '->addDefinitions() adds the service definitions');
|
||||
|
||||
try
|
||||
{
|
||||
@ -192,7 +192,7 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
$configuration = new BuilderConfiguration(array('foo' => $definition = new Definition('FooClass')));
|
||||
$configuration->setAlias('bar', 'foo');
|
||||
$configuration->setAlias('foobar', 'bar');
|
||||
$this->assertEquals($configuration->findDefinition('foobar'), $definition, '->findDefinition() returns a Definition');
|
||||
$this->assertEquals($definition, $configuration->findDefinition('foobar'), '->findDefinition() returns a Definition');
|
||||
}
|
||||
|
||||
public function testResources()
|
||||
@ -200,6 +200,6 @@ class BuilderConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
$configuration = new BuilderConfiguration();
|
||||
$configuration->addResource($a = new FileResource('foo.xml'));
|
||||
$configuration->addResource($b = new FileResource('foo.yml'));
|
||||
$this->assertEquals($configuration->getResources(), array($a, $b), '->getResources() returns an array of resources read for the current configuration');
|
||||
$this->assertEquals(array($a, $b), $configuration->getResources(), '->getResources() returns an array of resources read for the current configuration');
|
||||
}
|
||||
}
|
||||
|
@ -34,16 +34,16 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
'bar' => new Definition('BarClass'),
|
||||
);
|
||||
$builder->setDefinitions($definitions);
|
||||
$this->assertEquals($builder->getDefinitions(), $definitions, '->setDefinitions() sets the service 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');
|
||||
|
||||
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
|
||||
$this->assertEquals($builder->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
|
||||
$this->assertEquals($foo, $builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
|
||||
$this->assertTrue($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
|
||||
|
||||
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
|
||||
$this->assertEquals($builder->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
|
||||
$this->assertEquals(array_merge($definitions, $defs), $builder->getDefinitions(), '->addDefinitions() adds the service definitions');
|
||||
|
||||
try
|
||||
{
|
||||
@ -87,9 +87,9 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder->register('foo', 'stdClass');
|
||||
$this->assertTrue(is_object($builder->getService('foo')), '->getService() returns the service definition associated with the id');
|
||||
$builder->bar = $bar = new \stdClass();
|
||||
$this->assertEquals($builder->getService('bar'), $bar, '->getService() returns the service associated with the id');
|
||||
$this->assertEquals($bar, $builder->getService('bar'), '->getService() returns the service associated with the id');
|
||||
$builder->register('bar', 'stdClass');
|
||||
$this->assertEquals($builder->getService('bar'), $bar, '->getService() returns the service associated with the id even if a definition has been defined');
|
||||
$this->assertEquals($bar, $builder->getService('bar'), '->getService() returns the service associated with the id even if a definition has been defined');
|
||||
|
||||
$builder->register('baz', 'stdClass')->setArguments(array(new Reference('baz')));
|
||||
try
|
||||
@ -111,7 +111,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder->register('foo', 'stdClass');
|
||||
$builder->bar = $bar = new \stdClass();
|
||||
$builder->register('bar', 'stdClass');
|
||||
$this->assertEquals($builder->getServiceIds(), array('foo', 'bar', 'service_container'), '->getServiceIds() returns all defined service ids');
|
||||
$this->assertEquals(array('foo', 'bar', 'service_container'), $builder->getServiceIds(), '->getServiceIds() returns all defined service ids');
|
||||
}
|
||||
|
||||
public function testAliases()
|
||||
@ -121,7 +121,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$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->assertEquals($builder->getAlias('bar'), 'foo', '->getAlias() returns the aliased service');
|
||||
$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');
|
||||
|
||||
@ -140,11 +140,11 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder = new Builder();
|
||||
$builder->setAlias('bar', 'foo');
|
||||
$builder->setAlias('foobar', 'foo');
|
||||
$this->assertEquals($builder->getAliases(), array('bar' => 'foo', 'foobar' => 'foo'), '->getAliases() returns all service aliases');
|
||||
$this->assertEquals(array('bar' => 'foo', 'foobar' => 'foo'), $builder->getAliases(), '->getAliases() returns all service aliases');
|
||||
$builder->register('bar', 'stdClass');
|
||||
$this->assertEquals($builder->getAliases(), array('foobar' => 'foo'), '->getAliases() does not return aliased services that have been overridden');
|
||||
$this->assertEquals(array('foobar' => 'foo'), $builder->getAliases(), '->getAliases() does not return aliased services that have been overridden');
|
||||
$builder->setService('foobar', 'stdClass');
|
||||
$this->assertEquals($builder->getAliases(), array(), '->getAliases() does not return aliased services that have been overridden');
|
||||
$this->assertEquals(array(), $builder->getAliases(), '->getAliases() does not return aliased services that have been overridden');
|
||||
}
|
||||
|
||||
public function testCreateService()
|
||||
@ -171,7 +171,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder->register('bar', 'stdClass');
|
||||
$builder->register('foo1', 'FooClass')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
|
||||
$builder->setParameter('value', 'bar');
|
||||
$this->assertEquals($builder->getService('foo1')->arguments, array('foo' => 'bar', 'bar' => 'foo', $builder->getService('bar')), '->createService() replaces parameters and service references in the arguments provided by the service definition');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->getService('bar')), $builder->getService('foo1')->arguments, '->createService() replaces parameters and service references in the arguments provided by the service definition');
|
||||
}
|
||||
|
||||
public function testCreateServiceConstructor()
|
||||
@ -181,7 +181,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder->register('foo1', 'FooClass')->setConstructor('getInstance')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
|
||||
$builder->setParameter('value', 'bar');
|
||||
$this->assertTrue($builder->getService('foo1')->called, '->createService() calls the constructor to create the service instance');
|
||||
$this->assertEquals($builder->getService('foo1')->arguments, array('foo' => 'bar', 'bar' => 'foo', $builder->getService('bar')), '->createService() passes the arguments to the constructor');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->getService('bar')), $builder->getService('foo1')->arguments, '->createService() passes the arguments to the constructor');
|
||||
}
|
||||
|
||||
public function testCreateServiceMethodCalls()
|
||||
@ -190,7 +190,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$builder->register('bar', 'stdClass');
|
||||
$builder->register('foo1', 'FooClass')->addMethodCall('setBar', array(array('%value%', new Reference('bar'))));
|
||||
$builder->setParameter('value', 'bar');
|
||||
$this->assertEquals($builder->getService('foo1')->bar, array('bar', $builder->getService('bar')), '->createService() replaces the values in the method calls arguments');
|
||||
$this->assertEquals(array('bar', $builder->getService('bar')), $builder->getService('foo1')->bar, '->createService() replaces the values in the method calls arguments');
|
||||
}
|
||||
|
||||
public function testCreateServiceConfigurator()
|
||||
@ -222,16 +222,16 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testResolveValue()
|
||||
{
|
||||
$this->assertEquals(Builder::resolveValue('foo', array()), 'foo', '->resolveValue() returns its argument unmodified if no placeholders are found');
|
||||
$this->assertEquals(Builder::resolveValue('I\'m a %foo%', array('foo' => 'bar')), 'I\'m a bar', '->resolveValue() replaces placeholders by their values');
|
||||
$this->assertEquals('foo', Builder::resolveValue('foo', array()), '->resolveValue() returns its argument unmodified if no placeholders are found');
|
||||
$this->assertEquals('I\'m a bar', Builder::resolveValue('I\'m a %foo%', array('foo' => 'bar')), '->resolveValue() replaces placeholders by their values');
|
||||
$this->assertTrue(Builder::resolveValue('%foo%', array('foo' => true)) === true, '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
|
||||
|
||||
$this->assertEquals(Builder::resolveValue(array('%foo%' => '%foo%'), array('foo' => 'bar')), array('bar' => 'bar'), '->resolveValue() replaces placeholders in keys and values of arrays');
|
||||
$this->assertEquals(array('bar' => 'bar'), Builder::resolveValue(array('%foo%' => '%foo%'), array('foo' => 'bar')), '->resolveValue() replaces placeholders in keys and values of arrays');
|
||||
|
||||
$this->assertEquals(Builder::resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%'))), array('foo' => 'bar')), array('bar' => array('bar' => array('bar' => 'bar'))), '->resolveValue() replaces placeholders in nested arrays');
|
||||
$this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), Builder::resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%'))), array('foo' => 'bar')), '->resolveValue() replaces placeholders in nested arrays');
|
||||
|
||||
$this->assertEquals(Builder::resolveValue('I\'m a %%foo%%', array('foo' => 'bar')), 'I\'m a %foo%', '->resolveValue() supports % escaping by doubling it');
|
||||
$this->assertEquals(Builder::resolveValue('I\'m a %foo% %%foo %foo%', array('foo' => 'bar')), 'I\'m a bar %foo bar', '->resolveValue() supports % escaping by doubling it');
|
||||
$this->assertEquals('I\'m a %foo%', Builder::resolveValue('I\'m a %%foo%%', array('foo' => 'bar')), '->resolveValue() supports % escaping by doubling it');
|
||||
$this->assertEquals('I\'m a bar %foo bar', Builder::resolveValue('I\'m a %foo% %%foo %foo%', array('foo' => 'bar')), '->resolveValue() supports % escaping by doubling it');
|
||||
|
||||
try
|
||||
{
|
||||
@ -256,40 +256,40 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$builder = new Builder();
|
||||
$builder->register('foo', 'FooClass');
|
||||
$this->assertEquals($builder->resolveServices(new Reference('foo')), $builder->getService('foo'), '->resolveServices() resolves service references to service instances');
|
||||
$this->assertEquals($builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), array('foo' => array('foo', $builder->getService('foo'))), '->resolveServices() resolves service references to service instances in nested arrays');
|
||||
$this->assertEquals($builder->getService('foo'), $builder->resolveServices(new Reference('foo')), '->resolveServices() resolves service references to service instances');
|
||||
$this->assertEquals(array('foo' => array('foo', $builder->getService('foo'))), $builder->resolveServices(array('foo' => array('foo', new Reference('foo')))), '->resolveServices() resolves service references to service instances in nested arrays');
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
{
|
||||
$container = new Builder();
|
||||
$container->merge(null);
|
||||
$this->assertEquals($container->getParameters(), array(), '->merge() accepts null as an argument');
|
||||
$this->assertEquals($container->getDefinitions(), array(), '->merge() accepts null as an argument');
|
||||
$this->assertEquals(array(), $container->getParameters(), '->merge() accepts null as an argument');
|
||||
$this->assertEquals(array(), $container->getDefinitions(), '->merge() accepts null as an argument');
|
||||
|
||||
$container = new Builder(array('bar' => 'foo'));
|
||||
$config = new BuilderConfiguration();
|
||||
$config->setParameters(array('foo' => 'bar'));
|
||||
$container->merge($config);
|
||||
$this->assertEquals($container->getParameters(), array('bar' => 'foo', 'foo' => 'bar'), '->merge() merges current parameters with the loaded ones');
|
||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameters(), '->merge() merges current parameters with the loaded ones');
|
||||
|
||||
$container = new Builder(array('bar' => 'foo', 'foo' => 'baz'));
|
||||
$config = new BuilderConfiguration();
|
||||
$config->setParameters(array('foo' => 'bar'));
|
||||
$container->merge($config);
|
||||
$this->assertEquals($container->getParameters(), array('bar' => 'foo', 'foo' => 'baz'), '->merge() does not change the already defined parameters');
|
||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'baz'), $container->getParameters(), '->merge() does not change the already defined parameters');
|
||||
|
||||
$container = new Builder(array('bar' => 'foo'));
|
||||
$config = new BuilderConfiguration();
|
||||
$config->setParameters(array('foo' => '%bar%'));
|
||||
$container->merge($config);
|
||||
$this->assertEquals($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
|
||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameters(), '->merge() evaluates the values of the parameters towards already defined ones');
|
||||
|
||||
$container = new Builder(array('bar' => 'foo'));
|
||||
$config = new BuilderConfiguration();
|
||||
$config->setParameters(array('foo' => '%bar%', 'baz' => '%foo%'));
|
||||
$container->merge($config);
|
||||
$this->assertEquals($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
|
||||
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameters(), '->merge() evaluates the values of the parameters towards already defined ones');
|
||||
|
||||
$container = new Builder();
|
||||
$container->register('foo', 'FooClass');
|
||||
@ -298,14 +298,14 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$config->setDefinition('baz', new Definition('BazClass'));
|
||||
$config->setAlias('alias_for_foo', 'foo');
|
||||
$container->merge($config);
|
||||
$this->assertEquals(array_keys($container->getDefinitions()), array('foo', 'bar', 'baz'), '->merge() merges definitions already defined ones');
|
||||
$this->assertEquals($container->getAliases(), array('alias_for_foo' => 'foo'), '->merge() registers defined aliases');
|
||||
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
|
||||
$this->assertEquals(array('alias_for_foo' => 'foo'), $container->getAliases(), '->merge() registers defined aliases');
|
||||
|
||||
$container = new Builder();
|
||||
$container->register('foo', 'FooClass');
|
||||
$config->setDefinition('foo', new Definition('BazClass'));
|
||||
$container->merge($config);
|
||||
$this->assertEquals($container->getDefinition('foo')->getClass(), 'BazClass', '->merge() overrides already defined services');
|
||||
$this->assertEquals('BazClass', $container->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
|
||||
}
|
||||
|
||||
public function testFindAnnotatedServiceIds()
|
||||
@ -323,6 +323,6 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
array('foofoo' => 'foofoo'),
|
||||
)
|
||||
), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
|
||||
$this->assertEquals($builder->findAnnotatedServiceIds('foobar'), array(), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
|
||||
$this->assertEquals(array(), $builder->findAnnotatedServiceIds('foobar'), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
|
||||
}
|
||||
}
|
||||
|
@ -19,47 +19,47 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$sc = new Container();
|
||||
$this->assertEquals(spl_object_hash($sc->getService('service_container')), spl_object_hash($sc), '__construct() automatically registers itself as a service');
|
||||
$this->assertEquals(spl_object_hash($sc), spl_object_hash($sc->getService('service_container')), '__construct() automatically registers itself as a service');
|
||||
|
||||
$sc = new Container(array('foo' => 'bar'));
|
||||
$this->assertEquals($sc->getParameters(), array('foo' => 'bar'), '__construct() takes an array of parameters as its first argument');
|
||||
$this->assertEquals(array('foo' => 'bar'), $sc->getParameters(), '__construct() takes an array of parameters as its first argument');
|
||||
}
|
||||
|
||||
public function testGetSetParameters()
|
||||
{
|
||||
$sc = new Container();
|
||||
$this->assertEquals($sc->getParameters(), array(), '->getParameters() returns an empty array if no parameter has been defined');
|
||||
$this->assertEquals(array(), $sc->getParameters(), '->getParameters() returns an empty array if no parameter has been defined');
|
||||
|
||||
$sc->setParameters(array('foo' => 'bar'));
|
||||
$this->assertEquals($sc->getParameters(), array('foo' => 'bar'), '->setParameters() sets the parameters');
|
||||
$this->assertEquals(array('foo' => 'bar'), $sc->getParameters(), '->setParameters() sets the parameters');
|
||||
|
||||
$sc->setParameters(array('bar' => 'foo'));
|
||||
$this->assertEquals($sc->getParameters(), array('bar' => 'foo'), '->setParameters() overrides the previous defined parameters');
|
||||
$this->assertEquals(array('bar' => 'foo'), $sc->getParameters(), '->setParameters() overrides the previous defined parameters');
|
||||
|
||||
$sc->setParameters(array('Bar' => 'foo'));
|
||||
$this->assertEquals($sc->getParameters(), array('bar' => 'foo'), '->setParameters() converts the key to lowercase');
|
||||
$this->assertEquals(array('bar' => 'foo'), $sc->getParameters(), '->setParameters() converts the key to lowercase');
|
||||
}
|
||||
|
||||
public function testGetSetParameter()
|
||||
{
|
||||
$sc = new Container(array('foo' => 'bar'));
|
||||
$sc->setParameter('bar', 'foo');
|
||||
$this->assertEquals($sc->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter');
|
||||
$this->assertEquals($sc['bar'], 'foo', '->offsetGet() gets the value of a parameter');
|
||||
$this->assertEquals('foo', $sc->getParameter('bar'), '->setParameter() sets the value of a new parameter');
|
||||
$this->assertEquals('foo', $sc['bar'], '->offsetGet() gets the value of a parameter');
|
||||
|
||||
$sc['bar1'] = 'foo1';
|
||||
$this->assertEquals($sc['bar1'], 'foo1', '->offsetset() sets the value of a parameter');
|
||||
$this->assertEquals('foo1', $sc['bar1'], '->offsetset() sets the value of a parameter');
|
||||
|
||||
unset($sc['bar1']);
|
||||
$this->assertTrue(!isset($sc['bar1']), '->offsetUnset() removes a parameter');
|
||||
|
||||
$sc->setParameter('foo', 'baz');
|
||||
$this->assertEquals($sc->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter');
|
||||
$this->assertEquals('baz', $sc->getParameter('foo'), '->setParameter() overrides previously set parameter');
|
||||
|
||||
$sc->setParameter('Foo', 'baz1');
|
||||
$this->assertEquals($sc->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase');
|
||||
$this->assertEquals($sc->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase');
|
||||
$this->assertEquals($sc['FOO'], 'baz1', '->offsetGet() converts the key to lowercase');
|
||||
$this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
|
||||
$this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
|
||||
$this->assertEquals('baz1', $sc['FOO'], '->offsetGet() converts the key to lowercase');
|
||||
|
||||
try
|
||||
{
|
||||
@ -95,21 +95,21 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$sc = new Container(array('foo' => 'bar'));
|
||||
$sc->addParameters(array('bar' => 'foo'));
|
||||
$this->assertEquals($sc->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->addParameters() adds parameters to the existing ones');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo'), $sc->getParameters(), '->addParameters() adds parameters to the existing ones');
|
||||
$sc->addParameters(array('Bar' => 'fooz'));
|
||||
$this->assertEquals($sc->getParameters(), array('foo' => 'bar', 'bar' => 'fooz'), '->addParameters() converts keys to lowercase');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'fooz'), $sc->getParameters(), '->addParameters() converts keys to lowercase');
|
||||
}
|
||||
|
||||
public function testServices()
|
||||
{
|
||||
$sc = new Container();
|
||||
$sc->setService('foo', $obj = new \stdClass());
|
||||
$this->assertEquals(spl_object_hash($sc->getService('foo')), spl_object_hash($obj), '->setService() registers a service under a key name');
|
||||
$this->assertEquals(spl_object_hash($obj), spl_object_hash($sc->getService('foo')), '->setService() registers a service under a key name');
|
||||
|
||||
$sc->foo1 = $obj1 = new \stdClass();
|
||||
$this->assertEquals(spl_object_hash($sc->foo1), spl_object_hash($obj1), '->__set() sets a service');
|
||||
$this->assertEquals(spl_object_hash($obj1), spl_object_hash($sc->foo1), '->__set() sets a service');
|
||||
|
||||
$this->assertEquals(spl_object_hash($sc->foo), spl_object_hash($obj), '->__get() gets a service by name');
|
||||
$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');
|
||||
@ -121,10 +121,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
||||
$sc = new Container();
|
||||
$sc->setService('foo', $obj = new \stdClass());
|
||||
$sc->setService('bar', $obj = new \stdClass());
|
||||
$this->assertEquals($sc->getServiceIds(), array('service_container', 'foo', 'bar'), '->getServiceIds() returns all defined service ids');
|
||||
$this->assertEquals(array('service_container', 'foo', 'bar'), $sc->getServiceIds(), '->getServiceIds() returns all defined service ids');
|
||||
|
||||
$sc = new ProjectServiceContainer();
|
||||
$this->assertEquals(spl_object_hash($sc->getService('bar')), spl_object_hash($sc->__bar), '->getService() looks for a getXXXService() method');
|
||||
$this->assertEquals(spl_object_hash($sc->__bar), spl_object_hash($sc->getService('bar')), '->getService() looks for a getXXXService() method');
|
||||
$this->assertTrue($sc->hasService('bar'), '->hasService() returns true if the service has been defined as a getXXXService() method');
|
||||
|
||||
$sc->setService('bar', $bar = new \stdClass());
|
||||
@ -157,15 +157,15 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
||||
|
||||
$this->assertEquals(spl_object_hash($sc->getService('foo_bar')), spl_object_hash($sc->__foo_bar), '->getService() camelizes the service id when looking for a method');
|
||||
$this->assertEquals(spl_object_hash($sc->getService('foo.baz')), spl_object_hash($sc->__foo_baz), '->getService() camelizes the service id when looking for a method');
|
||||
$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');
|
||||
$this->assertEquals(spl_object_hash($sc->__foo_baz), spl_object_hash($sc->getService('foo.baz')), '->getService() camelizes the service id when looking for a method');
|
||||
}
|
||||
|
||||
public function testMagicCall()
|
||||
{
|
||||
$sc = new Container();
|
||||
$sc->setService('foo_bar.foo', $foo = new \stdClass());
|
||||
$this->assertEquals($sc->getFooBar_FooService(), $foo, '__call() finds services is the method is getXXXService()');
|
||||
$this->assertEquals($foo, $sc->getFooBar_FooService(), '__call() finds services is the method is getXXXService()');
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -65,9 +65,9 @@ class CrossCheckTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
unlink($tmp);
|
||||
|
||||
$this->assertEquals(serialize($container1), serialize($container2), 'loading a dump from a previously loaded container returns the same container');
|
||||
$this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container');
|
||||
|
||||
$this->assertEquals($container1->getParameters(), $container2->getParameters(), '->getParameters() returns the same value for both containers');
|
||||
$this->assertEquals($container2->getParameters(), $container1->getParameters(), '->getParameters() returns the same value for both containers');
|
||||
|
||||
$services1 = array();
|
||||
foreach ($container1 as $id => $service)
|
||||
@ -82,7 +82,7 @@ class CrossCheckTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
unset($services1['service_container'], $services2['service_container']);
|
||||
|
||||
$this->assertEquals($services1, $services2, 'Iterator on the containers returns the same services');
|
||||
$this->assertEquals($services2, $services1, 'Iterator on the containers returns the same services');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,73 +19,73 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals($def->getClass(), 'stdClass', '__construct() takes the class name as its first argument');
|
||||
$this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
|
||||
|
||||
$def = new Definition('stdClass', array('foo'));
|
||||
$this->assertEquals($def->getArguments(), array('foo'), '__construct() takes an optional array of arguments as its second argument');
|
||||
$this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
|
||||
}
|
||||
|
||||
public function testSetGetConstructor()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(spl_object_hash($def->setConstructor('foo')), spl_object_hash($def), '->setConstructor() implements a fluent interface');
|
||||
$this->assertEquals($def->getConstructor(), 'foo', '->getConstructor() returns the constructor name');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setConstructor('foo')), '->setConstructor() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getConstructor(), '->getConstructor() returns the constructor name');
|
||||
}
|
||||
|
||||
public function testSetGetClass()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(spl_object_hash($def->setClass('foo')), spl_object_hash($def), '->setClass() implements a fluent interface');
|
||||
$this->assertEquals($def->getClass(), 'foo', '->getClass() returns the class name');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setClass('foo')), '->setClass() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
|
||||
}
|
||||
|
||||
public function testArguments()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(spl_object_hash($def->setArguments(array('foo'))), spl_object_hash($def), '->setArguments() implements a fluent interface');
|
||||
$this->assertEquals($def->getArguments(), array('foo'), '->getArguments() returns the arguments');
|
||||
$this->assertEquals(spl_object_hash($def->addArgument('bar')), spl_object_hash($def), '->addArgument() implements a fluent interface');
|
||||
$this->assertEquals($def->getArguments(), array('foo', 'bar'), '->addArgument() adds an argument');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setArguments(array('foo'))), '->setArguments() implements a fluent interface');
|
||||
$this->assertEquals(array('foo'), $def->getArguments(), '->getArguments() returns the arguments');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addArgument('bar')), '->addArgument() implements a fluent interface');
|
||||
$this->assertEquals(array('foo', 'bar'), $def->getArguments(), '->addArgument() adds an argument');
|
||||
}
|
||||
|
||||
public function testMethodCalls()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(spl_object_hash($def->setMethodCalls(array(array('foo', array('foo'))))), spl_object_hash($def), '->setMethodCalls() implements a fluent interface');
|
||||
$this->assertEquals($def->getMethodCalls(), array(array('foo', array('foo'))), '->getMethodCalls() returns the methods to call');
|
||||
$this->assertEquals(spl_object_hash($def->addMethodCall('bar', array('bar'))), spl_object_hash($def), '->addMethodCall() implements a fluent interface');
|
||||
$this->assertEquals($def->getMethodCalls(), array(array('foo', array('foo')), array('bar', array('bar'))), '->addMethodCall() adds a method to call');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setMethodCalls(array(array('foo', array('foo'))))), '->setMethodCalls() implements a fluent interface');
|
||||
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->getMethodCalls() returns the methods to call');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addMethodCall('bar', array('bar'))), '->addMethodCall() implements a fluent interface');
|
||||
$this->assertEquals(array(array('foo', array('foo')), array('bar', array('bar'))), $def->getMethodCalls(), '->addMethodCall() adds a method to call');
|
||||
}
|
||||
|
||||
public function testSetGetFile()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(spl_object_hash($def->setFile('foo')), spl_object_hash($def), '->setFile() implements a fluent interface');
|
||||
$this->assertEquals($def->getFile(), 'foo', '->getFile() returns the file to include');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setFile('foo')), '->setFile() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getFile(), '->getFile() returns the file to include');
|
||||
}
|
||||
|
||||
public function testSetIsShared()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals($def->isShared(), true, '->isShared() returns true by default');
|
||||
$this->assertEquals(spl_object_hash($def->setShared(false)), spl_object_hash($def), '->setShared() implements a fluent interface');
|
||||
$this->assertEquals($def->isShared(), false, '->isShared() returns false if the instance must not be shared');
|
||||
$this->assertEquals(true, $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');
|
||||
}
|
||||
|
||||
public function testSetGetConfigurator()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(spl_object_hash($def->setConfigurator('foo')), spl_object_hash($def), '->setConfigurator() implements a fluent interface');
|
||||
$this->assertEquals($def->getConfigurator(), 'foo', '->getConfigurator() returns the configurator');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setConfigurator('foo')), '->setConfigurator() implements a fluent interface');
|
||||
$this->assertEquals('foo', $def->getConfigurator(), '->getConfigurator() returns the configurator');
|
||||
}
|
||||
|
||||
public function testAnnotations()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$this->assertEquals(spl_object_hash($def->addAnnotation('foo')), spl_object_hash($def), '->addAnnotation() implements a fluent interface');
|
||||
$this->assertEquals($def->getAnnotation('foo'), array(array()), '->getAnnotation() returns attributes for an annotation name');
|
||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addAnnotation('foo')), '->addAnnotation() implements a fluent interface');
|
||||
$this->assertEquals(array(array()), $def->getAnnotation('foo'), '->getAnnotation() returns attributes for an annotation name');
|
||||
$def->addAnnotation('foo', array('foo' => 'bar'));
|
||||
$this->assertEquals($def->getAnnotation('foo'), array(array(), array('foo' => 'bar')), '->addAnnotation() can adds the same annotation several times');
|
||||
$this->assertEquals(array(array(), array('foo' => 'bar')), $def->getAnnotation('foo'), '->addAnnotation() can adds the same annotation several times');
|
||||
$def->addAnnotation('bar', array('bar' => 'bar'));
|
||||
$this->assertEquals($def->getAnnotations(), array(
|
||||
'foo' => array(array(), array('foo' => 'bar')),
|
||||
|
@ -28,18 +28,18 @@ class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dumper = new GraphvizDumper($container = new Builder());
|
||||
|
||||
$this->assertEquals($dumper->dump(), file_get_contents(self::$fixturesPath.'/graphviz/services1.dot'), '->dump() dumps an empty container as an empty dot file');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/graphviz/services1.dot'), $dumper->dump(), '->dump() dumps an empty container as an empty dot file');
|
||||
|
||||
$container = new Builder();
|
||||
$dumper = new GraphvizDumper($container);
|
||||
|
||||
$container = include self::$fixturesPath.'/containers/container9.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
$this->assertEquals($dumper->dump(), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services9.dot')), '->dump() dumps services');
|
||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services9.dot')), $dumper->dump(), '->dump() dumps services');
|
||||
|
||||
$container = include self::$fixturesPath.'/containers/container10.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
$this->assertEquals($dumper->dump(), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10.dot')), '->dump() dumps services');
|
||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10.dot')), $dumper->dump(), '->dump() dumps services');
|
||||
|
||||
$container = include self::$fixturesPath.'/containers/container10.php';
|
||||
$dumper = new GraphvizDumper($container);
|
||||
|
@ -28,8 +28,8 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dumper = new PhpDumper($container = new Builder());
|
||||
|
||||
$this->assertEquals($dumper->dump(), file_get_contents(self::$fixturesPath.'/php/services1.php'), '->dump() dumps an empty container as an empty PHP class');
|
||||
$this->assertEquals($dumper->dump(array('class' => 'Container', 'base_class' => 'AbstractContainer')), file_get_contents(self::$fixturesPath.'/php/services1-1.php'), '->dump() takes a class and a base_class options');
|
||||
$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');
|
||||
|
||||
$container = new Builder();
|
||||
$dumper = new PhpDumper($container);
|
||||
@ -39,14 +39,14 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container8.php';
|
||||
$dumper = new PhpDumper($container);
|
||||
$this->assertEquals($dumper->dump(), file_get_contents(self::$fixturesPath.'/php/services8.php'), '->dump() dumps parameters');
|
||||
$this->assertEquals(file_get_contents(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($dumper->dump(), str_replace('%path%', self::$fixturesPath.'/includes', file_get_contents(self::$fixturesPath.'/php/services9.php')), '->dump() dumps services');
|
||||
$this->assertEquals(str_replace('%path%', self::$fixturesPath.'/includes', 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());
|
||||
|
@ -28,7 +28,7 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dumper = new XmlDumper($container = new Builder());
|
||||
|
||||
$this->assertEquals($dumper->dump(), file_get_contents(self::$fixturesPath.'/xml/services1.xml'), '->dump() dumps an empty container as an empty XML file');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services1.xml'), $dumper->dump(), '->dump() dumps an empty container as an empty XML file');
|
||||
|
||||
$container = new Builder();
|
||||
$dumper = new XmlDumper($container);
|
||||
@ -38,14 +38,14 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$container = include self::$fixturesPath.'//containers/container8.php';
|
||||
$dumper = new XmlDumper($container);
|
||||
$this->assertEquals($dumper->dump(), file_get_contents(self::$fixturesPath.'/xml/services8.xml'), '->dump() dumps parameters');
|
||||
$this->assertEquals(file_get_contents(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($dumper->dump(), str_replace('%path%', self::$fixturesPath.'/includes', file_get_contents(self::$fixturesPath.'/xml/services9.xml')), '->dump() dumps services');
|
||||
$this->assertEquals(str_replace('%path%', self::$fixturesPath.'/includes', 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());
|
||||
|
@ -28,7 +28,7 @@ class YamlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dumper = new YamlDumper($container = new Builder());
|
||||
|
||||
$this->assertEquals($dumper->dump(), file_get_contents(self::$fixturesPath.'/yaml/services1.yml'), '->dump() dumps an empty container as an empty YAML file');
|
||||
$this->assertEquals(file_get_contents(self::$fixturesPath.'/yaml/services1.yml'), $dumper->dump(), '->dump() dumps an empty container as an empty YAML file');
|
||||
|
||||
$container = new Builder();
|
||||
$dumper = new YamlDumper($container);
|
||||
@ -38,14 +38,14 @@ class YamlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container8.php';
|
||||
$dumper = new YamlDumper($container);
|
||||
$this->assertEquals($dumper->dump(), file_get_contents(self::$fixturesPath.'/yaml/services8.yml'), '->dump() dumps parameters');
|
||||
$this->assertEquals(file_get_contents(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($dumper->dump(), str_replace('%path%', self::$fixturesPath.'/includes', file_get_contents(self::$fixturesPath.'/yaml/services9.yml')), '->dump() dumps services');
|
||||
$this->assertEquals(str_replace('%path%', self::$fixturesPath.'/includes', 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());
|
||||
|
@ -33,7 +33,7 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetResource()
|
||||
{
|
||||
$this->assertEquals($this->resource->getResource(), $this->file, '->getResource() returns the path to the resource');
|
||||
$this->assertEquals($this->file, $this->resource->getResource(), '->getResource() returns the path to the resource');
|
||||
}
|
||||
|
||||
public function testIsUptodate()
|
||||
|
@ -20,25 +20,25 @@ class XmlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$loader = new ProjectLoader(__DIR__);
|
||||
$this->assertEquals($loader->paths, array(__DIR__), '__construct() takes a path as its second argument');
|
||||
$this->assertEquals(array(__DIR__), $loader->paths, '__construct() takes a path as its second argument');
|
||||
|
||||
$loader = new ProjectLoader(array(__DIR__, __DIR__));
|
||||
$this->assertEquals($loader->paths, array(__DIR__, __DIR__), '__construct() takes an array of paths as its second argument');
|
||||
$this->assertEquals(array(__DIR__, __DIR__), $loader->paths, '__construct() takes an array of paths as its second argument');
|
||||
}
|
||||
|
||||
public function testGetAbsolutePath()
|
||||
{
|
||||
$loader = new ProjectLoader(array(__DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/containers'));
|
||||
$this->assertEquals($loader->getAbsolutePath('/foo.xml'), '/foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
|
||||
$this->assertEquals($loader->getAbsolutePath('c:\\\\foo.xml'), 'c:\\\\foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
|
||||
$this->assertEquals($loader->getAbsolutePath('c:/foo.xml'), 'c:/foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
|
||||
$this->assertEquals($loader->getAbsolutePath('\\server\\foo.xml'), '\\server\\foo.xml', '->getAbsolutePath() return the path unmodified if it is already an absolute path');
|
||||
$this->assertEquals('/foo.xml', $loader->getAbsolutePath('/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
|
||||
$this->assertEquals('c:\\\\foo.xml', $loader->getAbsolutePath('c:\\\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
|
||||
$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($loader->getAbsolutePath('FileLoaderTest.php', __DIR__), __DIR__.'/FileLoaderTest.php', '->getAbsolutePath() returns an absolute filename if the file exists in the current 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($loader->getAbsolutePath('container10.php', __DIR__), __DIR__.'/../../../../../fixtures/Symfony/Components/DependencyInjection/containers/container10.php', '->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/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($loader->getAbsolutePath('foo.xml', __DIR__), 'foo.xml', '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths');
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class IniLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$loader = new IniFileLoader(self::$fixturesPath.'/ini');
|
||||
$config = $loader->load('parameters.ini');
|
||||
$this->assertEquals($config->getParameters(), array('foo' => 'bar', 'bar' => '%foo%'), '->load() takes a single file name as its first argument');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => '%foo%'), $config->getParameters(), '->load() takes a single file name as its first argument');
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -30,6 +30,6 @@ class LoaderExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$config = $extension->load('bar', array('foo' => 'bar'));
|
||||
$this->assertEquals($config->getParameters(), array('project.parameter.bar' => 'bar'), '->load() calls the method tied to the given tag');
|
||||
$this->assertEquals(array('project.parameter.bar' => 'bar'), $config->getParameters(), '->load() calls the method tied to the given tag');
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$xml = $loader->parseFile(self::$fixturesPath.'/xml/services1.xml');
|
||||
$this->assertEquals(get_class($xml), 'Symfony\\Components\\DependencyInjection\\SimpleXMLElement', '->parseFile() returns an SimpleXMLElement object');
|
||||
$this->assertEquals('Symfony\\Components\\DependencyInjection\\SimpleXMLElement', get_class($xml), '->parseFile() returns an SimpleXMLElement object');
|
||||
}
|
||||
|
||||
public function testLoadParameters()
|
||||
@ -78,7 +78,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$actual = $config->getParameters();
|
||||
$expected = array('a string', 'foo' => 'bar', 'values' => array(0, 'integer' => 4, 100 => null, 'true', true, false, 'on', 'off', 'float' => 1.3, 1000.3, 'a string', array('foo', 'bar')), 'foo_bar' => new Reference('foo_bar'));
|
||||
|
||||
$this->assertEquals($actual, $expected, '->load() converts XML values to PHP ones');
|
||||
$this->assertEquals($expected, $actual, '->load() converts XML values to PHP ones');
|
||||
}
|
||||
|
||||
public function testLoadImports()
|
||||
@ -89,7 +89,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$actual = $config->getParameters();
|
||||
$expected = array('a string', 'foo' => 'bar', 'values' => array(true, false), 'foo_bar' => new Reference('foo_bar'), 'bar' => '%foo%', 'imported_from_ini' => true, 'imported_from_yaml' => true);
|
||||
|
||||
$this->assertEquals(array_keys($actual), array_keys($expected), '->load() imports and merges imported files');
|
||||
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
|
||||
}
|
||||
|
||||
public function testLoadAnonymousServices()
|
||||
@ -97,20 +97,20 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new ProjectLoader2(self::$fixturesPath.'/xml');
|
||||
$config = $loader->load('services5.xml');
|
||||
$services = $config->getDefinitions();
|
||||
$this->assertEquals(count($services), 3, '->load() attributes unique ids to anonymous services');
|
||||
$this->assertEquals(3, count($services), '->load() attributes unique ids to anonymous services');
|
||||
$args = $services['foo']->getArguments();
|
||||
$this->assertEquals(count($args), 1, '->load() references anonymous services as "normal" ones');
|
||||
$this->assertEquals(get_class($args[0]), 'Symfony\\Components\\DependencyInjection\\Reference', '->load() converts anonymous services to references to "normal" services');
|
||||
$this->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
|
||||
$this->assertEquals('Symfony\\Components\\DependencyInjection\\Reference', get_class($args[0]), '->load() converts anonymous services to references to "normal" services');
|
||||
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
|
||||
$inner = $services[(string) $args[0]];
|
||||
$this->assertEquals($inner->getClass(), 'BarClass', '->load() uses the same configuration as for the anonymous ones');
|
||||
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
||||
|
||||
$args = $inner->getArguments();
|
||||
$this->assertEquals(count($args), 1, '->load() references anonymous services as "normal" ones');
|
||||
$this->assertEquals(get_class($args[0]), 'Symfony\\Components\\DependencyInjection\\Reference', '->load() converts anonymous services to references to "normal" services');
|
||||
$this->assertEquals(1, count($args), '->load() references anonymous services as "normal" ones');
|
||||
$this->assertEquals('Symfony\\Components\\DependencyInjection\\Reference', get_class($args[0]), '->load() converts anonymous services to references to "normal" services');
|
||||
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
|
||||
$inner = $services[(string) $args[0]];
|
||||
$this->assertEquals($inner->getClass(), 'BazClass', '->load() uses the same configuration as for the anonymous ones');
|
||||
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
||||
}
|
||||
|
||||
public function testLoadServices()
|
||||
@ -119,48 +119,48 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$config = $loader->load('services6.xml');
|
||||
$services = $config->getDefinitions();
|
||||
$this->assertTrue(isset($services['foo']), '->load() parses <service> elements');
|
||||
$this->assertEquals(get_class($services['foo']), 'Symfony\\Components\\DependencyInjection\\Definition', '->load() converts <service> element to Definition instances');
|
||||
$this->assertEquals($services['foo']->getClass(), 'FooClass', '->load() parses the class attribute');
|
||||
$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->assertEquals($services['constructor']->getConstructor(), 'getInstance', '->load() parses the constructor attribute');
|
||||
$this->assertEquals($services['file']->getFile(), '%path%/foo.php', '->load() parses the file tag');
|
||||
$this->assertEquals($services['arguments']->getArguments(), array('foo', new Reference('foo'), array(true, false)), '->load() parses the argument tags');
|
||||
$this->assertEquals($services['configurator1']->getConfigurator(), 'sc_configure', '->load() parses the configurator tag');
|
||||
$this->assertEquals($services['configurator2']->getConfigurator(), array(new Reference('baz'), 'configure'), '->load() parses the configurator tag');
|
||||
$this->assertEquals($services['configurator3']->getConfigurator(), array('BazClass', 'configureStatic'), '->load() parses the configurator tag');
|
||||
$this->assertEquals($services['method_call1']->getMethodCalls(), array(array('setBar', array())), '->load() parses the method_call tag');
|
||||
$this->assertEquals($services['method_call2']->getMethodCalls(), array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), '->load() parses the method_call tag');
|
||||
$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');
|
||||
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
|
||||
$this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
|
||||
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
|
||||
$this->assertEquals(array(array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
|
||||
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
|
||||
$aliases = $config->getAliases();
|
||||
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
|
||||
$this->assertEquals($aliases['alias_for_foo'], 'foo', '->load() parses aliases');
|
||||
$this->assertEquals('foo', $aliases['alias_for_foo'], '->load() parses aliases');
|
||||
}
|
||||
|
||||
public function testConvertDomElementToArray()
|
||||
{
|
||||
$doc = new \DOMDocument("1.0");
|
||||
$doc->loadXML('<foo>bar</foo>');
|
||||
$this->assertEquals(ProjectLoader2::convertDomElementToArray($doc->documentElement), 'bar', '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
$this->assertEquals('bar', ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
|
||||
$doc = new \DOMDocument("1.0");
|
||||
$doc->loadXML('<foo foo="bar" />');
|
||||
$this->assertEquals(ProjectLoader2::convertDomElementToArray($doc->documentElement), array('foo' => 'bar'), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
$this->assertEquals(array('foo' => 'bar'), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
|
||||
$doc = new \DOMDocument("1.0");
|
||||
$doc->loadXML('<foo><foo>bar</foo></foo>');
|
||||
$this->assertEquals(ProjectLoader2::convertDomElementToArray($doc->documentElement), array('foo' => 'bar'), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
$this->assertEquals(array('foo' => 'bar'), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
|
||||
$doc = new \DOMDocument("1.0");
|
||||
$doc->loadXML('<foo><foo>bar<foo>bar</foo></foo></foo>');
|
||||
$this->assertEquals(ProjectLoader2::convertDomElementToArray($doc->documentElement), array('foo' => array('value' => 'bar', 'foo' => 'bar')), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
$this->assertEquals(array('foo' => array('value' => 'bar', 'foo' => 'bar')), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
|
||||
$doc = new \DOMDocument("1.0");
|
||||
$doc->loadXML('<foo><foo></foo></foo>');
|
||||
$this->assertEquals(ProjectLoader2::convertDomElementToArray($doc->documentElement), array('foo' => null), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
$this->assertEquals(array('foo' => null), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
|
||||
$doc = new \DOMDocument("1.0");
|
||||
$doc->loadXML('<foo><foo><!-- foo --></foo></foo>');
|
||||
$this->assertEquals(ProjectLoader2::convertDomElementToArray($doc->documentElement), array('foo' => null), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
$this->assertEquals(array('foo' => null), ProjectLoader2::convertDomElementToArray($doc->documentElement), '::convertDomElementToArray() converts a \DomElement to an array');
|
||||
}
|
||||
|
||||
public function testExtensions()
|
||||
|
@ -69,7 +69,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$loader = new ProjectLoader3(self::$fixturesPath.'/yaml');
|
||||
$config = $loader->load('services2.yml');
|
||||
$this->assertEquals($config->getParameters(), array('foo' => 'bar', 'values' => array(true, false, 0, 1000.3), 'bar' => 'foo', 'foo_bar' => new Reference('foo_bar')), '->load() converts YAML keys to lowercase');
|
||||
$this->assertEquals(array('foo' => 'bar', 'values' => array(true, false, 0, 1000.3), 'bar' => 'foo', 'foo_bar' => new Reference('foo_bar')), $config->getParameters(), '->load() converts YAML keys to lowercase');
|
||||
}
|
||||
|
||||
public function testLoadImports()
|
||||
@ -79,7 +79,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$actual = $config->getParameters();
|
||||
$expected = array('foo' => 'bar', 'values' => array(true, false), 'bar' => '%foo%', 'foo_bar' => new Reference('foo_bar'), 'imported_from_ini' => true, 'imported_from_xml' => true);
|
||||
$this->assertEquals(array_keys($actual), array_keys($expected), '->load() imports and merges imported files');
|
||||
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
|
||||
}
|
||||
|
||||
public function testLoadServices()
|
||||
@ -88,21 +88,21 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$config = $loader->load('services6.yml');
|
||||
$services = $config->getDefinitions();
|
||||
$this->assertTrue(isset($services['foo']), '->load() parses service elements');
|
||||
$this->assertEquals(get_class($services['foo']), 'Symfony\\Components\\DependencyInjection\\Definition', '->load() converts service element to Definition instances');
|
||||
$this->assertEquals($services['foo']->getClass(), 'FooClass', '->load() parses the class attribute');
|
||||
$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->assertEquals($services['constructor']->getConstructor(), 'getInstance', '->load() parses the constructor attribute');
|
||||
$this->assertEquals($services['file']->getFile(), '%path%/foo.php', '->load() parses the file tag');
|
||||
$this->assertEquals($services['arguments']->getArguments(), array('foo', new Reference('foo'), array(true, false)), '->load() parses the argument tags');
|
||||
$this->assertEquals($services['configurator1']->getConfigurator(), 'sc_configure', '->load() parses the configurator tag');
|
||||
$this->assertEquals($services['configurator2']->getConfigurator(), array(new Reference('baz'), 'configure'), '->load() parses the configurator tag');
|
||||
$this->assertEquals($services['configurator3']->getConfigurator(), array('BazClass', 'configureStatic'), '->load() parses the configurator tag');
|
||||
$this->assertEquals($services['method_call1']->getMethodCalls(), array(array('setBar', array())), '->load() parses the method_call tag');
|
||||
$this->assertEquals($services['method_call2']->getMethodCalls(), array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), '->load() parses the method_call tag');
|
||||
$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');
|
||||
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
|
||||
$this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
|
||||
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
|
||||
$this->assertEquals(array(array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
|
||||
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
|
||||
$aliases = $config->getAliases();
|
||||
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses aliases');
|
||||
$this->assertEquals($aliases['alias_for_foo'], 'foo', '->load() parses aliases');
|
||||
$this->assertEquals('foo', $aliases['alias_for_foo'], '->load() parses aliases');
|
||||
}
|
||||
|
||||
public function testExtensions()
|
||||
|
@ -19,6 +19,6 @@ class ParameterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$ref = new Parameter('foo');
|
||||
$this->assertEquals((string) $ref, 'foo', '__construct() sets the id of the parameter, which is used for the __toString() method');
|
||||
$this->assertEquals('foo', (string) $ref, '__construct() sets the id of the parameter, which is used for the __toString() method');
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,6 @@ class ReferenceTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$ref = new Reference('foo');
|
||||
$this->assertEquals((string) $ref, 'foo', '__construct() sets the id of the reference, which is used for the __toString() method');
|
||||
$this->assertEquals('foo', (string) $ref, '__construct() sets the id of the reference, which is used for the __toString() method');
|
||||
}
|
||||
}
|
||||
|
@ -22,14 +22,14 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$dispatcher = new EventDispatcher();
|
||||
|
||||
$dispatcher->connect('bar', 'listenToBar');
|
||||
$this->assertEquals($dispatcher->getListeners('bar'), array('listenToBar'), '->connect() connects a listener to an event name');
|
||||
$this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->connect() connects a listener to an event name');
|
||||
$dispatcher->connect('bar', 'listenToBarBar');
|
||||
$this->assertEquals($dispatcher->getListeners('bar'), array('listenToBar', 'listenToBarBar'), '->connect() can connect several listeners for the same event name');
|
||||
$this->assertEquals(array('listenToBar', 'listenToBarBar'), $dispatcher->getListeners('bar'), '->connect() can connect several listeners for the same event name');
|
||||
|
||||
$dispatcher->connect('barbar', 'listenToBarBar');
|
||||
$dispatcher->disconnect('bar', 'listenToBarBar');
|
||||
$this->assertEquals($dispatcher->getListeners('bar'), array('listenToBar'), '->disconnect() disconnects a listener for an event name');
|
||||
$this->assertEquals($dispatcher->getListeners('barbar'), array('listenToBarBar'), '->disconnect() disconnects a listener for an event name');
|
||||
$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');
|
||||
}
|
||||
@ -38,15 +38,15 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
|
||||
$this->assertEquals($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener');
|
||||
$this->assertEquals(false, $dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
|
||||
$dispatcher->connect('foo', 'listenToFoo');
|
||||
$this->assertEquals($dispatcher->hasListeners('foo'), true, '->hasListeners() returns true if the event has some listeners');
|
||||
$this->assertEquals(true, $dispatcher->hasListeners('foo'), '->hasListeners() returns true if the event has some listeners');
|
||||
$dispatcher->disconnect('foo', 'listenToFoo');
|
||||
$this->assertEquals($dispatcher->hasListeners('foo'), false, '->hasListeners() returns false if the event has no listener');
|
||||
$this->assertEquals(false, $dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
|
||||
|
||||
$dispatcher->connect('bar', 'listenToBar');
|
||||
$this->assertEquals($dispatcher->getListeners('bar'), array('listenToBar'), '->getListeners() returns an array of listeners connected to the given event name');
|
||||
$this->assertEquals($dispatcher->getListeners('foobar'), array(), '->getListeners() returns an empty array if no listener are connected to the given event name');
|
||||
$this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->getListeners() returns an array of listeners connected to the given event name');
|
||||
$this->assertEquals(array(), $dispatcher->getListeners('foobar'), '->getListeners() returns an empty array if no listener are connected to the given event name');
|
||||
}
|
||||
|
||||
public function testNotify()
|
||||
@ -56,15 +56,15 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFoo'));
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFooBis'));
|
||||
$e = $dispatcher->notify($event = new Event(new \stdClass(), 'foo'));
|
||||
$this->assertEquals($listener->getValue(), 'listenToFoolistenToFooBis', '->notify() notifies all registered listeners in order');
|
||||
$this->assertEquals($e, $event, '->notify() returns the event object');
|
||||
$this->assertEquals('listenToFoolistenToFooBis', $listener->getValue(), '->notify() notifies all registered listeners in order');
|
||||
$this->assertEquals($event, $e, '->notify() returns the event object');
|
||||
|
||||
$listener->reset();
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFooBis'));
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFoo'));
|
||||
$dispatcher->notify(new Event(new \stdClass(), 'foo'));
|
||||
$this->assertEquals($listener->getValue(), 'listenToFooBislistenToFoo', '->notify() notifies all registered listeners in order');
|
||||
$this->assertEquals('listenToFooBislistenToFoo', $listener->getValue(), '->notify() notifies all registered listeners in order');
|
||||
}
|
||||
|
||||
public function testNotifyUntil()
|
||||
@ -74,15 +74,15 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFoo'));
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFooBis'));
|
||||
$e = $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo'));
|
||||
$this->assertEquals($listener->getValue(), 'listenToFoolistenToFooBis', '->notifyUntil() notifies all registered listeners in order and stops if it returns true');
|
||||
$this->assertEquals($e, $event, '->notifyUntil() returns the event object');
|
||||
$this->assertEquals('listenToFoolistenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops if it returns true');
|
||||
$this->assertEquals($event, $e, '->notifyUntil() returns the event object');
|
||||
|
||||
$listener->reset();
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFooBis'));
|
||||
$dispatcher->connect('foo', array($listener, 'listenToFoo'));
|
||||
$e = $dispatcher->notifyUntil($event = new Event(new \stdClass(), 'foo'));
|
||||
$this->assertEquals($listener->getValue(), 'listenToFooBis', '->notifyUntil() notifies all registered listeners in order and stops if it returns true');
|
||||
$this->assertEquals('listenToFooBis', $listener->getValue(), '->notifyUntil() notifies all registered listeners in order and stops if it returns true');
|
||||
}
|
||||
|
||||
public function testFilter()
|
||||
@ -92,15 +92,15 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$dispatcher->connect('foo', array($listener, 'filterFoo'));
|
||||
$dispatcher->connect('foo', array($listener, 'filterFooBis'));
|
||||
$e = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
|
||||
$this->assertEquals($e->getReturnValue(), '-*foo*-', '->filter() filters a value');
|
||||
$this->assertEquals($e, $event, '->filter() returns the event object');
|
||||
$this->assertEquals('-*foo*-', $e->getReturnValue(), '->filter() filters a value');
|
||||
$this->assertEquals($event, $e, '->filter() returns the event object');
|
||||
|
||||
$listener->reset();
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->connect('foo', array($listener, 'filterFooBis'));
|
||||
$dispatcher->connect('foo', array($listener, 'filterFoo'));
|
||||
$e = $dispatcher->filter($event = new Event(new \stdClass(), 'foo'), 'foo');
|
||||
$this->assertEquals($e->getReturnValue(), '*-foo-*', '->filter() filters a value');
|
||||
$this->assertEquals('*-foo-*', $e->getReturnValue(), '->filter() filters a value');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,22 +21,23 @@ class EventTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetSubject()
|
||||
{
|
||||
$this->assertEquals($this->createEvent()->getSubject(), $this->subject, '->getSubject() returns the event subject');
|
||||
$event = $this->createEvent();
|
||||
$this->assertEquals($this->subject, $event->getSubject(), '->getSubject() returns the event subject');
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals($this->createEvent()->getName(), 'name', '->getName() returns the event name');
|
||||
$this->assertEquals('name', $this->createEvent()->getName(), '->getName() returns the event name');
|
||||
}
|
||||
|
||||
public function testParameters()
|
||||
{
|
||||
$event = $this->createEvent();
|
||||
|
||||
$this->assertEquals($event->getParameters(), $this->parameters, '->getParameters() returns the event parameters');
|
||||
$this->assertEquals($event->getParameter('foo'), 'bar', '->getParameter() returns the value of a parameter');
|
||||
$this->assertEquals($this->parameters, $event->getParameters(), '->getParameters() returns the event parameters');
|
||||
$this->assertEquals('bar', $event->getParameter('foo'), '->getParameter() returns the value of a parameter');
|
||||
$event->setParameter('foo', 'foo');
|
||||
$this->assertEquals($event->getParameter('foo'), 'foo', '->setParameter() changes the value of a parameter');
|
||||
$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');
|
||||
@ -56,25 +57,25 @@ class EventTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$event = $this->createEvent();
|
||||
$event->setReturnValue('foo');
|
||||
$this->assertEquals($event->getReturnValue(), 'foo', '->getReturnValue() returns the return value of the event');
|
||||
$this->assertEquals('foo', $event->getReturnValue(), '->getReturnValue() returns the return value of the event');
|
||||
}
|
||||
|
||||
public function testSetIsProcessed()
|
||||
{
|
||||
$event = $this->createEvent();
|
||||
$event->setProcessed(true);
|
||||
$this->assertEquals($event->isProcessed(), true, '->isProcessed() returns true if the event has been processed');
|
||||
$this->assertEquals(true, $event->isProcessed(), '->isProcessed() returns true if the event has been processed');
|
||||
$event->setProcessed(false);
|
||||
$this->assertEquals($event->isProcessed(), false, '->setProcessed() changes the processed status');
|
||||
$this->assertEquals(false, $event->isProcessed(), '->setProcessed() changes the processed status');
|
||||
}
|
||||
|
||||
public function testArrayAccessInterface()
|
||||
{
|
||||
$event = $this->createEvent();
|
||||
|
||||
$this->assertEquals($event['foo'], 'bar', 'Event implements the ArrayAccess interface');
|
||||
$this->assertEquals('bar', $event['foo'], 'Event implements the ArrayAccess interface');
|
||||
$event['foo'] = 'foo';
|
||||
$this->assertEquals($event['foo'], 'foo', 'Event implements the ArrayAccess interface');
|
||||
$this->assertEquals('foo', $event['foo'], 'Event implements the ArrayAccess interface');
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -28,14 +28,14 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetRaw()
|
||||
{
|
||||
$this->assertEquals(self::$escaped->getRaw(0), '<strong>escaped!</strong>', '->getRaw() returns the raw value');
|
||||
$this->assertEquals('<strong>escaped!</strong>', self::$escaped->getRaw(0), '->getRaw() returns the raw value');
|
||||
}
|
||||
|
||||
public function testArrayAccessInterface()
|
||||
{
|
||||
$this->assertEquals(self::$escaped[0], '<strong>escaped!</strong>', 'The escaped object behaves like an array');
|
||||
$this->assertEquals(self::$escaped[2], null, 'The escaped object behaves like an array');
|
||||
$this->assertEquals(self::$escaped[3][1], '<strong>escaped!</strong>', 'The escaped object behaves like an array');
|
||||
$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->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)');
|
||||
|
||||
@ -67,13 +67,13 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
|
||||
switch ($key)
|
||||
{
|
||||
case 0:
|
||||
$this->assertEquals($value, '<strong>escaped!</strong>', 'The escaped object behaves like an array');
|
||||
$this->assertEquals('<strong>escaped!</strong>', $value, 'The escaped object behaves like an array');
|
||||
break;
|
||||
case 1:
|
||||
$this->assertEquals($value, 1, 'The escaped object behaves like an array');
|
||||
$this->assertEquals(1, $value, 'The escaped object behaves like an array');
|
||||
break;
|
||||
case 2:
|
||||
$this->assertEquals($value, null, 'The escaped object behaves like an array');
|
||||
$this->assertEquals(null, $value, 'The escaped object behaves like an array');
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
@ -85,6 +85,6 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testCountableInterface()
|
||||
{
|
||||
$this->assertEquals(count(self::$escaped), 4, 'The escaped object implements the Countable interface');
|
||||
$this->assertEquals(4, count(self::$escaped), 'The escaped object implements the Countable interface');
|
||||
}
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testEscapeDoesNotEscapeAValueWhenEscapingMethodIsRAW()
|
||||
{
|
||||
$this->assertEquals(Escaper::escape('raw', '<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::escape() takes an escaping strategy function name as its first argument');
|
||||
$this->assertEquals('<strong>escaped!</strong>', Escaper::escape('raw', '<strong>escaped!</strong>'), '::escape() takes an escaping strategy function name as its first argument');
|
||||
}
|
||||
|
||||
public function testEscapeEscapesStrings()
|
||||
{
|
||||
$this->assertEquals(Escaper::escape('entities', '<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::escape() returns an escaped string if the value to escape is a string');
|
||||
$this->assertEquals(Escaper::escape('entities', '<strong>échappé</strong>'), '<strong>échappé</strong>', '::escape() returns an escaped string if the value to escape is a string');
|
||||
$this->assertEquals('<strong>escaped!</strong>', Escaper::escape('entities', '<strong>escaped!</strong>'), '::escape() returns an escaped string if the value to escape is a string');
|
||||
$this->assertEquals('<strong>échappé</strong>', Escaper::escape('entities', '<strong>échappé</strong>'), '::escape() returns an escaped string if the value to escape is a string');
|
||||
}
|
||||
|
||||
public function testEscapeEscapesArrays()
|
||||
@ -47,9 +47,9 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
$output = Escaper::escape('entities', $input);
|
||||
$this->assertTrue($output instanceof ArrayDecorator, '::escape() returns a ArrayDecorator object if the value to escape is an array');
|
||||
$this->assertEquals($output['foo'], '<strong>escaped!</strong>', '::escape() escapes all elements of the original array');
|
||||
$this->assertEquals($output['bar']['foo'], '<strong>escaped!</strong>', '::escape() is recursive');
|
||||
$this->assertEquals($output->getRawValue(), $input, '->getRawValue() returns the unescaped value');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testEscapeEscapesObjects()
|
||||
@ -57,12 +57,12 @@ 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->assertEquals($output->getTitle(), '<strong>escaped!</strong>', '::escape() escapes all methods of the original object');
|
||||
$this->assertEquals($output->title, '<strong>escaped!</strong>', '::escape() escapes all properties of the original object');
|
||||
$this->assertEquals($output->getTitleTitle(), '<strong>escaped!</strong>', '::escape() is recursive');
|
||||
$this->assertEquals($output->getRawValue(), $input, '->getRawValue() returns the unescaped value');
|
||||
$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(Escaper::escape('entities', $output)->getTitle(), '<strong>escaped!</strong>', '::escape() does not double escape an object');
|
||||
$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');
|
||||
}
|
||||
|
||||
@ -99,8 +99,8 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testUnescapeUnescapesStrings()
|
||||
{
|
||||
$this->assertEquals(Escaper::unescape('<strong>escaped!</strong>'), '<strong>escaped!</strong>', '::unescape() returns an unescaped string if the value to unescape is a string');
|
||||
$this->assertEquals(Escaper::unescape('<strong>échappé</strong>'), '<strong>échappé</strong>', '::unescape() returns an unescaped string if the value to unescape is a string');
|
||||
$this->assertEquals('<strong>escaped!</strong>', Escaper::unescape('<strong>escaped!</strong>'), '::unescape() returns an unescaped string if the value to unescape is a string');
|
||||
$this->assertEquals('<strong>échappé</strong>', Escaper::unescape('<strong>échappé</strong>'), '::unescape() returns an unescaped string if the value to unescape is a string');
|
||||
}
|
||||
|
||||
public function testUnescapeUnescapesArrays()
|
||||
@ -111,8 +111,8 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
$output = Escaper::unescape($input);
|
||||
$this->assertTrue(is_array($output), '::unescape() returns an array if the input is a ArrayDecorator object');
|
||||
$this->assertEquals($output['foo'], '<strong>escaped!</strong>', '::unescape() unescapes all elements of the original array');
|
||||
$this->assertEquals($output['bar']['foo'], '<strong>escaped!</strong>', '::unescape() is recursive');
|
||||
$this->assertEquals('<strong>escaped!</strong>', $output['foo'], '::unescape() unescapes all elements of the original array');
|
||||
$this->assertEquals('<strong>escaped!</strong>', $output['bar']['foo'], '::unescape() is recursive');
|
||||
}
|
||||
|
||||
public function testUnescapeUnescapesObjects()
|
||||
@ -121,9 +121,9 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
|
||||
$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->assertEquals($output->getTitle(), '<strong>escaped!</strong>', '::unescape() unescapes all methods of the original object');
|
||||
$this->assertEquals($output->title, '<strong>escaped!</strong>', '::unescape() unescapes all properties of the original object');
|
||||
$this->assertEquals($output->getTitleTitle(), '<strong>escaped!</strong>', '::unescape() is recursive');
|
||||
$this->assertEquals('<strong>escaped!</strong>', $output->getTitle(), '::unescape() unescapes all methods of the original object');
|
||||
$this->assertEquals('<strong>escaped!</strong>', $output->title, '::unescape() unescapes all properties of the original object');
|
||||
$this->assertEquals('<strong>escaped!</strong>', $output->getTitleTitle(), '::unescape() is recursive');
|
||||
|
||||
$this->assertTrue(IteratorDecorator::unescape(Escaper::escape('entities', new \DirectoryIterator('.'))) instanceof \DirectoryIterator, '::unescape() unescapes IteratorDecorator objects');
|
||||
}
|
||||
@ -140,7 +140,7 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
|
||||
public function testUnescapeDoesNothingToResources()
|
||||
{
|
||||
$fh = fopen(__FILE__, 'r');
|
||||
$this->assertEquals(Escaper::unescape($fh), $fh, '::unescape() do nothing to resources');
|
||||
$this->assertEquals($fh, Escaper::unescape($fh), '::unescape() do nothing to resources');
|
||||
}
|
||||
|
||||
public function testUnescapeUnescapesMixedArrays()
|
||||
@ -156,7 +156,7 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
|
||||
'bar' => '<strong>bar</strong>',
|
||||
'foobar' => $object,
|
||||
);
|
||||
$this->assertEquals(Escaper::unescape($input), $output, '::unescape() unescapes values with some escaped and unescaped values');
|
||||
$this->assertEquals($output, Escaper::unescape($input), '::unescape() unescapes values with some escaped and unescaped values');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,15 +28,15 @@ class ObjectDecoratorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGenericBehavior()
|
||||
{
|
||||
$this->assertEquals(self::$escaped->getTitle(), '<strong>escaped!</strong>', 'The escaped object behaves like the real object');
|
||||
$this->assertEquals('<strong>escaped!</strong>', self::$escaped->getTitle(), 'The escaped object behaves like the real object');
|
||||
|
||||
$array = self::$escaped->getTitles();
|
||||
$this->assertEquals($array[2], '<strong>escaped!</strong>', 'The escaped object behaves like the real object');
|
||||
$this->assertEquals('<strong>escaped!</strong>', $array[2], 'The escaped object behaves like the real object');
|
||||
}
|
||||
|
||||
public function testMagicToString()
|
||||
{
|
||||
$this->assertEquals(self::$escaped->__toString(), '<strong>escaped!</strong>', 'The escaped object behaves like the real object');
|
||||
$this->assertEquals('<strong>escaped!</strong>', self::$escaped->__toString(), 'The escaped object behaves like the real object');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,35 +20,35 @@ class SafeDecoratorTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetValue()
|
||||
{
|
||||
$safe = new SafeDecorator('foo');
|
||||
$this->assertEquals($safe->getValue(), 'foo', '->getValue() returns the embedded value');
|
||||
$this->assertEquals('foo', $safe->getValue(), '->getValue() returns the embedded value');
|
||||
}
|
||||
|
||||
public function testMagicGetAndSet()
|
||||
{
|
||||
$safe = new SafeDecorator(new TestClass1());
|
||||
|
||||
$this->assertEquals($safe->foo, 'bar', '->__get() returns the object parameter');
|
||||
$this->assertEquals('bar', $safe->foo, '->__get() returns the object parameter');
|
||||
$safe->foo = 'baz';
|
||||
$this->assertEquals($safe->foo, 'baz', '->__set() sets the object parameter');
|
||||
$this->assertEquals('baz', $safe->foo, '->__set() sets the object parameter');
|
||||
}
|
||||
|
||||
public function testMagicCall()
|
||||
{
|
||||
$safe = new SafeDecorator(new TestClass2());
|
||||
|
||||
$this->assertEquals($safe->doSomething(), 'ok', '->__call() invokes the embedded method');
|
||||
$this->assertEquals('ok', $safe->doSomething(), '->__call() invokes the embedded method');
|
||||
}
|
||||
|
||||
public function testMagicIssetAndUnset()
|
||||
{
|
||||
$safe = new SafeDecorator(new TestClass3());
|
||||
|
||||
$this->assertEquals(isset($safe->boolValue), true, '->__isset() returns true if the property is not null');
|
||||
$this->assertEquals(isset($safe->nullValue), false, '->__isset() returns false if the property is null');
|
||||
$this->assertEquals(isset($safe->undefinedValue), false, '->__isset() returns false if the property does not exist');
|
||||
$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');
|
||||
|
||||
unset($safe->boolValue);
|
||||
$this->assertEquals(isset($safe->boolValue), false, '->__unset() unsets the embedded property');
|
||||
$this->assertEquals(false, isset($safe->boolValue), '->__unset() unsets the embedded property');
|
||||
}
|
||||
|
||||
public function testIteratorInterface()
|
||||
@ -68,12 +68,12 @@ class SafeDecoratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$safe = new SafeDecorator(array('foo' => 'bar'));
|
||||
|
||||
$this->assertEquals($safe['foo'], 'bar', '"ArrayAccess" implementation returns a value from the embedded array');
|
||||
$this->assertEquals('bar', $safe['foo'], '"ArrayAccess" implementation returns a value from the embedded array');
|
||||
$safe['foo'] = 'baz';
|
||||
$this->assertEquals($safe['foo'], 'baz', '"ArrayAccess" implementation sets a value on the embedded array');
|
||||
$this->assertEquals(isset($safe['foo']), true, '"ArrayAccess" checks if a value is set on the embedded array');
|
||||
$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');
|
||||
unset($safe['foo']);
|
||||
$this->assertEquals(isset($safe['foo']), false, '"ArrayAccess" unsets a value on the embedded array');
|
||||
$this->assertEquals(false, isset($safe['foo']), '"ArrayAccess" unsets a value on the embedded array');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,11 @@ class EngineTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$engine = new ProjectTemplateEngine(self::$loader);
|
||||
$this->assertEquals($engine->getLoader(), self::$loader, '__construct() takes a loader instance as its second first argument');
|
||||
$this->assertEquals(array_keys($engine->getRenderers()), array('php'), '__construct() automatically registers a PHP renderer if none is given');
|
||||
$this->assertEquals(self::$loader, $engine->getLoader(), '__construct() takes a loader instance as its second first argument');
|
||||
$this->assertEquals(array('php'), array_keys($engine->getRenderers()), '__construct() automatically registers a PHP renderer if none is given');
|
||||
|
||||
$engine = new ProjectTemplateEngine(self::$loader, array('foo' => self::$renderer));
|
||||
$this->assertEquals(array_keys($engine->getRenderers()), array('foo', 'php'), '__construct() takes an array of renderers as its third argument');
|
||||
$this->assertEquals(array('foo', 'php'), array_keys($engine->getRenderers()), '__construct() takes an array of renderers as its third argument');
|
||||
$this->assertTrue(self::$renderer->getEngine() === $engine, '__construct() registers itself on all renderers');
|
||||
|
||||
$engine = new ProjectTemplateEngine(self::$loader, array('php' => self::$renderer));
|
||||
@ -52,7 +52,7 @@ class EngineTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$engine = new ProjectTemplateEngine(self::$loader);
|
||||
$engine->set($helper = new \SimpleHelper('bar'), 'foo');
|
||||
$this->assertEquals($engine->foo, $helper, '->__get() returns the value of a helper');
|
||||
$this->assertEquals($helper, $engine->foo, '->__get() returns the value of a helper');
|
||||
|
||||
try
|
||||
{
|
||||
@ -69,10 +69,10 @@ class EngineTest extends \PHPUnit_Framework_TestCase
|
||||
$engine = new ProjectTemplateEngine(self::$loader);
|
||||
$foo = new \SimpleHelper('foo');
|
||||
$engine->set($foo);
|
||||
$this->assertEquals($engine->get('foo'), $foo, '->set() sets a helper');
|
||||
$this->assertEquals($foo, $engine->get('foo'), '->set() sets a helper');
|
||||
|
||||
$engine->set($foo, 'bar');
|
||||
$this->assertEquals($engine->get('bar'), $foo, '->set() takes an alias as a second argument');
|
||||
$this->assertEquals($foo, $engine->get('bar'), '->set() takes an alias as a second argument');
|
||||
|
||||
try
|
||||
{
|
||||
@ -113,33 +113,34 @@ class EngineTest extends \PHPUnit_Framework_TestCase
|
||||
$engine->set(new \SimpleHelper('bar'));
|
||||
self::$loader->setTemplate('foo.php', '<?php $view->extend("layout"); echo $view->foo.$foo ?>');
|
||||
self::$loader->setTemplate('layout.php', '-<?php echo $view->slots->get("_content") ?>-');
|
||||
$this->assertEquals($engine->render('foo', array('foo' => 'foo')), '-barfoo-', '->render() uses the decorator to decorate the template');
|
||||
$this->assertEquals('-barfoo-', $engine->render('foo', array('foo' => 'foo')), '->render() uses the decorator to decorate the template');
|
||||
|
||||
$engine = new ProjectTemplateEngine(self::$loader, array(), array(new SlotsHelper()));
|
||||
$engine->set(new \SimpleHelper('bar'));
|
||||
self::$loader->setTemplate('bar.php', 'bar');
|
||||
self::$loader->setTemplate('foo.php', '<?php $view->extend("layout"); echo $foo ?>');
|
||||
self::$loader->setTemplate('layout.php', '<?php echo $view->render("bar") ?>-<?php echo $view->slots->get("_content") ?>-');
|
||||
$this->assertEquals($engine->render('foo', array('foo' => 'foo', 'bar' => 'bar')), 'bar-foo-', '->render() supports render() calls in templates');
|
||||
$this->assertEquals('bar-foo-', $engine->render('foo', array('foo' => 'foo', 'bar' => 'bar')), '->render() supports render() calls in templates');
|
||||
|
||||
// compilable templates
|
||||
$engine = new ProjectTemplateEngine(new CompilableTemplateLoader(), array('foo' => new FooTemplateRenderer()));
|
||||
$this->assertEquals($engine->render('index'), 'foo', '->load() takes into account the renderer embedded in the Storage instance if not null');
|
||||
$this->assertEquals('foo', $engine->render('index'), '->load() takes into account the renderer embedded in the Storage instance if not null');
|
||||
}
|
||||
|
||||
public function testEscape()
|
||||
{
|
||||
$engine = new ProjectTemplateEngine(self::$loader);
|
||||
$this->assertEquals($engine->escape('<br />'), '<br />', '->escape() escapes strings');
|
||||
$this->assertEquals($engine->escape($foo = new \stdClass()), $foo, '->escape() does nothing on non strings');
|
||||
$this->assertEquals('<br />', $engine->escape('<br />'), '->escape() escapes strings');
|
||||
$foo = new \stdClass();
|
||||
$this->assertEquals($foo, $engine->escape($foo), '->escape() does nothing on non strings');
|
||||
}
|
||||
|
||||
public function testGetSetCharset()
|
||||
{
|
||||
$engine = new ProjectTemplateEngine(self::$loader);
|
||||
$this->assertEquals($engine->getCharset(), 'UTF-8', '->getCharset() returns UTF-8 by default');
|
||||
$this->assertEquals('UTF-8', $engine->getCharset(), '->getCharset() returns UTF-8 by default');
|
||||
$engine->setCharset('ISO-8859-1');
|
||||
$this->assertEquals($engine->getCharset(), 'ISO-8859-1', '->setCharset() changes the default charset to use');
|
||||
$this->assertEquals('ISO-8859-1', $engine->getCharset(), '->setCharset() changes the default charset to use');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,36 +20,36 @@ class AssetsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$helper = new AssetsHelper('foo', 'http://www.example.com', 'abcd');
|
||||
$this->assertEquals($helper->getBasePath(), '/foo/', '__construct() takes a base path as its first argument');
|
||||
$this->assertEquals($helper->getBaseURLs(), array('http://www.example.com'), '__construct() takes a base URL as its second argument');
|
||||
$this->assertEquals($helper->getVersion(), 'abcd', '__construct() takes a version as its thrid argument');
|
||||
$this->assertEquals('/foo/', $helper->getBasePath(), '__construct() takes a base path as its first argument');
|
||||
$this->assertEquals(array('http://www.example.com'), $helper->getBaseURLs(), '__construct() takes a base URL as its second argument');
|
||||
$this->assertEquals('abcd', $helper->getVersion(), '__construct() takes a version as its thrid argument');
|
||||
}
|
||||
|
||||
public function testGetSetBasePath()
|
||||
{
|
||||
$helper = new AssetsHelper();
|
||||
$helper->setBasePath('foo/');
|
||||
$this->assertEquals($helper->getBasePath(), '/foo/', '->setBasePath() prepends a / if needed');
|
||||
$this->assertEquals('/foo/', $helper->getBasePath(), '->setBasePath() prepends a / if needed');
|
||||
$helper->setBasePath('/foo');
|
||||
$this->assertEquals($helper->getBasePath(), '/foo/', '->setBasePath() appends a / is needed');
|
||||
$this->assertEquals('/foo/', $helper->getBasePath(), '->setBasePath() appends a / is needed');
|
||||
$helper->setBasePath('');
|
||||
$this->assertEquals($helper->getBasePath(), '/', '->setBasePath() returns / if no base path is defined');
|
||||
$this->assertEquals('/', $helper->getBasePath(), '->setBasePath() returns / if no base path is defined');
|
||||
$helper->setBasePath('0');
|
||||
$this->assertEquals($helper->getBasePath(), '/0/', '->setBasePath() returns /0/ if 0 is given');
|
||||
$this->assertEquals('/0/', $helper->getBasePath(), '->setBasePath() returns /0/ if 0 is given');
|
||||
}
|
||||
|
||||
public function testGetSetVersion()
|
||||
{
|
||||
$helper = new AssetsHelper();
|
||||
$helper->setVersion('foo');
|
||||
$this->assertEquals($helper->getVersion(), 'foo', '->setVersion() sets the version');
|
||||
$this->assertEquals('foo', $helper->getVersion(), '->setVersion() sets the version');
|
||||
}
|
||||
|
||||
public function testSetGetBaseURLs()
|
||||
{
|
||||
$helper = new AssetsHelper();
|
||||
$helper->setBaseURLs('http://www.example.com/');
|
||||
$this->assertEquals($helper->getBaseURLs(), array('http://www.example.com'), '->setBaseURLs() removes the / at the of an absolute base path');
|
||||
$this->assertEquals(array('http://www.example.com'), $helper->getBaseURLs(), '->setBaseURLs() removes the / at the of an absolute base path');
|
||||
$helper->setBaseURLs(array('http://www1.example.com/', 'http://www2.example.com/'));
|
||||
$URLs = array();
|
||||
for ($i = 0; $i < 20; $i++)
|
||||
@ -58,41 +58,41 @@ class AssetsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
$URLs = array_values(array_unique($URLs));
|
||||
sort($URLs);
|
||||
$this->assertEquals($URLs, array('http://www1.example.com', 'http://www2.example.com'), '->getBaseURL() returns a random base URL if several are given');
|
||||
$this->assertEquals(array('http://www1.example.com', 'http://www2.example.com'), $URLs, '->getBaseURL() returns a random base URL if several are given');
|
||||
$helper->setBaseURLs('');
|
||||
$this->assertEquals($helper->getBaseURL(1), '', '->getBaseURL() returns an empty string if no base URL exist');
|
||||
$this->assertEquals('', $helper->getBaseURL(1), '->getBaseURL() returns an empty string if no base URL exist');
|
||||
}
|
||||
|
||||
public function testGetUrl()
|
||||
{
|
||||
$helper = new AssetsHelper();
|
||||
$this->assertEquals($helper->getUrl('http://example.com/foo.js'), 'http://example.com/foo.js', '->getUrl() does nothing if an absolute URL is given');
|
||||
$this->assertEquals('http://example.com/foo.js', $helper->getUrl('http://example.com/foo.js'), '->getUrl() does nothing if an absolute URL is given');
|
||||
|
||||
$helper = new AssetsHelper();
|
||||
$this->assertEquals($helper->getUrl('foo.js'), '/foo.js', '->getUrl() appends a / on relative paths');
|
||||
$this->assertEquals($helper->getUrl('/foo.js'), '/foo.js', '->getUrl() does nothing on absolute paths');
|
||||
$this->assertEquals('/foo.js', $helper->getUrl('foo.js'), '->getUrl() appends a / on relative paths');
|
||||
$this->assertEquals('/foo.js', $helper->getUrl('/foo.js'), '->getUrl() does nothing on absolute paths');
|
||||
|
||||
$helper = new AssetsHelper('/foo');
|
||||
$this->assertEquals($helper->getUrl('foo.js'), '/foo/foo.js', '->getUrl() appends the basePath on relative paths');
|
||||
$this->assertEquals($helper->getUrl('/foo.js'), '/foo.js', '->getUrl() does not append the basePath on absolute paths');
|
||||
$this->assertEquals('/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() appends the basePath on relative paths');
|
||||
$this->assertEquals('/foo.js', $helper->getUrl('/foo.js'), '->getUrl() does not append the basePath on absolute paths');
|
||||
|
||||
$helper = new AssetsHelper(null, 'http://assets.example.com/');
|
||||
$this->assertEquals($helper->getUrl('foo.js'), 'http://assets.example.com/foo.js', '->getUrl() prepends the base URL');
|
||||
$this->assertEquals($helper->getUrl('/foo.js'), 'http://assets.example.com/foo.js', '->getUrl() prepends the base URL');
|
||||
$this->assertEquals('http://assets.example.com/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL');
|
||||
$this->assertEquals('http://assets.example.com/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL');
|
||||
|
||||
$helper = new AssetsHelper(null, 'http://www.example.com/foo');
|
||||
$this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL with a path');
|
||||
$this->assertEquals($helper->getUrl('/foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL with a path');
|
||||
$this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL with a path');
|
||||
$this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL with a path');
|
||||
|
||||
$helper = new AssetsHelper('/foo', 'http://www.example.com/');
|
||||
$this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL and the base path if defined');
|
||||
$this->assertEquals($helper->getUrl('/foo.js'), 'http://www.example.com/foo.js', '->getUrl() prepends the base URL but not the base path on absolute paths');
|
||||
$this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined');
|
||||
$this->assertEquals('http://www.example.com/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL but not the base path on absolute paths');
|
||||
|
||||
$helper = new AssetsHelper('/bar', 'http://www.example.com/foo');
|
||||
$this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/bar/foo.js', '->getUrl() prepends the base URL and the base path if defined');
|
||||
$this->assertEquals($helper->getUrl('/foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL but not the base path on absolute paths');
|
||||
$this->assertEquals('http://www.example.com/foo/bar/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined');
|
||||
$this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL but not the base path on absolute paths');
|
||||
|
||||
$helper = new AssetsHelper('/bar', 'http://www.example.com/foo', 'abcd');
|
||||
$this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/bar/foo.js?abcd', '->getUrl() appends the version if defined');
|
||||
$this->assertEquals('http://www.example.com/foo/bar/foo.js?abcd', $helper->getUrl('foo.js'), '->getUrl() appends the version if defined');
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,13 @@ class JavascriptsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
$assetHelper = new AssetsHelper();
|
||||
$helper = new JavascriptsHelper($assetHelper);
|
||||
$helper->add('foo');
|
||||
$this->assertEquals($helper->get(), array('/foo' => array()), '->add() adds a JavaScript');
|
||||
$this->assertEquals(array('/foo' => array()), $helper->get(), '->add() adds a JavaScript');
|
||||
$helper->add('/foo');
|
||||
$this->assertEquals($helper->get(), array('/foo' => array()), '->add() does not add the same JavaScript twice');
|
||||
$this->assertEquals(array('/foo' => array()), $helper->get(), '->add() does not add the same JavaScript twice');
|
||||
$helper = new JavascriptsHelper($assetHelper);
|
||||
$assetHelper->setBaseURLs('http://assets.example.com/');
|
||||
$helper->add('foo');
|
||||
$this->assertEquals($helper->get(), array('http://assets.example.com/foo' => array()), '->add() converts the JavaScript to a public path');
|
||||
$this->assertEquals(array('http://assets.example.com/foo' => array()), $helper->get(), '->add() converts the JavaScript to a public path');
|
||||
}
|
||||
|
||||
public function testMagicToString()
|
||||
@ -39,6 +39,6 @@ class JavascriptsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
$assetHelper->setBaseURLs('');
|
||||
$helper = new JavascriptsHelper($assetHelper);
|
||||
$helper->add('foo', array('class' => 'ba>'));
|
||||
$this->assertEquals($helper->__toString(), '<script type="text/javascript" src="/foo" class="ba>"></script>'."\n", '->__toString() converts the JavaScript configuration to HTML');
|
||||
$this->assertEquals('<script type="text/javascript" src="/foo" class="ba>"></script>'."\n", $helper->__toString(), '->__toString() converts the JavaScript configuration to HTML');
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ class SlotsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$helper = new SlotsHelper();
|
||||
$helper->set('foo', 'bar');
|
||||
$this->assertEquals($helper->get('foo'), 'bar', '->set() sets a slot value');
|
||||
$this->assertEquals($helper->get('bar', 'bar'), 'bar', '->get() takes a default value to return if the slot does not exist');
|
||||
$this->assertEquals('bar', $helper->get('foo'), '->set() sets a slot value');
|
||||
$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');
|
||||
@ -35,20 +35,20 @@ class SlotsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
ob_start();
|
||||
$ret = $helper->output('foo');
|
||||
$output = ob_get_clean();
|
||||
$this->assertEquals($output, 'bar', '->output() outputs the content of a slot');
|
||||
$this->assertEquals($ret, true, '->output() returns true if the slot exists');
|
||||
$this->assertEquals('bar', $output, '->output() outputs the content of a slot');
|
||||
$this->assertEquals(true, $ret, '->output() returns true if the slot exists');
|
||||
|
||||
ob_start();
|
||||
$ret = $helper->output('bar', 'bar');
|
||||
$output = ob_get_clean();
|
||||
$this->assertEquals($output, 'bar', '->output() takes a default value to return if the slot does not exist');
|
||||
$this->assertEquals($ret, true, '->output() returns true if the slot does not exist but a default value is provided');
|
||||
$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');
|
||||
|
||||
ob_start();
|
||||
$ret = $helper->output('bar');
|
||||
$output = ob_get_clean();
|
||||
$this->assertEquals($output, '', '->output() outputs nothing if the slot does not exist');
|
||||
$this->assertEquals($ret, false, '->output() returns false if the slot does not exist');
|
||||
$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');
|
||||
}
|
||||
|
||||
public function testStartStop()
|
||||
@ -57,7 +57,7 @@ class SlotsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
$helper->start('bar');
|
||||
echo 'foo';
|
||||
$helper->stop();
|
||||
$this->assertEquals($helper->get('bar'), 'foo', '->start() starts a slot');
|
||||
$this->assertEquals('foo', $helper->get('bar'), '->start() starts a slot');
|
||||
$this->assertTrue($helper->has('bar'), '->starts() starts a slot');
|
||||
|
||||
$helper->start('bar');
|
||||
|
@ -24,13 +24,13 @@ class StylesheetsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
$assetHelper = new AssetsHelper();
|
||||
$helper = new StylesheetsHelper($assetHelper);
|
||||
$helper->add('foo');
|
||||
$this->assertEquals($helper->get(), array('/foo' => array()), '->add() adds a stylesheet');
|
||||
$this->assertEquals(array('/foo' => array()), $helper->get(), '->add() adds a stylesheet');
|
||||
$helper->add('/foo');
|
||||
$this->assertEquals($helper->get(), array('/foo' => array()), '->add() does not add the same stylesheet twice');
|
||||
$this->assertEquals(array('/foo' => array()), $helper->get(), '->add() does not add the same stylesheet twice');
|
||||
$helper = new StylesheetsHelper($assetHelper);
|
||||
$assetHelper->setBaseURLs('http://assets.example.com/');
|
||||
$helper->add('foo');
|
||||
$this->assertEquals($helper->get(), array('http://assets.example.com/foo' => array()), '->add() converts the stylesheet to a public path');
|
||||
$this->assertEquals(array('http://assets.example.com/foo' => array()), $helper->get(), '->add() converts the stylesheet to a public path');
|
||||
}
|
||||
|
||||
public function testMagicToString()
|
||||
@ -39,6 +39,6 @@ class StylesheetsHelperTest extends \PHPUnit_Framework_TestCase
|
||||
$assetHelper->setBaseURLs('');
|
||||
$helper = new StylesheetsHelper($assetHelper);
|
||||
$helper->add('foo', array('media' => 'ba>'));
|
||||
$this->assertEquals($helper->__toString(), '<link href="/foo" rel="stylesheet" type="text/css" media="ba>" />'."\n", '->__toString() converts the stylesheet configuration to HTML');
|
||||
$this->assertEquals('<link href="/foo" rel="stylesheet" type="text/css" media="ba>" />'."\n", $helper->__toString(), '->__toString() converts the stylesheet configuration to HTML');
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class CacheLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), sys_get_temp_dir());
|
||||
$this->assertTrue($loader->getLoader() === $varLoader, '__construct() takes a template loader as its first argument');
|
||||
$this->assertEquals($loader->getDir(), sys_get_temp_dir(), '__construct() takes a directory where to store the cache as its second argument');
|
||||
$this->assertEquals(sys_get_temp_dir(), $loader->getDir(), '__construct() takes a directory where to store the cache as its second argument');
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
@ -50,11 +50,11 @@ class CacheLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader->setDebugger($debugger = new \ProjectTemplateDebugger());
|
||||
$template = $loader->load('special', array('renderer' => 'comp'));
|
||||
$this->assertTrue($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
|
||||
$this->assertEquals($template->getRenderer(), 'php', '->load() changes the renderer to php if the template is compilable');
|
||||
$this->assertEquals('php', $template->getRenderer(), '->load() changes the renderer to php if the template is compilable');
|
||||
|
||||
$template = $loader->load('special', array('renderer' => 'comp'));
|
||||
$this->assertTrue($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
|
||||
$this->assertEquals($template->getRenderer(), 'php', '->load() changes the renderer to php if the template is compilable');
|
||||
$this->assertEquals('php', $template->getRenderer(), '->load() changes the renderer to php if the template is compilable');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,14 +33,14 @@ class ChainLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$loader = new ProjectTemplateLoader1(array(self::$loader1, self::$loader2));
|
||||
$this->assertEquals($loader->getLoaders(), array(self::$loader1, self::$loader2), '__construct() takes an array of template loaders as its second argument');
|
||||
$this->assertEquals(array(self::$loader1, self::$loader2), $loader->getLoaders(), '__construct() takes an array of template loaders as its second argument');
|
||||
}
|
||||
|
||||
public function testAddLoader()
|
||||
{
|
||||
$loader = new ProjectTemplateLoader1(array(self::$loader1));
|
||||
$loader->addLoader(self::$loader2);
|
||||
$this->assertEquals($loader->getLoaders(), array(self::$loader1, self::$loader2), '->addLoader() adds a template loader at the end of the loaders');
|
||||
$this->assertEquals(array(self::$loader1, self::$loader2), $loader->getLoaders(), '->addLoader() adds a template loader at the end of the loaders');
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
|
@ -32,9 +32,9 @@ class FilesystemLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$pathPattern = self::$fixturesPath.'/templates/%name%.%renderer%';
|
||||
$path = self::$fixturesPath.'/templates';
|
||||
$loader = new ProjectTemplateLoader2($pathPattern);
|
||||
$this->assertEquals($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes a path as its second argument');
|
||||
$this->assertEquals(array($pathPattern), $loader->getTemplatePathPatterns(), '__construct() takes a path as its second argument');
|
||||
$loader = new ProjectTemplateLoader2(array($pathPattern));
|
||||
$this->assertEquals($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes an array of paths as its second argument');
|
||||
$this->assertEquals(array($pathPattern), $loader->getTemplatePathPatterns(), '__construct() takes an array of paths as its second argument');
|
||||
}
|
||||
|
||||
public function testIsAbsolutePath()
|
||||
@ -52,13 +52,13 @@ class FilesystemLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$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->assertEquals((string) $storage, $path.'/foo.php', '->load() returns a FileStorage pointing to the passed 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');
|
||||
|
||||
$storage = $loader->load('foo');
|
||||
$this->assertTrue($storage instanceof FileStorage, '->load() returns a FileStorage if you pass a relative template that exists');
|
||||
$this->assertEquals((string) $storage, $path.'/foo.php', '->load() returns a FileStorage pointing to the absolute path of the template');
|
||||
$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());
|
||||
|
@ -25,9 +25,9 @@ class PhpRendererTest extends \PHPUnit_Framework_TestCase
|
||||
$renderer = new PhpRenderer();
|
||||
|
||||
$template = new StringStorage('<?php echo $foo ?>');
|
||||
$this->assertEquals($renderer->evaluate($template, array('foo' => 'bar')), 'bar', '->evaluate() renders templates that are instances of StringStorage');
|
||||
$this->assertEquals('bar', $renderer->evaluate($template, array('foo' => 'bar')), '->evaluate() renders templates that are instances of StringStorage');
|
||||
|
||||
$template = new FileStorage(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/templates/foo.php');
|
||||
$this->assertEquals($renderer->evaluate($template, array('foo' => 'bar')), 'bar', '->evaluate() renders templates that are instances of FileStorage');
|
||||
$this->assertEquals('bar', $renderer->evaluate($template, array('foo' => 'bar')), '->evaluate() renders templates that are instances of FileStorage');
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ class FileStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$storage = new FileStorage('foo');
|
||||
$this->assertTrue($storage instanceof Storage, 'FileStorage is an instance of Storage');
|
||||
$storage = new FileStorage(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/templates/foo.php');
|
||||
$this->assertEquals($storage->getContent(), '<?php echo $foo ?>', '->getContent() returns the content of the template');
|
||||
$this->assertEquals('<?php echo $foo ?>', $storage->getContent(), '->getContent() returns the content of the template');
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class StorageTest extends \PHPUnit_Framework_TestCase
|
||||
public function testMagicToString()
|
||||
{
|
||||
$storage = new TestStorage('foo');
|
||||
$this->assertEquals((string) $storage, 'foo', '__toString() returns the template name');
|
||||
$this->assertEquals('foo', (string) $storage, '__toString() returns the template name');
|
||||
}
|
||||
|
||||
public function testGetRenderer()
|
||||
|
@ -23,6 +23,6 @@ class StringStorageTest extends \PHPUnit_Framework_TestCase
|
||||
$storage = new StringStorage('foo');
|
||||
$this->assertTrue($storage instanceof Storage, 'StringStorage is an instance of Storage');
|
||||
$storage = new StringStorage('foo');
|
||||
$this->assertEquals($storage->getContent(), 'foo', '->getContent() returns the content of the template');
|
||||
$this->assertEquals('foo', $storage->getContent(), '->getContent() returns the content of the template');
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class DumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$expected = eval('return '.trim($test['php']).';');
|
||||
|
||||
$this->assertEquals($this->parser->parse($this->dumper->dump($expected, 10)), $expected, $test['test']);
|
||||
$this->assertEquals($expected, $this->parser->parse($this->dumper->dump($expected, 10)), $test['test']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,8 +89,8 @@ class DumperTest extends \PHPUnit_Framework_TestCase
|
||||
$expected = <<<EOF
|
||||
{ '': bar, foo: '#bar', 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } }
|
||||
EOF;
|
||||
$this->assertEquals($this->dumper->dump($array, -10), $expected, '->dump() takes an inline level argument');
|
||||
$this->assertEquals($this->dumper->dump($array, 0), $expected, '->dump() takes an inline level argument');
|
||||
$this->assertEquals($expected, $this->dumper->dump($array, -10), '->dump() takes an inline level argument');
|
||||
$this->assertEquals($expected, $this->dumper->dump($array, 0), '->dump() takes an inline level argument');
|
||||
|
||||
$expected = <<<EOF
|
||||
'': bar
|
||||
@ -100,7 +100,7 @@ bar: [1, foo]
|
||||
foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } }
|
||||
|
||||
EOF;
|
||||
$this->assertEquals($this->dumper->dump($array, 1), $expected, '->dump() takes an inline level argument');
|
||||
$this->assertEquals($expected, $this->dumper->dump($array, 1), '->dump() takes an inline level argument');
|
||||
|
||||
$expected = <<<EOF
|
||||
'': bar
|
||||
@ -115,7 +115,7 @@ foobar:
|
||||
foobar: { foo: bar, bar: [1, foo] }
|
||||
|
||||
EOF;
|
||||
$this->assertEquals($this->dumper->dump($array, 2), $expected, '->dump() takes an inline level argument');
|
||||
$this->assertEquals($expected, $this->dumper->dump($array, 2), '->dump() takes an inline level argument');
|
||||
|
||||
$expected = <<<EOF
|
||||
'': bar
|
||||
@ -134,7 +134,7 @@ foobar:
|
||||
bar: [1, foo]
|
||||
|
||||
EOF;
|
||||
$this->assertEquals($this->dumper->dump($array, 3), $expected, '->dump() takes an inline level argument');
|
||||
$this->assertEquals($expected, $this->dumper->dump($array, 3), '->dump() takes an inline level argument');
|
||||
|
||||
$expected = <<<EOF
|
||||
'': bar
|
||||
@ -155,15 +155,15 @@ foobar:
|
||||
- foo
|
||||
|
||||
EOF;
|
||||
$this->assertEquals($this->dumper->dump($array, 4), $expected, '->dump() takes an inline level argument');
|
||||
$this->assertEquals($this->dumper->dump($array, 10), $expected, '->dump() takes an inline level argument');
|
||||
$this->assertEquals($expected, $this->dumper->dump($array, 4), '->dump() takes an inline level argument');
|
||||
$this->assertEquals($expected, $this->dumper->dump($array, 10), '->dump() takes an inline level argument');
|
||||
}
|
||||
|
||||
public function testObjectsSupport()
|
||||
{
|
||||
$a = array('foo' => new A(), 'bar' => 1);
|
||||
|
||||
$this->assertEquals($this->dumper->dump($a), '{ foo: !!php/object:O:40:"Symfony\Tests\Components\OutputEscaper\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', '->dump() is able to dump objects');
|
||||
$this->assertEquals('{ foo: !!php/object:O:40:"Symfony\Tests\Components\OutputEscaper\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $this->dumper->dump($a), '->dump() is able to dump objects');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
foreach ($this->getTestsForLoad() as $yaml => $value)
|
||||
{
|
||||
$this->assertEquals(Inline::load($yaml), $value, sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml));
|
||||
$this->assertEquals($value, Inline::load($yaml), sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml));
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
foreach ($testsForDump as $yaml => $value)
|
||||
{
|
||||
$this->assertEquals(Inline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
|
||||
$this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
|
||||
}
|
||||
|
||||
foreach ($this->getTestsForLoad() as $yaml => $value)
|
||||
@ -46,7 +46,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertEquals(Inline::load(Inline::dump($value)), $value, 'check consistency');
|
||||
$this->assertEquals($value, Inline::load(Inline::dump($value)), 'check consistency');
|
||||
}
|
||||
|
||||
foreach ($testsForDump as $yaml => $value)
|
||||
@ -56,7 +56,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertEquals(Inline::load(Inline::dump($value)), $value, 'check consistency');
|
||||
$this->assertEquals($value, Inline::load(Inline::dump($value)), 'check consistency');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$expected = var_export(eval('return '.trim($test['php']).';'), true);
|
||||
|
||||
$this->assertEquals(var_export($this->parser->parse($test['yaml']), true), $expected, $test['test']);
|
||||
$this->assertEquals($expected, var_export($this->parser->parse($test['yaml']), true), $test['test']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user