May 9, 2018
0
Level 9
Realtime facade with constructor in Test
Hi,
I have a class like this, where I can override an email when I need to in the constructor:
class MyClass
{
protected $email;
public function __construct($email = null)
{
$this->email = (null == $email) ? \Auth::user()->email : $email;
}
public function foo()
{
return 'bar';
}
}
Now in my tests I want to leverage the realtime Facades. So this is what it looks like:
use Facades\App\Services\MyClass;
class WhateverTest extends TestCase
{
/** @test */
public function it_tests_something()
{
MyClass::shouldReceive('foo')->andReturn('this is a test');
}
}
My problem now is the constructor in the MyClass. How can I put an email in the constructor?
Hope someone can help me!
Please or to participate in this conversation.