title: phpunit how to solve Error: Using $this when not in object context
body: <p>I am using php-7 and when running a test I came across with this error.</p>
  
  <pre><code>Error: Using $this when not in object context
  
  src/Notification.php:28
  tests/NotificationTest.php:10
  </code></pre>
  
  <p>It fails on <code>$this-&gt;log-&gt;info(" Message sent ");</code></p>
  
  <p>The contents</p>
  
  <pre><code>&lt;?php
  declare(strict_types=1);
  namespace CCP;
  
  use CCP\MyMailer;
  
  class Notification{
  
      private $log;
  
      public function __construct(){
          $this-&gt;log = $_SESSION['CFG']-&gt;log;
      }
  
      public function sendEmail(string $from, array $to, string $subject, string $body): boolean{
        $mail = new MyMailer;
        $mail-&gt;setFrom($from);
        foreach($to as $value){
          $mail-&gt;addAddress($value);
        }
        $mail-&gt;Subject = $subject;
        $mail-&gt;Body =  $body;
  
        if(!$mail-&gt;send())  {
          $this-&gt;log-&gt;error(" Message could not be sent for ");
          $this-&gt;log-&gt;error(" Mailer error: ".$mail-&gt;ErrorInfo);
          return false;
        } else {
          $this-&gt;log-&gt;info(" Message sent ");
        }
  
        return true;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>my test</p>
  
  <pre><code> public function testEmail(){
          $this-&gt;assertTrue(Notification::sendEmail("m.w@mail.com",["s.u@mail.com"],"phpunit testting","test true"),"send email");
      }
  </code></pre>
  
  <p>I have read a few articles/answers but they where related to static functions/variables so I don't see how this applies.</p>