tests/unit/Subjects/AbstractSubjectTest.php
/**
     * Test getStoreId() with an invalid store view code.
     *
     * @return void
     */
Test getStoreId() with an invalid store view code.
@return void
Test getStoreId () with an invalid store view code . @return void
public function testGetStoreIdWithException()
    {
        $this->expectException(\Exception::class);
        $this->expectExceptionMessage("Found invalid store view code unknown in file product-import_20170706-160000_01.csv on line 1");
        $filename = 'product-import_20170706-160000_01.csv';
        $this->abstractSubject->expects($this->any())->method('getFullOperationName')->willReturn('add-update');
        $this->abstractSubject->setFilename($filename);
        $this->abstractSubject->setHeaders(array('col1' => 0, 'col2' => 1, ColumnKeys::STORE_VIEW_CODE => 2));
        $this->abstractSubject
             ->getSystemLogger()
             ->expects($this->once())
             ->method('debug')
             ->with(sprintf('Successfully processed operation "add-update" in file %s on line 1', $filename))
             ->willReturn(null);
        $mockObserver = $this->getMockBuilder('TechDivision\Import\Observers\ObserverInterface')
                             ->setMethods(get_class_methods('TechDivision\Import\Observers\ObserverInterface'))
                             ->getMock();
        $mockObserver->expects($this->exactly(1))
                     ->method('handle')
                     ->willReturn($row = array(0 => 'value1', 1 => 100, 2 => 'en_US'));
        $this->abstractSubject->registerObserver($mockObserver, 'import');
        $this->abstractSubject->importRow($row);
        $this->abstractSubject->getStoreId('unknown');
    }
public function testGetStoreIdWithException ( ) { $ this -> expectException ( \ Exception :: class ) ; $ this -> expectExceptionMessage ( " Found invalid store view code unknown in file product-import_20170706-160000_01.csv on line 1 " ) ; $ filename = 'product-import_20170706-160000_01.csv' ; $ this -> abstractSubject -> expects ( $ this -> any ( ) ) -> method ( 'getFullOperationName' ) -> willReturn ( 'add-update' ) ; $ this -> abstractSubject -> setFilename ( $ filename ) ; $ this -> abstractSubject -> setHeaders ( array ( 'col1' => 0 , 'col2' => 1 , ColumnKeys :: STORE_VIEW_CODE => 2 ) ) ; $ this -> abstractSubject -> getSystemLogger ( ) -> expects ( $ this -> once ( ) ) -> method ( 'debug' ) -> with ( sprintf ( 'Successfully processed operation "add-update" in file %s on line 1' , $ filename ) ) -> willReturn ( null ) ; $ mockObserver = $ this -> getMockBuilder ( 'TechDivision\Import\Observers\ObserverInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Observers\ObserverInterface' ) ) -> getMock ( ) ; $ mockObserver -> expects ( $ this -> exactly ( 1 ) ) -> method ( 'handle' ) -> willReturn ( $ row = array ( 0 => 'value1' , 1 => 100 , 2 => 'en_US' ) ) ; $ this -> abstractSubject -> registerObserver ( $ mockObserver , 'import' ) ; $ this -> abstractSubject -> importRow ( $ row ) ; $ this -> abstractSubject -> getStoreId ( 'unknown' ) ; }
Test getStoreId() with an invalid store view code.
Test getStoreId () with an invalid store view code .
// set the filename // mock the full operation name // set filename, headers and skip the first row // mock the system loggers debug() method // create a mock observer and make sure, that it's handle() method will NOT be invoked // register the mock observers // start importing the row // try to load an unknown store view code