php - PHPUnit Test result type or also the result variables -


during unit testing i'm confused test. need test api , api or method result values.

class someeventhandler     {         public function ondispatch (event $event)         {             if ($event->hasfoo)             {                 $model = $this->createresponsemodel('foo');             }             else             {                 $model = $this->createresponsemodel('bar');             }              // end.             return $model;         }          private function createresponsemodel ($foo)         {             $vars = array(                 'somevare' => true,                 'foo'      => $foo             );              // end.             return new responsemodel($vars);         }     } 

so should test if method ondispatch returns instance of responsemodel or should test if variable foo set properly?

or test below fine?

    class someeventhandlertest     {         // assume instance of someeventhandler created         private $someeventhandler;          public function testondispatch_eventhasfoo_returnsresponsemodel ()         {             $e         = new event();             $e->hasfoo = true;              $result = $someeventhandler->ondispatch($e);              $this->assertinstanceof('responsemodel', $result);         }          public function testondispatch_eventhasnofoo_returnsresponsemodel ()         {             $e         = new event();             $e->hasfoo = false;              $result = $someeventhandler->ondispatch($e);              $this->assertinstanceof('responsemodel', $result);         }     } 

if checking code hand check? responsemodel returned or had proper values?

if weren't writing tests , executed code ensure code doing supposed to. check values in returned object correct. using public api of object , verify values right.

one idea have tests such if code deleted, able recreate functionality via having tests. checking returned object result in function has return new responsemodel();. pass test not want.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -