Changeset 145

Show
Ignore:
Timestamp:
02/06/07 18:41:05 (2 years ago)
Author:
hans
Message:

Cleaning up some unit tests & adding Phing build script for tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/test/classes/phing/BuildFileTest.php

    r144 r145  
    3939    protected $project; 
    4040     
    41     public $logBuffer; 
    42     public $fullLogBuffer; 
     41    /** 
     42     * @var array Array of log BuildEvent objects. 
     43     */ 
     44    public $logBuffer = array(); 
    4345     
    4446    private $outBuffer; 
     
    4648    private $buildException; 
    4749     
     50    /** 
     51     * Asserts that the log buffer contains specified message at specified priority. 
     52     * @param string $$expected Message subsctring 
     53     * @param int $priority Message priority (default: any) 
     54     * @param string $errmsg The error message to display. 
     55     */ 
     56    protected function assertInLogs($expected, $priority = null, $errormsg = "Expected to find '%s' in logs: %s") 
     57    { 
     58        foreach($this->logBuffer as $log) { 
     59                if (false !== stripos($log, $expected)) { 
     60                        return; 
     61                } 
     62        } 
     63        $this->fail(sprintf($errormsg, $expected, var_export($this->logBuffer,true))); 
     64    } 
    4865     
    4966    /** 
     
    6380    protected function expectLog($target, $log) {  
    6481        $this->executeTarget($target); 
    65         $realLog = $this->getLog(); 
    66         $this->assertEquals($log, $realLog); 
     82        $this->assertInLogs($log); 
    6783    } 
    6884 
     
    7389    protected function expectLogContaining($target, $log) {  
    7490        $this->executeTarget($target); 
    75         $realLog = $this->getLog(); 
    76         $this->assertTrue(strpos($realLog, $log) !== false, "expecting log to contain \"" . $log . "\" log was \"" 
    77                    . $realLog . "\""); 
    78     } 
    79  
    80     /** 
    81      *  Gets the log the BuildFileTest object. 
    82      *  only valid if configureProject() has 
    83      *  been called. 
    84      * @pre logBuffer!=null 
    85      * @return    The log value 
    86      */     
    87     protected function getLog() {  
    88         return $this->logBuffer; 
     91        $this->assertInLogs($log); 
    8992    } 
    9093 
     
    9598    protected function expectDebuglog($target, $log) {  
    9699        $this->executeTarget($target); 
    97         $realLog = $this->getFullLog(); 
    98         $this->assertEquals($log, $realLog); 
    99     } 
    100  
    101     /** 
    102      *  Gets the log the BuildFileTest object. 
    103      *  only valid if configureProject() has 
    104      *  been called. 
    105      * @pre fullLogBuffer!=null 
    106      * @return    The log value 
    107      */ 
    108     protected function getFullLog() {  
    109         return $this->fullLogBuffer; 
     100        $this->assertInLogs($log, Project::MSG_DEBUG); 
    110101    } 
    111102 
     
    344335    private $parent; 
    345336 
    346     function __construct($parent) { 
    347     $this->parent = $parent; 
     337    public function __construct($parent) { 
     338       $this->parent = $parent; 
    348339    } 
    349340 
     
    408399     */ 
    409400    public function messageLogged(BuildEvent $event) {         
    410         if ($event->getPriority() == Project::MSG_INFO || 
    411             $event->getPriority() == Project::MSG_WARN || 
    412             $event->getPriority() == Project::MSG_ERR) { 
    413             $this->parent->logBuffer .= $event->getMessage(); 
    414         } 
    415         $this->parent->fullLogBuffer .= $event->getMessage(); 
     401        $this->parent->logBuffer[] = $event->getMessage(); 
    416402    } 
    417403} 
  • trunk/test/classes/phing/tasks/TypedefTaskTest.php

    r123 r145  
    5050 
    5151    public function testGlobal() { 
    52         $this->expectLog("testGlobal", ""); 
     52        $this->expectLog("testGlobal", "Adding reference: global -> TypedefTestType"); 
    5353        $refs = $this->project->getReferences(); 
    5454        $ref = $refs["global"]; 
     
    5858 
    5959    public function testLocal() { 
    60         $this->expectLog("testLocal", ""); 
     60        $this->expectLog("testLocal", "Adding reference: local -> TypedefTestType"); 
    6161        $refs = $this->project->getReferences(); 
    6262        $ref = $refs["local"];