Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-80855

Restructure tests directories for PHPUnit tests

XMLWordPrintable

    • MOODLE_404_STABLE
    • Restructure Unit Test directories

      When we switched to phpunit we were perhaps a little care-free with our directory pattern. As a result we are now in the situation where we have unit tests in the same dir as the behat folder, fixtures, etc.

      Whilst discussing MDL-66903, it occurs to me that we can actually restructure tests and it won't break the world. We already run all tests in the tests/ directory, and subdirs of it, which match the naming pattern test_*.php. That will continue to wrok during a migration period, after which we can introduce a test to fail on any 'broken' tests.

      Fixtures could be either placed in ./tests/phpunit/fixtures, or perhaps in ./tests/fixtures

      I would propose that we go for a structure such as either:

      Proposal A

      • Move all tests to tests/phpunit/tests
      • Move all classes to tests/phpunit/classes

      .
      └── tests
          ├── behat
          │   ├── classes
          │   │   └── behat_context.php
          │   └── features
          │       └── my_thing.feature
          └── phpunit
              ├── classes
              │   └── my_testcase.php
              ├── fixtures
              │   └── my_fixture.php
              └── tests
                  ├── event
                  │   └── my_event_test.php
                  └── my_thing_test.php
      

      This means that we have a bit of a 'redundant' tests childir but it means that we don't have tests mixed in with helpers, testcases, and fixtures.

      Proposal B

      • Move all tests to tests/phpunit
      • Move all classes to tests/phpunit/classes

      .
      └── tests
          ├── behat
          │   ├── classes
          │   │   └── behat_context.php
          │   └── features
          │       └── my_thing.feature
          └── phpunit
              ├── classes
              │   └── my_testcase.php
              ├── event
              │   └── my_event_test.php
              ├── fixtures
              │   └── my_fixture.php
              └── my_thing_test.php
      

      Basically the same, but the test files are in the same dir as the classes, and fixtures.

      Proposal C

      • Move all tests to tests/phpunit
      • Move all classes to tests/classes

      .
      └── mod
          └── example
              └── tests
                  ├── behat
                  │   ├── classes
                  │   │   └── behat_mod_example.php
                  │   └── my_thing.feature
                  ├── classes
                  │   ├── generator.php
                  │   └── my_testcase.php
                  ├── fixtures
                  │   ├── fixture_data.csv
                  │   ├── my_fixture.php
                  │   └── mycat.jpg
                  └── phpunit
                      ├── event
                      │   └── my_event_test.php
                      ├── my_thing_test.php
                      └── task
                          └── my_task_test.php
      

      Notes

      • These proposals don't really touch on behat for now - we can/should deal with that separately.

            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 48 minutes
                48m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.