在我的网站的一个页面上,我有一个由用户创建的条目列表 - 标准HTML,<ul>其中包含<li>元素.
我想遍历列表,但元素的顺序很重要.
使用jQuery $('.myList li').each(),我可以保证我将li按照它们在DOM中出现的顺序获取元素吗?
从我到目前为止的测试来看,似乎它们按照正确的顺序迭代,但我找不到任何告诉我它保证的东西.
如果不能保证,那么按顺序迭代它们的下一个最佳替代方法是什么?
我试图用Mockery模拟Eloquent模型.模型正在Controller中注入
__construct(Post $model){$this->model=$model}
Run Code Online (Sandbox Code Playgroud)
现在我find()在控制器中调用该函数
$post = $this->model->find($id);
Run Code Online (Sandbox Code Playgroud)
这里是PostsController的测试
class PostsTest extends TestCase{
protected $mock;
public function setUp() {
parent::setUp();
$this->mock = Mockery::mock('Eloquent', 'Posts'); /*According to Jeffrey Way you have to add Eloquent in this function call to be able to use certain methods from model*/
$this->app->instance('Posts', $this->mock);
}
public function tearDown() {
Mockery::close();
}
public function testGetEdit()
{
$this->mock->shouldReceive('find')->with(1)->once()->andReturn(array('id'=>1));
$this->call('GET', 'admin/posts/edit/1');
$this->assertViewHas('post', array('id'=>1));
}
}
Run Code Online (Sandbox Code Playgroud)
运行PhpUnit给我错误:
Fatal error: Using $this when not in object context in ...\www\l4\vendor\mockery\mockery\library\Mockery\Generator.php(130) : …Run Code Online (Sandbox Code Playgroud)