Support the ongoing development of Laravel.io →
Eloquent Architecture Testing
Last updated 2 years ago.
0

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 ...

Last updated 2 years ago.
0

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);
	}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

SebSept sebsept Joined 20 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.