PHPUnit: Difference between revisions

From Freephile Wiki
No edit summary
No edit summary
Line 6: Line 6:


[https://2023.phpday.it/ phpday 2023] happened in Verona, Italy on 18th and 19th May 2023
[https://2023.phpday.it/ phpday 2023] happened in Verona, Italy on 18th and 19th May 2023
{{#ev:youtube|https://www.youtube.com/watch?v=KtbuEoLWRqQ}}





Revision as of 16:11, 1 February 2025

Dec 16, 2023
Version 10 is probably the biggest update so far for PHPUnit. Almost all internals of PHP's most widely used testing framework and test runner have undergone long overdue changes to improve the developer experience of those who work on PHPUnit. This presentation, however, focuses on the improvements that were made for those that write and run tests with PHPUnit every day. Join Sebastian Bergmann, creator, and maintainer of PHPUnit, to learn everything you need to know about PHPUnit 10. You will experience new features, big and small, in action and see how they can support you to effectively and efficiently test your software.


phpday 2023 happened in Verona, Italy on 18th and 19th May 2023



Stash[edit]

I'm just writing this because my IDE crashed and I need to stash it.

Example test

<?php

namespace SMW\Tests\Exporter\Controller;

use MediaWiki\MediaWikiServices;
use PHPUnit\Framework\TestCase;


/**
 * @covers \SMW\Exporter\SMWExportController
 * @group semantic-mediawiki
 *
 * @license GPL-2.0-or-later
 * @since 5.0-alpha
 *
 * @author freephile
 */

class SMW_ExportControllerTest extends TestCase {

	public function testGetDBHandle() {
		$mwVersion = MW_VERSION;

		if (version_compare($mwVersion, '1.42', '>=')) {
			$connectionProvider = $this->createMock(\Wikimedia\Rdbms\ConnectionProvider::class);
			$replicaDatabase = $this->createMock(\Wikimedia\Rdbms\IDatabase::class);
			$connectionProvider->method('getReplicaDatabase')->willReturn($replicaDatabase);

			$mediaWikiServices = $this->createMock(MediaWikiServices::class);
			$mediaWikiServices->method('getConnectionProvider')->willReturn($connectionProvider);

			MediaWikiServices::setInstanceForTesting($mediaWikiServices);

			$this->assertSame($replicaDatabase, SMWExportController::getDBHandle());
		} else {
			$dbLoadBalancer = $this->createMock(\Wikimedia\Rdbms\LoadBalancer::class);
			$replicaDatabase = $this->createMock(\Wikimedia\Rdbms\IDatabase::class);
			$dbLoadBalancer->method('getConnection')->with(DB_REPLICA)->willReturn($replicaDatabase);

			$mediaWikiServices = $this->createMock(MediaWikiServices::class);
			$mediaWikiServices->method('getDBLoadBalancer')->willReturn($dbLoadBalancer);

			MediaWikiServices::setInstanceForTesting($mediaWikiServices);

			$this->assertSame($replicaDatabase, SMWExportController::getDBHandle());
		}
	}
}