Commit graph

72 commits

Author SHA1 Message Date
Ori Livneh
acca48094c Make number of PBKDF2 iterations used for deriving session secret configurable
The intent is both to allow the number of iterations to be dialed up (either as
computational power increases, or on the basis of security needs) and dialed
down for the unit tests, where hash_pbkdf2() calls account for 15-40% of wall
time. The number of iterations is stored in the session, so changing the number
of iterations does not cause existing sessions to become invalid or corrupt.
Sessions that do not have wsSessionPbkdf2Iterations set (i.e., sessions which
precede this change) are transparently upgraded.

Change-Id: I084a97487ef4147eea0f0ce0cdf4b39ca569ef52
2016-05-28 07:06:30 -07:00
Brad Jorsch
d245bd25ae Add AuthManager
This implements the AuthManager class and its needed interfaces and
subclasses, and integrates them into the backend portion of MediaWiki.
Integration with frontend portions of MediaWiki (e.g. ApiLogin,
Special:Login) is left for a followup.

Bug: T91699
Bug: T71589
Bug: T111299
Co-Authored-By: Gergő Tisza <gtisza@wikimedia.org>
Change-Id: If89d24838e326fe25fe867d02181eebcfbb0e196
2016-05-16 15:11:02 +00:00
daniel
d7410db0fd Allow reset of global services (redux).
(This is part of I6ec374ac9 wich was a re-submit of Ie98bf5af5
which got reverted by Ide7ab563)

This change provides a mechanism to reset global service instances
in an orderly manner. There are three use cases for this:

* the installation process
* integration tests (which most of the existing phpunit tests are)

In contrast to I6ec374ac9, this change does not cause singeltons
of legacy services to be reset. It is assumed that legacy services
use global state to access services and configuration, so any
change in confuguration would affect them immediately.

NOTE: the original I6ec374ac9 would cause session information to
get lost if the user session was creatsed before initialization
was complete. This was apparently triggered by the MobileFrontend
extension under some circumstances. Check with Addshore and Catrope.

Change-Id: Ie06782ffb96e675c0aa55dc26fb8f22037e8517d
2016-05-04 19:18:29 +02:00
Catrope
1162ed5f88 Revert "Allow reset of global services."
Completely breaks login.

This reverts commit 8e7a0a0912.

Change-Id: Ide7ab5632e987e81374c21173df6ab3998649df7
2016-04-11 13:40:28 -07:00
daniel
8e7a0a0912 Allow reset of global services.
This change provides a mechanism to reset global service instances
in an orderly manner. There are three use cases for this:

* the installation process
* forking processes
* integration tests (which must of the existing phpunit tests are)

Depends-On: I5d638ad415fc3840186a0beaa09ac02ea688539b
Change-Id: Ie98bf5af59208f186dba59a9e971c72ea0b63e69
2016-04-11 16:22:40 +02:00
Brad Jorsch
6c0abf937a Use ::class in place of string constants
This takes advantage of namespacing, and avoids having
double-backslashes all over the place.

Change-Id: I450fe4e9b1c4cf4e24fced3932fe796cbbadf3a3
2016-03-28 14:53:45 -04:00
Adrian Heine
110dc4d9a2 Add --with-phpunitclass arg to phpunit.php
This would allow to easily use stuff like
https://github.com/fiunchinho/phpunit-randomizer.

Change-Id: I28e8b1d261de0395366b18465a0adc4d7c4fde4a
2016-03-17 13:58:17 +01:00
Max Semenik
b61be67549 Remove support for non-Composer PHPUnit
Composer is now a standard way to install MediaWiki's PHP dependencies,
no reason for it not to be the same for PHPUnit.

Change-Id: Ibd977eb3480dafaf270ff63abc43c413d7b72144
2016-03-14 11:29:34 -07:00
Timo Tijhof
dbe3499113 Upgrade from PHPunit 3.7.x to PHPUnit 4.8.x
Major changes:

* (4.0.0) Limited support for stubbing and mocking static methods was removed.
          (introduced in PHPUnit 3.5)
* (4.0.0) The addRiskyTest() was added to the PHPUnit_Framework_TestListener interface.
          Classes that implement this interface MUST implement this method.
* (4.5.0) The "--strict" catch-all option was deprecated. Use specific options instead.

Notable changes:

* (4.6.0) Tests not annotated with @small, @medium, or @large are no longer default
          to matching in group @small.
* (4.6.0) Result printer now checks hasColorSupport().
* (4.8.0) The name of the default group was changed from "__nogroup__" to "default".
* (4.8.0) This is the last release to support PHP 5.3, PHP 5.4, and PHP 5.5.
          PHPUnit 5 will require PHP 5.6 or higher.

