Page MenuHomeWickedGov Phorge

EventLoggingTestTrait.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

EventLoggingTestTrait.php

<?php
namespace MediaWiki\Extension\EventLogging\Test;
use Wikimedia\TestingAccessWrapper;
use Wikimedia\Timestamp\ConvertibleTimestamp;
/**
* A handful of helpful assertions that can be made about events in unit and integration tests.
*/
trait EventLoggingTestTrait {
public function assertIsTimestamp( string $timestamp ): void {
// FIXME: Find a better way to assert "this is an ISO 8601 timestamp"
$this->assertMatchesRegularExpression(
TestingAccessWrapper::newFromClass( ConvertibleTimestamp::class )->regexes['TS_ISO_8601'],
$timestamp
);
$this->assertStringEndsWith( 'Z', $timestamp );
}
public function assertEventCanBeIngested( $event, $schema, $streamName ): void {
$this->assertSame( $schema, $event['$schema'] );
$this->assertArrayHasKey( 'meta', $event );
$this->assertSame( $streamName, $event['meta']['stream'] );
$this->assertArrayHasKey( 'domain', $event['meta'] );
if ( array_key_exists( 'client_dt', $event ) ) {
$this->assertArrayNotHasKey( 'dt', $event );
} else {
$this->assertArrayHasKey( 'dt', $event );
$this->assertIsTimestamp( $event['dt'] );
}
$this->assertArrayHasKey( 'user-agent', $event['http']['request_headers'] );
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Oct 3, 20:53 (4 d, 23 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
00/20/744cd9d82edce65e4929db4bf384
Default Alt Text
EventLoggingTestTrait.php (1 KB)

Event Timeline