Repository navigation
Closed
Description
What are you trying to achieve?
Run more than one test requiring Static data in one TestClass Class
What do you get instead?
Error for missing data in static tables (in my case static_country)
How to reproduce the issue?
class PlatzTest extends FunctionalTestCase {
[...]
/**
* @test
*/
public function searchOverviewAction()
{
$response = $this->executeFrontendSubRequest(
(new InternalRequest())->withQueryParameters(
[
'id' => self::PLATZ_CONTROLLER_PID,
self::PLUGIN_NAME . '[action]' => 'search',
self::PLUGIN_NAME . '[controller]' => 'Platz',
]
)
);
$content = (string)$response->getBody();
self::assertMatchesRegularExpression('#<a href=".*"> Bayern</a>#', $content);
self::assertMatchesRegularExpression('#<a href=".*"> Nordrhein-Westfalen</a>#', $content);
}
/**
* @test
*/
public function searchBundeslandAction()
{
$respones = $this->executeFrontendSubRequest(
(new InternalRequest())->withQueryParameters(
[
'id' => self::PLATZ_CONTROLLER_PID,
self::PLUGIN_NAME . '[action]' => 'search',
self::PLUGIN_NAME . '[controller]' => 'Platz',
self::PLUGIN_NAME . '[countryZone]' => '88',
]
)
);
$content = (string)$respones->getBody();
// Check if campsite 1 is listed
self::assertMatchesRegularExpression('#Campsite 1564940472#', $content);
}
}Relevant code from the Tested Class:
/**
* @return array
*/
private function _getAllCountryZones(): array
{
/** @var \SJBR\StaticInfoTables\Domain\Model\Country $de */
$de = $this->countryRepository->findByUid($this->settings['germanyUid']??54);
$countryZones = $this->countryZoneRepository->findByCountry($de)->toArray();
// sort by name
usort($countryZones, function (CountryZone $a, CountryZone $b) {
return strnatcasecmp($a->getLocalName(), $b->getLocalName());
});
return $countryZones;
}Additional information you would like to provide?
The problem occures in the FunctionalTestCase line 303ff. Or more specific in Testbase.php::initializeTestDatabaseAndTruncateTables. It will truncate ALL tables. And does not insert the Static data back in as seen in Testbase::createDatabaseStructure().
Specify some data of the environment
- TYPO3 testing framework version: 6.16.5 (current main has still the same issue)
- TYPO3 version: 11.5
- TYPO3 installation type:
- PHP version: 7.4 and 8.0
- Web server used + version: apache
- Operating system: linux / docker
- Selenium server version:
- Browser driver (chromedriver/geckodriver...) version:
- Browser used + version:
Metadata
Metadata
Assignees
Labels
No labels
Activity
lolli42 commentedon Jul 13, 2022
Could you try if this solves your issue?
This triggers the db-snapshot functionality for second and further tests, so the imported rows of first test should survive.
I think the problem with your patch approach is that it would collide with the snapshot logic: When static data is imported in first test, and a second tests imports it again with your patch, the snapshotter would try to add those rows a second time and would fail due to duplicate keys. So we can't combine both well, and the static import is a default thing and would always kick in with your approach.
Maybe it's better to simply use the snapshotter in those (relatively rare?) cases, when you need static data combined with multiple tests? So, if the above solution works, I'd tend to keep it that way to avoid further trouble in this area?
sHorst commentedon Jul 13, 2022
i do have the snapshoter configured:
the problem is in the
setUp()of the FunctionalTestCase.phpin case this is not the firstTest, it will call
initializeTestDatabaseAndTruncateTables, which in turn will calltruncateAllTablesForMysqlwhich will truncate the table with this call$connection->truncate($tableName);. This will always truncate the Tables.It is possible, that i hold the tool wrong, but that is the code.
sHorst commentedon Jul 13, 2022
i see where you are heading, with the snapshot, i will check, why it does not work even though the snapshot is configured. (btw. i am on mysql)
lolli42 commentedon Jul 13, 2022
snapshotting as-such works: core uses it in cases where a lot of magic is done to set up db-content (for instance creating a lot of stuff via dataHandler before each test): to speed up things, snapshots are used for second and third tests. i'll also add a minor feature to the snapshot system soon.
lolli42 commentedon Jul 14, 2022
Talked with Stefan about this one:
We will probably remove the auto-loading of static sql files in createDatabaseStructure(). Doing this collides with the snapshot feature, which expects an empty database when it's called (there is currently a hack to prevent issues, which should fall anyways).
Instead, we'll establish a method that can be called to execute these imports manually, so tests that need this (relatively rare) feature can then call it manually. This will also solve the issue for subsequent tests in one test case.
What do you think?
lolli42 commentedon Jul 14, 2022
Ok, yet another thought on this, aligned with Stefan:
The fact that ext_tables_static+adt.sql files are auto-imported in the first place is unfortunate for various reasons:
We will now go ahead in this area and deprecate the auto-import of ext_tables_static+adt.sql within createDatabaseStructure() in v6 and v7 altogether, and will remove it in main (for core >=v12).
Extension's functional test setups that want to import these static data, then have two options:
This gives the test case full control on these cases, and the "broken on subsequent test" issue is solved along the ways since TF does not import such rows by default anymore.
lolli42 commentedon Jul 14, 2022
Note: Many thanks for bringing this up, even if the solution is not "TF magically does it now".
This issue and the related #359 helped a lot to review the current code and consider various possible solutions, and the resulting patches sharpen the TF responsibilities and simplify overall complexity a bit.
I think when you adapt your test cases now, you'll see that it ends up with just a couple of straight code lines to achieve what you need in a reliable way.
[TASK] Deprecate auto-import of ext_tables_static+adt.sql files
[TASK] Deprecate auto-import of ext_tables_static+adt.sql files (#384)
[TASK] Deprecate auto-import of ext_tables_static+adt.sql files (#384)
[TASK] Deprecate auto-import of ext_tables_static+adt.sql files (#384)
liayn commentedon Aug 10, 2022
This must ASAP be documented as "known issue".
@lolli42 I understand all this and I agree with the long-term goal. It cost me 2 hours of debugging through all extbase stuff finally find this cause and create #397.
But, I don't see a feasible way to work around this issue at the moment for v10 and v11.
In our case we have a dependency on static_info_tables and the tables are populated for the first test. I have no problem with providing our own datasets, but how should we import those, it will fail on the first run of course, since the table is already populated, right?
oliverklee commentedon Aug 11, 2022
@liayn I have approached this two different ways in my functional tests that use static records (e.g. countries):
liayn commentedon Aug 11, 2022
@oliverklee Thanks for the ideas. Will forward that internally.
[TASK][#377] Add readme section for static data problem (#398)
[TASK][#377] Add readme section for static data problem (#399)
[!!!][TASK] Remove auto-import of ext_tables_static+adt.sql files