Bug 36765

Summary: TestBuilder should explode if FK broken
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: Architecture, internals, and plumbingAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, kyle, martin.renvoize, tomascohen
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Tomás Cohen Arazi (tcohen) 2024-05-02 18:37:40 UTC
Right now, it only warns and continues. While this might mean 'there already exists a resource with the value we need for the test', this is really hiding a design issue with the tests.

For example

```perl
my $library = $builde->build_object(
    {
        class => 'Koha::Libraries,
        value => { branchcode => 'ILL', pickup_location => 1 }
    }
);
```

might fail because 'ILL' already exists, but if the DB entry doesn't contain the other fixed condition (pickup_location=1) then the tests could fail weirdly, and tracking it would be harder (i.e. you read the code, see you are setting pickup_location=1, but it fails because it is not).

I propose we make it explode loudly instead. And fix the poorly written tests that explode because of it.
Comment 1 Martin Renvoize (ashimema) 2024-05-02 19:47:01 UTC
Sounds sensible to me
Comment 2 Jonathan Druart 2024-05-06 12:32:02 UTC
IIRC we decided that on purpose, so the test does not fail if the DB had the data before running the tests.
Comment 3 Jonathan Druart 2024-05-06 12:33:04 UTC
But yes, I agree we could change the behaviour and explode instead.

In your example we do not care about the branchcode, we should build a library with a random branchcode and reuse it later.