Closed SMEWebify closed 1 month ago
namespace Tests\Unit;
use App\Models\Accounting\AccountingDelivery;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AccountingDeliveryTest extends TestCase
{
use RefreshDatabase; // Cela s'assure que la base de données est réinitialisée pour chaque test
public function testCreateAccountingDeliveryWithFactoryDefaults()
{
// Créer une instance de AccountingDelivery en utilisant la factory sans arguments supplémentaires
$delivery = AccountingDelivery::factory()->create();
// Vérifier que l'instance a été sauvegardée dans la base de données avec les attributs générés par la factory
$this->assertDatabaseHas('accounting_deliveries', [
'code' => $delivery->code,
'label' => $delivery->label,
]);
// Vérifier que les attributs correspondent à ceux générés par la factory
$this->assertContains($delivery->code, ['FREE_SHIPPING', 'TRANSPORT_COURIER', 'TRANSPORT_CARGO']);
$this->assertEquals($delivery->code, $delivery->label);
}
}
namespace Tests\Unit;
use App\Models\Accounting\AccountingPaymentConditions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AccountingPaymentConditionsTest extends TestCase
{
use RefreshDatabase; // Assure que chaque test est exécuté avec une base de données fraîche
/**
* Test the creation of AccountingPaymentConditions using the factory.
*/
public function testCreateAccountingPaymentConditions()
{
// Créer une instance en utilisant la factory
$paymentCondition = AccountingPaymentConditions::factory()->create();
// Vérifier que l'instance est bien enregistrée dans la base de données
$this->assertDatabaseHas('accounting_payment_conditions', [
'code' => $paymentCondition->code,
'label' => $paymentCondition->label,
'number_of_month' => $paymentCondition->number_of_month,
'number_of_day' => $paymentCondition->number_of_day,
'month_end' => $paymentCondition->month_end
]);
// Vérifier les attributs pour s'assurer qu'ils correspondent aux données générées par la factory
$this->assertEquals($paymentCondition->code, $paymentCondition->label);
$this->assertContains($paymentCondition->code, ['NODEF', '30FDM15', '30FDM', '30NET', '45FDM']);
$this->assertContains($paymentCondition->month_end, [1, 2]);
$this->assertIsNumeric($paymentCondition->number_of_month);
$this->assertIsNumeric($paymentCondition->number_of_day);
}
}
namespace Tests\Unit;
use App\Models\Accounting\AccountingPaymentMethod;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AccountingPaymentMethodTest extends TestCase
{
use RefreshDatabase; // Assure que chaque test est exécuté avec une base de données fraîche
/**
* Test the creation of AccountingPaymentMethod using the factory.
*/
public function testCreateAccountingPaymentMethod()
{
// Créer une instance en utilisant la factory
$paymentMethod = AccountingPaymentMethod::factory()->create();
// Vérifier que l'instance est bien enregistrée dans la base de données
$this->assertDatabaseHas('accounting_payment_methods', [
'code' => $paymentMethod->code,
'label' => $paymentMethod->label,
'code_account' => $paymentMethod->code_account,
]);
// Vérifier les attributs pour s'assurer qu'ils correspondent aux données générées par la factory
$this->assertEquals($paymentMethod->code, $paymentMethod->label);
$this->assertContains($paymentMethod->code, ['CACHE', 'BANK_CARD', 'BANCK_TRANSFER']);
$this->assertIsNumeric($paymentMethod->code_account);
}
namespace Tests\Unit;
use App\Models\Accounting\AccountingVat;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AccountingVatTest extends TestCase
{
use RefreshDatabase; // Assure que chaque test est exécuté avec une base de données fraîche
/**
* Test the creation of AccountingVat using the factory.
*/
public function testCreateAccountingVat()
{
// Créer une instance en utilisant la factory
$vat = AccountingVat::factory()->create();
// Vérifier que l'instance est bien enregistrée dans la base de données
$this->assertDatabaseHas('accounting_vats', [
'code' => $vat->code,
'label' => $vat->label,
'rate' => $vat->rate,
]);
// Vérifier les attributs pour s'assurer qu'ils correspondent aux données générées par la factory
$this->assertEquals($vat->code, $vat->label);
$this->assertContains($vat->code, ['TVA0', 'TVA5', 'TVA10', 'TVA20']);
$this->assertContains($vat->rate, [0, 5, 10, 20]);
}
}
Some error with php unit
Your requirements could not be resolved to an installable set of packages.
Problem 1
- phpunit/php-code-coverage 10.0 requires **phpunit/php-file-iterator ^3.0.3** -> found phpunit/php-file-iterator[3.0.3, ..., 3.0.x-dev] but the package
is fixed to 4.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- phpunit/phpunit 10.0.0 requires phpunit/php-code-coverage ^10.0 -> satisfiable by phpunit/php-code-coverage[10.0].
- Root composer.json requires phpunit/phpunit 10.0 -> satisfiable by phpunit/phpunit[10.0.0].
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires phpunit/phpunit 10.0 -> satisfiable by phpunit/phpunit[10.0.0].
- phpunit/phpunit 10.0.0 requires **phpunit/php-file-iterator ^4.0** -> found phpunit/php-file-iterator[4.0.0, ..., 4.1.x-dev] but the package is fixed to 3.0.3 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
phpunit/php-code-coverage need php-file-iterator 3.0.3 phpunit/phpunit 10.0.0 requires need phpunit/php-file-iterator 4.0
How do I get out of there?
composer update --with-all-dependencies Loading composer repositories with package information Updating dependencies Lock file operations: 0 installs, 16 updates, 0 removals
composer update phpunit/phpunit phpunit/php-code-coverage --with-all-dependencies Loading composer repositories with package information Updating dependencies Nothing to modify in lock file Installing dependencies from lock file (including require-dev) Nothing to install, update or remove
./vendor/bin/phpunit --version PHPUnit 9.6.19 by Sebastian Bergmann and contributors.
php artisan test --without-tty
NunoMaduro\Collision\Adapters\Laravel\Exceptions\RequirementsException
Running Collision 7.x artisan test command requires at least PHPUnit 10.x.
PASS Tests\Feature\AccountingDeliveryTest ✓ create accounting delivery with factory defaults 8.98s
PASS Tests\Feature\AccountingPaymentConditionsTest ✓ create accounting payment conditions 0.07s
PASS Tests\Feature\AccountingPaymentMethodTest ✓ create accounting payment method 0.06s
PASS Tests\Feature\AccountingVatTest ✓ create accounting vat 0.05s
Use existing factorys
First step Acounting model