[zf2 beta5] Solving dependencies in unit tests for View Helpers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[zf2 beta5] Solving dependencies in unit tests for View Helpers

Jonathan Maron
Hello all

In the setUp() method of the unit tests for View Helpers, which have a
dependency on another View Helper, I could use
HelperLoader::addStaticMap to inject the dependency into the component
under test, in zf2 prior to beta5, like this:

protected function setUp()
{
    HelperLoader::addStaticMap(array(
        'mailto' => 'My\View\Helper\Mailto',
    ));

    $this->view = new PhpRenderer();

    $this->helper = new Imprint();
    $this->helper->setView($this->view);
}

The View Helper "Imprint" returns HTML, which includes the HTML of (an
obfuscated) e-mail address. The View Helper "mailto" offers the
functionality to return the formatted e-mail address.

What is the best approach to do this in ZF2 beta5?

TIA

Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: [zf2 beta5] Solving dependencies in unit tests for View Helpers

HHGAG
Hi again,

this one should solve your problem:
http://zend-framework-community.634137.n4.nabble.com/Alias-for-translate-Helper-td4655640.html#a4655647

Hasan H. Gürsoy (HHGAG)

Jonathan Maron <[hidden email]> schrieb:

>Hello all
>
>In the setUp() method of the unit tests for View Helpers, which have a
>dependency on another View Helper, I could use
>HelperLoader::addStaticMap to inject the dependency into the component
>under test, in zf2 prior to beta5, like this:
>
>protected function setUp()
>{
>    HelperLoader::addStaticMap(array(
>        'mailto' => 'My\View\Helper\Mailto',
>    ));
>
>    $this->view = new PhpRenderer();
>
>    $this->helper = new Imprint();
>    $this->helper->setView($this->view);
>}
>
>The View Helper "Imprint" returns HTML, which includes the HTML of (an
>obfuscated) e-mail address. The View Helper "mailto" offers the
>functionality to return the formatted e-mail address.
>
>What is the best approach to do this in ZF2 beta5?
>
>TIA
>
>Jonathan
Hasan H. Gürsoy (HHGAG)
Reply | Threaded
Open this post in threaded view
|

Re: [zf2 beta5] Solving dependencies in unit tests for View Helpers

Jurian Sluiman
In reply to this post by Jonathan Maron
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: [zf2 beta5] Solving dependencies in unit tests for View Helpers

Jonathan Maron
Hello Jurian

Thank you very much for your suggestion.

> Like you, I also instantiate a view helper, then inject the PhpRenderer with
> $helper->setView($view); You can also register another view helper by the
> PhpRenderer's plugin manager:
>
> use Foo\View\Helper as FooHelper;
> use Zend\View\Renderer\PhpRenderer;
>
> $helper = new FooHelper();
> $view = new PhpRenderer();
> $manager = $view->getHelperPluginManager();
> $manager->setService('myCustomHelper', $helper);

This has solved the issue I was experiencing.

Jonathan