__construct() public method

Constructor.
public __construct ( string $inClassName, string $inSourceFile = '', string $outClassName = '', string $outSourceFile = '' )
$inClassName string
$inSourceFile string
$outClassName string
$outSourceFile string
Beispiel #1
0
 /**
  * Constructor.
  *
  * @param string $inClassName
  * @param string $inSourceFile
  * @param string $outClassName
  * @param string $outSourceFile
  * @throws RuntimeException
  */
 public function __construct($inClassName, $inSourceFile = '', $outClassName = '', $outSourceFile = '')
 {
     if (empty($inSourceFile)) {
         $inSourceFile = $inClassName . '.php';
     }
     if (!is_file($inSourceFile)) {
         throw new PHPUnit_Framework_Exception(sprintf('"%s" could not be opened.', $inSourceFile));
     }
     if (empty($outClassName)) {
         $outClassName = substr($inClassName, 0, strlen($inClassName) - 4);
     }
     if (empty($outSourceFile)) {
         $outSourceFile = dirname($inSourceFile) . DIRECTORY_SEPARATOR . $outClassName . '.php';
     }
     parent::__construct($inClassName, $inSourceFile, $outClassName, $outSourceFile);
 }
Beispiel #2
0
    /**
     * Constructor.
     *
     * @param string $inClassName
     * @param string $inSourceFile
     * @param string $outClassName
     * @param string $outSourceFile
     * @throws RuntimeException
     */
    public function __construct($inClassName, $inSourceFile = '', $outClassName = '', $outSourceFile = '')
    {
        if (class_exists($inClassName)) {
            $reflector    = new ReflectionClass($inClassName);
            $inSourceFile = $reflector->getFileName();

            if ($inSourceFile === FALSE) {
                $inSourceFile = '<internal>';
            }

            unset($reflector);
        } else {
            if (empty($inSourceFile)) {
                $possibleFilenames = array(
                  $inClassName . '.php',
                  PHPUnit_Util_Filesystem::classNameToFilename($inClassName)
                );

                foreach ($possibleFilenames as $possibleFilename) {
                    if (is_file($possibleFilename)) {
                        $inSourceFile = $possibleFilename;
                    }
                }
            }

            if (empty($inSourceFile)) {
                throw new PHPUnit_Framework_Exception(
                  sprintf(
                    'Neither "%s" nor "%s" could be opened.',
                    $possibleFilenames[0],
                    $possibleFilenames[1]
                  )
                );
            }

            if (!is_file($inSourceFile)) {
                throw new PHPUnit_Framework_Exception(
                  sprintf(
                    '"%s" could not be opened.',

                    $inSourceFile
                  )
                );
            }

            $inSourceFile = realpath($inSourceFile);
            include_once $inSourceFile;

            if (!class_exists($inClassName)) {
                throw new PHPUnit_Framework_Exception(
                  sprintf(
                    'Could not find class "%s" in "%s".',

                    $inClassName,
                    $inSourceFile
                  )
                );
            }
        }

        if (empty($outClassName)) {
            $outClassName = $inClassName . 'Test';
        }

        if (empty($outSourceFile)) {
            $outSourceFile = dirname($inSourceFile) . DIRECTORY_SEPARATOR . $outClassName . '.php';
        }

        parent::__construct(
          $inClassName, $inSourceFile, $outClassName, $outSourceFile
        );
    }