Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCaseTrait.php
Show First 20 Lines • Show All 489 Lines • ▼ Show 20 Lines | trait TestCaseTrait | ||||
* Call protected/private method of a class. | * Call protected/private method of a class. | ||||
* | * | ||||
* @param object $object Instantiated object that we will run method on. | * @param object $object Instantiated object that we will run method on. | ||||
* @param string $methodName Method name to call | * @param string $methodName Method name to call | ||||
* @param array $parameters Array of parameters to pass into method. | * @param array $parameters Array of parameters to pass into method. | ||||
* | * | ||||
* @return mixed Method return. | * @return mixed Method return. | ||||
*/ | */ | ||||
protected function invokeMethod($object, $methodName, array $parameters = array()) | protected function invokeMethod($object, $methodName, array $parameters = []) | ||||
{ | { | ||||
$reflection = new \ReflectionClass(get_class($object)); | $reflection = new \ReflectionClass(get_class($object)); | ||||
$method = $reflection->getMethod($methodName); | $method = $reflection->getMethod($methodName); | ||||
$method->setAccessible(true); | $method->setAccessible(true); | ||||
return $method->invokeArgs($object, $parameters); | return $method->invokeArgs($object, $parameters); | ||||
} | } | ||||
/** | |||||
* Extract content of an email message. | |||||
* | |||||
* @param \Illuminate\Mail\Mailable $mail Mailable object | |||||
* | |||||
* @return array Parsed message data: | |||||
* - 'plain': Plain text body | |||||
* - 'html: HTML body | |||||
* - 'subject': Mail subject | |||||
*/ | |||||
protected function renderMail(\Illuminate\Mail\Mailable $mail): array | |||||
{ | |||||
$mail->build(); // @phpstan-ignore-line | |||||
$result = $this->invokeMethod($mail, 'renderForAssertions'); | |||||
return [ | |||||
'plain' => $result[1], | |||||
'html' => $result[0], | |||||
'subject' => $mail->subject, | |||||
]; | |||||
} | |||||
protected function setUpTest() | protected function setUpTest() | ||||
{ | { | ||||
$this->userPassword = \App\Utils::generatePassphrase(); | $this->userPassword = \App\Utils::generatePassphrase(); | ||||
$this->domainHosted = $this->getTestDomain( | $this->domainHosted = $this->getTestDomain( | ||||
'test.domain', | 'test.domain', | ||||
[ | [ | ||||
'type' => \App\Domain::TYPE_EXTERNAL, | 'type' => \App\Domain::TYPE_EXTERNAL, | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |