Best Way to Unit Test a Website With Multiple User Types with PHPUnit -


i'm starting learn how use phpunit test website i'm working on. problem i'm running have 5 different user types defined , need able test every class different types. have user class , pass each function can't figure out how pass or test different errors come being correct or not.

edit: should have said. have user class , want pass different instance of class each unit test.

if various user classes inherit parent user class, recommend use same inheritance structure test case classes.

consider following sample classes:

class user {     public function commonfunctionality()     {         return 'something';     }      public function modifiedfunctionality()     {         return 'one thing';     } }  class specialuser extends user {     public function specialfunctionality()     {         return 'nothing';     }      public function modifiedfunctionality()     {         return 'another thing';     } } 

you following test case classes:

class test_user extends phpunit_framework_testcase {     public function create()     {         return new user();     }      public function testcommonfunctionality()     {         $user = $this->create();         $this->assertequals('something', $user->commonfunctionality);     }      public function testmodifiedfunctionality()     {         $user = $this->create();         $this->assertequals('one thing', $user->commonfunctionality);     } }  class test_specialuser extends test_user {     public function create() {         return new specialuser();     }      public function testspecialfunctionality()     {         $user = $this->create();         $this->assertequals('nothing', $user->commonfunctionality);     }      public function testmodifiedfunctionality()     {         $user = $this->create();         $this->assertequals('another thing', $user->commonfunctionality);     } } 

because each test depends on create method can override, , because test methods inherited parent test class, tests parent class run against child class, unless override them change expected behavior.

this has worked great in limited experience.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -