r72858 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72857‎ | r72858 | r72859 >
Date:13:42, 12 September 2010
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Follow up r72566. Per CR r9132#c9132 these files were intended to explicitely require the files holding the parent classes.
Modified paths:
  • /trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/search/SearchEngineTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php
@@ -1,5 +1,7 @@
22 <?php
33
 4+require_once 'ApiSetup.php';
 5+
46 class ApiWatchTest extends ApiTestSetup {
57
68 function setUp() {
Index: trunk/phase3/maintenance/tests/phpunit/includes/UploadFromUrlTest.php
@@ -1,5 +1,6 @@
22 <?php
33
 4+require_once 'api/ApiSetup.php';
45
56 class UploadFromUrlTest extends ApiTestSetup {
67
Index: trunk/phase3/maintenance/tests/phpunit/includes/search/SearchEngineTest.php
@@ -1,5 +1,7 @@
22 <?php
33
 4+require_once dirname(__FILE__) . '/../../bootstrap.php';
 5+
46 /**
57 * @group Stub
68 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r73064Absolutize require paths per r72858 CR.platonides14:37, 15 September 2010
r79443Use an autoloader for the tests, following the ideas from r72858....platonides22:04, 1 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r9132bug #73, ext. editorseloquence07:05, 22 May 2005
r72566Merged reorganization work for PHPUnit from branches/phpunit-restructure/tparscal23:02, 7 September 2010

Comments

#Comment by Trevor Parscal (WMF) (talk | contribs)   18:13, 13 September 2010

You don't need to include bootstrap, it's included when you run phpunit because it's defined in suite.xml.

#Comment by Platonides (talk | contribs)   22:35, 13 September 2010

I know, but that's not wrong either (just overly verbose) and keeps the script checking class existance happy.

#Comment by Tim Starling (talk | contribs)   02:36, 15 September 2010

Don't rely on include_path, you never know what it might be set to.

The default LocalSettings.php only adds "$IP/includes", not "$IP/includes/api", so here you're relying on undocumented behaviour in PHP which causes the directory of the currently executing script to be added to the end of the include_path. Not to the start, to the end. And the default LocalSettings.php only prepends to include_path, it doesn't replace it. This means that if any of the directories in the system default include_path have a file called ApiSetup.php, that file will be used instead of the MediaWiki one.

Use require_once(dirname(__FILE__).'/ApiSetup.php'), or better still, use the autoloader.

#Comment by Platonides (talk | contribs)   14:38, 15 September 2010

I had followed the example of ApiTest.php. Fixed in r73064.

#Comment by Trevor Parscal (WMF) (talk | contribs)   18:06, 15 September 2010

My fault, I put that there when I reorganized things. I think adding this stuff to Autoload.php is keeping dependency information too far from the dependent files. Either append $wgAutoloadClasses in bootstrap.php or include things directly -- the later of which is my preference in this case, since shared code is very limited and would be more visible. Either way, it won't hurt to add dirname(__FILE__) . '/' if you are including directly, but documented or not, it seems like PHP has supported this functionality for a long time and is unlikely to pull it - all in all, we could also just cross this imaginary bridge when we come to it.

#Comment by Tim Starling (talk | contribs)   02:14, 17 September 2010

The problem with direct inclusion is that people keep introducing security vulnerabilities with it, or messing it up in other ways. The autoloader is relatively foolproof.

#Comment by Trevor Parscal (WMF) (talk | contribs)   16:46, 17 September 2010

Fair enough. How do you feel about appending the autoloader in bootstap.php, or something else local to the tests?

#Comment by Platonides (talk | contribs)   16:47, 17 September 2010

It could be at maintenance/tests/phpunit/includes/Autoloader.php

#Comment by MarkAHershberger (talk | contribs)   23:33, 6 January 2011

resolved in r79443

Status & tagging log