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

Fix PHPUnit incompatibilities, update variable assignment #620

Merged
merged 4 commits into from May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -27,6 +27,12 @@ before_script:
if [[ ! -z "$WP_VERSION" ]] ; then
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
npm install
export PATH="$HOME/.composer/vendor/bin:$PATH"
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
composer global require "phpunit/phpunit=5.7.*"
else
composer global require "phpunit/phpunit=4.8.*"
fi
fi
- |
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
Expand Down
15 changes: 11 additions & 4 deletions bin/install-wp-tests.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
exit 1
fi

Expand All @@ -10,6 +10,7 @@ DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}

WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
Expand Down Expand Up @@ -79,13 +80,14 @@ install_test_suite() {
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

cd $WP_TESTS_DIR

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
Expand All @@ -95,6 +97,11 @@ install_test_suite() {
}

install_db() {

if [ ${SKIP_DB_CREATE} = "true" ]; then
return 0
fi

# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
Expand Down
9 changes: 6 additions & 3 deletions php/util/class-fieldmanager-util-term-meta.php
Expand Up @@ -227,7 +227,8 @@ public function delete_term_meta( $term_id, $taxonomy, $meta_key, $meta_value =
public function get_term_meta_post_id( $term_id, $taxonomy ) {
$cache_key = $this->get_term_meta_post_id_cache_key( $term_id, $taxonomy );

if ( false === ( $term_meta_post_id = wp_cache_get( $cache_key ) ) ) {
$term_meta_post_id = wp_cache_get( $cache_key );
if ( false === $term_meta_post_id ) {
// Check if a post exists for this term.
$query = new WP_Query( array(
'name' => $this->post_slug( $term_id, $taxonomy ),
Expand Down Expand Up @@ -305,7 +306,8 @@ public function add_term_meta_post( $term_id, $taxonomy ) {
* @param string $taxonomy Term taxonomy.
*/
public function collect_garbage( $term_id, $tt_id, $taxonomy ) {
if ( $post = get_page_by_path( $this->post_slug( $term_id, $taxonomy ), OBJECT, $this->post_type ) ) {
$post = get_page_by_path( $this->post_slug( $term_id, $taxonomy ), OBJECT, $this->post_type );
if ( $post ) {
wp_delete_post( $post->ID, true );
}
}
Expand All @@ -321,7 +323,8 @@ public function collect_garbage( $term_id, $tt_id, $taxonomy ) {
* @param string $taxonomy The taxonomy of the *split* term.
*/
public function split_shared_term( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
if ( false != ( $post_id = $this->get_term_meta_post_id( $old_term_id, $taxonomy ) ) ) {
$post_id = $this->get_term_meta_post_id( $old_term_id, $taxonomy );
if ( false != $post_id ) {
wp_update_post( array(
'ID' => $post_id,
'post_name' => $this->post_slug( $new_term_id, $taxonomy ),
Expand Down
2 changes: 1 addition & 1 deletion phpcs.ruleset.xml
Expand Up @@ -13,7 +13,7 @@
<exclude-pattern>templates/</exclude-pattern>
</rule>

<rule ref="WordPress.VIP.RestrictedFunctions.get_page_by_path">
<rule ref="WordPress.VIP.RestrictedFunctions.get_page_by_path_get_page_by_path">
<!-- Avoid functional churn in Fieldmanager_Util_Term_Meta, which is deprecated. -->
<exclude-pattern>class-fieldmanager-util-term-meta.php</exclude-pattern>
</rule>
Expand Down