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

Missing support to Infection PHP #4

Closed
nunomaduro opened this issue May 12, 2020 · 11 comments
Closed

Missing support to Infection PHP #4

nunomaduro opened this issue May 12, 2020 · 11 comments

Comments

@nunomaduro
Copy link
Member

Infection is a PHP mutation testing framework based on AST (Abstract Syntax Tree) mutations: https://infection.github.io/guide.

Problem: When running Infection against a test suite written in Pest, Infection will use the phpunit binary instead causing the following exception:

Pest\Exceptions\InvalidPestCommand: Please run `./vendor/bin/pest` instead
  of `/vendor/bin/phpunit`. in /Users/nunomaduro/laravel/vendor/pestphp/pest/
  src/TestSuite.php on line 106

How to fix this issue: Develop a Pest adapter and pull request it to the Infection repository.

@owenvoke
Copy link
Member

I might take a quick look at this tomorrow, just to see how it's done. 👍

@owenvoke
Copy link
Member

owenvoke commented May 13, 2020

Right, I've taken a look and this is probably going to be complicated.

New adapters are created as an additional repository, I was thinking of a pestphp/infection-adapter or, if Infection want to have it, an infection/pest-adapter package. I've created a test version that is partially working, after making sure it uses the right executable, etc.

However it looks like the TestFrameworkConfigLocator class is hardcoded to use {path}/{frameworkName}.{extension}, whereas Pest uses the phpunit.xml/phpunit.xml.dist file. 😕 I can get round this by copying the phpunit.xml.dist to pest.xml.dist.

But after that, and some tweaking (hacks?)...

Preview of Pest with Infection!

@nunomaduro
Copy link
Member Author

@owenvoke I guess we can create our own repository for this. Let's call it pest-plugin-infection.

@nunomaduro
Copy link
Member Author

This afternoon I going to create the template for that repository. Give me a couple hours.

@owenvoke
Copy link
Member

It looks like the only changes we'd need to PR to Infection is to add a Pest constant and entry to the TYPES constant in TestFrameworkTypes. 🎉 (At least, in master)

@maks-rafalko
Copy link

Hello, Infection's creator here.

Thanks for looking into this and creating this issue.

@owenvoke can you please share an adapter you created for Pest? I wonder how you deal with TestFrameworkAdapter interface and determining whether the test failed or not.

Regarding adapter: I would suggest creating an official repository at infection/pest-adapter to be in line with already 3 implemented:

  • infection/phpspec-adapter
  • infection/codeception-adapter
  • phpunit adapter (currently bundled into the core - infection/infection

You can be maintainers of this repo if that matters.

Why "official" repository is better? because

FYI, adapters should have a special composer package's type infection-extension to be autodiscovered and autoinstallable by our extensions-installer, e.g. see https://github.com/infection/codeception-adapter/blob/09dda58180bc3ba7ca3cb865ba0d0d84dfe3ef5a/composer.json#L4

Didn't dig into the Pest yet, but test framework should have some required features to be able to work efficiently with Infection, some of them are described here infection/infection#45 (comment). I guess if the Pest is just a wrapper for PHPUnit and works with PHPUnit's config, it shouldn't be an issue.

Anyway, I'm happy to help here.

@theofidry
Copy link

@maks-rafalko I think it's also an opportunity to adapt the config locator.

I don't think it makes sense anymore to have it in the core with hard-coded path when its responsibility is to locate the test framework config path, which depends on the test framework itself.

One way would be to move the interface directly in https://github.com/infection/abstract-testframework-adapter or it could even be completely hidden in the adapter, leaving the responsibility to have a dedicated class for that or not to each individual adapters. A non trivial question though is how all of that should interact with the TestFrameworkConfigPathProvider (used for initializing Infection).

@nunomaduro
Copy link
Member Author

Alright, I love infection - but at the moment I've no plans to work on this. Hopefully in the future someone will pick this.

@tomasnorre
Copy link

Missing a sad smiley. But you are the maintainer, it's your call.

@nunomaduro
Copy link
Member Author

@tomasnorre Yeah - unfortunately my free time is very limited. And of course, someone else that needs infection in their test suite can submit a pull request that addresses this issue.

@tomasnorre
Copy link

I totally get that, I wasn't meant as a blame, was just hoping for it.

We just started using pest and I think that mutation tests are really valuable. Perhaps I get to the point where I will make a PR. But like you, I have limited free time too :)

Stay safe and take care.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants