Jump to content

Unit testing a ZF application.


trq

Recommended Posts

Having a hell of a time getting this configured for a new application I'm about to undergo. Presently I only have a simple directory structure in place...

 

[pre]

thorpe@oblivion ~/www/devbox/libs/proem $ tree -I nbproject

.

|-- applications

|  |-- client

|  |  |-- controllers

|  |  |  `-- IndexController.php

|  |  `-- views

|  |      `-- scripts

|  |          `-- index

|  |              `-- index.phtml

|  `-- proem

|      |-- controllers

|      |  `-- IndexController.php

|      `-- views

|          `-- scripts

|              `-- index

|                  `-- index.phtml

|-- assets

|-- bootstrap

|  |-- init.php

|  |-- tests-env.php

|  `-- www-env.php

|-- config

|  |-- httpd.conf

|  `-- master.xml

|-- library

|  `-- Proem

|      `-- Bootstrap

|          `-- Resource

|              `-- Front.php

|-- tests

|  |-- applications

|  |  `-- proem

|  |      `-- controllers

|  |          `-- IndexControllerTest.php

|  |-- library

|  |  `-- Proem

|  `-- phpunit.xml

`-- var

    `-- apache

        `-- vhost.conf

 

26 directories, 13 files

[/pre]

 

/www/devbox/libs/proem/tests/phpunit.xml

 
<phpunit bootstrap="../bootstrap/tests-env.php" colors="true">
    <testsuite name="Proem Test Suite">
        <directory>./</directory>
    </testsuite>
    <filter>
        <whitelist>
            <directory suffix=".php">../library</directory>
            <directory suffix=".php">../applications</directory>
            <exclude>
            	<directory suffix=".phtml">../applications</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

 

/www/devbox/libs/proem/bootstrap/tests-env.php

 
<?php
define('PROEM_ROOT', getenv('PROEM_ROOT'));
define('PROEM_CONTEXT', getenv('PROEM_CONTEXT'));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
    public function setUp()
    {
        require 'init.php';
        $this->bootstrap = array($proem, 'bootstrap');
        parent::setUp();
    }
}

 

/www/devbox/libs/proem/bootstrap/init.php

 
<?php
$proem = new Zend_Application(
    PROEM_CONTEXT,
    array(
        'autoloaderNamespaces' => array('Proem_'),
        'pluginPaths' => array(
            'Proem_Bootstrap_Resource' => 'Proem/Bootstrap/Resource'
        ),
        'resources'     => array(
            'Front'     => array()
        )
    )
);

 

/www/devbox/libs/proem/tests/applications/proem/controllers/IndexControllerTest.php

 
<?php
class IndexControllerTest extends ControllerTestCase
{
    public function setUp()
    {
        define("PROEM_IS_CLIENT_ADMIN", 1);
        parent::setUp();
    }

    public function testIndexAction()
    {
        $this->assertTrue(true);
    }
}

 

Output....

 

thorpe@oblivion ~/www/devbox/libs/proem/tests $ phpunit
PHPUnit 3.4.5 by Sebastian Bergmann.

E

Time: 0 seconds, Memory: 10.50Mb

There was 1 error:

1) IndexControllerTest::testIndexAction
Zend_Application_Bootstrap_Exception: Resource matching "Front" not found

/usr/share/Zend-1.9.6/library/Zend/Application/Bootstrap/BootstrapAbstract.php:687
/usr/share/Zend-1.9.6/library/Zend/Application/Bootstrap/BootstrapAbstract.php:619
/usr/share/Zend-1.9.6/library/Zend/Application/Bootstrap/BootstrapAbstract.php:579
/usr/share/Zend-1.9.6/library/Zend/Application.php:347
/usr/share/Zend-1.9.6/library/Zend/Test/PHPUnit/ControllerTestCase.php:148
/usr/share/Zend-1.9.6/library/Zend/Test/PHPUnit/ControllerTestCase.php:126
/home/thorpe/www/devbox/libs/proem/bootstrap/tests-env.php:20
/home/thorpe/www/devbox/libs/proem/tests/applications/proem/controllers/IndexControllerTest.php:7

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

 

I can't for the life of me figure out why it can't find my Front resource. All my constants are properly defined and /home/thorpe/www/devbox/libs/proem/library is on my include_path.

 

The controllers work when called via a browser. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/185847-unit-testing-a-zf-application/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.