小编dom*_*all的帖子

PHPUnit,接口和命名空间(Symfony2)

我目前正在为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)

php tdd phpunit symfony

6
推荐指数
1
解决办法
2688
查看次数

标签 统计

php ×1

phpunit ×1

symfony ×1

tdd ×1