[英]trouble geting started with laravel testing and mockery
I'm trying to get started on unit testing with laravel and am trying to follow a couple of tutorials. 我试图开始使用laravel进行单元测试,并试图遵循一些教程。
Alot of my controllers have been generated using Jeffrey Ways excellent generators and they appear to create their own tests so I thought it would be simple to get started. 我的许多控制器都是使用Jeffrey Ways出色的生成器生成的,它们似乎是在创建自己的测试,因此我认为入门很简单。
I've installed mockery and sqlite - I've removed a lot of the tests from the folder for now so I can test one at a time but I'm having trouble with the first one that tests a create: 我已经安装了嘲笑和sqlite-我现在已经从文件夹中删除了很多测试,因此我可以一次测试一个,但是我遇到了第一个测试创建的测试:
Here's my test: 这是我的测试:
<?php
use Mockery as m;
use Way\Tests\Factory;
class BooksTest extends TestCase {
public function __construct()
{
$this->mock = m::mock('Eloquent', 'Book');
$this->collection = m::mock('Illuminate\Database\Eloquent\Collection')->shouldDeferMissing();
}
public function setUp()
{
parent::setUp();
$this->attributes = Factory::book(['id' => 1]);
$this->app->instance('Book', $this->mock);
}
public function tearDown()
{
m::close();
}
public function testIndex()
{
$this->mock->shouldReceive('all')->once()->andReturn($this->collection);
$this->call('GET', 'books');
$this->assertViewHas('books');
}
public function testCreate()
{
$this->call('GET', 'books/create');
$this->assertResponseOk();
}
public function testStore()
{
$this->mock->shouldReceive('create')->once();
$this->validate(true);
$this->call('POST', 'books');
$this->assertRedirectedToRoute('books.index');
}
}
When I run phpunit I get lots of php messages around mockery - theres so much there I cant see the specifc error message 当我运行phpunit时,我得到很多关于嘲讽的php消息-那里太多了,我看不到特定的错误消息
Is there a simple step I'm missing here in my set up?? 我的设置中是否缺少一个简单的步骤?
I've added mockery to my composer.json and updated. 我已将嘲笑添加到我的composer.json中并进行了更新。 I have not added anything to app.php in the config files - package didnt suggest I should or as a facade.
我没有在配置文件中的app.php中添加任何内容-包不建议我应该或作为外观。
So I'm not sure, never having used it before whether mockery is installed correctly - although I assume it is. 因此,我不确定,在正确安装嘲笑之前从未使用过它-尽管我认为是正确的。 Was it necessary for me to add mockery to a laravel installation or is it part of a normal install?
我是否有必要在laravel安装中添加嘲讽,还是正常安装的一部分?
Solved - definite PICNIC error 已解决-明确的PICNIC错误
I needed to extend the buffer size of my command line to scroll back and see the error which identified the problem - This is my first dip into testing so didnt quite expect the fail to go the way it did. 我需要扩展命令行的缓冲区大小以向后滚动,然后查看可识别出问题的错误-这是我第一次尝试测试,因此没想到失败会像以前那样。
Tiny steps required 需要微小的步骤
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.