View Issue Details

IDProjectCategoryView StatusLast Update
0035258mantisbtotherpublic2025-01-31 10:47
Reporterdregad Assigned Todregad  
PrioritynormalSeverityminorReproducibilitysometimes
Status resolvedResolutionfixed 
Product Version2.28.0 
Target Version2.28.0Fixed in Version2.28.0 
Summary0035258: Use of PHPUnit::toString() sometimes causes errors in tests
Description

toString() uses a fully qualified class name, and also appends details about test data which can easily result in fairly long strings. When it is too big to store in the underlying column, the test errors out:

Database query failed: Data too long for column 'name' at row 1

This happened to me with RestFiltersTest::testGetIssuesMatchingFilter(), while running the test suite after adding namespaces to the test scripts - mantis_filter_table.name is VARCHAR(64).

TagsNo tags attached.

Relationships

related to 0035223 resolvedcommunity MantisBT tests are not compatible with PHPUnit 11.5 
related to 0035259 resolveddregad Add namespaces to PHPUnit test suite 

Activities

dregad

dregad

2025-01-25 12:26

developer   ~0069751

@raspopov FYI - toString seemed to be a good idea at first, but considering this, and the fact that it is also a PHPUnit internal method just like getName() / name(), we might as well use our own function using the latter after all...

raspopov

raspopov

2025-01-26 00:02

reporter   ~0069752

That's the best I could come up with:

abstract class MantisTestCase extends TestCase {
...
    public static function name(): string {
        $t_call = debug_backtrace()[1];
        $t_class = explode( '\\', $t_call['class'] );
        return end( $t_class ) . '::' . $t_call['function'];
    }
...
dregad

dregad

2025-01-26 05:32

developer   ~0069753

Thanks for the feedback.

I considered using debug_backtrace() as well, but the problem is that the first parent in the call stack is not necessarily the test case, there could be intermediate helper methods in between.

I didn't try, but I guess we could walk the stack backwards until we get the first function called by PHPUnit's TestCase class...

Anyway, considering that PHPUnit's getName()/name() have been pretty stable for many years, despite them being internal methods, I'd rather stick to using them and adapt our code if and when it changes again in the future.

I have included a fix for this in PR https://github.com/mantisbt/mantisbt/pull/2082

Related Changesets

MantisBT: master 616d9bd0

2025-01-25 12:33

dregad


Details Diff
New MantisTestCase::getTestName() method

Used instead of PHPUnit TestCase::toString().

Avoids error on RestFiltersTest::testGetIssuesMatchingFilter():
Database query failed: Data too long for column 'name' at row 1

Fixes 0035258
Affected Issues
0035258
mod - tests/core/MantisTestCase.php Diff File
mod - tests/rest/RestBase.php Diff File
mod - tests/rest/RestFiltersTest.php Diff File
mod - tests/soap/ProjectTest.php Diff File
mod - tests/soap/SoapBase.php Diff File

MantisBT: master 5b4f46b2

2025-01-31 10:47

dregad


Details Diff
Add namespaces to PHPUnit test suite

Fixes 0035259, 0035258
Merge PR https://github.com/mantisbt/mantisbt/pull/2082
Affected Issues
0035258, 0035259
mod - composer.json Diff File
mod - composer.lock Diff File
mod - tests/Mantis/ConfigParserTest.php Diff File
mod - tests/Mantis/Helper/ArrayTransposeTest.php Diff File
mod - tests/Mantis/Helper/GetLinkAttributesTest.php Diff File
mod - tests/Mantis/MantisCoreBase.php Diff File
mod - tests/Mantis/MantisEnumTest.php Diff File
mod - tests/Mantis/MentionParsingTest.php Diff File
mod - tests/Mantis/PluginTest.php Diff File
mod - tests/Mantis/PrepareTest.php Diff File
mod - tests/Mantis/StringTest.php Diff File
mod - tests/Mantis/UserApiTest.php Diff File
mod - tests/TestConfig.php Diff File
mod - tests/core/Faker.php Diff File
add - tests/core/MantisTestCase.php Diff File
mod - tests/core/RequestBuilder.php Diff File
mod - tests/rest/RestBase.php Diff File
mod - tests/rest/RestFiltersTest.php Diff File
mod - tests/rest/RestImpersonateUserTest.php Diff File
mod - tests/rest/RestIssueRelationshipsTest.php Diff File
mod - tests/rest/RestIssueTest.php Diff File
mod - tests/rest/RestIssueUpdateVersion.php Diff File
mod - tests/rest/RestProjectTest.php Diff File
mod - tests/rest/RestProjectVersionTest.php Diff File
mod - tests/rest/RestUserTest.php Diff File
mod - tests/soap/AttachmentTest.php Diff File
mod - tests/soap/CategoryTest.php Diff File
mod - tests/soap/CompressionTest.php Diff File
mod - tests/soap/EnumTest.php Diff File
mod - tests/soap/FilterTest.php Diff File
mod - tests/soap/IssueAddTest.php Diff File
mod - tests/soap/IssueHistoryTest.php Diff File
mod - tests/soap/IssueMonitorTest.php Diff File
mod - tests/soap/IssueNoteTest.php Diff File
mod - tests/soap/IssueUpdateTest.php Diff File
mod - tests/soap/LoginTest.php Diff File
mod - tests/soap/MentionTest.php Diff File
mod - tests/soap/ProjectTest.php Diff File
mod - tests/soap/RelationshipTest.php Diff File
mod - tests/soap/SoapBase.php Diff File
mod - tests/soap/TagTest.php Diff File
mod - tests/soap/UserTest.php Diff File
mod - tests/soap/VersionTest.php Diff File