I replaced
$this->attributes = Factory::party(['id' => 1, 'name' => 'MyParty name - test']);
with
$this->attributes = Factory::create('SebSept\PokerEventRegistry\Models\Party',['id' => 1, 'name' => 'MyParty name - test']);
Now I have the error
There was 1 error:
1) PartiesTest::testIndexParty
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: parties.id (SQL: insert into "parties" ("id", "name", "description_short", "description_long", "created_at", "updated_at") values (1, MyParty name - test, bizz-4675, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce tortor nulla, cursus eu pellentesque sed, accumsan a risus. Pellentesque et commodo lectus. In ac urna., 2014-03-05 00:51:02, 2014-03-05 00:51:02))
This is because data are inserted in database ... So mocking fails ...
Ok, I was tired, read the doc then found https://github.com/JeffreyWay/Laravel-Test-Helpers/blob/master/docs/02-Factories.md#models this code must use Factory::make() Factory::create() uses the database.
This is ok :
public function setUp()
{
parent::setUp();
$this->mock = m::mock('Eloquent', 'SebSept\PokerEventRegistry\Models\Party');
$this->collection = m::mock('Illuminate\Database\Eloquent\Collection')->shouldDeferMissing();
$this->attributes = Factory::make('SebSept\PokerEventRegistry\Models\Party',['id' => 1, 'name' => 'MyParty name - test']);
$this->app->instance('SebSept\PokerEventRegistry\Models\Party', $this->mock);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community