0

I'm new to unit tests, i have been working on this tutorial i found on internet :

http://blog.fedecarg.com/2008/12/27/testing-zend-framework-controllers/

My problem is i simply can't execute the tests displayed in the tutorial!

C

:\wamp\www\portailmg\dev\tests>phpunit PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from C:\wamp\www\portailmg\dev\tests\phpunit.xml

Time: 0 seconds, Memory: 4.00Mb

No tests executed!

Generating code coverage report in HTML format ... done

C:\wamp\www\portailmg\dev\tests>

My bootstrap.php which is the only file i edited because i had the following error :

Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /www/zf-tutorial/library/Zend/Loader.php

I tried to fix this with that :

This is because you have the lines:

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

(or similar) somewhere in your bootstrap system.

The easiest solution is to change them to:

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('App_');

Where 'App_' is the name of a directory on your include path that has classes within it that follow the Zend Framework naming convention, so change it as appropriate and add more if you need them.

My bootstrap:

<?php 
error_reporting( E_ALL | E_STRICT );
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../applications'));
define('APPLICATION_ENV', 'loc');
define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/../library'));
define('TESTS_PATH', realpath(dirname(__FILE__)));

$_SERVER['SERVER_NAME'] = 'http://localhost';

$includePaths = array(LIBRARY_PATH, get_include_path());
set_include_path(implode(PATH_SEPARATOR, $includePaths));

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('LIBRARY_PATH');

Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
?>

Thanks in advance for your help

1 Answer 1

2

Your setup looks okay, although if I remember correctly zend framework 1 will only work with >=3.5.x so maybe downgrading from 3.7 to 3.5 may do the trick. Do ensure your phpunit.xml file is setup properly and pointing to the tests bootstrap and not your application bootstrap. Also be sure to be following the unit testing name conventions. See http://phpunit.de/manual/3.5/en/index.html

Sign up to request clarification or add additional context in comments.

2 Comments

that's correct, the version has to be 3.5.x, see here also link
framework.zend.com/blog/… ZF 1.12.4 and upwards support/work with phpunit 3.7

Your Answer

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