public function testAttachDocuments() { Document::deleteAll(); $model = new Number(); $model->_id = 'NumberId'; $this->specify("Error if Document model invalid.", function () use($model) { $model->attachDocument(Yii::getAlias('@data') . '/file2.pdf'); }, ['throws' => new \RuntimeException()]); $this->specify("Error if argument not instance of UploadedFile or valid path to file.", function ($file) use($model) { $model->attachDocument($file); }, ['examples' => [["", []]], 'throws' => new \InvalidArgumentException()]); $model->save(false); $this->specify("Attachment must be save.", function ($file) use($model) { $model->attachDocument($file); }, ['examples' => [[Yii::getAlias('@data') . '/file2.pdf'], [new UploadedFile(['name' => 'file1.jpg', 'tempName' => \Yii::getAlias('@data') . '/file1.jpg', 'type' => mime_content_type(Yii::getAlias('@data') . '/file1.jpg')])]]]); $this->tester->seeRecord(Document::className(), ['filename' => 'file2.pdf', 'contentType' => 'application/pdf', 'ownerId' => 'NumberId']); $this->tester->seeRecord(Document::className(), ['filename' => 'file1.jpg', 'contentType' => 'image/jpeg', 'ownerId' => 'NumberId']); }