mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the code style applied by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] ruleset to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started. For more information on customizing the code style applied by Shift, [watch this short video][4]. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://github.com/squizlabs/PHP_CodeSniffer [3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 [4]: https://laravelshift.com/videos/shift-code-style
153 lines
3.5 KiB
PHP
153 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Factory\ClientFactory;
|
|
use App\Factory\CloneInvoiceFactory;
|
|
use App\Factory\InvoiceFactory;
|
|
use App\Factory\ProductFactory;
|
|
use App\Factory\UserFactory;
|
|
use App\Models\User;
|
|
use App\Utils\Traits\MakesHash;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Tests\MockAccountData;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
class FactoryCreationTest extends TestCase
|
|
{
|
|
use MakesHash;
|
|
use DatabaseTransactions;
|
|
use MockAccountData;
|
|
|
|
public function setUp() :void
|
|
{
|
|
parent::setUp();
|
|
|
|
Session::start();
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
Model::reguard();
|
|
|
|
$this->makeTestData();
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @covers App\Factory\ProductFactory
|
|
*/
|
|
public function testProductionCreation()
|
|
{
|
|
$product = ProductFactory::create($this->company->id, $this->user->id);
|
|
$product->save();
|
|
|
|
$this->assertNotNull($product);
|
|
|
|
$this->assertIsInt($product->id);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @covers App\Factory\InvoiceFactory
|
|
*/
|
|
public function testInvoiceCreation()
|
|
{
|
|
$client = ClientFactory::create($this->company->id, $this->user->id);
|
|
|
|
$client->save();
|
|
|
|
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
|
|
$invoice->client_id = $client->id;
|
|
$invoice->save();
|
|
|
|
$this->assertNotNull($invoice);
|
|
|
|
$this->assertIsInt($invoice->id);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @covers App\Factory\CloneInvoiceFactory
|
|
*/
|
|
public function testCloneInvoiceCreation()
|
|
{
|
|
$client = ClientFactory::create($this->company->id, $this->user->id);
|
|
|
|
$client->save();
|
|
|
|
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
|
|
$invoice->client_id = $client->id;
|
|
$invoice->save();
|
|
|
|
$this->assertNotNull($invoice);
|
|
|
|
$this->assertIsInt($invoice->id);
|
|
|
|
$clone = CloneInvoiceFactory::create($invoice, $this->user->id);
|
|
$clone->save();
|
|
|
|
$this->assertNotNull($clone);
|
|
|
|
$this->assertIsInt($clone->id);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @covers App\Factory\ClientFactory
|
|
*/
|
|
public function testClientCreate()
|
|
{
|
|
$cliz = ClientFactory::create($this->company->id, $this->user->id);
|
|
|
|
$cliz->save();
|
|
|
|
$this->assertNotNull($cliz);
|
|
|
|
$this->assertIsInt($cliz->id);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @covers App\Factory\ClientContactFactory
|
|
*/
|
|
public function testClientContactCreate()
|
|
{
|
|
$cliz = ClientFactory::create($this->company->id, $this->user->id);
|
|
|
|
$cliz->save();
|
|
|
|
$this->assertNotNull($cliz->contacts);
|
|
$this->assertEquals(0, $cliz->contacts->count());
|
|
$this->assertIsInt($cliz->id);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @covers App\Factory\UserFactory
|
|
*/
|
|
public function testUserCreate()
|
|
{
|
|
$new_user = UserFactory::create($this->account->id);
|
|
$new_user->email = $this->faker->freeEmail;
|
|
$new_user->save();
|
|
|
|
$this->assertNotNull($new_user);
|
|
|
|
$this->assertIsInt($new_user->id);
|
|
}
|
|
}
|