scaffold-command icon indicating copy to clipboard operation
scaffold-command copied to clipboard

Bitbucket CI Tests do not work correctly

Open derweili opened this issue 6 years ago • 2 comments

The Bitbucket CI Tests added with the wp scaffold plugin-tests command do not work correctly. I always get following error with phpcs test.

<1s
+ phpcs
ERROR: Referenced sniff "PHPCompatibilityWP" does not exist
Run "phpcs --help" for usage information

When I try to skip the phpcs test (commenting it out) I get another error with the phpunit test:

+ phpunit
wp_die called
Message : <h1>Error establishing a database connection</h1>
<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can&#8217;t contact the database server at <code>127.0.0.1</code>. This could mean your host&#8217;s database server is down.</p>
<ul>
<li>Are you sure you have the correct username and password?</li>
<li>Are you sure that you have typed the correct hostname?</li>
<li>Are you sure that the database server is running?</li>
</ul>
<p>If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="https://wordpress.org/support/">WordPress Support Forums</a>.</p>
Title : 

Steps to reproduce:

  1. Create a new plugin with the wp scaffold plugin my-test-plugin command
  2. Add plugin tests for bitbucket with the wp scaffold plugin-tests my-test-plugin --ci=bitbucketcommand
  3. Add a remote bitbucket repository with pipelines enabled
  4. Push to remote
  5. Open Bitbucket pipelines for the repository.

I didn't edit any of the plugin files, i only used wp cli to add a blank plugin with bitbucket CI-tests I'm using WP-CLI version 2.1.0

derweili avatar Jan 14 '19 12:01 derweili

I am also experiencing this issue.

ricxsar avatar Apr 08 '19 02:04 ricxsar

I was able to solve the problem.

On the .phpcs.xml.dist, comment the PHPCompatibilityWP rule

<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<!-- <rule ref="PHPCompatibilityWP"/> -->

On the bitbucket-pipelines.yml, update the database definition similar below:

definitions:
  services:
    database:
      image: mysql:5.7
      environment:
        MYSQL_DATABASE: 'sample_database'
        MYSQL_ROOT_PASSWORD: 'root'

On the bitbucket-pipelines.yml, update the "# Run PHPUnit" section to:

          # Run PHPUnit
          - bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest

PHPUnit cannot access the database due to permission. PHPUnit should be the one to create the database.

ricxsar avatar Apr 08 '19 07:04 ricxsar