tests/unit/Subjects/AbstractSubjectTest.php
/**
     * Test the import() method with a matching filename.
     *
     * @return void
     */
Test the import() method with a matching filename.
@return void
Test the import () method with a matching filename . @return void
public function testImportWithMatchingFilename()
    {
        $filename = 'var/importexport/product-import_20170706-160000_01.csv';
        $mockImportAdapter = $this->getMockBuilder('TechDivision\Import\Adapter\ImportAdapterInterface')
                                  ->setMethods(get_class_methods('TechDivision\Import\Adapter\ImportAdapterInterface'))
                                  ->getMock();
        $mockImportAdapter->expects($this->once())
                          ->method('import')
                          ->willReturn(null);
        $this->abstractSubject->setImportAdapter($mockImportAdapter);
         $this->abstractSubject
             ->getConfiguration()
             ->expects($this->once())
             ->method('isCreatingImportedFile')
             ->willReturn(true);
        $this->abstractSubject
             ->expects($this->exactly(3))
             ->method('isFile')
             ->withConsecutive(
                 array(sprintf('%s.failed', $filename)),
                 array(sprintf('%s.imported', $filename)),
                 array(sprintf('%s.inProgress', $filename))
             )
             ->willReturnOnConsecutiveCalls(false, false, false);
        $this->abstractSubject
             ->expects($this->once())
             ->method('touch')
             ->with(sprintf('%s.inProgress', $filename))
             ->willReturn(true);
        $this->abstractSubject
             ->expects($this->once())
             ->method('rename')
             ->with(sprintf('%s.inProgress', $filename), sprintf('%s.imported', $filename))
             ->willReturn(true);
        $this->assertNull($this->abstractSubject->import(uniqid(), $filename));
    }
public function testImportWithMatchingFilename ( ) { $ filename = 'var/importexport/product-import_20170706-160000_01.csv' ; $ mockImportAdapter = $ this -> getMockBuilder ( 'TechDivision\Import\Adapter\ImportAdapterInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Adapter\ImportAdapterInterface' ) ) -> getMock ( ) ; $ mockImportAdapter -> expects ( $ this -> once ( ) ) -> method ( 'import' ) -> willReturn ( null ) ; $ this -> abstractSubject -> setImportAdapter ( $ mockImportAdapter ) ; $ this -> abstractSubject -> getConfiguration ( ) -> expects ( $ this -> once ( ) ) -> method ( 'isCreatingImportedFile' ) -> willReturn ( true ) ; $ this -> abstractSubject -> expects ( $ this -> exactly ( 3 ) ) -> method ( 'isFile' ) -> withConsecutive ( array ( sprintf ( '%s.failed' , $ filename ) ) , array ( sprintf ( '%s.imported' , $ filename ) ) , array ( sprintf ( '%s.inProgress' , $ filename ) ) ) -> willReturnOnConsecutiveCalls ( false , false , false ) ; $ this -> abstractSubject -> expects ( $ this -> once ( ) ) -> method ( 'touch' ) -> with ( sprintf ( '%s.inProgress' , $ filename ) ) -> willReturn ( true ) ; $ this -> abstractSubject -> expects ( $ this -> once ( ) ) -> method ( 'rename' ) -> with ( sprintf ( '%s.inProgress' , $ filename ) , sprintf ( '%s.imported' , $ filename ) ) -> willReturn ( true ) ; $ this -> assertNull ( $ this -> abstractSubject -> import ( uniqid ( ) , $ filename ) ) ; }
Test the import() method with a matching filename.
Test the import () method with a matching filename .
// set the filename // create the mock import adapter and mock the import() method // set the import adapter // mock the flag to create the .imported flagfile // mock the isFile() method // mock the touch() method // mock the rename() method // try to import the file with the passed name