function PhpMailTest::createPhpMailInstance
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Mail/Plugin/Mail/PhpMailTest.php \Drupal\Tests\Core\Mail\Plugin\Mail\PhpMailTest::createPhpMailInstance()
- 11.x core/tests/Drupal/Tests/Core/Mail/Plugin/Mail/PhpMailTest.php \Drupal\Tests\Core\Mail\Plugin\Mail\PhpMailTest::createPhpMailInstance()
Creates a mocked PhpMail object.
The method "doMail()" gets overridden to avoid a mail() call in tests.
Return value
\Drupal\Core\Mail\Plugin\Mail\PhpMail|\PHPUnit\Framework\MockObject\MockObject A PhpMail instance.
1 call to PhpMailTest::createPhpMailInstance()
- PhpMailTest::testMail in core/
tests/ Drupal/ Tests/ Core/ Mail/ Plugin/ Mail/ PhpMailTest.php - Tests sending a mail using a From address with a comma in it.
File
-
core/
tests/ Drupal/ Tests/ Core/ Mail/ Plugin/ Mail/ PhpMailTest.php, line 85
Class
- PhpMailTest
- @coversDefaultClass \Drupal\Core\Mail\Plugin\Mail\PhpMail @group Mail
Namespace
Drupal\Tests\Core\Mail\Plugin\MailCode
protected function createPhpMailInstance() : PhpMail {
$mailer = $this->getMockBuilder(PhpMail::class)
->onlyMethods([
'doMail',
])
->getMock();
$request = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->getMock();
$request->server = $this->getMockBuilder(ServerBag::class)
->onlyMethods([
'has',
'get',
])
->getMock();
$request->server
->method('has')
->willReturn(FALSE);
$request->server
->method('get')
->willReturn(FALSE);
$reflection = new \ReflectionClass($mailer);
$reflection_property = $reflection->getProperty('request');
$reflection_property->setValue($mailer, $request);
return $mailer;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.