tests/unit/Subjects/FileUploadTraitTest.php
/**
     * Test the getNewFileName() method when the file not already exists.
     *
     * @return void
     */
Test the getNewFileName() method when the file not already exists.
@return void
Test the getNewFileName () method when the file not already exists . @return void
public function testGetNewFileNameWithNotExistingFile()
    {
        $targetFilename = 'pub/media/images/test.jpg';
        $expectedFilename = basename($targetFilename);
        $mockFilesystem = $this->getMockBuilder('TechDivision\Import\Adapter\FilesystemAdapterInterface')
                               ->setMethods(get_class_methods('TechDivision\Import\Adapter\FilesystemAdapterInterface'))
                               ->getMock();
        $mockFilesystem->expects($this->once())
                       ->method('isFile')
                       ->with($targetFilename)
                       ->willReturn(false);
        $this->fileUploadTrait->setFilesystemAdapter($mockFilesystem);
        $this->assertSame($expectedFilename, $this->fileUploadTrait->getNewFileName($targetFilename));
    }
public function testGetNewFileNameWithNotExistingFile ( ) { $ targetFilename = 'pub/media/images/test.jpg' ; $ expectedFilename = basename ( $ targetFilename ) ; $ mockFilesystem = $ this -> getMockBuilder ( 'TechDivision\Import\Adapter\FilesystemAdapterInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Adapter\FilesystemAdapterInterface' ) ) -> getMock ( ) ; $ mockFilesystem -> expects ( $ this -> once ( ) ) -> method ( 'isFile' ) -> with ( $ targetFilename ) -> willReturn ( false ) ; $ this -> fileUploadTrait -> setFilesystemAdapter ( $ mockFilesystem ) ; $ this -> assertSame ( $ expectedFilename , $ this -> fileUploadTrait -> getNewFileName ( $ targetFilename ) ) ; }
Test the getNewFileName() method when the file not already exists.
Test the getNewFileName () method when the file not already exists .
// initialize old and new filename // mock the filesystem // set the mock filesystem // query whether or not the new file name is the same as the passed one