Bug 36765 - TestBuilder should explode if FK broken
Summary: TestBuilder should explode if FK broken
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-02 18:37 UTC by Tomás Cohen Arazi (tcohen)
Modified: 2024-05-06 12:33 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.