tests/unit/Subjects/ExportableTraitTest.php
/**
     * Test the addArtefacts() method with orginial data has been serialized in debug mode.
     *
     * @return void
     */
Test the addArtefacts() method with orginial data has been serialized in debug mode.
@return void
Test the addArtefacts () method with orginial data has been serialized in debug mode . @return void
public function testAddArtefactsWithOriginalDataInDebugMode()
    {
        $this->exportableTrait->setLastEntityId($lastEntityId = 1000);
        $type = 'product-variants';
        $artefacts = array(
            array(
                ColumnKeys::ORIGINAL_DATA  => array(
                    ColumnKeys::ORIGINAL_FILENAME     => 'product-import_20170101123000_01.csv',
                    ColumnKeys::ORIGINAL_LINE_NUMBER  => 2,
                    ColumnKeys::ORIGINAL_COLUMN_NAMES => array('col1', 'col2')
                ),
                ColumnKeys::ATTRIBUTE_CODE => 'a_attribute_code',
                ColumnKeys::VALUE          => 1001
            )
        );
        $expectedArtefacts = array();
        foreach ($artefacts as $key => $artefact) {
            $expectedArtefacts[$key] = $artefact;
            $expectedArtefacts[$key][ColumnKeys::ORIGINAL_DATA] = serialize(
                $expectedArtefacts[$key][ColumnKeys::ORIGINAL_DATA]
            );
        }
        $artfactsToCompare = array(
            $type => array($lastEntityId => $expectedArtefacts)
        );
        $this->exportableTrait
             ->expects($this->any())
             ->method('isDebugMode')
             ->willReturn(true);
        $this->assertNull($this->exportableTrait->addArtefacts($type, $artefacts));
        $this->assertCount(1, $this->exportableTrait->getArtefacts());
        $this->assertSame($artfactsToCompare, $this->exportableTrait->getArtefacts());
    }
public function testAddArtefactsWithOriginalDataInDebugMode ( ) { $ this -> exportableTrait -> setLastEntityId ( $ lastEntityId = 1000 ) ; $ type = 'product-variants' ; $ artefacts = array ( array ( ColumnKeys :: ORIGINAL_DATA => array ( ColumnKeys :: ORIGINAL_FILENAME => 'product-import_20170101123000_01.csv' , ColumnKeys :: ORIGINAL_LINE_NUMBER => 2 , ColumnKeys :: ORIGINAL_COLUMN_NAMES => array ( 'col1' , 'col2' ) ) , ColumnKeys :: ATTRIBUTE_CODE => 'a_attribute_code' , ColumnKeys :: VALUE => 1001 ) ) ; $ expectedArtefacts = array ( ) ; foreach ( $ artefacts as $ key => $ artefact ) { $ expectedArtefacts [ $ key ] = $ artefact ; $ expectedArtefacts [ $ key ] [ ColumnKeys :: ORIGINAL_DATA ] = serialize ( $ expectedArtefacts [ $ key ] [ ColumnKeys :: ORIGINAL_DATA ] ) ; } $ artfactsToCompare = array ( $ type => array ( $ lastEntityId => $ expectedArtefacts ) ) ; $ this -> exportableTrait -> expects ( $ this -> any ( ) ) -> method ( 'isDebugMode' ) -> willReturn ( true ) ; $ this -> assertNull ( $ this -> exportableTrait -> addArtefacts ( $ type , $ artefacts ) ) ; $ this -> assertCount ( 1 , $ this -> exportableTrait -> getArtefacts ( ) ) ; $ this -> assertSame ( $ artfactsToCompare , $ this -> exportableTrait -> getArtefacts ( ) ) ; }
Test the addArtefacts() method with orginial data has been serialized in debug mode.
Test the addArtefacts () method with orginial data has been serialized in debug mode .
// set last entity ID // initialize the artefact type // initialize the artefacts to import // prepare the expected result // initialize the artefacts to import // activate debug mode // assert that the original data has been serialized