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.
This commit is contained in:
Alexandre Janniaux 2023-11-19 15:05:32 +01:00
parent d4f61dcf59
commit c2c99ab2b8

View File

@ -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";