我有界面:
interface AbstractMapper
{
public function objectToArray(ActiveRecordBase $object);
}
Run Code Online (Sandbox Code Playgroud)
和课程:
class ActiveRecordBase
{
...
}
class Product extends ActiveRecordBase
{
...
}
Run Code Online (Sandbox Code Playgroud)
========
但我不能这样做:
interface ExactMapper implements AbstractMapper
{
public function objectToArray(Product $object);
}
Run Code Online (Sandbox Code Playgroud)
或这个:
interface ExactMapper extends AbstractMapper
{
public function objectToArray(Product $object);
}
Run Code Online (Sandbox Code Playgroud)
我有错误" 声明必须兼容 "
那么,有没有办法在PHP中执行此操作?
在我的 rails 应用程序中,我决定使用单例来创建某种工厂来正确获取对象。
配置/初始化程序/registry.rb:
registry = Registry.instance
registry.define_lazy :period_predictor do
PeriodPredictor.new(NotificationBuilder.new, 28, 4, 3)
end
registry.define_lazy :notification_sender do
NotificationSender.new
end
Run Code Online (Sandbox Code Playgroud)
库/registry.rb:
# Registry class which is singleton and stores values.
class Registry
include Singleton
# Define simple value. Like a constant.
#
# @param key [Symbol]
# @param value
def define(key, value)
container[key] = value
end
# Define value (block required) which will be calculated when it will be need.
# It will calculate it every time when it will …Run Code Online (Sandbox Code Playgroud) 我在Laravel 4中测试控制器时遇到问题.
我有下一个代码:
public function getRemind()
{
$status = \Session::get('status');
$error = \Session::get('error');
$email = \Session::get('email');
return \View::make('admin/reminds/remind_form', compact('status', 'error', 'email'));
}
Run Code Online (Sandbox Code Playgroud)
我想测试控制器在视图中传递的正确数据:
public function testGetRemind()
{
\Session::set('status', 'status');
\Session::set('error', 'error');
\Session::set('email', 'email');
$response = $this->action('GET', 'Admin\RemindersController@getRemind');
$this->assertTrue($response->isOk(), 'Get remind action is not ok');
$this->assertViewHas('status', 'status');
$this->assertViewHas('error', 'error');
$this->assertViewHas('email', 'email');
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
另外我不能模拟Session-class,因为框架不允许 - 当我尝试这样做时会有很多错误.