سؤال

I have a model class, that throw exception if some value is null. How I can test, that it condition is ok.

 $contact = $this->contactFactory->create()
            ->setEmail('testdelete@test.com')
            ->setFirstname('Pasha')
            ->setLastname('Doe')
            ->setPhone(1236547);
 $this->contactRepository->save($contact); //exception is here 
هل كانت مفيدة؟

المحلول

using php code, try:

if(isset($contact)) $this->contactRepository->save($contact);

or

try { $this->contactRepository->save($contact); } catch

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top