MDL-50926 phpunit: Upgrade to phpunit 4.x

This commit is contained in:
Tony Levi 2015-07-27 00:30:00 +09:30 committed by Eloy Lafuente (stronk7)
parent f5d23fc162
commit b80b35d0fc
9 changed files with 734 additions and 105 deletions

View file

@ -0,0 +1,75 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Base test case class.
*
* @package core
* @category test
* @author Tony Levi <tony.levi@blackboard.com>
* @copyright 2015 Blackboard (http://www.blackboard.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Base class for PHPUnit test cases customised for Moodle
*
* It is intended for functionality common to both basic and advanced_testcase.
*
* @package core
* @category test
* @author Tony Levi <tony.levi@blackboard.com>
* @copyright 2015 Blackboard (http://www.blackboard.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class base_testcase extends PHPUnit_Framework_TestCase {
/**
* Note: we are overriding this method to remove the deprecated error
* @see https://tracker.moodle.org/browse/MDL-47129
*
* @param array $matcher
* @param string $actual
* @param string $message
* @param boolean $ishtml
*
* @deprecated 3.0
*/
public static function assertTag($matcher, $actual, $message = '', $ishtml = true) {
$dom = PHPUnit_Util_XML::load($actual, $ishtml);
$tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $ishtml);
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
self::assertTrue($matched, $message);
}
/**
* Note: we are overriding this method to remove the deprecated error
* @see https://tracker.moodle.org/browse/MDL-47129
*
* @param array $matcher
* @param string $actual
* @param string $message
* @param boolean $ishtml
*
* @deprecated 3.0
*/
public static function assertNotTag($matcher, $actual, $message = '', $ishtml = true) {
$dom = PHPUnit_Util_XML::load($actual, $ishtml);
$tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $ishtml);
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
self::assertFalse($matched, $message);
}
}

View file

