Source for file Skeleton.php
Documentation is available at Skeleton.php
// +------------------------------------------------------------------------+
// +------------------------------------------------------------------------+
// | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// $Id: Skeleton.php,v 1.11.2.1 2004/10/01 06:11:54 sebastian Exp $
* Class for creating a PHPUnit2_Framework_TestCase skeleton file.
* This class will take a classname as a parameter on construction and will
* create a PHP file that contains the skeleton of a PHPUnit2_Framework_TestCase
* require_once 'PHPUnit2/Util/Skeleton.php';
* $skeleton = new PHPUnit2_Util_Skeleton(
* 'PHPUnit2_Util_Skeleton',
* 'PHPUnit2/Util/Skeleton.php'
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright Copyright © 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
const templateClassHeader =
if (!defined("PHPUnit2_MAIN_METHOD")) {
define("PHPUnit2_MAIN_METHOD", "%sTest::main");
require_once "PHPUnit2/Framework/IncompleteTestError.php";
require_once "PHPUnit2/Framework/TestCase.php";
* Generated by PHPUnit2_Util_Skeleton on %s at %s.
class %sTest extends PHPUnit2_Framework_TestCase {
public static function main() {
require_once "PHPUnit2/Framework/TestSuite.php";
require_once "PHPUnit2/TextUI/TestRunner.php";
$suite = new PHPUnit2_Framework_TestSuite("%sTest");
$result = PHPUnit2_TextUI_TestRunner::run($suite);
const templateClassFooter =
if (PHPUnit2_MAIN_METHOD == "%sTest::main") {
* @todo Implement test%s().
public function test%s() {
throw new PHPUnit2_Framework_IncompleteTestError;
// {{{ public function __construct($className, $classSourceFile = '')
* @param string $className
* @param string $classSourceFile
public function __construct($className, $classSourceFile = '') {
if ($classSourceFile == '') {
$classSourceFile = $className . '.php';
throw new Exception ('Could not open ' . $classSourceFile . '.');
throw new Exception ('Could not find class "' . $className . '".');
// {{{ public function generate()
* Generates the test class' source.
$class = new ReflectionClass ($this->className);
foreach ($class->getMethods () as $method) {
if (!$method->isConstructor () &&
!$method->isAbstract () &&
$method->isUserDefined () &&
$method->getDeclaringClass ()->getName () == $this->className) {
$testClassSource .= $this->testMethod($method->getName ());
// {{{ public function write()
* Generates the test class and writes it to a source file.
public function write($file = '') {
if ($fp = @fopen($file, 'w')) {
// {{{ protected function testClassHeader($className)
* @param string $className
self ::templateClassHeader ,
// {{{ protected function testClassFooter($className)
* @param string $className
self ::templateClassFooter ,
// {{{ protected function testMethod($methodName)
* @param string $methodName
$methodName = ucfirst($methodName);
* vim600: et sw=2 ts=2 fdm=marker
Documentation generated on Mon, 11 Mar 2019 13:58:19 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|