假设我有CtrlOne一个 extends CtrlTwo,还有一个componentOne在CtrlOne模板中实例化的。一些代码(我跳过了大部分不相关的代码,这样问题会更清楚):
class CtrlOne extends CtrlTwo {
constructor() { super(); }
}
class CtrlTwo {
sayMyName(name: string) {
console.log(this.getMyLastName() + name);
}
getMyLastName() {
return 'squarepants';
}
}
Run Code Online (Sandbox Code Playgroud)
这是与以下相关联的模板CtrlOne:
<component-one data-say-my-name="vm.sayMyName"></component-one>
Run Code Online (Sandbox Code Playgroud)
这是无状态的componentOne:
angular.module('mymodule').component('componentOne', {
bindings: {
sayMyName: '&'
},
template: '<button data-ng-click="$ctrl.sayMyName()('spongebob')></button>'
});
Run Code Online (Sandbox Code Playgroud)
点击之后,我顺利拿到该功能sayMyName的CtrlTwo,但它拒绝承认this.getMyLastName,投掷TypeError: this.getMyLastName is not a function。
如果我只是使用sayMyName或getMyLastName直接从CtrlOne模板中使用,则一切正常。但是,如果我通过传递给 的绑定使用它,则会componentOne出现错误。
我在这里缺少什么?
我正在尝试使用 reactPHP 实现类似 js 的承诺。但是由于某些原因方法同步执行,end_at只有在承诺解决后才打印。
代码:
function iterate() {
$deferred = new \React\Promise\Deferred();
sleep(2);
$deferred->resolve();
return $deferred->promise();
}
Route::get('test/async', function() {
echo "start execution at ".time()."<br>"; // this executed first
iterate()->then(function($result) {
echo "got result result at ". time() . "<br>"; // this is second
}, function($error) {
}, function ($finally) {
});
echo "end at " . time(); // this is executed only after then().
});
Run Code Online (Sandbox Code Playgroud) 我的 __constructurct 中有这段代码:
public function __construct(Guard $auth)
{
$this->auth = $auth;
$this->dbUserService = app()->make('DBUserService');
}
Run Code Online (Sandbox Code Playgroud)
现在,当我进行单元测试时,我知道我可以模拟 Guard 并将其模拟传递给 $auth,但我如何模拟dbUserService?它是通过 IoC 容器实例化的。
可以说我有以下代码块:
$i = 1;
if ($i > 1) {
$this->methodOne();
} else {
$this->methodTwo();
}
Run Code Online (Sandbox Code Playgroud)
如何检查我的PHPUnit测试中是否从已测试的类调用methodOne或methodTwo?
php ×3
phpunit ×2
angularjs ×1
javascript ×1
laravel ×1
reactphp ×1
typescript ×1
unit-testing ×1