Manual talk:PHP unit testing/Writing unit tests

Set all the configuration settings the test depends on

edit

Shouldn't the guide also tell to explicitly set all the configuration settings globals a test assumes, via setMWGlobals? Otherwise the test will test those globals, rather than whatever it's supposed to test: a nightmare for everyone running tests on a true development checkout (rather than vanilla core), or changing configuration defaults. Example: [1]. --Nemo 10:51, 5 December 2013 (UTC)Reply

Data Provider naming

edit

I disagree with provideFoo being a better name than fooProvider. We are generally following the second on for Wikibase (and we actually have over twice as many data providers as core). Now that I noticed some people are using the former one because that is listed here, I will updated the Wikibase guidelines. I can only suggest the same is done here. See also: PHPUnit docs. --Jeroen De Dauw (talk) 08:45, 21 April 2014 (UTC)Reply

404 error page for all urls of #Grouping_tests

edit

That means for the 3 following URLS : https://phpunit.readthedocs.io/en/8.0/appendixes.configuration.html https://phpunit.readthedocs.io/en/8.0/textui.html and https://phpunit.readthedocs.io/en/8.0/appendixes.annotations.html#appendixes.annotations.group

+ same pb applies in #Coverage when accessing to https://phpunit.readthedocs.io/en/8.0/code-coverage-analysis.html

+ same in #Databases when accessing to https://doc.wikimedia.org/mediawiki-core/master/php/classMediaWikiTestCase.html#ac52071ce3aa849874d6531edccb7328a and to https://doc.wikimedia.org/mediawiki-core/master/php/classMediaWiki_1_1Tests_1_1Maintenance_1_1MaintenanceBaseTestCase.html


- Can someone correct please, Thanks.

-- Christian 🇫🇷 FR (talk) 14:50, 21 November 2022 (UTC)Reply

Peeking at SQL tables during PHP tests

edit

Does anyone know why MediaWikiIntegrationTestCase only creates unittest_ SQL tables for some of the tables in the database and not all of them? I'm trying to spy on tables using HeidiSQL while step debugging and I observed this. Important tables such as page and user do not have an equivalent unittest_page, unittest_user, etc. Maybe @Daimona Eaytoy knows? I'm using Docker + MariaDB. Thanks. –Novem Linguae (talk) 16:17, 13 January 2024 (UTC)Reply

I think MWIntegrationTestCase is supposed to clone all tables, cfr. ::setupDatabaseWithTestPrefix(). This seems to be the case in my local. Maybe you could try stepping through that method to see if there's anything wrong? Daimona Eaytoy (talk) 00:03, 14 January 2024 (UTC)Reply
Thanks. Did some step debugging, everything looked OK. Then I figured out that it is using TEMPORARY tables, which are not viewable in the table list. Setting the .env variable PHPUNIT_USE_NORMAL_TABLES=1 turns this off. Will use that from now on. Thanks for helping me talk this out. –Novem Linguae (talk) 11:54, 14 January 2024 (UTC)Reply
Return to "PHP unit testing/Writing unit tests" page.