php - phpunit testing expectedException not working -


i trying test class invalidargumentexception

tests\bartest::should_receive_parameter missing argument 1 itdc\foo\bar::__construct(), called in /mypath/foo/tests/bartest.php on line 10 , defined

this test (bartest.php) file use:

<?php namespace tests; use itdc\foo\bar; class bartest extends \phpunit_framework_testcase {     /** @test */     public function should_receive_parameter() {         $this->setexpectedexception('exception');         $id = new bar;     } } 

this bar class:

<?php namespace itdc\foo; class bar {     public function __construct($a) {         //     } } 

i have tried puth setexpectedexception in comment section, tried use invalidargumentexception, no luck.

any suggetions doing wrong appreciated.

if catch directly can var_dump() exception.

/** @test */ public function shouldthrowexception() {   try {     new foo();   } catch (\exception $e) {     var_dump($e);   } } 

output:

class phpunit_framework_error_warning#19 (9) {   ... 

so here source not trigger exception error, phpunit converts error specific exception. not include in assertions.

try using specific exception name:

/** @test */ public function shouldthrowexception() {   $this->setexpectedexception('phpunit_framework_error_warning');   new foo(); } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -