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

Add new --ci option to pest bin #405

Merged
merged 9 commits into from
Sep 25, 2021
Merged

Add new --ci option to pest bin #405

merged 9 commits into from
Sep 25, 2021

Conversation

fabio-ivona
Copy link
Collaborator

Hi guys!

as already discussed on the discord channel with @nunomaduro , this PR wants to put a base for adding a new "environment aware" behaviour to pestphp

background

my main idea comes from my bad habit to forget to remove ->only method from a test (maybe added when fixing a bug) and this results the pipeline to execute only a partial set of my test suite, with the risk to deploy some other bug in production.

the idea

Pestphp could be able to detect the environment it is running into and sligthing changing its behaviour according to it.

to hint pest it is running in a CI pipeline, it could be launched with the --ci option:

vendor/bin/pest --colors=always --ci

and it would ignore all ->only() directives given to it

the implementation

I added a new $workingEnv attribute to the TestSuite class that holds the current working environment. Its default value is 'local' and it is set to ci if the pest binary is called with the --ci option

this way the ->only() behaviour can be disabled when in a CI environment:

final class TestRepository
{
  //...
  private function testsUsingOnly(): array
      {
          if (TestSuite::getInstance()->workingEnv === 'ci') {
              return [];
          }
  
          return array_filter($this->state, function ($testFactory): bool {
              return $testFactory->only;
          });
      }
   //...

future uses

the TestSuite::getInstance()->workingEnv attribute could be used in future implementation to fine tuning pest behaviour when in a continuous integration environment (or other ones, defined as necessary)

@nunomaduro
Copy link
Member

Can you refactor this, in a way that the option gets "setted" using a plugin class? https://github.com/pestphp/pest/tree/master/src/Plugins.

@fabio-ivona
Copy link
Collaborator Author

fabio-ivona commented Sep 22, 2021

Can you refactor this, in a way that the option gets "setted" using a plugin class? https://github.com/pestphp/pest/tree/master/src/Plugins.

Done, I've extracted environment informations in Context Plugin, this way we can add more contextual info in next developments, if necessary

@fabio-ivona
Copy link
Collaborator Author

@nunomaduro there are some strange errors in tests, are there currently any issues with them?

@nunomaduro
Copy link
Member

Not sure why, but can't resolve the conflicts. Can you do it please?

@fabio-ivona
Copy link
Collaborator Author

Not sure why, but can't resolve the conflicts. Can you do it please?

@nunomaduro I've solved merge conflicts

CI errors keep showing, I think they are related to the ones showing in #409

@nunomaduro nunomaduro merged commit a6e34d2 into pestphp:master Sep 25, 2021
@nunomaduro
Copy link
Member

@fabio-ivona Can you add docs about this?

@fabio-ivona fabio-ivona deleted the add-new-ci-option-to-pest-bin branch September 25, 2021 13:47
@fabio-ivona
Copy link
Collaborator Author

@fabio-ivona Can you add docs about this?

Sure! It's already written, will open a PR this night

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.

2 participants