tests/unit/Subjects/FileUploadTraitTest.php
/**
     * Test the uploadFile() method with a not existing file.
     *
     * @return void
     */
Test the uploadFile() method with a not existing file.
@return void
Test the uploadFile () method with a not existing file . @return void
public function testUploadFileWithNotExistingFile()
    {
        $this->expectException(\Exception::class);
        $this->expectExceptionMessage('Media file "pub/images/a/b/test.jpg" is not available');
        $this->fileUploadTrait->setMediaDir('var/importexport/media');
        $this->fileUploadTrait->setImagesFileDir($imagesFileDir = 'pub/images');
        $basename = '/a/b/test.jpg';
        $filename = sprintf('%s%s', $imagesFileDir, $basename);
        $mockFilesystem = $this->getMockBuilder('TechDivision\Import\Adapter\FilesystemAdapterInterface')
                               ->setMethods(get_class_methods('TechDivision\Import\Adapter\FilesystemAdapterInterface'))
                               ->getMock();
        $mockFilesystem->expects($this->once())
                       ->method('isFile')
                       ->with($filename)
                       ->willReturn(false);
        $this->fileUploadTrait->setFilesystemAdapter($mockFilesystem);
        $this->fileUploadTrait->uploadFile($basename);
    }
public function testUploadFileWithNotExistingFile ( ) { $ this -> expectException ( \ Exception :: class ) ; $ this -> expectExceptionMessage ( 'Media file "pub/images/a/b/test.jpg" is not available' ) ; $ this -> fileUploadTrait -> setMediaDir ( 'var/importexport/media' ) ; $ this -> fileUploadTrait -> setImagesFileDir ( $ imagesFileDir = 'pub/images' ) ; $ basename = '/a/b/test.jpg' ; $ filename = sprintf ( '%s%s' , $ imagesFileDir , $ basename ) ; $ mockFilesystem = $ this -> getMockBuilder ( 'TechDivision\Import\Adapter\FilesystemAdapterInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Adapter\FilesystemAdapterInterface' ) ) -> getMock ( ) ; $ mockFilesystem -> expects ( $ this -> once ( ) ) -> method ( 'isFile' ) -> with ( $ filename ) -> willReturn ( false ) ; $ this -> fileUploadTrait -> setFilesystemAdapter ( $ mockFilesystem ) ; $ this -> fileUploadTrait -> uploadFile ( $ basename ) ; }
Test the uploadFile() method with a not existing file.
Test the uploadFile () method with a not existing file .
// set media + images file directory // prepare basename, filename and the name of the uploaded file // mock the filesystem and its methods // set the mock filesystem // query whether or not the uploaded file has the expected name