for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yii\EventDispatcher\Tests\Provider;
use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\ListenerProviderInterface;
use Yii\EventDispatcher\Provider\Aggregate;
use Yii\EventDispatcher\Tests\Event\Event;
class AggregateTest extends TestCase
{
public function testProvidesAllListeners(): void
$event = new Event();
$provider1 = new class implements ListenerProviderInterface
public function getListenersForEvent(object $event): iterable
yield function (Event $event) {
$event->register(1);
};
}
$provider2 = new class implements ListenerProviderInterface
$event->register(2);
$aggregate = new Aggregate();
$aggregate->attach($provider1);
$aggregate->attach($provider2);
foreach ($aggregate->getListenersForEvent($event) as $listener) {
$event
object<Yii\EventDispatcher\Tests\Event\Event>
object<Yii\EventDispatcher\Provider\object>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
$listener($event);
$this->assertEquals([1, 2], $event->registered());
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: