title: Laravel 5.1: confused by the way namespaces and facades work within PHPUnit Test classes extending TestCase
body: <p>I'm creating base test class from which other test classes can extend from and be ran with PHPUnit. This base test class extends Laravel's provided <code>TestCase</code> class. Also, I'm using the <a href="https://github.com/fzaninotto/Faker" rel="nofollow">PHP Faker library</a> to create a faker generator and as, well, I'm calling on Laravel's Artisan facade to run a database migration in the <code>setUp</code> method. . Here's what it looked like initially:</p>
  
  <pre><code>&lt;?php
  // BaseTester.php
  
  use Artisan;
  use Faker\Factory as Faker;
  
  class BaseTester extends TestCase {
  
    protected $fake;
  
    function __construct() {
      $this-&gt;fake = Faker::create();
    }
  
    public function setUp()
    {
      parent::setUp();
  
      Artisan::call('migrate', [
        '--seed' =&gt; true,
      ]);
    }
  }
  </code></pre>
  
  <p>When I ran PHPUnit the first time, it succeeded but also gave this warning:</p>
  
  <p><code>PHP Warning:  The use statement with non-compound name 'Artisan' has no effect in /Users/myusername/Sites/app/tests/BaseTester.php on line 3</code></p>
  
  <p>Ok so then I wondered why it would give me that. So I tried removing:</p>
  
  <p><code>use Artisan;</code></p>
  
  <p>from the <code>BaseTester.php</code> class and it worked, all tests passed, and also no warning in the output.</p>
  
  <p>Now, I wondered why I had to remove that <code>use</code> statement. Then I remembered that on my <code>config/app.php</code> file that there's an alias available for the <code>Artisan</code> facade. </p>
  
  <pre><code>...
  
  'aliases' =&gt; [
  
          'App'       =&gt; Illuminate\Support\Facades\App::class,
          'Artisan'   =&gt; Illuminate\Support\Facades\Artisan::class,
          'Auth'      =&gt; Illuminate\Support\Facades\Auth::class,
  ...
  </code></pre>
  
  <p>So then it must get loaded automatically. Which means, if there's also an Alias for the Faker facade within the <code>config/app.php</code> file </p>
  
  <pre><code>...
  /*
   * Third party libraries / packages aliases
   */
  'Faker'     =&gt; Faker\Factory::class,
  ...
  </code></pre>
  
  <p>then it also must get loaded so I don't have to include:</p>
  
  <p><code>use Faker\Factory as Faker;</code></p>
  
  <p>in my <code>BaseTester.php</code> file and I can just call the <code>Faker::create</code> method within it. </p>
  
  <p>so I removed that <code>use</code> statement as well and ran PHPUnit but then I got this error:</p>
  
  <p><code>PHP Fatal error:  Class 'Faker' not found in /Users/myusername/Sites/app/tests/BaseTester.php on line 12</code></p>
  
  <p>So now I'm really confused because the call to <code>Artisan</code> which is included in the <code>config/app.php</code> file under the aliases section works but not the call to <code>Faker</code> which is also included in that same file under the same aliases section. </p>
  
  <p>In the end, my code looks like this, </p>
  
  <pre><code>&lt;?php
  // BaseTester.php
  
  use Faker\Factory as Faker;
  
  class BaseTester extends TestCase {
  
    protected $fake;
  
    function __construct() {
      $this-&gt;fake = Faker::create();
    }
  
    public function setUp()
    {
      parent::setUp();
  
      Artisan::call('migrate', [
        '--seed' =&gt; true,
      ]);
    }
  }
  </code></pre>
  
  <p>and it works without warnings, but I don't understand what's going in terms of aliases and namespaces and facades and I feel that until I get a handle on this then I don't truly understand how Laravel does its thing. </p>
  
  <p>I just end up trying to find the right combination of <code>use</code> statements with Laravel facades within other code files until I get no errors. </p>