public function testCopyAttachments() { $applicationAttachment1Data = ['getContent' => 'content', 'getName' => 'name', 'getType' => 'type', 'getDateUploaded' => new \DateTime()]; $applicationAttachment1 = $this->getMockBuilder(ApplicationAttachment::class)->setMethods(array_keys($applicationAttachment1Data))->getMock(); foreach ($applicationAttachment1Data as $method => $return) { $applicationAttachment1->expects($this->once())->method($method)->willReturn($return); } $applicationAttachments = new ArrayCollection([$applicationAttachment1]); $this->repository->expects($this->once())->method('create'); $job = new Job(); $user = new User(); $user->setId('jobUser'); $job->setUser($user); $application = $this->getMockBuilder(Application::class)->setMethods(['getContact', 'getAttachments'])->getMock(); $application->method('getContact')->willReturn(new ApplicationContact()); $application->expects($this->once())->method('getAttachments')->willReturn($applicationAttachments); $application->setJob($job); $cv = $this->repository->createFromApplication($application, $this->user); $this->assertSame($this->cv, $cv); $cvAttachments = $cv->getAttachments(); $this->assertSame($applicationAttachments->count(), $cvAttachments->count()); $cvAttachment1 = $cvAttachments->first(); $this->assertInstanceOf(CvAttachment::class, $cvAttachment1); $this->assertSame($applicationAttachment1Data['getContent'], $cvAttachment1->getFile()->getBytes()); $this->assertSame($applicationAttachment1Data['getName'], $cvAttachment1->getName()); $this->assertSame($applicationAttachment1Data['getType'], $cvAttachment1->getType()); $this->assertSame($applicationAttachment1Data['getDateUploaded'], $cvAttachment1->getDateUploaded()); $this->assertSame($user, $cvAttachment1->getUser()); }
public function testReturnsExpectedResult() { $resume = new \Cv\Entity\Cv(); $this->repositoryMock->expects($this->once())->method('find')->with(1234)->willReturn($resume); $acl = $this->getMockBuilder(Acl::class)->disableOriginalConstructor()->setMethods(['__invoke'])->getMock(); $acl->expects($this->once())->method('__invoke')->with($resume, 'view'); $this->target->getPluginManager()->setService('acl', $acl); $actual = $this->target->indexAction(); $expected = ['resume' => $resume]; $this->assertEquals($expected, $actual); }
public function indexAction() { /** @var string|null $id */ $id = $this->params('id'); $resume = $this->repository->find($id); if (!$resume) { $this->getResponse()->setStatusCode(Response::STATUS_CODE_404); return ['message' => sprintf($this->translator->translate('Resume with id "%s" not found'), $id)]; } /* @todo REMOVE THIS * @codeCoverageIgnoreStart */ if (!$resume->getDateCreated()) { $resume->setDateCreated(); } /* @codeCoverageIgnoreEnd */ $this->acl($resume, 'view'); return ['resume' => $resume]; }