Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework]Zend + PHPUnit - testy jednostkowe
sweter
post
Post #1





Grupa: Zarejestrowani
Postów: 623
Pomógł: 11
Dołączył: 1.01.2009
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Witam,
chciałem napisać testy jednostkowe do swojej nowej aplikacji pisanej w ZF. Przeczytałem już kilka tutoriali w Sieci na ten temat, ale nie mogę sobie poradzić z jednym problemem.
Mianowicie: nie mogę wykorzystać swoich klas, które są przechowywane w ./application/model. Testy przechowuje oczywiście w katalogu ./tests/application/constrollers.

Test, który chcę odpalić wygląda tak:
Kod
require_once 'PHPUnit/Framework/TestCase.php';

class TestControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
    private $model = null;
    
    public function setUp(){
        $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
        $this->bootstrap = array($application->getBootstrap(), 'bootstrap');
        $this->model = new Application_Model_TagList(100);
        return parent::setUp();
    }
    
    public function testFirst(){
        $this->model->addItem(new Application_Model_Tag('pierwszy_tag'));
        $this->assertEquals(count($this->model->getArray()), 1);
    }

    public function tearDown()
    {
        /* Tear Down Routine */
    }
}


plik ./tests/application/boostrap.php ma taką zawartość:
Kod
set_include_path(implode(PATH_SEPARATOR, array(
            realpath(dirname(__FILE__) . '/../../library'),
            get_include_path(),
        )));

defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing');
defined('APPLICATION_LOAD_TESTDATA') || define('APPLICATION_LOAD_TESTDATA', true);

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
spl_autoload_unregister(array($autoloader, 'autoload'));

Zend_Loader_Autoloader::resetInstance();
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('PHPUnit_');


a ./tests/phpunit.xml taką:
  1. <phpunit bootstrap="./application/bootstrap.php"
  2. colors="true"
  3. convertErrorsToExceptions="true"
  4. convertNoticesToExceptions="true"
  5. convertWarningsToExceptions="true"
  6. stopOnFailure="false">
  7.  
  8. <testsuite name="Test_ZF">
  9. <directory>./application/</directory>
  10. </testsuite>
  11. </phpunit>


Test odpalam poleceniem "phpunit" będąc w katalogu ./tests. W odpowiedzi konsola zwraca mi komunikat:
Cytat
szymon@szymon-Vostro-1440:/var/www/tt/tests$ phpunit
PHPUnit 3.6.10 by Sebastian Bergmann.

Configuration read from /var/www/tt/tests/phpunit.xml

.E

Time: 1 second, Memory: 8.25Mb

There was 1 error:

1) TestControllerTest::testFirst
Zend_Db_Table_Exception: No adapter found for Application_Model_DbTable_MomentToTag

/var/www/tt/library/Zend/Db/Table/Abstract.php:755
/var/www/tt/library/Zend/Db/Table/Abstract.php:739
/var/www/tt/library/Zend/Db/Table/Abstract.php:268
/var/www/tt/application/models/TagList.php:15
/var/www/tt/tests/application/controllers/TestControllerTest.php:16

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


Co mam zrobić, aby móc bezproblemowo używać testów jednostkowych wykorzystujących bibliotekę Zenda i moje klasy?
Proszę o pomoc, bo już nie mam do tego cierpliwości. Z góry dzięki smile.gif

Pozdrawiam

Ten post edytował sweter 14.04.2012, 18:49:54


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 07:38