<p>I'm starting to learn how to use PHPUnit to test the website I'm working on.  The problem I'm running into is that I have five different user types defined and I need to be able to test every class with the different types.  I currently have a user class and I would like to pass this to each function but I can't figure out how to pass this or test the different errors that could come back as being correct or not.</p>

<p><b>Edit:</b> I should have said.  I have a user class and I want to pass a different instance of this class to each unit test. </p>

[{'answer_id': 58982, 'author': 'Peter Bernier', 'author_id': 6112, 'author_profile': 'https://Stackoverflow.com/users/6112', 'pm_score': 1, 'selected': False, 'text': "<p>If you're looking to test the actual UI, you could try using something like Selenium (www.openqa.org). It lets you write the code in PHP (which I'm assuming would work with phpUnit) to drive the browser..</p>\n\n<p>Another approach would be to have a common method that could be called by each test for your different user type. ie, something like 'ValidatePage', which you could then call from TestAdminUser or TestRegularUser and have the method simply perform the same basic validation of what you're expecting..</p>\n"}, {'answer_id': 63442, 'author': 'Andrew Culver', 'author_id': 7549, 'author_profile': 'https://Stackoverflow.com/users/7549', 'pm_score': 3, 'selected': True, 'text': "<p>If your various user classes inherit from a parent user class, then I recommend you use the same inheritance structure for your test case classes.</p>\n\n<p>Consider the following sample classes:</p>\n\n<pre><code>class User\n{\n    public function commonFunctionality()\n    {\n        return 'Something';\n    }\n\n    public function modifiedFunctionality()\n    {\n        return 'One Thing';\n    }\n}\n\nclass SpecialUser extends User\n{\n    public function specialFunctionality()\n    {\n        return 'Nothing';\n    }\n\n    public function modifiedFunctionality()\n    {\n        return 'Another Thing';\n    }\n}\n</code></pre>\n\n<p>You could do the following with your test case classes:</p>\n\n<pre><code>class Test_User extends PHPUnit_Framework_TestCase\n{\n    public function create()\n    {\n        return new User();\n    }\n\n    public function testCommonFunctionality()\n    {\n        $user = $this-&gt;create();\n        $this-&gt;assertEquals('Something', $user-&gt;commonFunctionality);\n    }\n\n    public function testModifiedFunctionality()\n    {\n        $user = $this-&gt;create();\n        $this-&gt;assertEquals('One Thing', $user-&gt;commonFunctionality);\n    }\n}\n\nclass Test_SpecialUser extends Test_User\n{\n    public function create() {\n        return new SpecialUser();\n    }\n\n    public function testSpecialFunctionality()\n    {\n        $user = $this-&gt;create();\n        $this-&gt;assertEquals('Nothing', $user-&gt;commonFunctionality);\n    }\n\n    public function testModifiedFunctionality()\n    {\n        $user = $this-&gt;create();\n        $this-&gt;assertEquals('Another Thing', $user-&gt;commonFunctionality);\n    }\n}\n</code></pre>\n\n<p>Because each test depends on a create method which you can override, and because the test methods are inherited from the parent test class, all tests for the parent class will be run against the child class, unless you override them to change the expected behavior.</p>\n\n<p>This has worked great in my limited experience.</p>\n"}, {'answer_id': 82752, 'author': 'Paweł Hajdan', 'author_id': 9403, 'author_profile': 'https://Stackoverflow.com/users/9403', 'pm_score': 1, 'selected': False, 'text': "<p>Just make sure you're not running into an <strong>anti-pattern</strong> here. Maybe you do too much work in the constructor? Or maybe these should be in fact different classes? Tests often give you clues about <strong>design of code.</strong> Listen to them.</p>\n"}]
['https://Stackoverflow.com/questions/58969', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4437/']