title: PHPUnit Mocking class constant
body: <p>I am testing a class that has a dependency injected. In my infinite cleverness, I scattered references to the dependency's class constant throughout my code.</p>
  
  <p>(Sorry for the stupid example, wanted to deviate from foobar.)</p>
  
  <pre><code>&lt;?php
  
  class Book_PhoneBook extends Book {
  
      private $author;
  
      public function __construct(Author $author) {
          $this-&gt;author = $author;
      }
  
      public function getCover() {
          return $this-&gt;author-&gt;getTitle(Author::NAME_UNKNOWN) . ' - YELLOW PAGES';
      }
  }
  
  
  class Author {
      const NAME_UNKNOWN = 'anonymous';
  
      public function getTitle($nameStyle) {
          //do complicated calculation of author name
          if ($nameStyle == $this::NAME_UNKNOWN) {
              $name = "Anonymous";
          }
  
          //do further complicated calculations, modifying $name
  
          return $name;
      }
  }
  </code></pre>
  
  <p>My problem is with unit tests! I'm getting "Fatal error: Undefined class constant 'NAME_UNKNOWN'" when I mock <code>Author</code>. The whole purpose of mocking is to avoid including the Author class file, so what is the correct way to handle that constant?</p>
  
  <p>I could split <code>Author</code> into several objects or split the method that relies on the constant, but that would incur much repetition.</p>