0

I've just started with Zend framework 2. I want to set up unit testing for my Cart module.

I have followed the steps of http://framework.zend.com/manual/current/en/tutorials/unittesting.html

When I run :/var/www/AHA/CDP/module/Cart/tests$ phpunit from terminal I am getting following output:

PHPUnit 3.7.28 by Sebastian Bergmann.

Configuration read from /var/www/ZF2Sample/module/Cart/tests/phpunit.xml

E

Time: 146 ms, Memory: 5.50Mb

There was 1 error:

1) Cart\tests\Cart\Controller\CartControllerTest::testIndexActionCanBeAccessed include(/var/www/ZF2Sample/module/Admin/config/../view/error/index.phtml): failed to open stream: No such file or directory

/var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:506 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:506 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/View/View.php:205 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/View/View.php:233 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/View/View.php:198 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php:102 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:468 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:207 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php:112 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:468 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:207 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:352 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:327 /var/www/ZF2Sample/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:288 /var/www/ZF2Sample/module/Cart/tests/Cart/Controller/CartControllerTest.php:30

FAILURES! Tests: 1, Assertions: 0, Errors: 1.

Below is my global.php :

<?php
    define('SITE_URL', 'http://' . $_SERVER['SERVER_NAME'].'/');
    define('JS_URL', 'http://' . $_SERVER['SERVER_NAME'].'/js/');
    define('CSS_URL', 'http://' . $_SERVER['SERVER_NAME'].'/css/');
    define('IMG_URL', 'http://' . $_SERVER['SERVER_NAME'].'/img/');
    return array(
        'cart_webservice_url' => "http://" . $_SERVER['SERVER_NAME'] . "/ecommercewebservices",
    );
?>

I placed $_SERVER['SERVER_NAME'] = 'myproject.com'; at beginning of global.php

Then I got below output :

PHPUnit 3.7.28 by Sebastian Bergmann.

Configuration read from /var/www/AHA/CDP/module/Cart/tests/phpunit.xml

I searched a lot but could not find any answer . Please suggest.

1 Answer 1

8

You can setup different $_SERVER params with the following example in your phpunit.xml file.

<phpunit>
....
    <php>
        <server name='HTTP_HOST' value='http://localhost' />
        <server name="SERVER_NAME" value="http://foo.bar"/>
        <server name="SERVER_PORT" value="80"/>
        <server name="REMOTE_ADDR" value="127.1.2.3"/>
    </php>
....
</phpunit>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.