code_junkie

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

Nov 10th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. class User
  2. {
  3. public function commonFunctionality()
  4. {
  5. return 'Something';
  6. }
  7.  
  8. public function modifiedFunctionality()
  9. {
  10. return 'One Thing';
  11. }
  12. }
  13.  
  14. class SpecialUser extends User
  15. {
  16. public function specialFunctionality()
  17. {
  18. return 'Nothing';
  19. }
  20.  
  21. public function modifiedFunctionality()
  22. {
  23. return 'Another Thing';
  24. }
  25. }
  26.  
  27. class Test_User extends PHPUnit_Framework_TestCase
  28. {
  29. public function create()
  30. {
  31. return new User();
  32. }
  33.  
  34. public function testCommonFunctionality()
  35. {
  36. $user = $this->create();
  37. $this->assertEquals('Something', $user->commonFunctionality);
  38. }
  39.  
  40. public function testModifiedFunctionality()
  41. {
  42. $user = $this->create();
  43. $this->assertEquals('One Thing', $user->commonFunctionality);
  44. }
  45. }
  46.  
  47. class Test_SpecialUser extends Test_User
  48. {
  49. public function create() {
  50. return new SpecialUser();
  51. }
  52.  
  53. public function testSpecialFunctionality()
  54. {
  55. $user = $this->create();
  56. $this->assertEquals('Nothing', $user->commonFunctionality);
  57. }
  58.  
  59. public function testModifiedFunctionality()
  60. {
  61. $user = $this->create();
  62. $this->assertEquals('Another Thing', $user->commonFunctionality);
  63. }
  64. }
Add Comment
Please, Sign In to add comment