@ -34,7 +34,7 @@
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class basic_testcase extends PHPUnit_Framework_TestCase {
abstract class basic_testcase extends \base_testcase {
/**
* Constructs a test case with the given name.

View file

@ -45,7 +45,7 @@ class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter {
}
}
// Fallback if something goes wrong.
parent::__construct(null, false, false, false);
parent::__construct(null, false, self::COLOR_DEFAULT, false);
}
protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect) {
@ -135,7 +135,7 @@ class Hacky_TextUI_Command_reader extends PHPUnit_TextUI_Command {
$verbose = isset($config['verbose']) ? $config['verbose'] : false;
$verbose = isset($arguments['verbose']) ? $arguments['verbose'] : $verbose;
$colors = isset($config['colors']) ? $config['colors'] : false;
$colors = isset($config['colors']) ? $config['colors'] : Hint_ResultPrinter::COLOR_DEFAULT;
$colors = isset($arguments['colors']) ? $arguments['colors'] : $colors;
$debug = isset($config['debug']) ? $config['debug'] : false;

View file

@ -30,6 +30,7 @@ require_once(__DIR__.'/classes/event_mock.php');
require_once(__DIR__.'/classes/event_sink.php');
require_once(__DIR__.'/classes/message_sink.php');
require_once(__DIR__.'/classes/phpmailer_sink.php');
require_once(__DIR__.'/classes/base_testcase.php');
require_once(__DIR__.'/classes/basic_testcase.php');
require_once(__DIR__.'/classes/database_driver_testcase.php');
require_once(__DIR__.'/classes/arraydataset.php');

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--moodle: this schema was generated using code from https://github.com/gooh/phpunit-schema-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xs:annotation>
<xs:documentation source="http://www.phpunit.de/manual/current/en/appendixes.configuration.html">
This Schema file defines the rules by which the XML configuration file of PHPUnit may be structured.
</xs:documentation>
<xs:documentation source="https://phpunit.de/manual/4.7/en/appendixes.configuration.html">
This Schema file defines the rules by which the XML configuration file of PHPUnit 4.7 may be structured.
</xs:documentation>
<xs:appinfo source="http://www.phpunit.de/manual/current/en/appendixes.configuration.html"/>
</xs:annotation>
<xs:element name="phpunit" type="phpUnitType">
<xs:annotation>
@ -35,7 +35,8 @@
<xs:complexType name="whiteListType">
<xs:complexContent>
<xs:extension base="filterType">
<xs:attribute name="addUncoveredFilesFromWhitelist" default="true" type="xs:boolean"/>
<xs:attribute name="addUncoveredFilesFromWhitelist" default="false" type="xs:boolean"/>
<xs:attribute name="processUncoveredFilesFromWhitelist" default="true" type="xs:boolean"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
@ -114,7 +115,9 @@
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="coverage-html"/>
<xs:enumeration value="coverage-text"/>
<xs:enumeration value="coverage-clover"/>
<xs:enumeration value="coverage-crap4j"/>
<xs:enumeration value="json"/>
<xs:enumeration value="plain"/>
<xs:enumeration value="tap"/>
@ -125,13 +128,10 @@
</xs:simpleType>
</xs:attribute>
<xs:attribute name="target" type="xs:anyURI"/>
<xs:attribute name="title" type="xs:string"/>
<xs:attribute name="charset" type="xs:string" default="UTF-8"/>
<xs:attribute name="yui" type="xs:boolean" default="true"/>
<xs:attribute name="highlight" type="xs:boolean" default="false"/>
<xs:attribute name="lowUpperBound" type="xs:nonNegativeInteger" default="35"/>
<xs:attribute name="highLowerBound" type="xs:nonNegativeInteger" default="70"/>
<xs:attribute name="logIncompleteSkipped" type="xs:boolean" default="false"/>
<xs:attribute name="showUncoveredFiles" type="xs:boolean" default="false"/>
</xs:complexType>
<xs:group name="pathGroup">
<xs:sequence>
@ -190,6 +190,7 @@
<xs:attribute name="bootstrap" type="xs:anyURI"/>
<xs:attribute name="cacheTokens" type="xs:boolean"/>
<xs:attribute name="colors" type="xs:boolean" default="false"/>
<xs:attribute name="columns" type="xs:integer" default="80"/>
<xs:attribute name="convertErrorsToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertNoticesToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertWarningsToExceptions" type="xs:boolean" default="true"/>
@ -201,7 +202,14 @@
<xs:attribute name="stopOnError" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnFailure" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnIncomplete" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnRisky" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnSkipped" type="xs:boolean" default="false"/>
<xs:attribute name="beStrictAboutTestsThatDoNotTestAnything" type="xs:boolean" default="false"/>
<xs:attribute name="beStrictAboutOutputDuringTests" type="xs:boolean" default="false"/>
<xs:attribute name="beStrictAboutTestSize" type="xs:boolean" default="false"/>
<xs:attribute name="beStrictAboutTodoAnnotatedTests" type="xs:boolean" default="false"/>
<xs:attribute name="beStrictAboutChangesToGlobalState" type="xs:boolean" default="false"/>
<xs:attribute name="checkForUnintentionallyCoveredCode" type="xs:boolean" default="false"/>
<xs:attribute name="strict" type="xs:boolean" default="false"/>
<xs:attribute name="testSuiteLoaderClass" type="xs:string" default="PHPUnit_Runner_StandardTestSuiteLoader"/>
<xs:attribute name="testSuiteLoaderFile" type="xs:anyURI"/>
@ -209,6 +217,7 @@
<xs:attribute name="timeoutForMediumTests" type="xs:integer" default="10"/>
<xs:attribute name="timeoutForLargeTests" type="xs:integer" default="60"/>
<xs:attribute name="verbose" type="xs:boolean" default="false"/>
<xs:attribute name="stderr" type="xs:boolean" default="false"/>
</xs:attributeGroup>
<xs:group name="configGroup">
<xs:all>
@ -238,11 +247,14 @@
<xs:element name="testsuites" type="testSuitesType" substitutionGroup="testSuiteFacet"/>
<xs:complexType name="testSuitesType">
<xs:sequence>
<xs:element name="testsuite" type="testSuiteType" maxOccurs="unbounded"/><!--moodle: added macOccures-->
<xs:element name="testsuite" type="testSuiteType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="testSuiteType">
<xs:group ref="pathGroup"/>
<xs:sequence>
<xs:group ref="pathGroup"/>
<xs:element name="exclude" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>