Apache Zeta Components Manual :: File Source for regression_test.php

Source for file regression_test.php

Documentation is available at regression_test.php

  1. <?php
  2. /**
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  * 
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  * 
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  *
  21.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22.  * @version //autogentag//
  23.  * @filesource
  24.  * @package Feed
  25.  * @subpackage Tests
  26.  */
  27.  
  28. /**
  29.  * @package Feed
  30.  * @subpackage Tests
  31.  */
  32. {
  33.     /**
  34.      * How to sort the test files: 'mtime' sorts by modification time, any other
  35.      * value sorts by name.
  36.      */
  37.     const SORT_MODE = 'name';
  38.  
  39.     protected $files = array();
  40.     protected $currentFile;
  41.  
  42.     public function __construct()
  43.     {
  44.         if self::SORT_MODE === 'mtime' )
  45.         {
  46.             // Sort by modification time to get updated tests first
  47.             usort$this->files,
  48.                    array$this'sortTestsByMtime' ) );
  49.         }
  50.         else
  51.         {
  52.             // Sort it, then the file a.in will be processed first. Handy for development.
  53.             usort$this->files,
  54.                    array$this'sortTestsByName' ) );
  55.         }
  56.         parent::__construct();
  57.     }
  58.  
  59.     public function getName$withDataSet TRUE )
  60.     {
  61.         return $this->currentFile;
  62.     }
  63.  
  64.     public function getFiles()
  65.     {
  66.         return $this->files;
  67.     }
  68.  
  69.     public function setCurrentFile$file )
  70.     {
  71.         $this->currentFile = $file;
  72.     }
  73.  
  74.     protected function readDirRecursively$dir&$total$onlyWithExtension false )
  75.     {
  76.         $extensionLength strlen$onlyWithExtension );
  77.         $path opendir$dir );
  78.  
  79.         if $path === false )
  80.         {
  81.             return;
  82.         }
  83.  
  84.         while false !== $file readdir$path ) ) )
  85.         {
  86.             if $file !== "." && $file !== ".." )
  87.             {
  88.                 $new $dir DIRECTORY_SEPARATOR $file;
  89.  
  90.                 if is_file$new ) )
  91.                 {
  92.                     if !$onlyWithExtension ||
  93.                          substr$file,  -$extensionLength === ".{$onlyWithExtension})
  94.                     {
  95.                         $total[array'file' => $new,
  96.                                           'mtime' => filemtime$new ) );
  97.                     }
  98.                 }
  99.                 elseif is_dir$new ) )
  100.                 {
  101.                     $this->readDirRecursively$new$total$onlyWithExtension );
  102.                 }
  103.             }
  104.         }
  105.     }
  106.  
  107.     protected function sortTestsByMtime$a$b )
  108.     {
  109.         if $a['mtime'!= $b['mtime')
  110.         {
  111.             return $a['mtime'$b['mtime': -1;
  112.         }
  113.         return strnatcmp$a['file']$b['file');
  114.     }
  115.  
  116.     protected function sortTestsByName$a$b )
  117.     {
  118.         return strnatcmp$a['file']$b['file');
  119.     }
  120.  
  121.     protected function outFileName$file$inExtension$outExtension '.out' )
  122.     {
  123.         $baseFile substr$file0strlen$file strlen$inExtension ) );
  124.         return $baseFile $outExtension;
  125.     }
  126.  
  127.     public function runTest()
  128.     {
  129.         if $this->currentFile === false )
  130.         {
  131.             throw new PHPUnit_Framework_ExpectationFailedException"No currentFile set for test " . __CLASS__ );
  132.         }
  133.  
  134.         $exception null;
  135.         $this->retryTest true;
  136.         while $this->retryTest )
  137.         {
  138.             try
  139.             {
  140.                 $this->retryTest false;
  141.                 $this->testRunRegression$this->currentFile );
  142.             }
  143.             catch Exception $e )
  144.             {
  145.                 $exception $e;
  146.             }
  147.         }
  148.  
  149.         if $exception !== null )
  150.         {
  151.             throw $exception;
  152.         }
  153.     }
  154.  
  155.     public static function suite()
  156.     {
  157.         return new ezcMvcRegressionSuite__CLASS__ );
  158.     }
  159. }
  160. ?>
Documentation generated by phpDocumentor 1.4.3