Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCaseTrait.php
Show First 20 Lines • Show All 411 Lines • ▼ Show 20 Lines | protected function getTestResource($email, $attrib = []) | ||||
$resource = Resource::where('email', $email)->first(); | $resource = Resource::where('email', $email)->first(); | ||||
if (!$resource) { | if (!$resource) { | ||||
list($local, $domain) = explode('@', $email, 2); | list($local, $domain) = explode('@', $email, 2); | ||||
$resource = new Resource(); | $resource = new Resource(); | ||||
$resource->email = $email; | $resource->email = $email; | ||||
$resource->domain = $domain; | $resource->domainName = $domain; | ||||
if (!isset($attrib['name'])) { | if (!isset($attrib['name'])) { | ||||
$resource->name = $local; | $resource->name = $local; | ||||
} | } | ||||
} | } | ||||
foreach ($attrib as $key => $val) { | foreach ($attrib as $key => $val) { | ||||
$resource->{$key} = $val; | $resource->{$key} = $val; | ||||
Show All 15 Lines | protected function getTestSharedFolder($email, $attrib = []) | ||||
$folder = SharedFolder::where('email', $email)->first(); | $folder = SharedFolder::where('email', $email)->first(); | ||||
if (!$folder) { | if (!$folder) { | ||||
list($local, $domain) = explode('@', $email, 2); | list($local, $domain) = explode('@', $email, 2); | ||||
$folder = new SharedFolder(); | $folder = new SharedFolder(); | ||||
$folder->email = $email; | $folder->email = $email; | ||||
$folder->domain = $domain; | $folder->domainName = $domain; | ||||
if (!isset($attrib['name'])) { | if (!isset($attrib['name'])) { | ||||
$folder->name = $local; | $folder->name = $local; | ||||
} | } | ||||
} | } | ||||
foreach ($attrib as $key => $val) { | foreach ($attrib as $key => $val) { | ||||
$folder->{$key} = $val; | $folder->{$key} = $val; | ||||
Show All 29 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 |