I’m trying to improve my coding practices for our MW extensions, and I’m very 
confused by whether my problem with PHPUnit is a problem with the test I’m 
writing or with the extension object class I’m trying to test.

My extension uses some custom database tables to store the properties of 
objects that are created during execution. In older versions of MW, I could 
just create an object and test that the methods of the object class returned 
appropriate values for known data that was already in the database. Now, 
instantiating an object is creating temporary tables that don’t exist and 
causing fatal errors. Example:

7) CacaoModelAnnotationTest::testNewCacaoModelAnnotationSuccess
Wikimedia\Rdbms\DBQueryError: A database query error has occurred. Did you 
forget to run your application's database schema updater after upgrading? 
Query: SELECT  
annotation_id,row_id,original_row_data,annotation_timestamp,user_id,team_id,session_id,annotation_inning
  FROM `unittest_cacao_annotation` INNER JOIN `unittest_cacao_user` ON 
((annotation_user = cacao_user.id))   WHERE annotation_id = "6057"  
Function: CacaoModelAnnotation::load
Error: 1054 Unknown column 'cacao_user.id' in 'on clause' (localhost)

This is the load method from class CacaoModelAnnotation:

        public function load() {
                try{
                        wfProfileIn( __METHOD__ );
        
                        if ( $this->loaded ) {
                                return false;
                        }

                        MWDebug::log( __METHOD__ . ' called for annotation_id: 
' . $this->id );

                        $dbr = wfGetDB( DB_SLAVE );
                
                        // query to get annotation attributes
                        $result = $dbr->select(
                                array( 'cacao_annotation', 'cacao_user' ),
                                array( 
                                        'annotation_id', 'row_id', 
'original_row_data',  'annotation_timestamp', 
                                        'user_id', 'team_id', 'session_id', 
'annotation_inning'
                                ),
                                'annotation_id = "' . $this->id . '"',
                                __METHOD__,
                                array(),
                                array(
                                        'cacao_user' => array('INNER JOIN', 
'annotation_user = cacao_user.id' ),
                                )
                        );
                        if ( $dbr->numRows($result) == 0 ) {
                                throw new CacaoException( 
wfMessage('cacao-annotation-load-returned-zero-rows', $this->id)->text() );
                        }
                        $resultRow = $dbr->fetchObject( $result ); 
                        $this->loadFromResultRow($resultRow);
                
                        wfProfileOut( __METHOD__ );
                }catch(CacaoException $e){
                        if(!isset($thrown)){
                                throw $e;
                        }
                        $thrown = true; 
                }       
        }

Is there a good example of an extension that uses custom database tables that I 
can use as a role model?
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to