mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Test for factory creations
This commit is contained in:
parent
49427b1acb
commit
a9fe211799
@ -2,19 +2,23 @@
|
|||||||
|
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Factory\ClientContactFactory;
|
||||||
|
use App\Factory\ClientFactory;
|
||||||
use App\Factory\UserFactory;
|
use App\Factory\UserFactory;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @covers App\Factory\
|
|
||||||
*/
|
*/
|
||||||
class FactoryCreationTest extends TestCase
|
class FactoryCreationTest extends TestCase
|
||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
public function setUp() :void
|
public function setUp() :void
|
||||||
{
|
{
|
||||||
@ -27,8 +31,77 @@ class FactoryCreationTest extends TestCase
|
|||||||
|
|
||||||
Model::reguard();
|
Model::reguard();
|
||||||
|
|
||||||
|
|
||||||
|
$this->account = factory(\App\Models\Account::class)->create();
|
||||||
|
$this->company = factory(\App\Models\Company::class)->create([
|
||||||
|
'account_id' => $this->account->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->account->default_company_id = $this->company->id;
|
||||||
|
$this->account->save();
|
||||||
|
|
||||||
|
$this->user = factory(\App\Models\User::class)->create([
|
||||||
|
// 'account_id' => $account->id,
|
||||||
|
'confirmation_code' => $this->createDbHash(config('database.default'))
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App|Factory\ClientFactory
|
||||||
|
*/
|
||||||
|
public function testClientCreate()
|
||||||
|
{
|
||||||
|
$client = ClientFactory::create($this->company->id, $this->user->id);
|
||||||
|
|
||||||
|
$client->save();
|
||||||
|
|
||||||
|
$this->assertNotNull($client);
|
||||||
|
|
||||||
|
$this->assertInternalType("int", $client->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App|Factory\ClientContactFactory
|
||||||
|
*/
|
||||||
|
public function testClientContactCreate()
|
||||||
|
{
|
||||||
|
|
||||||
|
factory(\App\Models\Client::class)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c){
|
||||||
|
|
||||||
|
factory(\App\Models\ClientContact::class,1)->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $c->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'is_primary' => 1
|
||||||
|
]);
|
||||||
|
|
||||||
|
factory(\App\Models\ClientContact::class,2)->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $c->id,
|
||||||
|
'company_id' => $this->company->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$client = Client::whereUserId($this->user->id)->whereCompanyId($this->company->id)->first();
|
||||||
|
|
||||||
|
|
||||||
|
$contact = ClientContactFactory::create($this->company->id, $this->user->id);
|
||||||
|
$contact->client_id = $client->id;
|
||||||
|
$contact->save();
|
||||||
|
|
||||||
|
$this->assertNotNull($contact);
|
||||||
|
|
||||||
|
$this->assertInternalType("int", $contact->id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App|Factory\UserFactory
|
||||||
|
*/
|
||||||
public function testUserCreate()
|
public function testUserCreate()
|
||||||
{
|
{
|
||||||
$new_user = UserFactory::create();
|
$new_user = UserFactory::create();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user