PHPUnit 3.7.17 was released March 2013.
PHPUnit 4.8.0 was released August 2015.
PHPUnit 4.8.23 was released January 2016.

Details:

* https://github.com/sebastianbergmann/phpunit/wiki/ChangeLog-for-PHPUnit-3.7
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.0.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.1.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.2.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.3.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.4.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.5.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.6.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.7.0
* https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.8.0

Bug: T99982
Change-Id: I70ad81513812aa76a84fa55be14135aac94d55e8
2016-02-23 00:57:48 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Reedy
9d19133bad Remove < PHP 5.4 register_shutdown_function() from phpunit.php
Change-Id: Ic4efeca82762b3c50cd2e1b45e43a6f1ef0f5710
2016-02-10 22:06:45 +00:00
Kunal Mehta
82c6f0ff03 Output PHP version before running PHPUnit tests
For sanity checking CI changes, as well as to match the PHPUnit
version output.

Change-Id: Ib807f8650992adada97226cd96282484392f71e8
2016-02-07 17:43:33 -08:00
Aaron Schulz
3592f8cea3 Add simple JobQueueMemory class for testing
Change-Id: I1acce43dbab3b12393d6dc4675850695c619d88a
2016-01-14 00:23:05 +00:00
Aaron Schulz
95ebc3d956 Fix undeclared global $wgMainStash
Change-Id: I95d4194199a064221a56e0b10b236dd2564d1855
2016-01-12 21:56:26 -08:00
Brad Jorsch
a73c5b7395 Add SessionManager
SessionManager is a general-purpose session management framework, rather
than the cookie-based sessions that PHP wants to provide us.

While fallback is provided for using $_SESSION and other PHP session
management functions, they should be avoided in favor of using
SessionManager directly.

For proof-of-concept extensions, see OAuth change Ib40b221 and
CentralAuth change I27ccabdb.

Bug: T111296
Change-Id: Ic1ffea74f3ccc8f93c8a23b795ecab6f06abca72
2016-01-12 21:57:01 +00:00
Florian
be60ba4cb4 Use wikimedia/at-ease insteaad of @
Change-Id: Icba412dd5db11b596ad1cf740b8408823297bc86
2015-12-27 21:51:16 +01:00
Reedy
cc7fca0c14 Support phpunit-old.phar
Bug: T122485
Change-Id: Ic21c6c1ca5afaac0e298cf0259f5dc273dfec128
2015-12-27 20:26:05 +00:00
umherirrender
54c1e18eec Remove various double empty newlines
The double empty newline is not needed between functions, variable or at
end of file

Change-Id: Ib866a95084c4601ac150a2b402cfa184ebc18afa
2015-12-27 18:55:12 +00:00
saper
71443707ad set serialize_precision to 17, current PHP default
Follow up to:
https://gerrit.wikimedia.org/r/#/c/249018/

Bug: T116683
Change-Id: I6e8dfab473ae2c18e68c8e4360159c9cc0e09758
2015-10-27 18:44:41 +01:00
saper
f076661442 Reset serialize_precision to stabilize tests
With serialize_precision = 100 the following
failures were generated:

1) ApiFormatPhpTest::testGeneralEncoding with data set #7
(array(1.0E+42), 'a:1:{i:0;d:1.0E+42;}', array(1))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-a:1:{i:0;d:1.0E+42;}
+a:1:{i:0;d:1000000000000000044885712678075916785549312;}

/usr/home/saper/public_html/ybabel/tests/phpunit/includes/api/format/ApiFormatTestBase.php:61
/usr/home/saper/public_html/ybabel/tests/phpunit/MediaWikiTestCase.php:137

2) ApiFormatPhpTest::testGeneralEncoding with data set #30
(array(1.0E+42), 'a:1:{i:0;d:1.0E+42;}', array(2))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-a:1:{i:0;d:1.0E+42;}
+a:1:{i:0;d:1000000000000000044885712678075916785549312;}

/usr/home/saper/public_html/ybabel/tests/phpunit/includes/api/format/ApiFormatTestBase.php:61
/usr/home/saper/public_html/ybabel/tests/phpunit/MediaWikiTestCase.php:137

Bug: T116683
Change-Id: I5e760b4632d2ab326954fe5769476e143c376d7c
2015-10-26 23:55:48 +01:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Amir E. Aharoni
e17c107ba8 phpunit.php: Make lines shorter to make phpcs happier
Change-Id: Ide48ca85912ab55184588a1144f9fdca7ad48227
2015-09-26 13:44:30 +00:00
Timo Tijhof
74433a3ca8 phpunit: Set $wgMainStash to 'hash' during test execution
Also clean up the other cache settings to match their order
as defined in DefaultSettings.php.

