oxid esales – show me your 94% Unit Test coverage!

August 26, 2009

Zend, PHP-Architect and all you others out there praising open source projects… can you please give more priority to really quality work?

I was desperately searching for OXID esales Unit Tests after checking out their community edition from svn. Or are the Unit Tests only accessible for paying customers?

The blog post claiming the 93.x % code coverage:

code-coverage

While searching for it, I came across this forum entry:


http://www.oxid-esales.com/forum/showthread.php?p=12831

Which makes me kind of happy, since I am not the only one who does not just rely on the PHP community back patting the “great” open source projects like WordPress .. and now OXID ?

Curious what the OXID people will reply to this?

I am waiting … also for Zend and PHP Architect on this topic….

oxid esales – The extend parade!

August 26, 2009

In oxid esales everybody likes to extend everything.

Its a bunch of happy ox-classes that just love each other, hug eachother and extend, make out the whooooooole day.

A simple example

oxI18n extends oxBase extends oxSuperCfg

Ok, I understand that you want every happy oxid-super-object to be able to read, write, delete the config, right?

But what the heck are you doing? Did you guys ever hear about design patterns?.

Maybe you should take a look at our friends from pureMVC. They have their patterns well organized in an extra folder:

puremvc-patterns

It gets even better: The Super-Extender

When you want to create an oxoutput object with the following??modules?? loaded:

sub/suboutput1&sub/suboutput2&sub/suboutput3

it magically creates / extends / parties with your classes!

It uses a kind of extension g*ngb*ng function to hook up everyone with everything:


public function getClassName( $sClassName )
{
        $aModules = $this->getConfig()->getConfigParam( 'aModules' );
        if ( is_array( $aModules ) &&
          array_key_exists( $sClassName, $aModules ) ) {
            //multiple inheritance implementation
            //in case we have multiple modules:
            //like oxoutput
               //=> sub/suboutput1&sub/suboutput2&sub/suboutput3
            $aClassChain = explode( "&", $aModules[$sClassName] );

            $sParent = $sClassName;

            //security: just preventing string termination
            $sParent = str_replace(chr(0), '', $sParent);

            //building middle classes if needed
            $sClassName =
            $this->_makeSafeModuleClassParents( $aClassChain, $sParent );
    }

 // check if there is a path, if yes, remove it
 $sClassName = basename( $sClassName );

 return $sClassName;
}

....

/**
 * Creates middle classes if needed.
*
* @param array  $aClassChain Module names
* @param string $sBaseModule Oxid base class
*
* @throws oxSystemComponentException missing system
*             component exception
*
* @return string
*/
private function _makeSafeModuleClassParents( $aClassChain, $sBaseModule )
{
  $myConfig = $this->getConfig();
  $sParent = $sBaseModule;

  //building middle classes if needed
  foreach ($aClassChain as $sModule) {
     //creating middle classes
     //e.g. class suboutput1_parent extends oxoutput {}
     //     class suboutput2_parent extends suboutput1 {}
     //$sModuleClass = $this->getClassName($sModule);

    //security: just preventing string termination
    $sModule = str_replace(chr(0), '', $sModule);

    //get parent and module class names from sub/suboutput2
    $sParentClass = basename($sParent);
    $sModuleClass = basename($sModule);

    //P
    //$sInitClass = "class ".$sModuleClass."_parent extends $sParentClass
    //{ function ".$sModuleClass."_parent(){
    // return ".$sParentClass."::".$sParentClass."();} }";
    $sInitClass = "class ".$sModuleClass."_parent extends $sParentClass {}";

    //initializing middle class
    if (!class_exists($sModuleClass."_parent", false)) {
       eval($sInitClass);
    }
   $sParentPath = $myConfig->getConfigParam( 'sShopDir' ).
                              "/modules/".$sModule.".php";

   //including original file
   if ( file_exists( $sParentPath ) ) {
	require_once $sParentPath;
   } elseif ( !class_exists( $sModuleClass ) ) {
        //to avoid problems with unitest and only throw a
        // exception if class does not exists MAFI
	$oEx = new oxSystemComponentException();
	$oEx->setMessage('EXCEPTION_SYSTEMCOMPONENT_CLASSNOTFOUND');
	$oEx->setComponent($sModule);
   }

   $sParent = $sModule;
 }

   //returning the last module from the chain
   $sClassName = $aClassChain[count($aClassChain) - 1];
   return $sClassName;

}

So … with all the magic party stuff you end up having created / included these classes, all done by their wonderful __autload function:

  • class oxoutput extends oxSuperCfg { … }
  • class suboutput1_parent extends oxoutput {}
  • class suboutput2_parent extends suboutput1 {}
  • class suboutput3_parent extends suboutput2 {}

But what the hell is this stuff for?

A module like MyOrder extends MyOrder_parent. For what? Somebody enlighten me!

You extend non-existing classes just for the sake of creating them from the magic __autoload function, is that it?

Related post:

oxid esales – show me your 94% Unit Test coverage!

Trac does not like PHP namespaces either….

August 25, 2009

ns2


http://trac.doctrine-project.org/browser/trunk/lib/Doctrine/Common/ClassLoader.php

__sh*tload to the rescue!

August 23, 2009

How do you think the PureMVC guy tests this autoload function?

/**
* Checks all paths defined in $_includePaths for
* the existence of $class and loads $class if found.
*
* @param string $class The class to search for.
*/
function __autoload( $class )
{
    $_includePaths = array(
                       PMVC_BASE_DIR . '/org/puremvc/php/core',
                       PMVC_BASE_DIR . '/org/puremvc/php/interfaces',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/command',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/facade',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/mediator',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/observer',
                       PMVC_BASE_DIR . '/org/puremvc/php/patterns/proxy',
     );

    $classPath = get_include_path();
    $classPathTokens = explode( ':', $classPath );

    $classXtn = '.php';

    foreach ($classPathTokens as $prefix)
    {
        foreach ($_includePaths as $includePath)
        {
             $path = "$includePath/$class$classXtn";
             if (file_exists($path))
             {
                require_once $path;
                return;
             }
       }
   }

}

Taken from:
http://svn.puremvc.org/PureMVC_PHP/tags/1.0.2/puremvc_autoloader.php

Dude, did you know that your get_include_path() is not used at all in this autoload function?

But here, I unit tested it for you

autoload unit test

If you don’t get this joke see here

Yes we can Unit Test!

August 23, 2009

The PHP Community learned a new buzz word.

PHPUnit

And some early-adopters in the php world were brave enough to actually use this new thing called unit testing in their opensource projects and expose its usage to the outside world.

  • Unit Testing is good.
  • Unit Tests are necessary.
  • Unit Tests can improve the quality.
  • Unit Tests add trust to your open source project.

Something like that must have been on the mind of the guy who unit tested the PureMVC PHP Port. He was so proud of his achievement, being an early adopter of unit tests in php, that he wanted to communicate the fact that his framework is quite well unit-tested:

Yes we can Unit Test!

You cannot believe what you are seeing? Have a look for yourself:
http://trac.puremvc.org/PureMVC_PHP_UnitTests

Now, was this unit testing done by a web designer?

Seems like it, and we have some exclusive coverage of his daily unit testing work:

unit-testing-webdesigner

But how bad is the code really?

I tell ya…. there is only so much a man can take. See for yourself:
http://svn.puremvc.org/PureMVC_PHP/tags/1.0.2/

Found anything useful in these Unit Test?

Please leave a comment if you think you made some sense out of it!


Follow

Get every new post delivered to your Inbox.