symfony 2.1 phpunit Swift_Message class not found -


i've issue symfony , phpunit. our peoject growing bigger , bigger. decided activate process isolation phpunit because server couldn't stand amount of tests anymore (not enough ram). since test send mails aren't working anymore. please us? test below works fine if processisolation="false" fails if processisolation="true"

versions:

  • symfony 2.1.8-dev

  • phpunit 3.7.9

error message

project\appbundle\tests\mailtest::testsendmail phpunit_framework_exception: php fatal error: class 'swift_message' not found in /var/www/project/src/project/appbundle/tests/mailtest.php

test

public function testsendmail() {     $client = static::createclient();      $message = \swift_message::newinstance();     $message->setfrom('example@example.com')         ->setto('example@example.com')         ->setsubject('subject')         ->setbody('hello world')         ->setcontenttype('text/html');      $client->getcontainer()->get('mailer')->send($message);     $this->asserttrue(true); } 

phpunit.xml

<phpunit     backupglobals="false"     backupstaticattributes="false"     colors="true"     converterrorstoexceptions="true"     convertnoticestoexceptions="true"     convertwarningstoexceptions="true"     bootstrap="./autoload.php"     processisolation="true"     stoponfailure="false"     syntaxcheck="false" >      <testsuites>         <testsuite name="project test suite">             <directory>../src/project/appbundle/tests/mailtest.php</directory>         </testsuite> </testsuites> </phpunit> 

this error caused because switfmailer defines constant swift_required_loaded after installs it's autoloader. autoloader checks constant, , if it's defined, refuses install autoloader. in process isolation, phpunit ensures defined constants re-defined in processs gets spawned run test. unfortunately, means swift_required_loaded defined in test process, autoloader doesn't load (see "swift_required.php" in swiftmailer source directory). note if turn off include global state test via annotations tests still won't work, because bootstrap file passed test process via __phpunit_bootstrap global variable (see testcasemethod.tpl in phpunit directory). without globals, global undefined in test process , bootstrap file not included breaking tests.

the work around found works replace line $constants = phpunit_util_globalstate::getconstantsasstring(); $constants = ''; in run method of testcase.php in phpunit source distribution. if code relies on global constants defined before test cases run fix won't work (class constants different story); unless said constants redefined safely in course of running test cases.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -