Shmock PHP 测试框架开源项目

我要开发同款
匿名用户2014年04月14日
98阅读

技术信息

开源地址
https://github.com/box/shmock
授权协议
Apache

作品详情

Shmock(SHorthadforMOCKig)是PHPUit创建mocks的平稳替代,使用EasyMock的mock/replay概念,但是又使用mockig定义的闭包范围。

示例代码:

<?php    amespace Foo;    /**     * Here's a class we're tryig to test yay.     */    class Foo    {        private $foo = 0;        private $icremetig_service = ull;        public fuctio __costruct(Icremetig_Service $icremetig_service)        {            $this->icremetig_service = $icremetig_service;        }        public fuctio ext_foo()        {            $this->foo = $this->icremetig_service->icremet($this->foo);            retur $this->foo;        }    }    /**     * Our test case rus the same test case twice - oce with the origial PHPUit mockig     * sytax ad a secod time with Shmock sytax.     */    class Foo_Test exteds PHPUit_Framework_TestCase    {                use \Shmock\Shmockers; // This eables the use of the Shmock helper methods (replicated below)                public fuctio test_phpuit_origial_mockig_sytax()        {            // this is the origial PHPUit mock sytax            $icremetig_service_mock = $this->getMock('\Foo\Icremetig_Service', array('icremet'));            $icremetig_service_mock->expects($this->oce())                ->method('icremet')                ->with($this->equalTo(0))                ->will($this->returValue(1));            $foo = ew Foo($icremetig_service_mock);            $this->assertEquals(1, $foo->ext_foo(0));        }        /**         * Create a shmock represetatio for $class_ame ad cofigure expected         * mock iteractio with $cof_closure         * @retur Shmock A fully cofigured mock object         * @ote You do ot eed this protected method if you use the Shmockers trait, show above         */        protected fuctio shmock($class_ame, $cof_closure)        {            retur \Shmock\Shmock::create_class($this, $class_ame, $cof_closure);        }        public fuctio test_shmock_sytax()        {            // here's shmock. Neat huh?            $icremetig_service_mock = $this->shmock('\Foo\Icremetig_Service', fuctio($shmock)            {                $shmock->icremet(0)->retur_value(1);            });            $foo = ew Foo($icremetig_service_mock);            $this->assertEquals(1, $foo->ext_foo(0));        }    }

 

功能介绍

Shmock(SHorthand for MOCKing)是 PHPUnit 创建 mocks 的平稳替代,使用 EasyMock 的 mock/replay 概念,但是又使用 mocking ...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论