build() public static method

public static build ( $class, $data = [] )
コード例 #1
0
 public function test_Should_ConvertMessageToText()
 {
     $deployment = Factory::build('App\\Models\\Deployment', ['id' => 1, 'project_id' => 1, 'number' => 1, 'status' => null, 'task' => 'deploy', 'user_id' => 1, 'message' => 'Message', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon(), 'user' => new App\Models\User()]);
     $converter = new AnsiToHtmlConverter();
     $deploymentPresenter = new DeploymentPresenter($deployment, $converter);
     $html = $deploymentPresenter->messageText();
     $this->assertEquals('Message', $html);
 }
コード例 #2
0
 public function test_Should_DisplayShowPage_When_ShowPageIsRequestedAndResourceIsFound()
 {
     $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()]);
     $project = $this->mockProjectModel->shouldReceive('getDeploymentByNumber')->once()->andReturn($deployment)->mock();
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $this->get('projects/1/deployments/1');
     $this->assertResponseOk();
     $this->assertViewHas('deployment');
 }
コード例 #3
0
 public function test_Should_ReturnStatusCode400_When_StoreProcessFails()
 {
     $project = Factory::build('App\\Models\\Project', ['id' => 1, 'name' => 'Project 1', 'github_webhook_user_id' => 1, 'created_at' => new \Carbon\Carbon(), 'updated_at' => new \Carbon\Carbon()]);
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $this->mockDeploymentForm->shouldReceive('save')->once()->andReturn(false);
     $this->mockDeploymentForm->shouldReceive('errors')->once()->andReturn(new \Illuminate\Support\MessageBag());
     $this->post('webhook/github/v1/projects/1/deployments');
     $this->assertResponseStatus(400);
 }
コード例 #4
0
ファイル: DeploymentFormTest.php プロジェクト: ngmy/webloyer
 public function test_Should_FailToSave_When_ValidationPassesAndSaveToDatabaseFails()
 {
     $this->mockValidator->shouldReceive('with')->once()->andReturn($this->mockValidator);
     $this->mockValidator->shouldReceive('passes')->once()->andReturn(true);
     $project = $this->mockProjectModel;
     $maxDeployment = Factory::build('App\\Models\\MaxDeployment', ['id' => 1, 'project_id' => $project->id, 'number' => 1, 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $project->shouldReceive('getMaxDeployment')->once()->andReturn($maxDeployment)->shouldReceive('addDeployment')->once()->shouldReceive('updateMaxDeployment')->once()->shouldReceive('getDeploymentByNumber')->once()->andReturn(false)->mock();
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $form = new DeploymentForm($this->mockValidator, $this->mockProjectRepository, $this->mockDeployCommander);
     $result = $form->save(['project_id' => $project->id, 'task' => 'deploy']);
     $this->assertFalse($result, 'Expected save to fail.');
 }
コード例 #5
0
ファイル: UsersControllerTest.php プロジェクト: ngmy/webloyer
 public function test_Should_RedirectToIndexPage_When_DestroyProcessIsRequestedAndDestroyProcessSucceeds()
 {
     $user = Factory::build('App\\Models\\User', ['id' => 1, 'name' => 'User 1', 'email' => '*****@*****.**', 'password' => '12345678', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $this->mockUserRepository->shouldReceive('byId')->once()->andReturn($user);
     $this->mockUserRepository->shouldReceive('delete')->once();
     $this->delete('users/1');
     $this->assertRedirectedToRoute('users.index');
 }
コード例 #6
0
 public function test_Should_RedirectToIndexPage_When_DestroyProcessIsRequestedAndDestroyProcessSucceeds()
 {
     $project = Factory::build('App\\Models\\Project', ['id' => 1, 'name' => 'Project 1', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $this->mockProjectRepository->shouldReceive('byId')->once()->andReturn($project);
     $this->mockProjectRepository->shouldReceive('delete')->once();
     $this->delete('projects/1');
     $this->assertRedirectedToRoute('projects.index');
 }
コード例 #7
0
ファイル: DeployTest.php プロジェクト: ngmy/webloyer
 public function test_Should_WorkAndSendNotification_When_DeployerIsAbnormalEndAndEmailNotificationRecipientIsSet()
 {
     $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(), 'stauts' => 1]);
     $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(false);
     $this->mockProcess->shouldReceive('getErrorOutput')->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 Deploy($deployment);
     $job->handle($this->mockProjectRepository, $this->mockServerRepository, $this->mockProcessBuilder, $this->mockNotifier, $this->mockSettingRepositroy);
 }
コード例 #8
0
 public function test_Should_RedirectToIndexPage_When_DestroyProcessIsRequestedAndDestroyProcessSucceeds()
 {
     $recipe = Factory::build('App\\Models\\Recipe', ['id' => 1, 'name' => 'Recipe 1', 'description' => '', 'body' => '', 'created_at' => new Carbon\Carbon(), 'updated_at' => new Carbon\Carbon()]);
     $this->mockRecipeRepository->shouldReceive('byId')->once()->andReturn($recipe);
     $this->mockRecipeRepository->shouldReceive('delete')->once();
     $this->delete('recipes/1');
     $this->assertRedirectedToRoute('recipes.index');
 }