App\Services\Form\Setting\MailSettingForm::update PHP Method

update() public method

Update an existing setting.
public update ( array $input ) : boolean
$input array Data to update a setting
return boolean
    public function update(array $input)
    {
        if (!$this->valid($input)) {
            return false;
        }
        foreach ($input as $key => $value) {
            if ($value === '') {
                $input[$key] = null;
            }
        }
        $mailSetting = new \App\Entities\Setting\MailSettingEntity();
        $mailSetting->setDriver($input['driver']);
        $mailSetting->setFrom(['address' => $input['from_address'], 'name' => $input['from_name']]);
        $mailSetting->setSmtpHost($input['smtp_host']);
        $mailSetting->setSmtpPort($input['smtp_port']);
        $mailSetting->setSmtpEncryption($input['smtp_encryption']);
        $mailSetting->setSmtpUsername($input['smtp_username']);
        $mailSetting->setSmtpPassword($input['smtp_password']);
        $mailSetting->setSendmailPath($input['sendmail_path']);
        $input['attributes'] = $mailSetting;
        $input['type'] = 'mail';
        $this->setting->updateByType($input);
        return true;
    }

Usage Example

Example #1
0
 public function test_Should_FailToUpdate_When_ValidationFails()
 {
     $this->mockValidator->shouldReceive('with')->once()->andReturn($this->mockValidator);
     $this->mockValidator->shouldReceive('passes')->once()->andReturn(false);
     $form = new MailSettingForm($this->mockValidator, $this->mockSettingRepository);
     $result = $form->update([]);
     $this->assertFalse($result, 'Expected update to fail.');
 }
All Usage Examples Of App\Services\Form\Setting\MailSettingForm::update