donglu9825 2013-03-08 16:50
浏览 39
已采纳

如果不调用所需的方法,Mockery / Etsy PHPExtensions不会失败测试

I have the below code, which I would expect to fail when run as the class DoesNothing doesn't use the mock class or call any of the required methods on it.

<?php
class DoesNothing
{

}

class DoesNothingTest extends YourMockeryTestCase
{
    /**
     * @test
     */
    public function somethingIsCalled()
    {
        $this->mock = Mockery::mock();

        $keys = array(
            '1234',
            'abcxyz',
            '*&(%&^$-*/~@:{}',
            ')*&GA^FAUIB(*',
            '',
            ' ',
        );

        foreach ($keys as $key) {
            $this->mock
                ->shouldReceive('remove')
                ->atLeast()->times(1)
                ->with($key);
        }
        $var = new DoesNothing($this->mock);
    }
}

But when I run it, it passes. I would expect it to say "method remove was not called" etc.

What could be wrong? Something to do with how Mockery Talks to PHPUnit?

Thanks, Martin

Edit: I shoudl also mention we are using Etsy's PHPExtensions to integrate it into PHPUnit

  • 写回答

1条回答 默认 最新

  • dongshou2017 2013-03-08 20:50
    关注

    Your method name should start with test, otherwise PHPUnit will not determine it as test.

    public function testSomethingIsCalled()
    

    edit

    You have to call Mockery::close() in your teardown method for expectations to be executed. i.e.

    /**
     * Tear down
     */
    public function tearDown()
    {
        \Mockery::close();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数
  • ¥15 关于#线性回归#的问题:【统计】回归系数要转化为相关系数才能进行Fisher' Z转化吗(相关搜索:回归模型)
  • ¥100 使用matlab解决含分段变量的优化问题
  • ¥15 matlab基于鲸鱼算法优化vmd
  • ¥20 PCB设计与制作问答
  • ¥20 课堂跑如何下载ppt
  • ¥15 STM32阿里云平台显示不了传感器采集的数据