Zend_Test and unexpected failures after many tests

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

Zend_Test and unexpected failures after many tests

Hector Virgen
Hello!

I have been using Zend_Test to test my MVC application and currently all of my tests pass when executed in isolation. But when I execute the whole suite, I get some strange errors. My setUp method is based on the reference guide and looks like this:

public function setUp()
{
    $this->bootstrap = new Zend_Application(
        APPLICATION_ENV,
        APPLICATION_PATH . '/configs/application.ini'
    );
    parent::setUp();
}

After about 130 tests, I get this error: 

PHP Fatal error:  Method PEAR_Autoloader::__call() must take exactly 2 arguments in /usr/local/zend/share/pear/PEAR/autoloader.php on line 211

I suspected the autoloader was somehow causing an issue, so I modified my setUp method to reset Zend_Loader_Autoloader before setting the bootstrap:

public function setUp()
{
    require_once 'Zend/Loader/Autoloader.php';
    Zend_Loader_Autoloader::resetInstance();
    $this->bootstrap = new Zend_Application(
        APPLICATION_ENV,
        APPLICATION_PATH . '/configs/application.ini'
    );
    parent::setUp();
}

This seemed to help, but after about 184 tests I got another unexpected error:

Fatal error: Zend_Config_Ini::_parseIniFile(): Failed opening required 'Zend/Config/Exception.php' (include_path='/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirge in /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php on line 0

So now it seems my include path is growing with each test, so I added another line to my setUp() method:

public function setUp()
{
    require_once 'Zend/Loader/Autoloader.php';
    Zend_Loader_Autoloader::resetInstance();
    set_include_path(TEST_INCLUDE_PATH);
    $this->bootstrap = new Zend_Application(
        APPLICATION_ENV,
        APPLICATION_PATH . '/configs/application.ini'
    );
    parent::setUp();
}

After running the suite again, the same unexpected error showed up, but now the include path looks correct:

PHP Fatal error:  Zend_Config_Ini::_parseIniFile(): Failed opening required 'Zend/Config/Exception.php' (include_path='/Users/hvirgen/Web/projects/datadirector3/library:/Users/hvirgen/Web/library/ZendFramework-1.10.2/library:/Users/hvirgen/Web/library/doctrine-2.0.0-alpha4/lib:/usr/local/zend/share/pear/PEAR:.') in /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php on line 0

What's confusing me is that:

A) My application.ini didn't change from one test to the next, so why would Zend_Config_Ini need to throw an exception?
B) The file *does* exist with that include path, so why can't PHP load it?

Is there something else I may need to reset for each test? I assumed Zend_Test and PHPUnit would reset globals automatically... am I missing something?

Thanks!

BTW I'm using ZF 1.10.2 on Zend Server CE with PHP 5.3 on Mac OS X.

--
Hector
--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test and unexpected failures after many tests

till
On Sat, Feb 27, 2010 at 1:21 AM, Hector Virgen <[hidden email]> wrote:

