From c2c99ab2b86b8ee4ee252a67ecf8a01d0b1cf80d Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Sun, 19 Nov 2023 15:05:32 +0100 Subject: [PATCH] FIX: ContratTest: fix create when no societe exists The testContratCreate() is using the default value for Contrat::socid, which is defined by Contrat::initAsSpecimen to `0`. But if no companies have been created, the test will fail with the following error: Failed asserting that 0 is less than -1. Or with the additional logging: UnknownError: ERROR: 23503: insert or update on table "llx_contrat" violates foreign key constraint "fk_contrat_fk_soc" DETAIL: Key (fk_soc)=(1) is not present in table "llx_societe". SCHEMA NAME: public TABLE NAME: llx_contrat CONSTRAINT NAME: fk_contrat_fk_soc LOCATION: ri_ReportViolation, ri_triggers.c:2596 -, Failed asserting that 0 is less than -1. The test doesn't really depends on specific test data so we can create the company directly instead. --- test/phpunit/ContratTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/phpunit/ContratTest.php b/test/phpunit/ContratTest.php index ac919f8d69c..9e035c7b69d 100644 --- a/test/phpunit/ContratTest.php +++ b/test/phpunit/ContratTest.php @@ -139,8 +139,14 @@ class ContratTest extends PHPUnit\Framework\TestCase $langs=$this->savlangs; $db=$this->savdb; + $soc = new Societe($db); + $soc->name = "ContratTest Unittest"; + $socid = $soc->create($user); + $this->assertLessThan($socid, 0, $soc->errorsToString()); + $localobject=new Contrat($db); $localobject->initAsSpecimen(); + $localobject->socid = $socid; $result=$localobject->create($user); print __METHOD__." result=".$result."\n";