Don't disable MessageCacheType, ParserCacheType etc. This could
prevent bugs from happening during tests. They are enabled by default
in MediaWiki with CACHE_ANYTHING. At least let them use 'hash'
during tests to resemble a more realistic environment.

Change-Id: Id9edf33c600db3ac4d837e1674a8eb2f5363a4f8
2015-09-25 04:57:31 +00:00
Aaron Schulz
d18722f7bc Set $wgMainWANCache to none for PHPUnit, as is done for $wgMainCacheType
Change-Id: I0518876d7df7027c934d1199543a3185732df663
2015-07-13 23:18:30 +00:00
Kunal Mehta
71ede19ea8 Don't try looking for phpunit if it is already loaded
If phpunit is installed via composer, it will already be present in the
autoloader, so including other paths won't do anything.

Also add some output to make it easier to figure out where phpunit is
being loaded from.

Change-Id: Id6d23626b158779f6ff56e6d0f20d519f2f4ad18
2015-07-01 21:36:43 +00:00
Vivek Ghaisas
9359cfffd4 tests/phpunit/phpunit.php: Add @codingStandardsIgnore comment
MediaWiki Codesniffer warns that "Silencing errors is discouraged".
Assuming this was done with good reason, this patch surrounds the
offending line with comments asking codesniffer to ignore the line.

Ironically, silencing errors about silencing errors.

Change-Id: Ib811b03b0a53735ce0da38bc8861ff38f9d1a666
2015-06-20 23:55:06 +03:00
Marius Hoch
85acf8afba Have phpunit.php exit with 1 in case it couldn't run the tests
Just makes more sense not to claim we could complete everything
if we actually couldn't.

Change-Id: I4ec3a2da8913ca546782919813eb18a05a5cca0a
2015-04-09 10:32:59 +02:00
Timo Tijhof
399ba2fecf MWException: Log stack traces for php errors (not exceptions)
* Remove use of 'error' where it's redundant.
* Remove call to logException from responsibility of MWException.
  Call from exception handler instead.

Change-Id: I8764cf5df87b226813c9b9cf99f9b4f3fa4b7c92
2014-11-16 14:37:15 +01:00
umherirrender
861617ca24 Fixed spacing
- Removed spaces around array index
- Changed else if to elseif
- Added space after foreach/if/function
- include_once is not a function

Change-Id: I7745ae791d1b7e60cfebec6d268513a9cc071bdd
2014-08-04 11:51:22 +02:00
Ori Livneh
555e0b4b3c Improve PHPUnit detection code
The code that attempts to load PHPUnit is simpler and clearer when rewritten as
a loop that iterates through a set of possible include paths for PHPUnit,
ordered from most to least desirable, and which tries each include path in turn
and then checks if the requisite classes are now loaded.

Also simplify check for PHP version: MediaWiki requires 5.3+, so might as well
assume it.

Change-Id: I9e25d69c1381cf3a87e7df2baf346bc6bb5aa052
2014-08-03 23:04:45 -07:00
addshore
33ea33f7b6 Allow use of phpunit.phar with MediaWiki's phpunit.php test entry point
MediaWiki tends to assume installation of phpunit via PEAR.
Distribution of phpunit via PEAR will eventually be discontinued,
in favor of distribution via PHAR or composer. PEAR installation
of phpunit 4.0 essentially distributes a phar.

https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-4.0.0

This patch allows phpunit.php to work with a phpunit.phar file,
as long as it's in the include path.  --with-phpunitdir can be used
to add a directory to the include path.

With composer install, no options are needed and it works.

Bug: 58881
Change-Id: Ibac9b36bbb9614d990c697a091947a64c8987d1d
2014-08-02 21:41:38 +00:00
addshore
892a992ab8 Remove MediaWikiPHPUnitCommand
All functionality has been moved to other places

Change-Id: I6b6b0ef846bc63108c4dff9e17098432fd9d1697
2014-08-02 21:35:34 +00:00
addshore
c454a77916 Move debug-tests out of MediaWikiPHPUnitCommand
This also slightly refactors MediaWikiPHPUnitTestListener
so we can pass it into phpunit directly using the
--printer option

Change-Id: I6a19e3902130eeba6a0941f24a4f440b712058e5
2014-08-02 21:34:34 +00:00
umherirrender
53c420e278 Fixed spacing
- use tab as indent instead of spaces
- Added space after closures "function"
- Added spaces around string_concat
- Added newline inside empty blocks
- Removed four spaces after comma

