UrlHelper example

use Symfony\Component\Routing\RequestContextAwareInterface;

class UrlHelperTest extends TestCase
{
    /** * @dataProvider getGenerateAbsoluteUrlData */
    public function testGenerateAbsoluteUrl($expected$path$pathinfo)
    {
        $stack = new RequestStack();
        $stack->push(Request::create($pathinfo));
        $helper = new UrlHelper($stack);

        $this->assertEquals($expected$helper->getAbsoluteUrl($path));
    }

    public static function getGenerateAbsoluteUrlData()
    {
        return [
            ['http://localhost/foo.png', '/foo.png', '/foo/bar.html'],
            ['http://localhost/foo/foo.png', 'foo.png', '/foo/bar.html'],
            ['http://localhost/foo/foo.png', 'foo.png', '/foo/bar'],
            ['http://localhost/foo/bar/foo.png', 'foo.png', '/foo/bar/'],

            [
use Symfony\Component\Routing\RequestContext;

class HttpFoundationExtensionTest extends TestCase
{
    /** * @dataProvider getGenerateAbsoluteUrlData */
    public function testGenerateAbsoluteUrl($expected$path$pathinfo)
    {
        $stack = new RequestStack();
        $stack->push(Request::create($pathinfo));
        $extension = new HttpFoundationExtension(new UrlHelper($stack));

        $this->assertEquals($expected$extension->generateAbsoluteUrl($path));
    }

    public static function getGenerateAbsoluteUrlData()
    {
        return [
            ['http://localhost/foo.png', '/foo.png', '/foo/bar.html'],
            ['http://localhost/foo/foo.png', 'foo.png', '/foo/bar.html'],
            ['http://localhost/foo/foo.png', 'foo.png', '/foo/bar'],
            ['http://localhost/foo/bar/foo.png', 'foo.png', '/foo/bar/'],

            [
Home | Imprint | This part of the site doesn't use cookies.