tests/unit/Subjects/AbstractSubjectTest.php
/**
     * Test the importRow() method and skip processing.
     *
     * @return void
     */
Test the importRow() method and skip processing.
@return void
Test the importRow () method and skip processing . @return void
public function testImportRowAndSkip()
    {
        $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));
        $mockObserver = $this->getMockBuilder('TechDivision\Import\Observers\ObserverInterface')
            ->setMethods(get_class_methods('TechDivision\Import\Observers\ObserverInterface'))
            ->getMock();
        $mockObserver->expects($this->exactly(0))
            ->method('handle');
        $this->abstractSubject
             ->getSystemLogger()
             ->expects($this->exactly(2))
             ->method('debug')
             ->withConsecutive(
                 array(sprintf('Skip processing operation "add-update" after observer "%s" in file %s on line 1', get_class($mockObserver), $filename)),
                 array(sprintf('Successfully processed operation "add-update" in file %s on line 1', $filename))
             )
             ->willReturn(null);
        $this->abstractSubject->registerObserver(new SkipObserverImpl(), 'import');
        $this->abstractSubject->registerObserver($mockObserver, 'import');
        $this->abstractSubject->importRow($row = array(0 => 'value1', 1 => 100));
        $this->assertSame($row, $this->abstractSubject->getRow());
    }
public function testImportRowAndSkip ( ) { $ 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 ) ) ; $ mockObserver = $ this -> getMockBuilder ( 'TechDivision\Import\Observers\ObserverInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Observers\ObserverInterface' ) ) -> getMock ( ) ; $ mockObserver -> expects ( $ this -> exactly ( 0 ) ) -> method ( 'handle' ) ; $ this -> abstractSubject -> getSystemLogger ( ) -> expects ( $ this -> exactly ( 2 ) ) -> method ( 'debug' ) -> withConsecutive ( array ( sprintf ( 'Skip processing operation "add-update" after observer "%s" in file %s on line 1' , get_class ( $ mockObserver ) , $ filename ) ) , array ( sprintf ( 'Successfully processed operation "add-update" in file %s on line 1' , $ filename ) ) ) -> willReturn ( null ) ; $ this -> abstractSubject -> registerObserver ( new SkipObserverImpl ( ) , 'import' ) ; $ this -> abstractSubject -> registerObserver ( $ mockObserver , 'import' ) ; $ this -> abstractSubject -> importRow ( $ row = array ( 0 => 'value1' , 1 => 100 ) ) ; $ this -> assertSame ( $ row , $ this -> abstractSubject -> getRow ( ) ) ; }
Test the importRow() method and skip processing.
Test the importRow () method and skip processing .
// set the filename // mock the full operation name // set filename, headers and skip the first row // create a mock observer and make sure, that it's handle() method will NOT be invoked // mock the system loggers debug() method // register the mock observers // start importing the row // query whether or not the row have been initialized