Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force-autoloading class-tgm-plugin-activation.php breaks my plugin's tests because its code doesn't account for WordPress not yet loaded #792

Open
cliffordp opened this issue Jul 4, 2020 · 10 comments

Comments

@cliffordp
Copy link

Re: https://github.com/TGMPA/TGM-Plugin-Activation/blob/develop/composer.json#L36-L38

"autoload": {
  "files": ["class-tgm-plugin-activation.php"]
}

Force-loading this file causes errors when running Codeception tests on a plugin that implements TGMPA, failing because class-tgm-plugin-activation.php does not have defensive code if did_action function exists or if ABSPATH is not defined.

Screenshot:

image

If ☝️ gets fixed, that's when the ABSPATH one appears. This has to be fixed in the package because TGMPA is installed via Composer.

I'd be willing to submit a PR but am unsure if it'd be received/implemented.

I had bookmarked checking out https://github.com/afragen/wp-dependency-installer anyway so that's what I'm going to try next.

@cliffordp cliffordp changed the title Force-autoloading class-tgm-plugin-activation.php breaks my plugin's tests Force-autoloading class-tgm-plugin-activation.php breaks my plugin's tests because its code doesn't account for WordPress not yet loaded Jul 4, 2020
@jrfnl
Copy link
Contributor

jrfnl commented Jul 4, 2020

@cliffordp I'm not sure I understand the problem.

The file does contain defensive coding for ABSPATH and will return without doing anything if ABSPATH is not defined.

If ABSPATH is defined, WP must be loaded, so did_action() should be available.

@jrfnl
Copy link
Contributor

jrfnl commented Jul 4, 2020

Only thing I can think of is that that code may not be in the last release. It is in the file in master.

@cliffordp
Copy link
Author

cliffordp commented Jul 4, 2020

I've got v2.6.1 as confirmed by PhpStorm in this screenshot, which is the latest version from https://packagist.org/packages/tgmpa/tgm-plugin-activation
image

I see neither v2.6.1 nor master have the ABSPATH check that's present in develop.

Adding that check from develop does fix the issue with my tests. Sounds like a version bump would be the path forward. Thanks for the quick help! :)

@cliffordp
Copy link
Author

@jrfnl any idea why https://packagist.org/packages/tgmpa/tgm-plugin-activation has v2.6.1 as latest version still - no version bump yet? Using dev-develop instead is of risk since I don't know what goes into there compared to an official release.

@jrfnl
Copy link
Contributor

jrfnl commented Sep 1, 2020

@cliffordp Because that is the latest version. See my previous answer to you about releasing a new version: #741 (comment)

Also, you can see exactly what has changed between the last release and develop:

@cliffordp
Copy link
Author

cliffordp commented Sep 1, 2020

I understand. How can we get 2.6.2 (or whatever other number, such as 2.6.1.1) released that ONLY has the defensive coding for ABSPATH so dev-develop can be a development branch but Composer installs (including GitHub Actions tests) can specify a version number?

@jrfnl
Copy link
Contributor

jrfnl commented Sep 1, 2020

See my previous answer and no, that will not be a release just with that fix.

@cliffordp
Copy link
Author

boo 😜

thanks for the quick, thorough help nonetheless. appreciate ya!

@seothemes
Copy link

One workaround is to use the git repository:

"repositories": [
    {
      "type": "package",
      "package": {
        "name": "tgm/plugin-activation",
        "version": "2.6.1",
        "source": {
          "url": "https://github.com/TGMPA/TGM-Plugin-Activation.git",
          "type": "git",
          "reference": "master"
        }
      }
    }
  ],

And then require the latest:

"require": {
    "tgmpa/tgm-plugin-activation": "*",
  },

@XedinUnknown
Copy link

Or, you could define dependency on tgmpa/tgm-plugin-activation:dev-develop to get latest develop branch, provided you have minimum-stability set to dev.

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

No branches or pull requests

4 participants