I'm trying to get into the workfow of using phpSpec to desing my classes. I have stumbled on testing a handle method on one of my event handlers.
My spec:
use App\Order;
use App\Models\Payments\Payment;
use App\Services\Payments\PaymentService;
use App\Events\Payments\AccountPayment;
class RecordPaymentTransactionSpec extends ObjectBehavior
{
function let(PaymentService $paymentService)
{
$this->beConstructedWith($paymentService);
}
function it_is_initializable()
{
$this->shouldHaveType('App\Handlers\Events\Payments\RecordPaymentTransaction');
}
function it_should_record_payment_transaction(AccountPayment $event)
{
$this->paymentService->recordPayment($event)->shouldBeCalled();
}
}
And this my implementation:
class RecordPaymentTransaction {
public $paymentService;
/**
* Create the event handler.
*
* RecordPaymentTransaction constructor.
* @param PaymentService $paymentService
*/
public function __construct(PaymentService $paymentService)
{
$this->paymentService = $paymentService;
}
/**
* Handle the event.
*
* @param AccountPayment $event
* @return void
*/
public function handle(AccountPayment $event)
{
$this->paymentService->recordPayment($event);
}
}
However, I keep getting this error:
- it should record payment transaction
no beCalled([array:0]) matcher found for null.
Cannot see what I'm doing wrong here, help please.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire