Skip to content

Prevent autoloading of tests/php folder#1940

Merged
jarednova merged 3 commits intomasterfrom
tests/php-folder-autoloading
Mar 8, 2019
Merged

Prevent autoloading of tests/php folder#1940
jarednova merged 3 commits intomasterfrom
tests/php-folder-autoloading

Conversation

@gchtr
Copy link
Copy Markdown
Member

@gchtr gchtr commented Mar 5, 2019

Issue

In the unit tests, we sometimes require other PHP files, e.g. in test-timber-term.php:

require_once('php/timber-post-subclass.php');

When using classmap, Composer autoloads these classes whenever class_exists() is called, not only when we require them:

timber/composer.json

Lines 51 to 54 in 7385f93

"autoload-dev": {
"classmap": [
"tests/"
]

In #1931, I wrote a test where I needed a particular class to exist only for a particular test. For the other tests, the class shouldn’t exist.

That test failed in Travis, because I didn’t use composer dump-autoload locally before running the tests and so in Travis, the class was found and triggered the error, while locally I didn’t see that error.

Solution

I looked for an option to ignore certain classes from autoloading and found that we can use exclude-from-classmap to prevent certain files to be autoloaded.

This pull requests sets the tests/php folder to be excluded from the Composer classmaps, so that all classes in that folder always have to required manually by unit tests.

Impact

By not autoloading the tests/php folder, we should have better expectations of what should happen in tests.

Usage Changes

None?

Considerations

Can you imagine how much I learn every day about various coding stuff when working on Timber 😎?

Testing

Tested. There should be no changes for the current tests.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2019

Codecov Report

Merging #1940 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1940   +/-   ##
=========================================
  Coverage     95.04%   95.04%           
  Complexity     1556     1556           
=========================================
  Files            48       48           
  Lines          3672     3672           
=========================================
  Hits           3490     3490           
  Misses          182      182

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff327bf...825d079. Read the comment docs.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 5, 2019

Coverage Status

Coverage remained the same at 94.324% when pulling 825d079 on tests/php-folder-autoloading into ff327bf on master.

@jarednova
Copy link
Copy Markdown
Member

Indeed, the things you learn everyday — looks good to me!

@jarednova jarednova merged commit a020533 into master Mar 8, 2019
@jarednova jarednova deleted the tests/php-folder-autoloading branch March 8, 2019 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants