tests/unit/Observers/AbstractAttributeObserverTest.php
/**
     * Test the handle() method with an unknown attribute.
     *
     * @return void
     */
Test the handle() method with an unknown attribute.
@return void
Test the handle () method with an unknown attribute . @return void
public function testHandleWithUnknownAttribute()
    {
        $this->attributeObserver->expects($this->once())
                                ->method('isDebugMode')
                                ->willReturn(true);
        $this->attributeObserver->expects($this->never())
                                ->method('persistVarcharAttribute');
        $headers = array($attributeCode = 'unknown_attribute_code' => 0);
        $row = array(0 => 'a-attribute-value');
        $backendTypes = array(
            BackendTypeKeys::BACKEND_TYPE_VARCHAR  => array('persistVarcharAttribute', 'loadVarcharAttribute', 'deleteVarcharAttribute')
        );
        $mockSystemLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')
                                 ->setMethods(get_class_methods('Psr\Log\LoggerInterface'))
                                 ->getMock();
        $mockSystemLogger->expects($this->once())
                         ->method('debug')
                         ->with(sprintf('Can\'t find attribute with attribute code "%s"', $attributeCode))
                         ->willReturn(null);
        $mockSubjectConfiguration = $this->getMockBuilder('TechDivision\Import\Configuration\SubjectConfigurationInterface')
                                         ->setMethods(get_class_methods('TechDivision\Import\Configuration\SubjectConfigurationInterface'))
                                         ->getMock();
        $mockSubjectConfiguration->expects($this->once())
                                 ->method('hasParam')
                                 ->with(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS)
                                 ->willReturn(false);
        $mockJmsConfiguration = $this->createMock('TechDivision\Import\Configuration\ConfigurationInterface');
        $mockSubjectConfiguration->expects($this->once())
            ->method('getConfiguration')
            ->willReturn($mockJmsConfiguration);
        $mockSubject = $this->getMockBuilder('TechDivision\Import\Observers\EntitySubjectImpl')
                            ->setMethods(get_class_methods('TechDivision\Import\Observers\EntitySubjectImpl'))
                            ->getMock();
        $mockSubject->expects($this->once())
                    ->method('appendExceptionSuffix')
                    ->willReturnArgument(0);
        $mockSubject->expects($this->once())
                    ->method('getSystemLogger')
                    ->willReturn($mockSystemLogger);
        $mockSubject->expects($this->once())
                    ->method('appendExceptionSuffix')
                    ->willReturnArgument(0);
        $mockSubject->expects($this->atLeastOnce())
                    ->method('getConfiguration')
                    ->willReturn($mockSubjectConfiguration);
        $mockSubject->expects($this->once())
                    ->method('prepareStoreViewCode')
                    ->willReturn(null);
        $mockSubject->expects($this->once())
                    ->method('getAttributes')
                    ->willReturn(array());
        $mockSubject->expects($this->once())
                    ->method('getHeaders')
                    ->willReturn($headers);
        $mockSubject->expects($this->once())
                    ->method('getRow')
                    ->willReturn($row);
        $mockSubject->expects($this->once())
                    ->method('getBackendTypes')
                    ->willReturn($backendTypes);
        $mockSubject->expects($this->once())
                    ->method('getDefaultColumnValues')
                    ->willReturn(array());
        $this->attributeObserver->handle($mockSubject);
    }
public function testHandleWithUnknownAttribute ( ) { $ this -> attributeObserver -> expects ( $ this -> once ( ) ) -> method ( 'isDebugMode' ) -> willReturn ( true ) ; $ this -> attributeObserver -> expects ( $ this -> never ( ) ) -> method ( 'persistVarcharAttribute' ) ; $ headers = array ( $ attributeCode = 'unknown_attribute_code' => 0 ) ; $ row = array ( 0 => 'a-attribute-value' ) ; $ backendTypes = array ( BackendTypeKeys :: BACKEND_TYPE_VARCHAR => array ( 'persistVarcharAttribute' , 'loadVarcharAttribute' , 'deleteVarcharAttribute' ) ) ; $ mockSystemLogger = $ this -> getMockBuilder ( 'Psr\Log\LoggerInterface' ) -> setMethods ( get_class_methods ( 'Psr\Log\LoggerInterface' ) ) -> getMock ( ) ; $ mockSystemLogger -> expects ( $ this -> once ( ) ) -> method ( 'debug' ) -> with ( sprintf ( 'Can\'t find attribute with attribute code "%s"' , $ attributeCode ) ) -> willReturn ( null ) ; $ mockSubjectConfiguration = $ this -> getMockBuilder ( 'TechDivision\Import\Configuration\SubjectConfigurationInterface' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Configuration\SubjectConfigurationInterface' ) ) -> getMock ( ) ; $ mockSubjectConfiguration -> expects ( $ this -> once ( ) ) -> method ( 'hasParam' ) -> with ( ConfigurationKeys :: CLEAN_UP_EMPTY_COLUMNS ) -> willReturn ( false ) ; $ mockJmsConfiguration = $ this -> createMock ( 'TechDivision\Import\Configuration\ConfigurationInterface' ) ; $ mockSubjectConfiguration -> expects ( $ this -> once ( ) ) -> method ( 'getConfiguration' ) -> willReturn ( $ mockJmsConfiguration ) ; $ mockSubject = $ this -> getMockBuilder ( 'TechDivision\Import\Observers\EntitySubjectImpl' ) -> setMethods ( get_class_methods ( 'TechDivision\Import\Observers\EntitySubjectImpl' ) ) -> getMock ( ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'appendExceptionSuffix' ) -> willReturnArgument ( 0 ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'getSystemLogger' ) -> willReturn ( $ mockSystemLogger ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'appendExceptionSuffix' ) -> willReturnArgument ( 0 ) ; $ mockSubject -> expects ( $ this -> atLeastOnce ( ) ) -> method ( 'getConfiguration' ) -> willReturn ( $ mockSubjectConfiguration ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'prepareStoreViewCode' ) -> willReturn ( null ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'getAttributes' ) -> willReturn ( array ( ) ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'getHeaders' ) -> willReturn ( $ headers ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'getRow' ) -> willReturn ( $ row ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'getBackendTypes' ) -> willReturn ( $ backendTypes ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'getDefaultColumnValues' ) -> willReturn ( array ( ) ) ; $ this -> attributeObserver -> handle ( $ mockSubject ) ; }
Test the handle() method with an unknown attribute.
Test the handle () method with an unknown attribute .
// mock filename + line number and the method call to the isDebugMode() method // make sure the persist method will NEVER be invoked // prepare the headers // prepare the row // prepare the backend types // mock a system logger // mock a subject configuration // mock a jms configuration // mock a subject // invoke the handle method