我目前正在为Symfony2开发一个开源软件包,并且真的希望它在单元测试覆盖率和一般可靠性方面成为狗nadgers,但是由于我缺乏PHPUnit知识(或者复杂的场景,谁知道)..
目前,我有一个Mailer类,用于处理个别邮件方案.看起来有点像这样:
<?php
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Routing\RouterInterface;
class Mailer
{
protected $mailer;
protected $router;
protected $templating;
protected $parameters;
public function __construct($mailer, RouterInterface $router, EngineInterface $templating, array $parameters)
{
$this->mailer = $mailer;
$this->router = $router;
$this->templating = $templating;
$this->parameters = $parameters;
}
}
Run Code Online (Sandbox Code Playgroud)
很简单,在那里得到了一些Symfony2接口gubbins来处理不同的路由和模板系统,快乐的快乐快乐.
这是我尝试为上述设置的初始测试:
<?php
use My\Bundle\Mailer\Mailer
class MailerTest extends \PHPUnit_Framework_TestCase
{
public function testConstructMailer
{
$systemMailer = $this->getSystemMailer();
$router = $this->getRouter();
$templatingEngine = $this->getTemplatingEngine();
$mailer = new Mailer($systemMailer, $router, $templatingEngine, array());
}
protected function getSystemMailer()
{
$this->getMock('SystemMailer', array('send');
} …Run Code Online (Sandbox Code Playgroud)