⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtk.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    {        // Create the progress bar.        $this->progress =& new GtkProgressBar(new GtkAdjustment(0, 0, 1, .1, 1, 0));        // Set the progress bar to print the percentage.        $this->progress->set_show_text(true);        return $this->progress;    }    /**     * Create the report text areas.     *     * The report area consists of one text area for failures, one     * text area for errors and one label for identification purposes.     * All three widgets are packed into a box.     *     * @access private     * @param  none     * @return &object The box containing the report areas.     */    function &_createReportAreas()    {        // Create the containing box.        $reportBox =& new GtkVBox;        // Create the identification label        $reportLabel =& new GtkLabel('Errors and Failures:');        $reportLabel->set_alignment(0, 0);        // Create the scrolled windows for the text areas.        $reportScroll =& new GtkScrolledWindow;        $dumpScroll   =& new GtkScrolledWindow;        // Make the scroll areas big enough.        $reportScroll->set_usize(-1, 150);        $dumpScroll->set_usize(-1, 150);        // Only show the vertical scroll bar when needed.        // Never show the horizontal scroll bar.        $reportScroll->set_policy(GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);        $dumpScroll->set_policy(GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);        // Create the text areas.        $this->reportArea =& new GtkText;        $this->dumpArea =& new GtkText;        // Don't let words get broken.        $this->reportArea->set_word_wrap(true);        $this->dumpArea->set_word_wrap(true);        // Pack everything in.        $reportBox->pack_start($reportLabel);        $reportScroll->add($this->reportArea);        $reportBox->pack_start($reportScroll);        $dumpScroll->add($this->dumpArea);        $reportBox->pack_start($dumpScroll);        return $reportBox;    }    /**     * Create a status label.     *     * A status line at the bottom of the application is used     * to notify the user of non-test related messages such as     * failures loading a test suite.     *     * @access private     * @param  none     * @return &object The status label.     */    function &_createStatusLine()    {        // Create the status label.        $this->statusLine =& new GtkLabel('');        $this->statusLine->set_alignment(0, 0);        return $this->statusLine;    }    /**     * Show a popup with information about the application.     *     * The popup should show information about the version,     * the author, the license, where to get the latest     * version and a short description.     *     * @access public     * @param  none     * @return void     */    function about()    {        // Create the new window.        $about =& new GtkWindow;        $about->set_title('About PHPUnit GUI Gtk');        $about->set_usize(250, -1);        // Put two vboxes in the hbox.        $vBox =& new GtkVBox;        $about->add($vBox);        // Create the labels.        $version     =& new GtkLabel(" Version: 1.0");        $license     =& new GtkLabel(" License: PHP License v3.0");        $where       =& new GtkLabel(" Download from: http://pear.php.net/PHPUnit/");        $unitAuth    =& new GtkLabel(" PHPUnit Author: Sebastian Bergman");        $gtkAuth     =& new GtkLabel(" Gtk GUI Author: Scott Mattocks");        // Align everything to the left        $where->set_alignment(0, .5);        $version->set_alignment(0, .5);        $license->set_alignment(0, .5);        $gtkAuth->set_alignment(0, .5);        $unitAuth->set_alignment(0, .5);        // Pack everything into the vBox;        $vBox->pack_start($version);        $vBox->pack_start($license);        $vBox->pack_start($where);        $vBox->pack_start($unitAuth);        $vBox->pack_start($gtkAuth);        // Connect the destroy signal.        $about->connect('destroy', array('gtk', 'true'));        // Show the goods.        $about->show_all();    }    /**     * Load the test suite.     *     * This method tries to load test suite based on the user     * info. If the user passes the name of a tests suite, it     * is instantiated and a new object is returned. If the     * user passes a file that contains a test suite, the class     * is instantiated and a new object is returned. If the user     * passes a file that contains a test case, the test case is     * passed to a new test suite and the new suite object is     * returned.     *     * @access public     * @param  string  The file that contains a test case/suite or the classname.     * @return &object The new test suite.     */    function &loadTest(&$file)    {        // Check to see if a class name was given.        if (is_a($file, 'PHPUnit_TestSuite')) {            return $file;        } elseif (class_exists($file)) {            require_once 'PHPUnit/TestSuite.php';            return new PHPUnit_TestSuite($file);        }        // Check that the file exists.        if (!@is_readable($file)) {            $this->_showStatus('Cannot find file: ' . $file);            return false;        }        $this->_showStatus('Loading test suite...');        // Instantiate the class.        // If the path is /path/to/test/TestClass.php        // the class name should be test_TestClass        require_once $file;        $className = str_replace(DIRECTORY_SEPARATOR, '_', $file);        $className = substr($className, 0, strpos($className, '.'));        require_once 'PHPUnit/TestSuite.php';        return new PHPUnit_TestSuite($className);    }    /**     * Run the test suite.     *     * This method runs the test suite and updates the messages     * for the user. When finished it changes the status line     * to 'Test Complete'     *     * @access public     * @param  none     * @return void     */    function runTest()    {        // Notify the user that the test is running.        $this->_showStatus('Running Test...');        // Run the test.        $result = PHPUnit::run($this->suite);        // Update the labels.        $this->_setLabelValue($this->numberOfRuns,     $result->runCount());        $this->_setLabelValue($this->numberOfErrors,   $result->errorCount());        $this->_setLabelValue($this->numberOfFailures, $result->failureCount());        // Update the progress bar.        $this->_updateProgress($result->runCount(),                               $result->errorCount(),                               $result->failureCount()                               );        // Show the errors.        $this->_showFailures($result->errors(), $this->dumpArea);        // Show the messages from the tests.        if ($this->showPassed->get_active()) {            // Show failures and success.            $this->_showAll($result, $this->reportArea);        } else {            // Show only failures.            $this->_showFailures($result->failures(), $this->reportArea);        }        // Update the status message.        $this->_showStatus('Test complete');    }    /**     * Set the text of a label.     *     * Change the text of a given label.     *     * @access private     * @param  widget  &$label The label whose value is to be changed.     * @param  string  $value  The new text of the label.     * @return void     */    function _setLabelValue(&$label, $value)    {        $label->set_text($value);    }    /**     * The main work of the application.     *     * Load the test suite and then execute the tests.     *     * @access public     * @param  none     * @return void     */    function run()    {        // Load the test suite.        $this->suite =& $this->loadTest($this->suiteField->get_text());        // Check to make sure the suite was loaded properly.        if (!is_object($this->suite)) {            // Raise an error.            $this->_showStatus('Could not load test suite.');            return false;        }        // Run the tests.        $this->runTest();    }    /**     * Update the status message.     *     * @access private     * @param  string  $status The new message.     * @return void     */    function _showStatus($status)    {        $this->statusLine->set_text($status);    }    /**     * Alias for main()     *     * @see main     */    function show($showPassed = true)    {        $this->main($showPassed);    }    /**     * Add a suite to the tests.     *     * This method is require by SetupDecorator. It adds a     * suite to the the current set of suites.     *     * @access public     * @param  object $testSuite The suite to add.     * @return void     */    function addSuites($testSuite)    {        if (!is_array($testSuite)) {            settype($testSuite, 'array');        }        foreach ($testSuite as $suite) {            if (is_a($this->suite, 'PHPUnit_TestSuite')) {                $this->suite->addTestSuite($suite->getName());            } else {                $this->suite =& $this->loadTest($suite);            }            // Set the suite field.            $text = $this->suiteField->get_text();            if (empty($text)) {                $this->suiteField->set_text($this->suite->getName());            }        }    }    /**     * Show all test messages.     *     * @access private     * @param  object  The TestResult from the test suite.     * @return void     */    function _showAll(&$result)    {        // Clear the area first.        $this->reportArea->delete_text(0, -1);        $this->reportArea->insert_text($result->toString(), 0);    }    /**     * Show failure/error messages in the given text area.     *     * @access private     * @param  object  &$results The results of the test.     * @param  widget  &$area    The area to show the results in.     */    function _showFailures(&$results, &$area)    {        $area->delete_text(0, -1);        foreach (array_reverse($results, true) as $result) {            $area->insert_text($result->toString(), 0);        }    }    /**     * Update the progress indicator.     *     * @access private     * @param  integer $runs     * @param  integer $errors     * @param  integer $failures     * @return void     */    function _updateProgress($runs, $errors, $failures)    {        $percentage = 1 - (($errors + $failures) / $runs);        $this->progress->set_percentage($percentage);    }}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -