/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Notifier/Tests/TexterTest.php
67 строк
2 KB
Christian Flothmann
do not use PHPUnit mock objects without configured expectations
04 янв 2026, 15:27
04 янв 2026, 15:27
cf72e93
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Notifier\Tests; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Notifier\Message\SentMessage; use Symfony\Component\Notifier\Tests\Transport\DummyMessage; use Symfony\Component\Notifier\Texter; use Symfony\Component\Notifier\Transport\TransportInterface; class TexterTest extends TestCase { private MockObject&TransportInterface $transport; protected function setUp(): void { $this->transport = $this->createMock(TransportInterface::class); } public function testSendWithoutBus() { $message = new DummyMessage(); $sentMessage = new SentMessage($message, 'any'); $this->transport ->expects($this->once()) ->method('send') ->with($message) ->willReturn($sentMessage); $texter = new Texter($this->transport); $this->assertSame($sentMessage, $texter->send($message)); $this->assertSame($message, $sentMessage->getOriginalMessage()); } public function testSendWithBus() { $message = new DummyMessage(); $this->transport ->expects($this->never()) ->method('send') ->with($message); $bus = $this->createMock(MessageBusInterface::class); $bus ->expects($this->once()) ->method('dispatch') ->with($message) ->willReturn(new Envelope(new \stdClass())); $texter = new Texter($this->transport, $bus); $this->assertNull($texter->send($message)); } }