ray/fake-module

该包已被弃用且不再维护。作者建议使用 ray/test-double 包。

这是用于开发模拟功能的 Ray.Di 模块。

0.1.0 2015-05-15 10:23 UTC

This package is not auto-updated.

Last update: 2019-02-20 18:31:46 UTC


README

此包已过时。请使用 Ray.TestDouble 代替。

Scrutinizer Code Quality Build Status

安装

Composer 安装

$ composer require ray/fake-module

模块安装

use Ray\Di\AbstractModule;
use Ray\FakeModule\FakeModule;

class AppModule extends AbstractModule
{
    protected function configure()
    {
        $this->install(new FakeModule);
    }
}

使用

模拟资源 URI。

@FakeResource 注解用于模拟 URI 以构建模拟功能。使用 @FakeResource 注解标注你想要模拟的目标资源。然后,当调用原始资源方法时,将通过拦截器调用同一命名空间中前缀为 'Fake' 的资源。

此功能高度依赖于 BEAR.Resource [https://github.com/bearsunday/BEAR.Resource]

真实资源

namespace FakeVendor\Sandbox\Resource\App;

use BEAR\Resource\ResourceObject;
use Ray\FakeModule\Annotation\FakeResource;

/**
 * @FakeResource
 */
class User extends ResourceObject
{
    public function onGet($id)
    {
        // ...
    }
}

模拟资源

namespace FakeVendor\Sandbox\Resource\App;

use BEAR\Resource\ResourceObject;

class FakeUser extends ResourceObject
{
    public function onGet($id)
    {
        // ...
    }
}

模拟类方法。

@FakeClass 注解的作用与 @FakeResource 相同。

真实类。

namespace FakeVendor\Sandbox\Module;

use Ray\FakeModule\Annotation\FakeClass;

/**
 * @FakeClass
 */
class TestClass
{
    public function output() {
        return  "test class output";
    }
}

模拟类。

namespace FakeVendor\Sandbox\Module;

class FakeTestClass
{
    public function output() {
        return "fake class output";
    }
}

要求

  • PHP 5.5+
  • hhvm