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 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题