Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Build some unit tests #369

Closed
SMEWebify opened this issue Apr 29, 2024 · 10 comments
Closed

[TEST] Build some unit tests #369

SMEWebify opened this issue Apr 29, 2024 · 10 comments
Assignees
Labels
help wanted Extra attention is needed php Pull requests that update Php code Reduce technical debt Facilitates long-term thinking

Comments

@SMEWebify
Copy link
Owner

Use existing factorys

First step Acounting model

@SMEWebify SMEWebify added Reduce technical debt Facilitates long-term thinking php Pull requests that update Php code labels Apr 29, 2024
@SMEWebify SMEWebify self-assigned this Apr 29, 2024
@SMEWebify
Copy link
Owner Author

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);
    }
}

@SMEWebify
Copy link
Owner Author

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);
    }
}

@SMEWebify
Copy link
Owner Author

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);
    }

@SMEWebify
Copy link
Owner Author

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]);
    }
}

@SMEWebify SMEWebify added the help wanted Extra attention is needed label May 2, 2024
SMEWebify added a commit that referenced this issue May 2, 2024
@SMEWebify
Copy link
Owner Author

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?

@SMEWebify
Copy link
Owner Author

composer update --with-all-dependencies
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 16 updates, 0 removals

  • Downgrading phpunit/php-code-coverage (10.0 => 9.2.31)
  • Upgrading phpunit/php-file-iterator (3.0.3 => 3.0.6)
  • Downgrading phpunit/php-invoker (4.0 => 3.1.1)
  • Downgrading phpunit/php-text-template (3.0 => 2.0.4)
  • Downgrading phpunit/php-timer (6.0 => 5.0.3)
  • Downgrading sebastian/cli-parser (2.0 => 1.0.2)
  • Downgrading sebastian/code-unit (2.0 => 1.0.8)
  • Downgrading sebastian/comparator (5.0 => 4.0.8)
  • Downgrading sebastian/diff (5.0 => 4.0.6)
  • Downgrading sebastian/environment (6.0 => 5.1.5)
  • Downgrading sebastian/exporter (5.0 => 4.0.6)
  • Downgrading sebastian/global-state (6.0 => 5.0.7)
  • Downgrading sebastian/object-enumerator (5.0 => 4.0.4)
  • Downgrading sebastian/recursion-context (5.0 => 4.0.5)
  • Downgrading sebastian/type (4.0 => 3.2.1)
  • Downgrading sebastian/version (4.0 => 3.0.2)

@SMEWebify
Copy link
Owner Author

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

@SMEWebify
Copy link
Owner Author

./vendor/bin/phpunit --version
PHPUnit 9.6.19 by Sebastian Bergmann and contributors.

@SMEWebify
Copy link
Owner Author

php artisan test --without-tty

NunoMaduro\Collision\Adapters\Laravel\Exceptions\RequirementsException

Running Collision 7.x artisan test command requires at least PHPUnit 10.x.

SMEWebify added a commit that referenced this issue May 2, 2024
@SMEWebify SMEWebify pinned this issue Aug 23, 2024
@SMEWebify
Copy link
Owner Author

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

SMEWebify added a commit that referenced this issue Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed php Pull requests that update Php code Reduce technical debt Facilitates long-term thinking
Projects
Status: Done
Development

No branches or pull requests

1 participant