Is it possible to pass in PHP variables into a custom Listener for PHPUnit if the Listener is defined in phpunit.xml? -



Is it possible to pass in PHP variables into a custom Listener for PHPUnit if the Listener is defined in phpunit.xml? -

situation

i may not using phpunit in traditional sense. i'm using phpunit selenium 2. had thought record actions selenium performing in "steps reproduce" sort of way. meaning if phone call selenium "click" or "type", action recorded. if action fails, recorded. aren't calling asserts setup-type actions. example, if we're testing page view client information, before can page need login, don't assert login actions, assert final part when have view client information.

now when assert, want record result. created custom listener capture result. problem we're having how send result our action recorder.

i ran phpunit test so:

class sandboxtest extends phpunit_framework_testcase { /* tests */ } $steptracker = new qa_steptracker(); // our custom action recorder $suite = new phpunit_framework_testsuite(); $listener = new qa_listener(); // our client listener $listener->setsteptracker($steptracker); // passing action recorder object our client listener $result = new phpunit_framework_testresult(); $suite->addtestsuite('sandboxtest'); $result->addlistener($listener); $suite->run($result);

this works expect to, though feels running way i'm losing out lot of functionality phpunit command has offer. want go using phpunit command , utilize phpunit.xml config file define custom listener.

checking phpunit documentation, noticed can pass parameters when define client listener in phpunit.xml.

<listeners> <listener class="mylistener" file="/optional/path/to/mylistener.php"> <arguments> <array> <element key="0"> <string>sebastian</string> </element> </array> <integer>22</integer> <string>april</string> <double>19.78</double> <null/> <object class="stdclass"/> </arguments> </listener> </listeners>

is equivalent to

$listener = new mylistener( array('sebastian'), 22, 'april', 19.78, null, new stdclass );

according example, looks pass in object... newly instantiated object , not pre-existing one.

also, if utilize illustration above, rid of setsteptracker() in our client listener , pass in action recorder object through client listener's __construct()

question

is @ possible pass in variable through custom listener via phpunit.xml?

we define bootstrap initialize action recorder.

if not, best course of study of action create action recorder object global in bootstrap , have custom listener access way?

since phpunit.xml processed before bootstrap.php listener created afterwards, can utilize global variables in listener's constructor.

// bootstrap.php $steptracker = new qa_steptracker(); // listener class qa_listener implements phpunit_framework_testlistener { public function __construct() { global $steptracker; $this->steptracker = $steptracker; ... } }

update: fixed take business relationship bootstrap.php executed before creating listener.

php phpunit

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -