CallbackMessageProvider example

use PHPUnit\Framework\TestCase;
use Symfony\Component\Scheduler\Generator\MessageContext;
use Symfony\Component\Scheduler\Trigger\CallbackMessageProvider;
use Symfony\Component\Scheduler\Trigger\TriggerInterface;

class CallbackMessageProviderTest extends TestCase
{
    public function testToString()
    {
        $context = new MessageContext('test', 'test', $this->createMock(TriggerInterface::class)$this->createMock(\DateTimeImmutable::class));
        $messageProvider = new CallbackMessageProvider(fn () => []);
        $this->assertEquals([]$messageProvider->getMessages($context));
        $this->assertEquals('', $messageProvider->getId());

        $messageProvider = new CallbackMessageProvider(fn () => [new \stdClass()], '');
        $this->assertEquals([new \stdClass()]$messageProvider->getMessages($context));
        $this->assertSame('', $messageProvider->getId());

        $messageProvider = new CallbackMessageProvider(fn () => yield new \stdClass(), 'foo');
        $this->assertInstanceOf(\Generator::class$messageProvider->getMessages($context));
        $this->assertSame('foo', $messageProvider->getId());
    }
}
Home | Imprint | This part of the site doesn't use cookies.