public function test_Should_WorkAndSendNotification_When_DeployerIsNormalEndAndEmailNotificationRecipientIsSet() { $deployment = Factory::build('App\\Models\\Deployment', ['id' => 1, 'project_id' => 1, 'number' => 1, 'task' => 'deploy', 'user_id' => 1, 'created_at' => new \Carbon\Carbon(), 'updated_at' => new \Carbon\Carbon(), 'user' => new \App\Models\User()]); $updatedDeployment = Factory::build('App\\Models\\Deployment', ['id' => 1, 'project_id' => 1, 'number' => 1, 'task' => 'deploy', 'user_id' => 1, 'created_at' => new \Carbon\Carbon(), 'updated_at' => new \Carbon\Carbon(), 'user' => new \App\Models\User(), 'status' => 0]); $recipe = factory::build('app\\models\\recipe', ['id' => 1, 'name' => 'recipe 1', 'desctiption' => '', 'body' => '']); $project = $this->mockProjectModel->shouldReceive('updateDeployment')->once()->shouldReceive('getDeploymentByNumber')->once()->andReturn($updatedDeployment)->mock(); $project = $this->mockProjectModel->shouldReceive('getRecipes')->once()->andReturn([$recipe])->mock(); $project->email_notification_recipient = '*****@*****.**'; $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project); $this->mockServerRepository->shouldReceive('byId')->once()->andReturn($this->mockServerModel); $mockDeployerFile = $this->mock('App\\Services\\Deployment\\DeployerFile')->shouldReceive('getFullPath')->once()->mock(); $this->mockDeployerFileDirector->shouldReceive('construct')->andReturn($mockDeployerFile)->times(3); $this->mockProcess->shouldReceive('run')->once(); $this->mockProcess->shouldReceive('isSuccessful')->twice()->andReturn(true); $this->mockProcess->shouldReceive('getOutput')->once(); $this->mockProcess->shouldReceive('getExitCode')->once(); $this->mockProcessBuilder->shouldReceive('add')->times(7)->andReturn($this->mockProcessBuilder); $this->mockProcessBuilder->shouldReceive('getProcess')->once()->andReturn($this->mockProcess); $this->mockNotifier->shouldReceive('to')->once()->andReturn($this->mockNotifier); $this->mockNotifier->shouldReceive('notify')->once(); $this->mockMailSettingEntity->shouldReceive('getDriver')->once()->shouldReceive('getFrom')->twice()->shouldReceive('getSmtpHost')->once()->shouldReceive('getSmtpPort')->once()->shouldReceive('getSmtpEncryption')->once()->shouldReceive('getSmtpUsername')->once()->shouldReceive('getSmtpPassword')->once()->shouldReceive('getSendmailPath')->once(); $this->mockSettingModel->shouldReceive('getAttribute')->with('attributes')->andReturn($this->mockMailSettingEntity); $this->mockSettingRepositroy->shouldReceive('byType')->once()->andReturn($this->mockSettingModel); $this->mockServerListFileBuilder->shouldReceive('setServer')->once()->andReturn($this->mockServerListFileBuilder); $this->mockServerListFileBuilder->shouldReceive('setProject')->once()->andReturn($this->mockServerListFileBuilder); $this->mockRecipeFileBuilder->shouldReceive('setRecipe')->once(); $this->mockDeploymentFileBuilder->shouldReceive('setProject')->once()->andReturn($this->mockDeploymentFileBuilder); $this->mockDeploymentFileBuilder->shouldReceive('setServerListFile')->once()->andReturn($this->mockDeploymentFileBuilder); $this->mockDeploymentFileBuilder->shouldReceive('setRecipeFile')->once()->andReturn($this->mockDeploymentFileBuilder); $job = new Rollback($deployment); $job->handle($this->mockProjectRepository, $this->mockServerRepository, $this->mockProcessBuilder, $this->mockNotifier, $this->mockSettingRepositroy); }