Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit events for E_* and E_USER_* triggered in data provider methods #5784

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions .psalm/baseline.xml
Expand Up @@ -6,10 +6,27 @@
</UndefinedInterfaceMethod>
</file>
<file src="src/Event/Emitter/DispatchingEmitter.php">
<DeprecatedClass>
<code><![CDATA[new DeprecatedDataProviderMethodCalled(
$this->telemetryInfo(),
$testMethod,
$dataProviderMethod,
)]]></code>
<code><![CDATA[new DeprecatedDataProviderMethodFinished(
$this->telemetryInfo(),
$testMethod,
...$calledMethods,
)]]></code>
</DeprecatedClass>
<RedundantCondition>
<code><![CDATA[assert($test instanceof TestMethod)]]></code>
</RedundantCondition>
</file>
<file src="src/Event/Events/DataProvider/Lifecycle/MethodFinished.php">
<PropertyTypeCoercion>
<code><![CDATA[$calledMethods]]></code>
</PropertyTypeCoercion>
</file>
<file src="src/Event/Events/Test/HookMethod/AfterLastTestMethodFinished.php">
<PropertyTypeCoercion>
<code><![CDATA[$calledMethods]]></code>
Expand Down Expand Up @@ -40,11 +57,21 @@
<code><![CDATA[$calledMethods]]></code>
</PropertyTypeCoercion>
</file>
<file src="src/Event/Events/Test/Lifecycle/DataProviderMethodCalledSubscriber.php">
<DeprecatedClass>
<code><![CDATA[DataProviderMethodCalled]]></code>
</DeprecatedClass>
</file>
<file src="src/Event/Events/Test/Lifecycle/DataProviderMethodFinished.php">
<PropertyTypeCoercion>
<code><![CDATA[$calledMethods]]></code>
</PropertyTypeCoercion>
</file>
<file src="src/Event/Events/Test/Lifecycle/DataProviderMethodFinishedSubscriber.php">
<DeprecatedClass>
<code><![CDATA[DataProviderMethodFinished]]></code>
</DeprecatedClass>
</file>
<file src="src/Event/Events/Test/TestDouble/MockObjectFromWsdlCreated.php">
<PropertyTypeCoercion>
<code><![CDATA[$methods]]></code>
Expand All @@ -59,6 +86,10 @@
<ArgumentTypeCoercion>
<code><![CDATA[$eventClass . 'Subscriber']]></code>
</ArgumentTypeCoercion>
<DeprecatedClass>
<code><![CDATA[Test\DataProviderMethodCalled::class]]></code>
<code><![CDATA[Test\DataProviderMethodFinished::class]]></code>
</DeprecatedClass>
<InvalidArrayOffset>
<code><![CDATA[gc_status()['running']]]></code>
</InvalidArrayOffset>
Expand Down Expand Up @@ -619,6 +650,18 @@
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorFile]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
Expand All @@ -627,6 +670,15 @@
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorLine]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
<code><![CDATA[$errorString]]></code>
Expand Down
191 changes: 189 additions & 2 deletions src/Event/Emitter/DispatchingEmitter.php
Expand Up @@ -17,8 +17,17 @@
use PHPUnit\Event\Code\TestMethod;
use PHPUnit\Event\Code\TestMethodBuilder;
use PHPUnit\Event\Code\Throwable;
use PHPUnit\Event\Test\DataProviderMethodCalled;
use PHPUnit\Event\Test\DataProviderMethodFinished;
use PHPUnit\Event\DataProvider\DeprecationTriggered as DataProviderTriggeredDeprecation;
use PHPUnit\Event\DataProvider\ErrorTriggered as DataProviderTriggeredError;
use PHPUnit\Event\DataProvider\MethodCalled as DataProviderMethodCalled;
use PHPUnit\Event\DataProvider\MethodFinished as DataProviderMethodFinished;
use PHPUnit\Event\DataProvider\NoticeTriggered as DataProviderTriggeredNotice;
use PHPUnit\Event\DataProvider\PhpDeprecationTriggered as DataProviderTriggeredPhpDeprecation;
use PHPUnit\Event\DataProvider\PhpNoticeTriggered as DataProviderTriggeredPhpNotice;
use PHPUnit\Event\DataProvider\PhpWarningTriggered as DataProviderTriggeredPhpWarning;
use PHPUnit\Event\DataProvider\WarningTriggered as DataProviderTriggeredWarning;
use PHPUnit\Event\Test\DataProviderMethodCalled as DeprecatedDataProviderMethodCalled;
use PHPUnit\Event\Test\DataProviderMethodFinished as DeprecatedDataProviderMethodFinished;
use PHPUnit\Event\TestSuite\Filtered as TestSuiteFiltered;
use PHPUnit\Event\TestSuite\Finished as TestSuiteFinished;
use PHPUnit\Event\TestSuite\Loaded as TestSuiteLoaded;
Expand Down Expand Up @@ -150,6 +159,14 @@
$dataProviderMethod,
),
);

