aboutsummaryrefslogtreecommitdiffstats
path: root/tests/controller/controller_test.php
diff options
context:
space:
mode:
authorTristan Darricau <tristan.darricau@sensiolabs.com>2016-04-03 16:04:59 +0200
committerTristan Darricau <tristan.darricau@sensiolabs.com>2016-04-03 16:04:59 +0200
commite8762ce3cb25faddfb1797377208876e1e65c785 (patch)
tree42a2d35a310dcba88927bb46715f432377f585f3 /tests/controller/controller_test.php
parent8769e765a2e3cb4fb78d4f9d66e6e72bff9a0649 (diff)
parent01d56673889cb12a11fca24b62f6e93e1c9f8dd8 (diff)
downloadforums-e8762ce3cb25faddfb1797377208876e1e65c785.tar
forums-e8762ce3cb25faddfb1797377208876e1e65c785.tar.gz
forums-e8762ce3cb25faddfb1797377208876e1e65c785.tar.bz2
forums-e8762ce3cb25faddfb1797377208876e1e65c785.tar.xz
forums-e8762ce3cb25faddfb1797377208876e1e65c785.zip
Merge pull request #4266 from marc1706/ticket/13502
[ticket/13502] Handle callable functions/objects in controller resolver * marc1706/ticket/13502: [ticket/13502] Also cover passing object to resolver in tests [ticket/13502] Test getArguments() method of controller resolver [ticket/13502] Fix coding style [ticket/13502] Controller resolver should handle callable functions and objects
Diffstat (limited to 'tests/controller/controller_test.php')
-rw-r--r--tests/controller/controller_test.php58
1 files changed, 47 insertions, 11 deletions
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php
index abc1124a90..d921d0eade 100644
--- a/tests/controller/controller_test.php
+++ b/tests/controller/controller_test.php
@@ -11,6 +11,9 @@
*
*/
+include_once(__DIR__ . '/ext/vendor2/foo/controller.php');
+include_once(__DIR__.'/phpbb/controller/foo.php');
+
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -64,7 +67,7 @@ class phpbb_controller_controller_test extends phpbb_test_case
$this->assertNull($routes->get('controller_noroute'));
}
- public function test_controller_resolver()
+ protected function get_foo_container()
{
$container = new ContainerBuilder();
// YamlFileLoader only uses one path at a time, so we need to loop
@@ -75,26 +78,59 @@ class phpbb_controller_controller_test extends phpbb_test_case
$loader->load('services.yml');
}
- // Autoloading classes within the tests folder does not work
- // so I'll include them manually.
- if (!class_exists('vendor2\\foo\\controller'))
- {
- include(__DIR__ . '/ext/vendor2/foo/controller.php');
- }
- if (!class_exists('phpbb\\controller\\foo'))
- {
- include(__DIR__.'/phpbb/controller/foo.php');
- }
+ return $container;
+ }
+
+ public function test_controller_resolver()
+ {
+ $container = $this->get_foo_container();
$resolver = new \phpbb\controller\resolver($container, dirname(__FILE__) . '/');
$symfony_request = new Request();
$symfony_request->attributes->set('_controller', 'foo.controller:handle');
$this->assertEquals($resolver->getController($symfony_request), array(new foo\controller, 'handle'));
+ $this->assertEquals(array('foo'), $resolver->getArguments($symfony_request, $resolver->getController($symfony_request)));
$symfony_request = new Request();
$symfony_request->attributes->set('_controller', 'core_foo.controller:bar');
$this->assertEquals($resolver->getController($symfony_request), array(new phpbb\controller\foo, 'bar'));
+ $this->assertEquals(array(), $resolver->getArguments($symfony_request, $resolver->getController($symfony_request)));
+ }
+
+ public function data_get_arguments()
+ {
+ return array(
+ array(array(new foo\controller(), 'handle2'), array('foo', 0)),
+ array(array(new foo\controller(), 'handle_fail'), array('default'), array('no_default' => 'default')),
+ array(new foo\controller(), array(), array()),
+ array(array(new foo\controller(), 'handle_fail'), array(), array(), '\phpbb\controller\exception', 'CONTROLLER_ARGUMENT_VALUE_MISSING'),
+ array('', array(), array(), '\ReflectionException', 'Function () does not exist'),
+ array(new phpbb\controller\foo, array(), array(), '\ReflectionException', 'Method __invoke does not exist'),
+ );
+ }
+
+ /**
+ * @dataProvider data_get_arguments
+ */
+ public function test_get_arguments($input, $expected, $set_attributes = array(), $exception = '', $exception_message = '')
+ {
+ $container = $this->get_foo_container();
+
+ $resolver = new \phpbb\controller\resolver($container, dirname(__FILE__) . '/');
+ $symfony_request = new Request();
+
+ foreach ($set_attributes as $name => $value)
+ {
+ $symfony_request->attributes->set($name, $value);
+ }
+
+ if (!empty($exception))
+ {
+ $this->setExpectedException($exception, $exception_message);
+ }
+
+ $this->assertEquals($expected, $resolver->getArguments($symfony_request, $input));
}
}