<p>I'm a longtime Java programmer working on a PHP project, and I'm trying to get PHPUnit up and working.  When unit testing in Java, it's common to put test case classes and regular classes into separate directories, like this -</p>

<pre><code>/src  
  MyClass.java

/test  
  MyClassTest.java
</code></pre>

<p>and so on.</p>

<p>When unit testing with PHPUnit, is it common to follow the same directory structure, or is there a better way to lay out test classes?  So far, the only way I can get the "include("MyClass.php")" statement to work correctly is to include the test class in the same directory, but I don't want to include the test classes when I push to production.</p>

[{'answer_id': 65754, 'author': 'Brian Phillips', 'author_id': 7230, 'author_profile': 'https://Stackoverflow.com/users/7230', 'pm_score': 2, 'selected': False, 'text': '<p>You need to modify PHP\'s include_path so that it knows where to find MyClass.php when you <code>include()</code> it in your unit test.</p>\n\n<p>You could have something like this at the top of your test file (preceding your include):</p>\n\n<pre>\n<code>\nset_include_path(get_include_path() . PATH_SEPARATOR . "../src");\n</code>\n</pre>\n\n<p>This appends your <code>src</code> directory onto the include path and should allow you to keep your real code separate from your test code.</p>\n'}, {'answer_id': 65814, 'author': 'Mattias', 'author_id': 261, 'author_profile': 'https://Stackoverflow.com/users/261', 'pm_score': 5, 'selected': True, 'text': "<p>I think it's a good idea to keep your files separate. I normally use a folder structure like this:</p>\n\n<pre><code>/myapp/src/        &lt;- my classes\n/myapp/tests/       &lt;- my tests for the classes\n/myapp/public/      &lt;- document root\n</code></pre>\n\n<p>In your case, for including the class in your test file, why not just pass the the whole path to the include method?</p>\n\n<pre><code>include('/path/to/myapp/src/MyClass.php');\n</code></pre>\n\n<p>or </p>\n\n<pre><code>include('../src/MyClass.php');\n</code></pre>\n"}, {'answer_id': 100911, 'author': 'Colonel Sponsz', 'author_id': 11651, 'author_profile': 'https://Stackoverflow.com/users/11651', 'pm_score': 1, 'selected': False, 'text': '<p>I put my test cases next the the source in a file with the same name but a .phpt extension.  The deployment script simply filters out *.phpt when they push to production.</p>\n'}, {'answer_id': 614392, 'author': 'willw', 'author_id': 66081, 'author_profile': 'https://Stackoverflow.com/users/66081', 'pm_score': 2, 'selected': False, 'text': '<p>Brian Phillips\'s answer does not go quite far enough, in my experience. You don\'t know what the current directory is when your tests are run by PHPUnit. So you need to reference the absolute path of the test class file in your set_include_path() expression. Like this:</p>\n\n<pre><code>set_include_path(get_include_path() . PATH_SEPARATOR . \n                        dirname(__FILE__) . "/../src");\n</code></pre>\n\n<p>This fragment can be placed in its own header file SetupIncludePath.php and included in test files with a \'require_once\', so that test suites don\'t append the path multiple times.</p>\n'}]
['https://Stackoverflow.com/questions/65651', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8770/']