View Issue Details

IDProjectCategoryView StatusLast Update
0034379mantisbtcode cleanuppublic2024-04-02 18:15
Reporterhotzeplotz Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Target Version2.27.0Fixed in Version2.27.0 
Summary0034379: Modernizing Tests (partially tests/Mantis)
Description

At first focusing on tests/Mantis.

Tests for Helper

  • Add new Test for Helper helper_api:::get_link_attributes()
  • Rename current HelperTest to ArrayTransposeTest
  • Organize them in an new subdirectory tests/Mantis/Helper
  • Add a new HelperTest as a collection of smaller tests, but larger ones should get their own file

Not sure how many could easily created, but will try to cover helper_api.

Fixing

Found at least one bug in ConfigParserTest.

Arguments for ->assertEqual must be flipped.

public function testExtraTokensIgnore() {
// …
$this->assertEquals( $t_result, 1 ); 
// …
$this->assertEquals( $t_result, array() );
}

Modernizing

Namespaces and autoload

  • Add a classmap to composer.json (at least for the includes that are needed for the tests)
  • Add a psr-4 root for the tests.
    "classmap": [
        "core/classes"
    ],
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },

From:

require_once 'MantisCoreBase.php';
require_once 'MantisEnum.class.php';

To:

namespace Tests\Mantis;

use MantisCoreBase;
use MantisEnum;

PHP language level

  • Update to PHP language level 7.4
  • Add type hints
  • Add declaration for strict_types
  • Array syntax from array() to []
  • Replace assertEquals with the strict assertSame
TagsNo tags attached.

Activities

hotzeplotz

hotzeplotz

2024-03-30 17:02

reporter   ~0068756

Namespaces and autoload

Not yet :-)

dregad

dregad

2024-03-31 05:54

developer   ~0068757

Last edited: 2024-03-31 05:56

PRs

Related Changesets

MantisBT: master 4e60470b

2024-03-31 06:56

grummbeer

Committer: community


Details Diff
ConfigParserTest: swap assertEquals arguments

Fix wrong order of arguments for assertEquals(): expected value comes
first, actual value second.

Issue 0034379

Signed-off-by: Damien Regad <dregad@mantisbt.org>
Affected Issues
0034379
mod - tests/Mantis/ConfigParserTest.php Diff File

MantisBT: master aa93edbf

2024-03-31 09:45

grummbeer

Committer: community


Details Diff
Add test for helper_api::helper_get_link_attributes

Issue 0034379, PR https://github.com/mantisbt/mantisbt/pull/1983

Co-authored-by: Damien Regad <dregad@mantisbt.org>
Affected Issues
0034379
add - tests/Mantis/Helper/GetLinkAttributesTest.php Diff File

MantisBT: master be443604

2024-04-01 04:45

grummbeer

Committer: dregad


Details Diff
Improve ArrayTransposeTest

- Update array syntax from array() to []
- Add type hints and add declare(strict_types=1);
- Use the Generator syntax to yield the samples instead of creating an
array first.
- Change assertEquals to assertSame to be more strict.

Fixes 0034379, PR https://github.com/mantisbt/mantisbt/pull/1985

Signed-off-by: Damien Regad <dregad@mantisbt.org>

Separated Move and Rename operations into distinct commits for better
continuity in Git history.
Affected Issues
0034379
mod - tests/Mantis/Helper/ArrayTransposeTest.php Diff File

MantisBT: master c4011982

2024-04-02 17:45

dregad


Details Diff
Rename HelperTest to ArrayTransposeTest

Issue 0034379
Affected Issues
0034379
mv - tests/Mantis/HelperTest.php → tests/Mantis/ArrayTransposeTest.php Diff File

MantisBT: master 62ead2c4

2024-04-02 17:48

dregad


Details Diff
Move ArrayTransposeTest to tests/Mantis/Helper

Issue 0034379
Affected Issues
0034379
mv - tests/Mantis/ArrayTransposeTest.php → tests/Mantis/Helper/ArrayTransposeTest.php Diff File