$this->dispatcher->dispatch(
new DeprecatedDataProviderMethodCalled(
$this->telemetryInfo(),
$testMethod,
$dataProviderMethod,
),
);
}

/**
Expand All @@ -165,6 +182,176 @@
...$calledMethods,
),
);

$this->dispatcher->dispatch(
new DeprecatedDataProviderMethodFinished(
$this->telemetryInfo(),
$testMethod,
...$calledMethods,
),
);
}

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function dataProviderTriggeredDeprecation(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, IssueTrigger $trigger): void
{
$this->dispatcher->dispatch(
new DataProviderTriggeredDeprecation(
$this->telemetryInfo(),
$dataProvider,
$message,
$file,
$line,
$suppressed,
$ignoredByBaseline,
$trigger,
),
);
}

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function dataProviderTriggeredError(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed): void
{
$this->dispatcher->dispatch(
new DataProviderTriggeredError(
$this->telemetryInfo(),
$dataProvider,
$message,
$file,
$line,
$suppressed,
),
);
}

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function dataProviderTriggeredNotice(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void
{
$this->dispatcher->dispatch(
new DataProviderTriggeredNotice(
$this->telemetryInfo(),
$dataProvider,
$message,
$file,
$line,
$suppressed,
$ignoredByBaseline,
),
);
}

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function dataProviderTriggeredPhpDeprecation(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, IssueTrigger $trigger): void

Check warning on line 272 in src/Event/Emitter/DispatchingEmitter.php

View check run for this annotation

Codecov / codecov/patch

src/Event/Emitter/DispatchingEmitter.php#L272

Added line #L272 was not covered by tests
{
$this->dispatcher->dispatch(
new DataProviderTriggeredPhpDeprecation(
$this->telemetryInfo(),
$dataProvider,
$message,
$file,
$line,
$suppressed,
$ignoredByBaseline,
$trigger,
),

Check warning on line 284 in src/Event/Emitter/DispatchingEmitter.php

View check run for this annotation

Codecov / codecov/patch

src/Event/Emitter/DispatchingEmitter.php#L274-L284

Added lines #L274 - L284 were not covered by tests
);
}

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function dataProviderTriggeredPhpNotice(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void
{
$this->dispatcher->dispatch(
new DataProviderTriggeredPhpNotice(
$this->telemetryInfo(),
$dataProvider,
$message,
$file,
$line,
$suppressed,
$ignoredByBaseline,
),
);
}

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function dataProviderTriggeredPhpWarning(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void
{
$this->dispatcher->dispatch(
new DataProviderTriggeredPhpWarning(
$this->telemetryInfo(),
$dataProvider,
$message,
$file,
$line,
$suppressed,
$ignoredByBaseline,
),
);
}

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function dataProviderTriggeredWarning(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void
{
$this->dispatcher->dispatch(
new DataProviderTriggeredWarning(
$this->telemetryInfo(),
$dataProvider,
$message,
$file,
$line,
$suppressed,
$ignoredByBaseline,
),
);
}

/**
Expand Down
49 changes: 49 additions & 0 deletions src/Event/Emitter/Emitter.php
Expand Up @@ -41,6 +41,55 @@ public function dataProviderMethodCalled(ClassMethod $testMethod, ClassMethod $d

public function dataProviderMethodFinished(ClassMethod $testMethod, ClassMethod ...$calledMethods): void;

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*/
public function dataProviderTriggeredDeprecation(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, IssueTrigger $trigger): void;

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*/
public function dataProviderTriggeredError(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed): void;

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*/
public function dataProviderTriggeredNotice(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void;

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*/
public function dataProviderTriggeredPhpDeprecation(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline, IssueTrigger $trigger): void;

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*/
public function dataProviderTriggeredPhpNotice(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void;

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*/
public function dataProviderTriggeredPhpWarning(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void;

/**
* @psalm-param non-empty-string $message
* @psalm-param non-empty-string $file
* @psalm-param positive-int $line
*/
public function dataProviderTriggeredWarning(ClassMethod $dataProvider, string $message, string $file, int $line, bool $suppressed, bool $ignoredByBaseline): void;

public function testSuiteLoaded(TestSuite $testSuite): void;

public function testSuiteFiltered(TestSuite $testSuite): void;
Expand Down