/** * @test */ public function createNewAttachment() { $filename = 'file.ext'; $content = '_some_dummy_content'; $fileRealPath = 'dummy/file/real/path/' . $filename; $attachmentId = 1; $attachment = new AttachmentStub(new File($fileRealPath)); $attachment->setId($attachmentId); $this->fileStorageService->expects($this->once())->method('upload')->with($this->logicalAnd($this->isType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING), $this->stringContains($filename)), $this->equalTo($content))->will($this->returnValue($fileRealPath)); $this->factory->expects($this->once())->method('create')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Attachment\\File'), $this->callback(function ($other) use($filename) { /** * @var $other \Diamante\DeskBundle\Model\Attachment\File */ return $filename == $other->getFilename(); })))->will($this->returnValue($attachment)); $this->holder->expects($this->once())->method('addAttachment')->with($this->equalTo($attachment)); $this->repository->expects($this->once())->method('store')->with($this->equalTo($attachment)); $createdAttachment = $this->manager->createNewAttachment($filename, $content, $this->holder); $this->assertNotNull($createdAttachment->getId()); $this->assertEquals($attachmentId, $createdAttachment->getId()); }