tests/unit/Observers/AbstractAttributeObserverTest.php
/**
     * Test the handle() method with an empty attribute.
     *
     * @return void
     */
Test the handle() method with an empty attribute.
@return void
Test the handle () method with an empty attribute . @return void
public function testHandleWithEmptyAttribute()
    {
        $backendTypes = array(
            BackendTypeKeys::BACKEND_TYPE_VARCHAR  => array('persistVarcharAttribute', 'loadVarcharAttribute', 'deleteVarcharAttribute')
        );
        $attributes = array(
            $attributeCode = 'url_key' => array(
                MemberNames::ATTRIBUTE_ID => 124,
                MemberNames::ENTITY_TYPE_ID => 4,
                MemberNames::ATTRIBUTE_CODE => $attributeCode,
                MemberNames::BACKEND_TYPE => BackendTypeKeys::BACKEND_TYPE_VARCHAR
            )
        );
        $headers = array($attributeCode => 0);
        $row = array(0 => 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');
        $mockJmsConfiguration->expects($this->once())
            ->method('getEmptyAttributeValueConstant')
            ->willReturn('FooBar');
        $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->atLeastOnce())
                    ->method('getConfiguration')
                    ->willReturn($mockSubjectConfiguration);
        $mockSubject->expects($this->never())
                    ->method('getSystemLogger');
        $mockSubject->expects($this->once())
                    ->method('prepareStoreViewCode')
                    ->willReturn(null);
        $mockSubject->expects($this->once())
                    ->method('getAttributes')
                    ->willReturn($attributes);
        $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->expects($this->never())
                                ->method('persistVarcharAttribute');
        $this->attributeObserver->handle($mockSubject);
    }
public function testHandleWithEmptyAttribute ( ) { $ backendTypes = array ( BackendTypeKeys :: BACKEND_TYPE_VARCHAR => array ( 'persistVarcharAttribute' , 'loadVarcharAttribute' , 'deleteVarcharAttribute' ) ) ; $ attributes = array ( $ attributeCode = 'url_key' => array ( MemberNames :: ATTRIBUTE_ID => 124 , MemberNames :: ENTITY_TYPE_ID => 4 , MemberNames :: ATTRIBUTE_CODE => $ attributeCode , MemberNames :: BACKEND_TYPE => BackendTypeKeys :: BACKEND_TYPE_VARCHAR ) ) ; $ headers = array ( $ attributeCode => 0 ) ; $ row = array ( 0 => 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' ) ; $ mockJmsConfiguration -> expects ( $ this -> once ( ) ) -> method ( 'getEmptyAttributeValueConstant' ) -> willReturn ( 'FooBar' ) ; $ 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 -> atLeastOnce ( ) ) -> method ( 'getConfiguration' ) -> willReturn ( $ mockSubjectConfiguration ) ; $ mockSubject -> expects ( $ this -> never ( ) ) -> method ( 'getSystemLogger' ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'prepareStoreViewCode' ) -> willReturn ( null ) ; $ mockSubject -> expects ( $ this -> once ( ) ) -> method ( 'getAttributes' ) -> willReturn ( $ attributes ) ; $ 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 -> expects ( $ this -> never ( ) ) -> method ( 'persistVarcharAttribute' ) ; $ this -> attributeObserver -> handle ( $ mockSubject ) ; }
Test the handle() method with an empty attribute.
Test the handle () method with an empty attribute .
// prepare the backend types // prepare the attributes // prepare the headers // prepare the row // mock a subject configuration // mock a jms configuration // mock a subject // make sure the persist method will NEVER be invoked // invoke the handle method