Skip to content

Commit

Permalink
Merge branch '10.5' into 11.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 9, 2025
2 parents 6093ee5 + a7dbfad commit 25c813d
Show file tree
Hide file tree
Showing 31 changed files with 1,252 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ChangeLog-11.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi

## [11.5.3] - 2025-MM-DD

### Added

* `Test\AfterLastTestMethodErrored`, `Test\AfterTestMethodErrored`, `Test\BeforeTestMethodErrored`, `Test\PostConditionErrored`, and `Test\PreConditionErrored` events

### Fixed

* [#6095](https://github.com/sebastianbergmann/phpunit/issues/6095): Expectation is not counted correctly when a doubled method is called more often than is expected
Expand Down
90 changes: 90 additions & 0 deletions src/Event/Emitter/DispatchingEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,24 @@ public function testBeforeTestMethodCalled(string $testClassName, ClassMethod $c
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testBeforeTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
{
$this->dispatcher->dispatch(
new Test\BeforeTestMethodErrored(
$this->telemetryInfo(),
$testClassName,
$calledMethod,
$throwable,
),
);
}

/**
* @psalm-param class-string $testClassName
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testBeforeTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void
{
$this->dispatcher->dispatch(
Expand Down Expand Up @@ -446,6 +464,24 @@ public function testPreConditionCalled(string $testClassName, ClassMethod $calle
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testPreConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
{
$this->dispatcher->dispatch(
new Test\PreConditionErrored(
$this->telemetryInfo(),
$testClassName,
$calledMethod,
$throwable,
),
);
}

/**
* @psalm-param class-string $testClassName
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testPreConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void
{
$this->dispatcher->dispatch(
Expand Down Expand Up @@ -1016,6 +1052,24 @@ public function testPostConditionCalled(string $testClassName, ClassMethod $call
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testPostConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
{
$this->dispatcher->dispatch(
new Test\PostConditionErrored(
$this->telemetryInfo(),
$testClassName,
$calledMethod,
$throwable,
),
);
}

/**
* @psalm-param class-string $testClassName
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testPostConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void
{
$this->dispatcher->dispatch(
Expand Down Expand Up @@ -1050,6 +1104,24 @@ public function testAfterTestMethodCalled(string $testClassName, ClassMethod $ca
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testAfterTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
{
$this->dispatcher->dispatch(
new Test\AfterTestMethodErrored(
$this->telemetryInfo(),
$testClassName,
$calledMethod,
$throwable,
),
);
}

/**
* @psalm-param class-string $testClassName
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testAfterTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void
{
$this->dispatcher->dispatch(
Expand Down Expand Up @@ -1084,6 +1156,24 @@ public function testAfterLastTestMethodCalled(string $testClassName, ClassMethod
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testAfterLastTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void
{
$this->dispatcher->dispatch(
new Test\AfterLastTestMethodErrored(
$this->telemetryInfo(),
$testClassName,
$calledMethod,
$throwable,
),
);
}

/**
* @psalm-param class-string $testClassName
*
* @throws InvalidArgumentException
* @throws UnknownEventTypeException
*/
public function testAfterLastTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void
{
$this->dispatcher->dispatch(
Expand Down
25 changes: 25 additions & 0 deletions src/Event/Emitter/Emitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function testBeforeTestMethodCalled(string $testClassName, ClassMethod $c
/**
* @param class-string $testClassName
*/
public function testBeforeTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;

/**
* @psalm-param class-string $testClassName
*/
public function testBeforeTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void;

/**
Expand All @@ -98,6 +103,11 @@ public function testPreConditionCalled(string $testClassName, ClassMethod $calle
/**
* @param class-string $testClassName
*/
public function testPreConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;

/**
* @psalm-param class-string $testClassName
*/
public function testPreConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void;

public function testPrepared(Code\Test $test): void;
Expand Down Expand Up @@ -254,6 +264,11 @@ public function testPostConditionCalled(string $testClassName, ClassMethod $call
/**
* @param class-string $testClassName
*/
public function testPostConditionErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;

/**
* @psalm-param class-string $testClassName
*/
public function testPostConditionFinished(string $testClassName, ClassMethod ...$calledMethods): void;

/**
Expand All @@ -264,6 +279,11 @@ public function testAfterTestMethodCalled(string $testClassName, ClassMethod $ca
/**
* @param class-string $testClassName
*/
public function testAfterTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;

/**
* @psalm-param class-string $testClassName
*/
public function testAfterTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void;

/**
Expand All @@ -274,6 +294,11 @@ public function testAfterLastTestMethodCalled(string $testClassName, ClassMethod
/**
* @param class-string $testClassName
*/
public function testAfterLastTestMethodErrored(string $testClassName, ClassMethod $calledMethod, Throwable $throwable): void;

/**
* @psalm-param class-string $testClassName
*/
public function testAfterLastTestMethodFinished(string $testClassName, ClassMethod ...$calledMethods): void;

public function testSuiteFinished(TestSuite $testSuite): void;
Expand Down
84 changes: 84 additions & 0 deletions src/Event/Events/Test/HookMethod/AfterLastTestMethodErrored.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Event\Test;

use const PHP_EOL;
use function sprintf;
use PHPUnit\Event\Code;
use PHPUnit\Event\Code\Throwable;
use PHPUnit\Event\Event;
use PHPUnit\Event\Telemetry;

/**
* @psalm-immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
final class AfterLastTestMethodErrored implements Event
{
private readonly Telemetry\Info $telemetryInfo;

/**
* @psalm-var class-string
*/
private readonly string $testClassName;
private readonly Code\ClassMethod $calledMethod;
private readonly Throwable $throwable;

/**
* @psalm-param class-string $testClassName
*/
public function __construct(Telemetry\Info $telemetryInfo, string $testClassName, Code\ClassMethod $calledMethod, Throwable $throwable)
{
$this->telemetryInfo = $telemetryInfo;
$this->testClassName = $testClassName;
$this->calledMethod = $calledMethod;
$this->throwable = $throwable;
}

public function telemetryInfo(): Telemetry\Info
{
return $this->telemetryInfo;
}

/**
* @psalm-return class-string
*/
public function testClassName(): string
{
return $this->testClassName;
}

public function calledMethod(): Code\ClassMethod
{
return $this->calledMethod;
}

public function throwable(): Throwable
{
return $this->throwable;
}

public function asString(): string
{
$message = $this->throwable->message();

if (!empty($message)) {
$message = PHP_EOL . $message;
}

return sprintf(
'After Last Test Method Errored (%s::%s)%s',
$this->calledMethod->className(),
$this->calledMethod->methodName(),
$message,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Event\Test;

use PHPUnit\Event\Subscriber;

/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
interface AfterLastTestMethodErroredSubscriber extends Subscriber
{
public function notify(AfterLastTestMethodErrored $event): void;
}
84 changes: 84 additions & 0 deletions src/Event/Events/Test/HookMethod/AfterTestMethodErrored.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Event\Test;

use const PHP_EOL;
use function sprintf;
use PHPUnit\Event\Code;
use PHPUnit\Event\Code\Throwable;
use PHPUnit\Event\Event;
use PHPUnit\Event\Telemetry;

/**
* @psalm-immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
final class AfterTestMethodErrored implements Event
{
private readonly Telemetry\Info $telemetryInfo;

/**
* @psalm-var class-string
*/
private readonly string $testClassName;
private readonly Code\ClassMethod $calledMethod;
private readonly Throwable $throwable;

/**
* @psalm-param class-string $testClassName
*/
public function __construct(Telemetry\Info $telemetryInfo, string $testClassName, Code\ClassMethod $calledMethod, Throwable $throwable)
{
$this->telemetryInfo = $telemetryInfo;
$this->testClassName = $testClassName;
$this->calledMethod = $calledMethod;
$this->throwable = $throwable;
}

public function telemetryInfo(): Telemetry\Info
{
return $this->telemetryInfo;
}

/**
* @psalm-return class-string
*/
public function testClassName(): string
{
return $this->testClassName;
}

public function calledMethod(): Code\ClassMethod
{
return $this->calledMethod;
}

public function throwable(): Throwable
{
return $this->throwable;
}

public function asString(): string
{
$message = $this->throwable->message();

if (!empty($message)) {
$message = PHP_EOL . $message;
}

return sprintf(
'After Test Method Errored (%s::%s)%s',
$this->calledMethod->className(),
$this->calledMethod->methodName(),
$message,
);
}
}
Loading

0 comments on commit 25c813d

Please sign in to comment.