Include phpunit license for backported classes
authorErik Bernhardson <ebernhardson@wikimedia.org>
Fri, 25 Sep 2015 17:58:35 +0000 (10:58 -0700)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Fri, 25 Sep 2015 18:18:20 +0000 (11:18 -0700)
Bug: T113765
Change-Id: I3f4242d4323d447097b2de42bfade969a6e3fd9d

tests/phpunit/includes/ConsecutiveParametersMatcher.php [deleted file]
tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php
tests/phpunit/includes/phpunit/ConsecutiveParametersMatcher.php [new file with mode: 0644]
tests/phpunit/includes/phpunit/LICENSE [new file with mode: 0644]
tests/phpunit/includes/phpunit/README [new file with mode: 0644]

diff --git a/tests/phpunit/includes/ConsecutiveParametersMatcher.php b/tests/phpunit/includes/ConsecutiveParametersMatcher.php
deleted file mode 100644 (file)
index 8de467f..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-// @codingStandardsIgnoreFile
-/*
- * This file is part of the PHPUnit_MockObject package.
- *
- * (c) Sebastian Bergmann <sebastian@phpunit.de>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Invocation matcher which looks for sets of specific parameters in the invocations.
- *
- * Checks the parameters of the incoming invocations, the parameter list is
- * checked against the defined constraints in $parameters. If the constraint
- * is met it will return true in matches().
- *
- * It takes a list of match groups and and increases a call index after each invocation.
- * So the first invocation uses the first group of constraints, the second the next and so on.
- */
-class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
-{
-    /**
-     * @var array
-     */
-    private $_parameterGroups = array();
-
-    /**
-     * @var array
-     */
-    private $_invocations = array();
-
-    /**
-     * @param array $parameterGroups
-     */
-    public function __construct(array $parameterGroups)
-    {
-        foreach ($parameterGroups as $index => $parameters) {
-            foreach ($parameters as $parameter) {
-                if (!($parameter instanceof \PHPUnit_Framework_Constraint)) {
-                    $parameter = new \PHPUnit_Framework_Constraint_IsEqual($parameter);
-                }
-                $this->_parameterGroups[$index][] = $parameter;
-            }
-        }
-    }
-
-    /**
-     * @return string
-     */
-    public function toString()
-    {
-        $text = 'with consecutive parameters';
-
-        return $text;
-    }
-
-    /**
-     * @param  PHPUnit_Framework_MockObject_Invocation $invocation
-     * @return bool
-     */
-    public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
-    {
-        $this->_invocations[] = $invocation;
-        $callIndex            = count($this->_invocations) - 1;
-        $this->verifyInvocation($invocation, $callIndex);
-
-        return false;
-    }
-
-    public function verify()
-    {
-        foreach ($this->_invocations as $callIndex => $invocation) {
-            $this->verifyInvocation($invocation, $callIndex);
-        }
-    }
-
-    /**
-     * Verify a single invocation
-     *
-     * @param  PHPUnit_Framework_MockObject_Invocation      $invocation
-     * @param  int                                          $callIndex
-     * @throws PHPUnit_Framework_ExpectationFailedException
-     */
-    private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex)
-    {
-
-        if (isset($this->_parameterGroups[$callIndex])) {
-            $parameters = $this->_parameterGroups[$callIndex];
-        } else {
-          // no parameter assertion for this call index
-            return;
-        }
-
-        if ($invocation === null) {
-            throw new PHPUnit_Framework_ExpectationFailedException(
-                'Mocked method does not exist.'
-            );
-        }
-
-        if (count($invocation->parameters) < count($parameters)) {
-            throw new PHPUnit_Framework_ExpectationFailedException(
-                sprintf(
-                    'Parameter count for invocation %s is too low.',
-                    $invocation->toString()
-                )
-            );
-        }
-
-        foreach ($parameters as $i => $parameter) {
-            $parameter->evaluate(
-                $invocation->parameters[$i],
-                sprintf(
-                    'Parameter %s for invocation #%d %s does not match expected ' .
-                    'value.',
-                    $i,
-                    $callIndex,
-                    $invocation->toString()
-                )
-            );
-        }
-    }
-}
index 090f439..ef6f847 100644 (file)
@@ -24,7 +24,7 @@ use MediaWikiTestCase;
 use Monolog\Logger;
 
 // not available in the version of phpunit mw uses, so copied into repo