Change-Id: I4425b0c6a69b36f40acfea6511b8950cf09ce2b2
2014-07-20 21:41:41 +02:00
umherirrender
2b021dc48a Fixed spacing
- Added/removed spaces around parenthesis
- Added space after switch/if/foreach
- changed else if to elseif

Change-Id: I99cda543e0e077320091addd75c188cb6e3a42c2
2014-07-19 23:12:10 +02:00
Brandon Black
e323bc3393 Speed up CIDR matching from $wgSquidServersNoPurge
This adds a new generic library class IPSet, which precomputes
a reasonably-efficient data structure from the input list of
addresses and CIDR net/mask specs for fast runtime matching,
and then uses it to check trusted XFF-setters.

See also: 32b4f19f173fc5cff1029eedee63a39a2d72dd3a
Bug: 57021
Change-Id: Ia3b12fb90c3e7e492374a128943b014481cc2730
2014-05-15 17:23:12 +00:00
addshore
e7867c803f Remove includepath stuff from MediaWikiPHPUnitCommand
Change-Id: I949c1ca350a28c606fba7406e9904e836e596b49
2014-05-05 13:17:22 +01:00
addshore
fefc843bd7 Remove color opt setting from MediaWikiPHPUnitCommand
Change-Id: I08d3b53f80520452aef3fcf2017747406a38664d
2014-05-05 13:09:56 +01:00
Siebrand Mazeland
4ede8c2e9d Pass phpcs-strict on some test files (11/11)
Woo!

Change-Id: I9fc116dfdf18c2772d047adb5bb14535d0bd39ed
2014-04-24 13:51:05 -07:00
csteipp
90b3d62854 Prevent GC during phpunit shutdown
To keep phpunit from segfaulting during shutdown, turn off GC for
php 5.3.

Bug: 62623
Change-Id: Ie59780e37cbea027cc204a43df406667c3f432ab
2014-04-14 21:09:10 +00:00
addshore
3b3806d27a Remove assignment in conditon in phpunit.php
Change-Id: I817af3cf5344d9ffe2a66048f6d32835712ba11c
2014-03-14 19:13:06 +01:00
Adrian Lang
46db65ed07 Update PHPUnit version check to 3.7.0
assertContainsOnlyInstancesOf has been added in PHPUnit 3.7.0, so we need to
have that version for running the tests.

Bug: 59759
Change-Id: I25dbd377b97ec0b9062d3c8cf495ba3f06956ac4
2014-01-07 09:46:46 +00:00
Siebrand Mazeland
e711503e7a Remove underscore from classes LCStore_*
iPart of program to remove underscores from class names. Checked core and
600+ extensions for occurrences. All uses are in core, and are updated in
this change.

Change-Id: I432dc249d22053728013ae7d0d56c3c398021c5e
2013-11-17 22:09:31 +01:00
umherirrender
24bfde2710 Fix spacing and break some lines
Change-Id: Ia57685d8858e02e399ad5c75ce64d12609d340ac
2013-08-24 17:06:25 +02:00
Daniel Friesen
2740518620 Support installing PHPUnit using composer.
"phpunit/phpunit" already exists inside our composer.json's "require-dev" however this has been
entirely useless as we don't include the autoloader which would load composer's PHPUnit.

This change begins including composer's autoloader when present and also tweaks phpunit.php
to ensure PHPUnit isn't double loaded. As a result besides supporting PHPUnit via composer this
also means that we're ready to make use of any library we add to our composer.json in the future.

Change-Id: I891740e8fd3d237c5f473862027205d951f564b9
2013-06-07 02:07:27 -07:00
Antoine Musso
7a82d5b779 test: inject autoloader in Maintenance class
We used to inject the test autoloader from the global space after the
Maintenance class has been initialized.  That prevents us from using
tests classes (such as Mock) during the Maintenance setup.

This patch move the TestsAutoLoader.php require() at the beginning of
finalSetup() which would let use Mock classes.

Change-Id: Ia402eafae8407d1516e3d200ac97539e3681fdc6
2013-06-01 09:27:11 +02:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00
Siebrand Mazeland
791d0b2a98 Update code formatting
Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
2013-04-26 14:21:20 +00:00
Siebrand Mazeland
6da93fc6f6 Update code formatting
Also update some previous inconsistencies pointed out by Krinkle in change IDs:
* Ide20743a2e84ff68549286120e6cff9d9f396f54
* I811ca957b6588085d67606ebc0cd4033a1e53839

Change-Id: Ife33b931870d0d7e04fcb40974997436d27f528f
2013-03-27 14:15:11 +01:00