PHPUnit: Difference between revisions
No edit summary |
Add link to Changelog |
||
Line 1: | Line 1: | ||
The new<ref>PHPUnit 11 is also released as of this writing Feb 2025 and was actually first released around Feb 2024</ref> PHPUnit 10 is full of new features and changes. See the [https://github.com/sebastianbergmann/phpunit/blob/10.0.0/ChangeLog-10.0.md#1000---2023-02-03 CHANGELOG] | |||
{{#ev:youtube|https://www.youtube.com/watch?v=TVHDYpYxBHQ}} | {{#ev:youtube|https://www.youtube.com/watch?v=TVHDYpYxBHQ}} | ||
Line 7: | Line 9: | ||
[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 | ||
== Event based == | |||
PHPUnit 10 takes a whole new approach by using an event system - which replaces the old (bad) Listener and Hook system. You can read about it at https://github.com/sebastianbergmann/phpunit/issues/4676 | |||
{{#ev:youtube|https://www.youtube.com/watch?v=KtbuEoLWRqQ}} | {{#ev:youtube|https://www.youtube.com/watch?v=KtbuEoLWRqQ}} |
Revision as of 16:31, 1 February 2025
The new[1] PHPUnit 10 is full of new features and changes. See the CHANGELOG
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
Event based[edit]
PHPUnit 10 takes a whole new approach by using an event system - which replaces the old (bad) Listener and Hook system. You can read about it at https://github.com/sebastianbergmann/phpunit/issues/4676
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());
}
}
}
- ↑ PHPUnit 11 is also released as of this writing Feb 2025 and was actually first released around Feb 2024