> Hello!
>
> I have been using Zend_Test to test my MVC application and currently all of
> my tests pass when executed in isolation. But when I execute the whole
> suite, I get some strange errors. My setUp method is based on the reference
> guide and looks like this:
> public function setUp()
> {
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> After about 130 tests, I get this error:
>>
>> PHP Fatal error:  Method PEAR_Autoloader::__call() must take exactly 2
>> arguments in /usr/local/zend/share/pear/PEAR/autoloader.php on line 211
>
> I suspected the autoloader was somehow causing an issue, so I modified my
> setUp method to reset Zend_Loader_Autoloader before setting the bootstrap:
> public function setUp()
> {
>     require_once 'Zend/Loader/Autoloader.php';
>     Zend_Loader_Autoloader::resetInstance();
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> This seemed to help, but after about 184 tests I got another unexpected
> error:
>>
>> Fatal error: Zend_Config_Ini::_parseIniFile(): Failed opening required
>> 'Zend/Config/Exception.php'
>> (include_path='/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirge
>> in
>> /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php
>> on line 0
>
> So now it seems my include path is growing with each test, so I added
> another line to my setUp() method:
> public function setUp()
> {
>     require_once 'Zend/Loader/Autoloader.php';
>     Zend_Loader_Autoloader::resetInstance();
>     set_include_path(TEST_INCLUDE_PATH);
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> After running the suite again, the same unexpected error showed up, but now
> the include path looks correct:
>>
>> PHP Fatal error:  Zend_Config_Ini::_parseIniFile(): Failed opening
>> required 'Zend/Config/Exception.php'
>> (include_path='/Users/hvirgen/Web/projects/datadirector3/library:/Users/hvirgen/Web/library/ZendFramework-1.10.2/library:/Users/hvirgen/Web/library/doctrine-2.0.0-alpha4/lib:/usr/local/zend/share/pear/PEAR:.')
>> in
>> /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php
>> on line 0
>
> What's confusing me is that:
> A) My application.ini didn't change from one test to the next, so why would
> Zend_Config_Ini need to throw an exception?

Good question, but what's more confusing is that it cannot load the
file. It looks as if you should have it. Once you manage to make that
work, you should see why the exception is thrown.

I had weird autoloader issues in my tests as well. I don't remember
what the fix was, in my case a model didn't load all of a sudden, so I
required it and moved on.

Maybe you can install xdebug to get a full stack trace, that could help.

> B) The file *does* exist with that include path, so why can't PHP load it?
> Is there something else I may need to reset for each test? I assumed
> Zend_Test and PHPUnit would reset globals automatically... am I missing
> something?

There's tearDown() :)

Till
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test and unexpected failures after many tests

Hector Virgen
Thanks for the quick response. I do have xdebug installed, but the trace pointed to Zend_Config_Ini not being able to parse the ini file:

PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:54
PHP   3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PEAR/PHPUnit/TextUI/Command.php:146
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/zend/share/pear/PEAR/PHPUnit/TextUI/Command.php:213
PHP   5. PHPUnit_Framework_TestSuite->run() /usr/local/zend/share/pear/PEAR/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:688
PHP   7. PHPUnit_Framework_TestSuite->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:688
PHP   8. PHPUnit_Framework_TestSuite->runTest() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:745
PHP   9. PHPUnit_Framework_TestCase->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:770
PHP  10. PHPUnit_Framework_TestResult->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestCase.php:652
PHP  11. PHPUnit_Framework_TestCase->runBare() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestResult.php:686
PHP  12. ControllerTestCase->setUp() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestCase.php:700
PHP  13. Zend_Application->__construct() /Users/hvirgen/Web/projects/datadirector3/tests/application/ControllerTestCase.php:47
PHP  14. Zend_Application->_loadConfig() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Application.php:85
PHP  15. Zend_Config_Ini->__construct() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Application.php:383
PHP  16. Zend_Config_Ini->_loadIniFile() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php:125
PHP  17. Zend_Config_Ini->_parseIniFile() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php:201

--
Hector


On Fri, Feb 26, 2010 at 4:28 PM, till <[hidden email]> wrote:
On Sat, Feb 27, 2010 at 1:21 AM, Hector Virgen <[hidden email]> wrote:
> Hello!
>
> I have been using Zend_Test to test my MVC application and currently all of
> my tests pass when executed in isolation. But when I execute the whole
> suite, I get some strange errors. My setUp method is based on the reference
> guide and looks like this:
> public function setUp()
> {
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> After about 130 tests, I get this error:
>>
>> PHP Fatal error:  Method PEAR_Autoloader::__call() must take exactly 2
>> arguments in /usr/local/zend/share/pear/PEAR/autoloader.php on line 211
>
> I suspected the autoloader was somehow causing an issue, so I modified my
> setUp method to reset Zend_Loader_Autoloader before setting the bootstrap:
> public function setUp()
> {
>     require_once 'Zend/Loader/Autoloader.php';
>     Zend_Loader_Autoloader::resetInstance();
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> This seemed to help, but after about 184 tests I got another unexpected
> error:
>>
>> Fatal error: Zend_Config_Ini::_parseIniFile(): Failed opening required
>> 'Zend/Config/Exception.php'
>> (include_path='/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirge
>> in
>> /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php
>> on line 0
>
> So now it seems my include path is growing with each test, so I added
> another line to my setUp() method:
> public function setUp()
> {
>     require_once 'Zend/Loader/Autoloader.php';
>     Zend_Loader_Autoloader::resetInstance();
>     set_include_path(TEST_INCLUDE_PATH);
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> After running the suite again, the same unexpected error showed up, but now
> the include path looks correct:
>>
>> PHP Fatal error:  Zend_Config_Ini::_parseIniFile(): Failed opening
>> required 'Zend/Config/Exception.php'
>> (include_path='/Users/hvirgen/Web/projects/datadirector3/library:/Users/hvirgen/Web/library/ZendFramework-1.10.2/library:/Users/hvirgen/Web/library/doctrine-2.0.0-alpha4/lib:/usr/local/zend/share/pear/PEAR:.')
>> in
>> /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php
>> on line 0
>
> What's confusing me is that:
> A) My application.ini didn't change from one test to the next, so why would
> Zend_Config_Ini need to throw an exception?

Good question, but what's more confusing is that it cannot load the
file. It looks as if you should have it. Once you manage to make that
work, you should see why the exception is thrown.

I had weird autoloader issues in my tests as well. I don't remember
what the fix was, in my case a model didn't load all of a sudden, so I
required it and moved on.

Maybe you can install xdebug to get a full stack trace, that could help.

> B) The file *does* exist with that include path, so why can't PHP load it?
> Is there something else I may need to reset for each test? I assumed
> Zend_Test and PHPUnit would reset globals automatically... am I missing
> something?

There's tearDown() :)

Till

--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test and unexpected failures after many tests

Hector Virgen
I built a test to make sure that it's not an error from one of my tests:

<?php

class ApplicationTest extends ControllerTestCase
{
  /**
   * @dataProvider runs
   */
  public function testMultipleRuns()
  {
     // do nothing
  }

  public function runs()
  {
     $runs = array();
     for ($i = 0; $i < 500; $i++) {
        $runs[] = array();
     }
     return $runs;
  }
}

When running this test alone, I got the same error:

$ phpunit application/ApplicationTest.php 
PHPUnit 3.4.10 by Sebastian Bergmann.

............................................................  60 / 500
............................................................ 120 / 500
............................................................ 180 / 500
............................................................ 240 / 500
............PHP Fatal error:  Zend_Config_Ini::_parseIniFile(): Failed opening required 'Zend/Config/Exception.php'

--
Hector


On Fri, Feb 26, 2010 at 4:35 PM, Hector Virgen <[hidden email]> wrote:
Thanks for the quick response. I do have xdebug installed, but the trace pointed to Zend_Config_Ini not being able to parse the ini file:

PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:54
PHP   3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PEAR/PHPUnit/TextUI/Command.php:146
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/zend/share/pear/PEAR/PHPUnit/TextUI/Command.php:213
PHP   5. PHPUnit_Framework_TestSuite->run() /usr/local/zend/share/pear/PEAR/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:688
PHP   7. PHPUnit_Framework_TestSuite->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:688
PHP   8. PHPUnit_Framework_TestSuite->runTest() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:745
PHP   9. PHPUnit_Framework_TestCase->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestSuite.php:770
PHP  10. PHPUnit_Framework_TestResult->run() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestCase.php:652
PHP  11. PHPUnit_Framework_TestCase->runBare() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestResult.php:686
PHP  12. ControllerTestCase->setUp() /usr/local/zend/share/pear/PEAR/PHPUnit/Framework/TestCase.php:700
PHP  13. Zend_Application->__construct() /Users/hvirgen/Web/projects/datadirector3/tests/application/ControllerTestCase.php:47
PHP  14. Zend_Application->_loadConfig() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Application.php:85
PHP  15. Zend_Config_Ini->__construct() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Application.php:383
PHP  16. Zend_Config_Ini->_loadIniFile() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php:125
PHP  17. Zend_Config_Ini->_parseIniFile() /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php:201

--
Hector



On Fri, Feb 26, 2010 at 4:28 PM, till <[hidden email]> wrote:
On Sat, Feb 27, 2010 at 1:21 AM, Hector Virgen <[hidden email]> wrote:
> Hello!
>
> I have been using Zend_Test to test my MVC application and currently all of
> my tests pass when executed in isolation. But when I execute the whole
> suite, I get some strange errors. My setUp method is based on the reference
> guide and looks like this:
> public function setUp()
> {
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> After about 130 tests, I get this error:
>>
>> PHP Fatal error:  Method PEAR_Autoloader::__call() must take exactly 2
>> arguments in /usr/local/zend/share/pear/PEAR/autoloader.php on line 211
>
> I suspected the autoloader was somehow causing an issue, so I modified my
> setUp method to reset Zend_Loader_Autoloader before setting the bootstrap:
> public function setUp()
> {
>     require_once 'Zend/Loader/Autoloader.php';
>     Zend_Loader_Autoloader::resetInstance();
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> This seemed to help, but after about 184 tests I got another unexpected
> error:
>>
>> Fatal error: Zend_Config_Ini::_parseIniFile(): Failed opening required
>> 'Zend/Config/Exception.php'
>> (include_path='/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirgen/Web/projects/datadirector3/application/../library:/Users/hvirge
>> in
>> /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php
>> on line 0
>
> So now it seems my include path is growing with each test, so I added
> another line to my setUp() method:
> public function setUp()
> {
>     require_once 'Zend/Loader/Autoloader.php';
>     Zend_Loader_Autoloader::resetInstance();
>     set_include_path(TEST_INCLUDE_PATH);
>     $this->bootstrap = new Zend_Application(
>         APPLICATION_ENV,
>         APPLICATION_PATH . '/configs/application.ini'
>     );
>     parent::setUp();
> }
> After running the suite again, the same unexpected error showed up, but now
> the include path looks correct:
>>
>> PHP Fatal error:  Zend_Config_Ini::_parseIniFile(): Failed opening
>> required 'Zend/Config/Exception.php'
>> (include_path='/Users/hvirgen/Web/projects/datadirector3/library:/Users/hvirgen/Web/library/ZendFramework-1.10.2/library:/Users/hvirgen/Web/library/doctrine-2.0.0-alpha4/lib:/usr/local/zend/share/pear/PEAR:.')
>> in
>> /Users/hvirgen/Web/library/ZendFramework-1.10.2/library/Zend/Config/Ini.php
>> on line 0
>
> What's confusing me is that:
> A) My application.ini didn't change from one test to the next, so why would
> Zend_Config_Ini need to throw an exception?

Good question, but what's more confusing is that it cannot load the
file. It looks as if you should have it. Once you manage to make that
work, you should see why the exception is thrown.

I had weird autoloader issues in my tests as well. I don't remember
what the fix was, in my case a model didn't load all of a sudden, so I
required it and moved on.

Maybe you can install xdebug to get a full stack trace, that could help.

> B) The file *does* exist with that include path, so why can't PHP load it?
> Is there something else I may need to reset for each test? I assumed
> Zend_Test and PHPUnit would reset globals automatically... am I missing
> something?

There's tearDown() :)

Till


--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test and unexpected failures after many tests

Andreas Baumgart
Hi Hector

We discovered the same issue on a project running ZF 1.11.11.
As it turned out, Zend_Log opened to many file handles and finally reached the OS limit.

We solved the problem by using Zend_Log_Writer_Mock for our test cases. Perhaps there is a better solution like closing log files in the destructor or so - but I guess this would require patching the ZF.

When using MVC bootstrap with application.init this would be something like:
[testing : production]
resources.log.stream.writerName = "Mock"

Cheers!
Andreas