public function run() { // Command Pattern - CLIENT - to execute command it passes the command obj to the invoker obj. // === ActionStrategyClient(); // === setCommand(CommandInterface) // will call command->invokeReceiversMethod(); $result = []; foreach ($this->commands as $pair) { // TODO: How to get schedule here? in order to bookkeep. $commandObj = $pair['command']; $this->bookkeepStart($pair['schedule']); $success = true; $message = ''; $commandResult = ''; try { $invokerObj = new ActionCommandInvoker($commandObj); $commandResult = $invokerObj->executeCommand(); } catch (\Exception $e) { $success = false; $message = $e->getMessage(); } $result[] = ['command' => get_class($commandObj), 'result' => $commandResult, 'success' => $success, 'message' => $message]; $this->bookkeepFinish($success, $pair['schedule']); } return $result; }
public function test_invoke_command() { $company = factory(Company::class)->create(); $this->mockEmail(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'), $company, 'Licence Reminder', 'emails.company-reminder'); $commandObj = new ActionCommandSendReminderEmailCommand($company->id); $invokerObj = new ActionCommandInvoker($commandObj); $actualNumberOfEmailSent = $invokerObj->executeCommand(); // $commandObj->execute(); $this->assertEquals(1, $actualNumberOfEmailSent); }