daithi-coombes / api-connection-manager

Manages connections and requests to 3rd party providers or services
0 stars 1 forks source link

Jenkins Wordpress Unit Tests #77

Closed daithi-coombes closed 11 years ago

daithi-coombes commented 11 years ago

Getting an error in jenkins when running unit tests that utilize the wordpress make unit tests, such as this plugin. Without the wordpress make unit tests phpunit cannot be used as calls such as wp_user() will throw errors.

Fatal error: Class 'API_Con_Mngr_Error' not found in /var/lib/jenkins/jobs/API-Connection-Manager/workspace/tests/class-api-con-mngr-errorTest.php on line 19
daithi-coombes commented 11 years ago

As the tests are working on localhost, the only difference being that the plugin files are in a wordpress installation locally and in the CI they are in the jenkins/jobs/project/workspace folder.

Seems that whats happening is the class-api-con-mngr-errorTest.php file is being run against the blog set in the wp-tests-config.php file:

<?php
/* Path to the WordPress codebase you'd like to test. Add a backslash in the end. */
define( 'ABSPATH', '/var/www/myBlog/public_html/' );
...

So a possible solution is to create a blog somewhere and get jenkins to copy the new commit to that blogs plugins folder before testing - and set the blog path in the above file (same blog can be used for all plugins on this CI)

mrdavidlaing commented 11 years ago

Jenkins sets the ENV variable WORKSPACE to the absolute path to where the job's working folder.

https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables

Rather than hard coding an ABSPATH, could you derive it from this variable?

On Tuesday, June 11, 2013, daithi-coombes wrote:

As the tests are working on localhost, the only difference being that the plugin files are in a wordpress installation locally and in the CI they are in the jenkins/jobs/project/workspace folder.

Seems that whats happening is the class-api-con-mngr-errorTest.php file is being run against the blog set in the wp-tests-config.php file:

<?php/* Path to the WordPress codebase you'd like to test. Add a backslash in the end. */define( 'ABSPATH', '/var/www/myBlog/public_html/' );...

So a possible solution is to create a blog somewhere and get jenkins to copy the new commit to that blogs plugins folder before testing - and set the blog path in the above file (same blog can be used for all plugins on this CI)

— Reply to this email directly or view it on GitHubhttps://github.com/daithi-coombes/api-connection-manager/issues/77#issuecomment-19273368 .

David Laing Open source @ City Index - github.com/cityindex http://davidlaing.com Twitter: @davidlaing

daithi-coombes commented 11 years ago

unfortunately not for this scenario. The wordpress unit tests hold the test cases and run these against your blog. I wrote up tut on my blog, should give an idea of the steps involved.. http://david-coombes.com/phpunit-testing-wordpress-plugins-with-wordpress-make/

The solution in the end was to use niko's repo instead, this has been moved to the wp core so is accepted as standard.

Ran the fist set of tests and just going through the failures now, but no fatal errors or exceptions thrown (gettin closer)

daithi-coombes commented 11 years ago

@mrdavidlaing

what I got working in the end was to place the wp make unit tests in the normal workspace directory /var/lib/jenkins/jobs/api-con/ and change the workspace dir in the project settings: jenkins dash->api-con->configure->advanced project options

The make unit tests have a wordpress blog included in them, so now the workspace for the project is at: /var/lib/jenkins/jobs/API Connection Manager/workspace/wordpress-tests/wordpress/wp-content/plugins/api-connection-manager

the metrics are at: http://david-coombes.com:8080/jenkins/job/API-Connection-Manager/