-require_once __DIR__ . '/../../../ConsecutiveParametersMatcher.php';
+require_once __DIR__ . '/../../../phpunit/ConsecutiveParametersMatcher.php';
 
 class KafkaHandlerTest extends MediaWikiTestCase {
 
diff --git a/tests/phpunit/includes/phpunit/ConsecutiveParametersMatcher.php b/tests/phpunit/includes/phpunit/ConsecutiveParametersMatcher.php
new file mode 100644 (file)
index 0000000..8de467f
--- /dev/null
@@ -0,0 +1,124 @@
+<?php
+// @codingStandardsIgnoreFile
+/*
+ * This file is part of the PHPUnit_MockObject package.
+ *
+ * (c) Sebastian Bergmann <sebastian@phpunit.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Invocation matcher which looks for sets of specific parameters in the invocations.
+ *
+ * Checks the parameters of the incoming invocations, the parameter list is
+ * checked against the defined constraints in $parameters. If the constraint
+ * is met it will return true in matches().
+ *
+ * It takes a list of match groups and and increases a call index after each invocation.
+ * So the first invocation uses the first group of constraints, the second the next and so on.
+ */
+class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
+{
+    /**
+     * @var array
+     */
+    private $_parameterGroups = array();
+
+    /**
+     * @var array
+     */
+    private $_invocations = array();
+
+    /**
+     * @param array $parameterGroups
+     */
+    public function __construct(array $parameterGroups)
+    {
+        foreach ($parameterGroups as $index => $parameters) {
+            foreach ($parameters as $parameter) {
+                if (!($parameter instanceof \PHPUnit_Framework_Constraint)) {
+                    $parameter = new \PHPUnit_Framework_Constraint_IsEqual($parameter);
+                }
+                $this->_parameterGroups[$index][] = $parameter;
+            }
+        }
+    }
+
+    /**
+     * @return string
+     */
+    public function toString()
+    {
+        $text = 'with consecutive parameters';
+
+        return $text;
+    }
+
+    /**
+     * @param  PHPUnit_Framework_MockObject_Invocation $invocation
+     * @return bool
+     */
+    public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
+    {
+        $this->_invocations[] = $invocation;
+        $callIndex            = count($this->_invocations) - 1;
+        $this->verifyInvocation($invocation, $callIndex);
+
+        return false;
+    }
+
+    public function verify()
+    {
+        foreach ($this->_invocations as $callIndex => $invocation) {
+            $this->verifyInvocation($invocation, $callIndex);
+        }
+    }
+
+    /**
+     * Verify a single invocation
+     *
+     * @param  PHPUnit_Framework_MockObject_Invocation      $invocation
+     * @param  int                                          $callIndex
+     * @throws PHPUnit_Framework_ExpectationFailedException
+     */
+    private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex)
+    {
+
+        if (isset($this->_parameterGroups[$callIndex])) {
+            $parameters = $this->_parameterGroups[$callIndex];
+        } else {
+          // no parameter assertion for this call index
+            return;
+        }
+
+        if ($invocation === null) {
+            throw new PHPUnit_Framework_ExpectationFailedException(
+                'Mocked method does not exist.'
+            );
+        }
+
+        if (count($invocation->parameters) < count($parameters)) {
+            throw new PHPUnit_Framework_ExpectationFailedException(
+                sprintf(
+                    'Parameter count for invocation %s is too low.',
+                    $invocation->toString()
+                )
+            );
+        }
+
+        foreach ($parameters as $i => $parameter) {
+            $parameter->evaluate(
+                $invocation->parameters[$i],
+                sprintf(
+                    'Parameter %s for invocation #%d %s does not match expected ' .
+                    'value.',
+                    $i,
+                    $callIndex,
+                    $invocation->toString()
+                )
+            );
+        }
+    }
+}
diff --git a/tests/phpunit/includes/phpunit/LICENSE b/tests/phpunit/includes/phpunit/LICENSE
new file mode 100644 (file)
index 0000000..fe178b0
--- /dev/null
@@ -0,0 +1,33 @@
+PHPUnit
+
+Copyright (c) 2001-2014, Sebastian Bergmann <sebastian@phpunit.de>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in
+   the documentation and/or other materials provided with the
+   distribution.
+
+ * Neither the name of Sebastian Bergmann nor the names of his
+   contributors may be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/tests/phpunit/includes/phpunit/README b/tests/phpunit/includes/phpunit/README
new file mode 100644 (file)
index 0000000..3ec3fd9
--- /dev/null
@@ -0,0 +1,2 @@
+This directory contains classes duplicated from new versions of phpunit
+that also work in the older php 3.7.37 used by wmf CI servers.