title: Organizing PHPUnit Tests in Namespaces
body: <p>I see two options for organizing PHPUnit unit tests into a namespace hierarchy. What are the advantages/disadvantages to these two approaches? Are there any obvious flaws I haven't considered that would make one the obvious better choice?</p>
  
  <p>Consider a sample class like <code>\SomeFramework\Utilities\AwesomeClass</code>:</p>
  
  <ul>
  <li><p><strong>Approach 1:</strong> Place each TestCase class into the same namespace as the covered class.</p>
  
  <pre><code>\SomeFramework\Utilities\AwesomeClassTest
  </code></pre>
  
  <ul>
  <li><strong>Advantages</strong>
  <ul>
  <li>Consistent with the traditional approach to writing PHPUnit tests.</li>
  </ul></li>
  <li><strong>Disadvantages</strong>
  <ul>
  <li>Less flexibility.</li>
  <li>Seems to break the principle behind using namespaces - unrelated tests are grouped into the same namespace.
  <br />
  <br /></li>
  </ul></li>
  </ul></li>
  <li><p><strong>Approach 2:</strong> Place each TestCase in a namespace named after the covered class.</p>
  
  <pre><code>\SomeFramework\Utilities\AwesomeClass\Test
  </code></pre>
  
  <ul>
  <li><strong>Advantages</strong>
  <ul>
  <li>Provides a very easy/obvious way to group multiple related TestCase classes together, say for different test suites.</li>
  </ul></li>
  <li><strong>Disadvantages</strong>
  <ul>
  <li>Could result in a deeper, more complex hierarchy.</li>
  </ul></li>
  </ul></li>
  </ul>