From cb190a938bc6c506ac467964e9efe1b3cf3550f8 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Mon, 4 Jul 2016 19:52:22 -0700 Subject: [PATCH 01/28] add .gitattributes --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a18b435 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +* text=auto + +.gitattributes export-ignore +.gitignore export-ignore +composer.json export-ignore +/spec export-ignore From 45e47f7cbfc7f93538ae6f3c89b3af8b1c13bb87 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Thu, 6 Apr 2017 09:57:10 +0200 Subject: [PATCH 02/28] Class structure for notices --- src/Notices/Abstract.php | 19 +++++++++++++++++++ src/Notices/Interface.php | 6 ++++++ src/Notices/Minimum.php | 11 +++++++++++ src/Notices/Recommended.php | 11 +++++++++++ 4 files changed, 47 insertions(+) create mode 100644 src/Notices/Abstract.php create mode 100644 src/Notices/Interface.php create mode 100644 src/Notices/Minimum.php create mode 100644 src/Notices/Recommended.php diff --git a/src/Notices/Abstract.php b/src/Notices/Abstract.php new file mode 100644 index 0000000..70c55ff --- /dev/null +++ b/src/Notices/Abstract.php @@ -0,0 +1,19 @@ +version = $version; + $this->plugin_name = $plugin_name; + } + + public function display() + { + return '
' . $this->getNoticeText() . '
'; + } +} diff --git a/src/Notices/Interface.php b/src/Notices/Interface.php new file mode 100644 index 0000000..dd04b5f --- /dev/null +++ b/src/Notices/Interface.php @@ -0,0 +1,6 @@ +plugin_name ? $this->plugin_name : 'this plugin'; + + return 'Unfortunately, ' . $plugin_name . ' cannot run on PHP versions older than ' . $this->version . '. Read more information about how you can update. + } +} diff --git a/src/Notices/Recommended.php b/src/Notices/Recommended.php new file mode 100644 index 0000000..6ee1a08 --- /dev/null +++ b/src/Notices/Recommended.php @@ -0,0 +1,11 @@ +plugin_name ? $this->plugin_name : 'This plugin'; + + return $plugin_name . ' recommends a PHP version higher than ' . $this->version . '. Read more information about how you can update.'; + } +} From 086bc766e411e9d53abe594fc844c51bc5e152d2 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Thu, 6 Apr 2017 10:03:14 +0200 Subject: [PATCH 03/28] Implement new notices class structure --- src/WPUpdatePhp.php | 56 ++++----------------------------------------- 1 file changed, 4 insertions(+), 52 deletions(-) diff --git a/src/WPUpdatePhp.php b/src/WPUpdatePhp.php index 16a21bb..a33e461 100644 --- a/src/WPUpdatePhp.php +++ b/src/WPUpdatePhp.php @@ -52,7 +52,8 @@ public function does_it_meet_required_php_version( $version = PHP_VERSION ) { return true; } - $this->load_version_notice( array( $this, 'minimum_admin_notice' ) ); + $notice = new WPUP_Minimum_Notice( $this->minimum_version, $this->plugin_name ); + $this->load_version_notice( array( $notice, 'display' ) ); return false; } @@ -69,7 +70,8 @@ public function does_it_meet_recommended_php_version( $version = PHP_VERSION ) { return true; } - $this->load_version_notice( array( $this, 'recommended_admin_notice' ) ); + $notice = new WPUP_Recommended_Notice( $this->recommended_version, $this->plugin_name ); + $this->load_version_notice( array( $notice, 'display' ) ); return false; } @@ -95,54 +97,4 @@ private function load_version_notice( $callback ) { add_action( 'network_admin_notices', $callback ); } } - - /** - * Return the string to be shown in the admin notice. - * - * This is based on the level (`recommended` or default `minimum`) of the - * notice. This will also add the plugin name to the notice string, if set. - * - * @param string $level Optional. Admin notice level, `recommended` or `minimum`. - * Default is `minimum`. - * @return string - */ - public function get_admin_notice( $level = 'minimum' ) { - if ( 'recommended' === $level ) { - if ( ! empty( $this->plugin_name ) ) { - return '

' . $this->plugin_name . ' recommends a PHP version higher than ' . $this->recommended_version . '. Read more information about how you can update.

'; - } else { - return '

This plugin recommends a PHP version higher than ' . $this->recommended_version . '. Read more information about how you can update.

'; - } - } - - if ( ! empty( $this->plugin_name ) ) { - return '

Unfortunately, ' . $this->plugin_name . ' cannot run on PHP versions older than ' . $this->minimum_version . '. Read more information about how you can update.

'; - } else { - return '

Unfortunately, this plugin cannot run on PHP versions older than ' . $this->minimum_version . '. Read more information about how you can update.

'; - } - } - - /** - * Method hooked into admin_notices when minimum required PHP version is not - * available to show this in a notice. - * - * @hook admin_notices - */ - public function minimum_admin_notice() { - echo '
'; - echo $this->get_admin_notice( 'minimum' ); - echo '
'; - } - - /** - * Method hooked into admin_notices when recommended PHP version is not - * available to show this in a notice. - * - * @hook admin_notices - */ - public function recommended_admin_notice() { - echo '
'; - echo $this->get_admin_notice( 'recommended' ); - echo '
'; - } } From db604693c09a1f1551a1982685ec23a8f1a41c1a Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Thu, 6 Apr 2017 10:10:41 +0200 Subject: [PATCH 04/28] Fixed typo missing quote in notice string --- src/Notices/Minimum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notices/Minimum.php b/src/Notices/Minimum.php index c36efe4..57eea34 100644 --- a/src/Notices/Minimum.php +++ b/src/Notices/Minimum.php @@ -6,6 +6,6 @@ protected function getNoticeText() { $plugin_name = $this->plugin_name ? $this->plugin_name : 'this plugin'; - return 'Unfortunately, ' . $plugin_name . ' cannot run on PHP versions older than ' . $this->version . '. Read more information about how you can update. + return 'Unfortunately, ' . $plugin_name . ' cannot run on PHP versions older than ' . $this->version . '. Read more information about how you can update.'; } } From 67753974418e7379fb33c7036c93140ca9005528 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Thu, 6 Apr 2017 10:13:03 +0200 Subject: [PATCH 05/28] Interface methods should be public --- src/Notices/Interface.php | 2 +- src/Notices/Minimum.php | 2 +- src/Notices/Recommended.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Notices/Interface.php b/src/Notices/Interface.php index dd04b5f..28166fd 100644 --- a/src/Notices/Interface.php +++ b/src/Notices/Interface.php @@ -2,5 +2,5 @@ interface WPUP_Notice_Interface { - protected function getNoticeText(); + public function getNoticeText(); } diff --git a/src/Notices/Minimum.php b/src/Notices/Minimum.php index 57eea34..5c20c95 100644 --- a/src/Notices/Minimum.php +++ b/src/Notices/Minimum.php @@ -2,7 +2,7 @@ class WPUP_Minimum_Notice extends WPUP_Notice { - protected function getNoticeText() + public function getNoticeText() { $plugin_name = $this->plugin_name ? $this->plugin_name : 'this plugin'; diff --git a/src/Notices/Recommended.php b/src/Notices/Recommended.php index 6ee1a08..2b969ce 100644 --- a/src/Notices/Recommended.php +++ b/src/Notices/Recommended.php @@ -2,7 +2,7 @@ class WPUP_Recommended_Notice extends WPUP_Notice { - protected function getNoticeText() + public function getNoticeText() { $plugin_name = $this->plugin_name ? $this->plugin_name : 'This plugin'; From 646da4e8df1b06a95b191f48e39ed744db3e3c17 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 14 Jul 2017 18:39:15 +0200 Subject: [PATCH 06/28] Update README file to reflect 5.6 minimum --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62d8dc5..0974c68 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ For example, when you start your plugin by instantiating a new object, you shoul _Example:_ ```php -$updatePhp = new WPUpdatePhp( '5.4.0' ); +$updatePhp = new WPUpdatePhp( '5.6.0' ); if ( $updatePhp->does_it_meet_required_php_version() ) { // Instantiate new object here From 8edd16ddce9e2c7324d860e171259aab6e3fa6cc Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Sun, 16 Jul 2017 15:44:14 +0200 Subject: [PATCH 07/28] Fixed tests by testing new notice object --- spec/WPUP/Minimum/NoticeSpec.php | 25 +++++++++++++++++++++++++ spec/WPUP/Recommended/NoticeSpec.php | 19 +++++++++++++++++++ spec/WPUpdatePhpSpec.php | 7 ------- 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 spec/WPUP/Minimum/NoticeSpec.php create mode 100644 spec/WPUP/Recommended/NoticeSpec.php diff --git a/spec/WPUP/Minimum/NoticeSpec.php b/spec/WPUP/Minimum/NoticeSpec.php new file mode 100644 index 0000000..92241a6 --- /dev/null +++ b/spec/WPUP/Minimum/NoticeSpec.php @@ -0,0 +1,25 @@ +beConstructedWith('5.4.0', 'Test Plugin'); + } + + function it_adds_plugin_name_to_admin_notice() + { + $this->getNoticeText()->shouldMatch('/Test Plugin/i'); + } + } +} diff --git a/spec/WPUP/Recommended/NoticeSpec.php b/spec/WPUP/Recommended/NoticeSpec.php new file mode 100644 index 0000000..3bed0f5 --- /dev/null +++ b/spec/WPUP/Recommended/NoticeSpec.php @@ -0,0 +1,19 @@ +beConstructedWith('5.4.0', 'Test Plugin'); + } + + function it_adds_plugin_name_to_admin_notice() + { + $this->getNoticeText()->shouldMatch('/Test Plugin/i'); + } + } +} diff --git a/spec/WPUpdatePhpSpec.php b/spec/WPUpdatePhpSpec.php index 96fdeee..2007e19 100644 --- a/spec/WPUpdatePhpSpec.php +++ b/spec/WPUpdatePhpSpec.php @@ -13,7 +13,6 @@ function is_admin() { namespace spec { use PhpSpec\ObjectBehavior; - use Prophecy\Argument; class WPUpdatePhpSpec extends ObjectBehavior { function let() { @@ -35,11 +34,5 @@ function it_will_not_run_on_old_version() { function it_fails_the_recommended_version() { $this->does_it_meet_recommended_php_version( '5.2.9' )->shouldReturn( false ); } - - function it_adds_plugin_name_to_admin_notice() { - $this->set_plugin_name( 'Test Plugin' ); - $this->get_admin_notice()->shouldMatch('/Test Plugin/i'); - $this->get_admin_notice( 'recommended' )->shouldMatch('/Test Plugin/i'); - } } } \ No newline at end of file From f03f74be3be519c379bdcd61344254dbd4192c5d Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Sun, 16 Jul 2017 15:56:28 +0200 Subject: [PATCH 08/28] Move mocked WordPress functions to spec bootstrap file --- phpspec.yml | 1 + spec/WPUP/Minimum/NoticeSpec.php | 6 ------ spec/WPUpdatePhpSpec.php | 10 ---------- spec/bootstrap.php | 13 +++++++++++++ 4 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 phpspec.yml create mode 100644 spec/bootstrap.php diff --git a/phpspec.yml b/phpspec.yml new file mode 100644 index 0000000..ccfd7f7 --- /dev/null +++ b/phpspec.yml @@ -0,0 +1 @@ +bootstrap: spec/bootstrap.php \ No newline at end of file diff --git a/spec/WPUP/Minimum/NoticeSpec.php b/spec/WPUP/Minimum/NoticeSpec.php index 92241a6..6e1d8df 100644 --- a/spec/WPUP/Minimum/NoticeSpec.php +++ b/spec/WPUP/Minimum/NoticeSpec.php @@ -1,11 +1,5 @@ Date: Sun, 16 Jul 2017 15:57:31 +0200 Subject: [PATCH 09/28] Cleaned up spec namespace formatting --- spec/WPUP/Minimum/NoticeSpec.php | 23 +++++++++--------- spec/WPUP/Recommended/NoticeSpec.php | 23 +++++++++--------- spec/WPUpdatePhpSpec.php | 35 ++++++++++++++-------------- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/spec/WPUP/Minimum/NoticeSpec.php b/spec/WPUP/Minimum/NoticeSpec.php index 6e1d8df..c18c59f 100644 --- a/spec/WPUP/Minimum/NoticeSpec.php +++ b/spec/WPUP/Minimum/NoticeSpec.php @@ -1,19 +1,18 @@ beConstructedWith('5.4.0', 'Test Plugin'); - } + $this->beConstructedWith('5.4.0', 'Test Plugin'); + } - function it_adds_plugin_name_to_admin_notice() - { - $this->getNoticeText()->shouldMatch('/Test Plugin/i'); - } + function it_adds_plugin_name_to_admin_notice() + { + $this->getNoticeText()->shouldMatch('/Test Plugin/i'); } -} +} \ No newline at end of file diff --git a/spec/WPUP/Recommended/NoticeSpec.php b/spec/WPUP/Recommended/NoticeSpec.php index 3bed0f5..e8355e4 100644 --- a/spec/WPUP/Recommended/NoticeSpec.php +++ b/spec/WPUP/Recommended/NoticeSpec.php @@ -1,19 +1,18 @@ beConstructedWith('5.4.0', 'Test Plugin'); - } + $this->beConstructedWith('5.4.0', 'Test Plugin'); + } - function it_adds_plugin_name_to_admin_notice() - { - $this->getNoticeText()->shouldMatch('/Test Plugin/i'); - } + function it_adds_plugin_name_to_admin_notice() + { + $this->getNoticeText()->shouldMatch('/Test Plugin/i'); } -} +} \ No newline at end of file diff --git a/spec/WPUpdatePhpSpec.php b/spec/WPUpdatePhpSpec.php index db1abbd..54ccb66 100644 --- a/spec/WPUpdatePhpSpec.php +++ b/spec/WPUpdatePhpSpec.php @@ -1,28 +1,27 @@ beConstructedWith( '5.4.0', '5.3.0' ); - } +class WPUpdatePhpSpec extends ObjectBehavior { + function let() { + $this->beConstructedWith( '5.4.0', '5.3.0' ); + } - function it_can_run_on_minimum_version() { - $this->does_it_meet_required_php_version( '5.4.0' )->shouldReturn( true ); - } + function it_can_run_on_minimum_version() { + $this->does_it_meet_required_php_version( '5.4.0' )->shouldReturn( true ); + } - function it_passes_the_recommended_version() { - $this->does_it_meet_recommended_php_version( '5.3.0' )->shouldReturn( true ); - } + function it_passes_the_recommended_version() { + $this->does_it_meet_recommended_php_version( '5.3.0' )->shouldReturn( true ); + } - function it_will_not_run_on_old_version() { - $this->does_it_meet_required_php_version( '5.2.4' )->shouldReturn( false ); - } + function it_will_not_run_on_old_version() { + $this->does_it_meet_required_php_version( '5.2.4' )->shouldReturn( false ); + } - function it_fails_the_recommended_version() { - $this->does_it_meet_recommended_php_version( '5.2.9' )->shouldReturn( false ); - } + function it_fails_the_recommended_version() { + $this->does_it_meet_recommended_php_version( '5.2.9' )->shouldReturn( false ); } } \ No newline at end of file From dbeb00fbad4314b0efc926f224a9dfaf9a76be7c Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 11 Aug 2017 14:52:55 +0200 Subject: [PATCH 10/28] Basic translator class for pushing plugin strings in --- src/Translator.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Translator.php diff --git a/src/Translator.php b/src/Translator.php new file mode 100644 index 0000000..ec377a9 --- /dev/null +++ b/src/Translator.php @@ -0,0 +1,32 @@ + 'Unfortunately, %s cannot run on PHP versions older than %s. Read more information about how you can update.', + 'recommended' => '%s recommends a PHP version higher than %s. Read more information about how you can update.', + ); + + /** + * @param $key string + * @return bool|string + */ + public function getString($key ) + { + if ( isset($this->strings[$key] ) ) { + return $this->strings[$key]; + } + + return false; + } + + /** + * @param $key string + * @param $string string + */ + public function setString($key, $string ) + { + $this->strings[$key] = $string; + } +} \ No newline at end of file From b8971e491163d3b48e6f3a7a01b6ae00f3282cc1 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 11 Aug 2017 14:53:14 +0200 Subject: [PATCH 11/28] Spec for the new translator class --- spec/WPUP/TranslatorSpec.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/WPUP/TranslatorSpec.php diff --git a/spec/WPUP/TranslatorSpec.php b/spec/WPUP/TranslatorSpec.php new file mode 100644 index 0000000..e3eae13 --- /dev/null +++ b/spec/WPUP/TranslatorSpec.php @@ -0,0 +1,21 @@ +setString('minimum', 'test string'); + $this->getString('minimum')->shouldMatch('/test string/i'); + } + + + function it_returns_false_if_no_string_is_set_for_requested_key() + { + $this->getString('test')->shouldReturn(false); + } +} From ff5814762bae2500c133ff9137850b7fba9f34f3 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 11 Aug 2017 14:53:38 +0200 Subject: [PATCH 12/28] Introduce the translator logic in all notices --- src/Notices/Abstract.php | 11 +++++++++++ src/Notices/Minimum.php | 8 ++++++-- src/Notices/Recommended.php | 8 ++++++-- src/WPUpdatePhp.php | 6 ++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Notices/Abstract.php b/src/Notices/Abstract.php index 70c55ff..ddead0c 100644 --- a/src/Notices/Abstract.php +++ b/src/Notices/Abstract.php @@ -6,12 +6,23 @@ abstract class WPUP_Notice implements WPUP_Notice_Interface protected $plugin_name; protected $url = 'http://wpupdatephp.com/update/'; + /** @var WPUP_Translator */ + protected $translator; + public function __construct( $version, $plugin_name = NULL ) { $this->version = $version; $this->plugin_name = $plugin_name; } + /** + * @param $translator WPUP_Translator + */ + public function setTranslator($translator ) + { + $this->translator = $translator; + } + public function display() { return '
' . $this->getNoticeText() . '
'; diff --git a/src/Notices/Minimum.php b/src/Notices/Minimum.php index 5c20c95..dfc304b 100644 --- a/src/Notices/Minimum.php +++ b/src/Notices/Minimum.php @@ -2,10 +2,14 @@ class WPUP_Minimum_Notice extends WPUP_Notice { - public function getNoticeText() + /** + * @return string + */ + public function getNoticeText() { + $string = $this->translator->getString('minimum'); $plugin_name = $this->plugin_name ? $this->plugin_name : 'this plugin'; - return 'Unfortunately, ' . $plugin_name . ' cannot run on PHP versions older than ' . $this->version . '. Read more information about how you can update.'; + return sprintf($string, $plugin_name, $this->version, esc_url($this->url)); } } diff --git a/src/Notices/Recommended.php b/src/Notices/Recommended.php index 2b969ce..51c2710 100644 --- a/src/Notices/Recommended.php +++ b/src/Notices/Recommended.php @@ -2,10 +2,14 @@ class WPUP_Recommended_Notice extends WPUP_Notice { - public function getNoticeText() + /** + * @return string + */ + public function getNoticeText() { + $string = $this->translator->getString('minimum'); $plugin_name = $this->plugin_name ? $this->plugin_name : 'This plugin'; - return $plugin_name . ' recommends a PHP version higher than ' . $this->version . '. Read more information about how you can update.'; + return sprintf($string, $plugin_name, $this->version, esc_url($this->url)); } } diff --git a/src/WPUpdatePhp.php b/src/WPUpdatePhp.php index a33e461..4a7157f 100644 --- a/src/WPUpdatePhp.php +++ b/src/WPUpdatePhp.php @@ -21,6 +21,9 @@ class WPUpdatePhp { /** @var string */ private $plugin_name = ''; + /** @var WPUP_Translator */ + public $translator; + /** * @param string $minimum_version Minimum version of PHP. * @param string $recommended_version Recommended version of PHP. @@ -28,6 +31,7 @@ class WPUpdatePhp { public function __construct( $minimum_version, $recommended_version = null ) { $this->minimum_version = $minimum_version; $this->recommended_version = $recommended_version; + $this->translator = new WPUP_Translator(); } /** @@ -53,6 +57,7 @@ public function does_it_meet_required_php_version( $version = PHP_VERSION ) { } $notice = new WPUP_Minimum_Notice( $this->minimum_version, $this->plugin_name ); + $notice->setTranslator($this->translator); $this->load_version_notice( array( $notice, 'display' ) ); return false; } @@ -71,6 +76,7 @@ public function does_it_meet_recommended_php_version( $version = PHP_VERSION ) { } $notice = new WPUP_Recommended_Notice( $this->recommended_version, $this->plugin_name ); + $notice->setTranslator($this->translator); $this->load_version_notice( array( $notice, 'display' ) ); return false; } From 7693dd52022b5621097ca72f514cafae3ab56d2c Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 11 Aug 2017 14:53:57 +0200 Subject: [PATCH 13/28] Updated specs to use new translator strings --- spec/WPUP/Minimum/NoticeSpec.php | 1 + spec/WPUP/Recommended/NoticeSpec.php | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/WPUP/Minimum/NoticeSpec.php b/spec/WPUP/Minimum/NoticeSpec.php index c18c59f..c806a29 100644 --- a/spec/WPUP/Minimum/NoticeSpec.php +++ b/spec/WPUP/Minimum/NoticeSpec.php @@ -13,6 +13,7 @@ function let() function it_adds_plugin_name_to_admin_notice() { + $this->setTranslator( new \WPUP_Translator() ); $this->getNoticeText()->shouldMatch('/Test Plugin/i'); } } \ No newline at end of file diff --git a/spec/WPUP/Recommended/NoticeSpec.php b/spec/WPUP/Recommended/NoticeSpec.php index e8355e4..ef9d94f 100644 --- a/spec/WPUP/Recommended/NoticeSpec.php +++ b/spec/WPUP/Recommended/NoticeSpec.php @@ -13,6 +13,7 @@ function let() function it_adds_plugin_name_to_admin_notice() { + $this->setTranslator( new \WPUP_Translator() ); $this->getNoticeText()->shouldMatch('/Test Plugin/i'); } } \ No newline at end of file From 7cd9152119872bc4b69e98cc8b8620b2f4be3393 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 11 Aug 2017 15:01:53 +0200 Subject: [PATCH 14/28] Fix indenting --- spec/WPUP/TranslatorSpec.php | 7 +++---- src/Notices/Abstract.php | 2 +- src/Notices/Interface.php | 2 +- src/Notices/Minimum.php | 2 +- src/Notices/Recommended.php | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/WPUP/TranslatorSpec.php b/spec/WPUP/TranslatorSpec.php index e3eae13..21540a8 100644 --- a/spec/WPUP/TranslatorSpec.php +++ b/spec/WPUP/TranslatorSpec.php @@ -9,13 +9,12 @@ class WPUP_TranslatorSpec extends ObjectBehavior { function it_should_return_new_set_string() { - $this->setString('minimum', 'test string'); - $this->getString('minimum')->shouldMatch('/test string/i'); + $this->setString('minimum', 'test string'); + $this->getString('minimum')->shouldMatch('/test string/i'); } - function it_returns_false_if_no_string_is_set_for_requested_key() { - $this->getString('test')->shouldReturn(false); + $this->getString('test')->shouldReturn(false); } } diff --git a/src/Notices/Abstract.php b/src/Notices/Abstract.php index ddead0c..bfd1d07 100644 --- a/src/Notices/Abstract.php +++ b/src/Notices/Abstract.php @@ -27,4 +27,4 @@ public function display() { return '
' . $this->getNoticeText() . '
'; } -} +} \ No newline at end of file diff --git a/src/Notices/Interface.php b/src/Notices/Interface.php index 28166fd..6c42e9a 100644 --- a/src/Notices/Interface.php +++ b/src/Notices/Interface.php @@ -3,4 +3,4 @@ interface WPUP_Notice_Interface { public function getNoticeText(); -} +} \ No newline at end of file diff --git a/src/Notices/Minimum.php b/src/Notices/Minimum.php index dfc304b..fbcea5e 100644 --- a/src/Notices/Minimum.php +++ b/src/Notices/Minimum.php @@ -12,4 +12,4 @@ public function getNoticeText() return sprintf($string, $plugin_name, $this->version, esc_url($this->url)); } -} +} \ No newline at end of file diff --git a/src/Notices/Recommended.php b/src/Notices/Recommended.php index 51c2710..8826e47 100644 --- a/src/Notices/Recommended.php +++ b/src/Notices/Recommended.php @@ -12,4 +12,4 @@ public function getNoticeText() return sprintf($string, $plugin_name, $this->version, esc_url($this->url)); } -} +} \ No newline at end of file From 02ef4a9fb51cb33b832bd821487f72cbb56a42e9 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 11 Aug 2017 15:24:30 +0200 Subject: [PATCH 15/28] Suggest Mozart to install this library with Tooting my own horn, I know. I just like to make it easier for people to use this library, without having to prefix everything manually. --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index b2f3eb6..33ddb61 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,9 @@ "require-dev": { "phpspec/phpspec": "~2.0" }, + "suggest": { + "coenjacobs/mozart": "Easily wrap this library with your own prefix, to prevent collisions when multiple plugins use this library" + }, "autoload": { "classmap": ["src"] }, From 01767a265ed540b9fd13d698aba43732bcacd03e Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 11 Aug 2017 16:00:39 +0200 Subject: [PATCH 16/28] Added travis configuration file --- .travis.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7d94754 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: php + +php: + - 5.2 + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - 7.1 + - hhvm + +before_script: + - travis_retry composer install --prefer-source --no-interaction --dev + +script: + - vendor/bin/phpspec run --config=phpspec.yml --no-interaction \ No newline at end of file From 0d4df261d5dcc88a148d2bf79318d599a94b2568 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Mon, 14 Aug 2017 19:58:02 +0200 Subject: [PATCH 17/28] Make plugin name mandatory argument in library constructor --- spec/WPUpdatePhpSpec.php | 2 +- src/Notices/Minimum.php | 3 +-- src/Notices/Recommended.php | 3 +-- src/WPUpdatePhp.php | 21 +++++++-------------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/spec/WPUpdatePhpSpec.php b/spec/WPUpdatePhpSpec.php index 54ccb66..9c61efd 100644 --- a/spec/WPUpdatePhpSpec.php +++ b/spec/WPUpdatePhpSpec.php @@ -6,7 +6,7 @@ class WPUpdatePhpSpec extends ObjectBehavior { function let() { - $this->beConstructedWith( '5.4.0', '5.3.0' ); + $this->beConstructedWith( 'Test Plugin', '5.4.0', '5.3.0' ); } function it_can_run_on_minimum_version() { diff --git a/src/Notices/Minimum.php b/src/Notices/Minimum.php index fbcea5e..e7a9250 100644 --- a/src/Notices/Minimum.php +++ b/src/Notices/Minimum.php @@ -8,8 +8,7 @@ class WPUP_Minimum_Notice extends WPUP_Notice public function getNoticeText() { $string = $this->translator->getString('minimum'); - $plugin_name = $this->plugin_name ? $this->plugin_name : 'this plugin'; - return sprintf($string, $plugin_name, $this->version, esc_url($this->url)); + return sprintf($string, $this->plugin_name, $this->version, esc_url($this->url)); } } \ No newline at end of file diff --git a/src/Notices/Recommended.php b/src/Notices/Recommended.php index 8826e47..fb3775f 100644 --- a/src/Notices/Recommended.php +++ b/src/Notices/Recommended.php @@ -8,8 +8,7 @@ class WPUP_Recommended_Notice extends WPUP_Notice public function getNoticeText() { $string = $this->translator->getString('minimum'); - $plugin_name = $this->plugin_name ? $this->plugin_name : 'This plugin'; - return sprintf($string, $plugin_name, $this->version, esc_url($this->url)); + return sprintf($string, $this->plugin_name, $this->version, esc_url($this->url)); } } \ No newline at end of file diff --git a/src/WPUpdatePhp.php b/src/WPUpdatePhp.php index 4a7157f..4b39fe7 100644 --- a/src/WPUpdatePhp.php +++ b/src/WPUpdatePhp.php @@ -24,25 +24,18 @@ class WPUpdatePhp { /** @var WPUP_Translator */ public $translator; - /** - * @param string $minimum_version Minimum version of PHP. - * @param string $recommended_version Recommended version of PHP. - */ - public function __construct( $minimum_version, $recommended_version = null ) { + /** + * @param string $plugin_name + * @param string $minimum_version Minimum version of PHP. + * @param string $recommended_version Recommended version of PHP. + */ + public function __construct( $plugin_name, $minimum_version, $recommended_version = null ) { + $this->plugin_name = $plugin_name; $this->minimum_version = $minimum_version; $this->recommended_version = $recommended_version; $this->translator = new WPUP_Translator(); } - /** - * Set the plugin name for the admin notice. - * - * @param string $name Name of the plugin to be used in admin notices. - */ - public function set_plugin_name( $name ) { - $this->plugin_name = $name; - } - /** * Check given PHP version against minimum required version. * From 11bd745885cb6e927e563a5ecb2cfa7ec6cc7663 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Thu, 17 Aug 2017 13:50:01 +0200 Subject: [PATCH 18/28] Replace translator spec with phpunit test --- .travis.yml | 3 ++- composer.json | 3 ++- phpunit.xml | 17 +++++++++++++++++ spec/WPUP/TranslatorSpec.php | 20 -------------------- tests/unit/TranslatorTest.php | 21 +++++++++++++++++++++ 5 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 phpunit.xml delete mode 100644 spec/WPUP/TranslatorSpec.php create mode 100644 tests/unit/TranslatorTest.php diff --git a/.travis.yml b/.travis.yml index 7d94754..17ebfce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,5 @@ before_script: - travis_retry composer install --prefer-source --no-interaction --dev script: - - vendor/bin/phpspec run --config=phpspec.yml --no-interaction \ No newline at end of file + - vendor/bin/phpspec run --config=phpspec.yml --no-interaction + - phpunit --configuration phpunit.xml --coverage-text \ No newline at end of file diff --git a/composer.json b/composer.json index 33ddb61..10ba4c4 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "source": "https://github.com/wpupdatephp/wp-update-php" }, "require-dev": { - "phpspec/phpspec": "~2.0" + "phpspec/phpspec": "~2.0", + "phpunit/phpunit": "^6.3" }, "suggest": { "coenjacobs/mozart": "Easily wrap this library with your own prefix, to prevent collisions when multiple plugins use this library" diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..aa84417 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ./tests/unit/ + + + \ No newline at end of file diff --git a/spec/WPUP/TranslatorSpec.php b/spec/WPUP/TranslatorSpec.php deleted file mode 100644 index 21540a8..0000000 --- a/spec/WPUP/TranslatorSpec.php +++ /dev/null @@ -1,20 +0,0 @@ -setString('minimum', 'test string'); - $this->getString('minimum')->shouldMatch('/test string/i'); - } - - function it_returns_false_if_no_string_is_set_for_requested_key() - { - $this->getString('test')->shouldReturn(false); - } -} diff --git a/tests/unit/TranslatorTest.php b/tests/unit/TranslatorTest.php new file mode 100644 index 0000000..3ae5969 --- /dev/null +++ b/tests/unit/TranslatorTest.php @@ -0,0 +1,21 @@ +setString('minimum', 'test string'); + $this->assertEquals('test string', $translator->getString('minimum')); + } + + /** @test */ + public function itReturnsFalseIfNoStringIsSetForKey() + { + $translator = new WPUP_Translator(); + $this->assertFalse($translator->getString('test')); + } +} \ No newline at end of file From 4f01a02ee2a779cb38ebc8964b2ecb9f06d9a592 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 18 Aug 2017 11:57:55 +0200 Subject: [PATCH 19/28] Fall back to PHP 5.2 compatible phpunit version --- .travis.yml | 7 ++++++- composer.json | 30 ++++++++++++++++++++++++++++-- phpunit.xml | 2 +- tests/unit/TranslatorTest.php | 4 +--- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 17ebfce..addfeac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,14 @@ php: - 7.1 - hhvm +before_install: + - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then `phpenv global 5.3`; fi + - composer update + - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then `phpenv global "$TRAVIS_PHP_VERSION"`; fi + before_script: - travis_retry composer install --prefer-source --no-interaction --dev script: - vendor/bin/phpspec run --config=phpspec.yml --no-interaction - - phpunit --configuration phpunit.xml --coverage-text \ No newline at end of file + - phpunit52 --configuration phpunit.xml --coverage-text \ No newline at end of file diff --git a/composer.json b/composer.json index 10ba4c4..48a4145 100644 --- a/composer.json +++ b/composer.json @@ -5,15 +5,41 @@ "issues": "https://github.com/wpupdatephp/wp-update-php/issues", "source": "https://github.com/wpupdatephp/wp-update-php" }, + "require": { + "php": ">=5.2.4", + "xrstf/composer-php52": "^1.0" + }, "require-dev": { "phpspec/phpspec": "~2.0", - "phpunit/phpunit": "^6.3" + "phpunit/phpunit-php52": "dev-3.6.12-php52", + "phpunit/phpunit-mock-objects-php52": "dev-1.1.0-php52" }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/garex/phpunit" + }, + { + "type": "git", + "url": "https://github.com/garex/phpunit-mock-objects" + } + ], "suggest": { "coenjacobs/mozart": "Easily wrap this library with your own prefix, to prevent collisions when multiple plugins use this library" }, "autoload": { "classmap": ["src"] }, - "license": "GPL-2.0+" + "license": "GPL-2.0+", + "scripts": { + "post-install-cmd": [ + "xrstf\\Composer52\\Generator::onPostInstallCmd" + ], + "post-update-cmd": [ + "xrstf\\Composer52\\Generator::onPostInstallCmd" + ], + "post-autoload-dump": [ + "xrstf\\Composer52\\Generator::onPostInstallCmd" + ] + } } diff --git a/phpunit.xml b/phpunit.xml index aa84417..0dcf807 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ Date: Thu, 24 Aug 2017 12:06:24 +0200 Subject: [PATCH 20/28] PHP 5.2 compatible Travis configuration Get rid of all the specs, as that's impossible to run on PHP 5.2 as well as on modern PHP versions. Going full PhpUnit. --- .travis.yml | 38 +++++++++++++++------------- composer.json | 13 +--------- phpspec.yml | 1 - phpunit.xml | 4 +-- spec/WPUP/Minimum/NoticeSpec.php | 19 -------------- spec/WPUP/Recommended/NoticeSpec.php | 19 -------------- spec/WPUpdatePhpSpec.php | 27 -------------------- spec/bootstrap.php | 13 ---------- tests/bootstrap.php | 5 ++++ 9 files changed, 29 insertions(+), 110 deletions(-) delete mode 100644 phpspec.yml delete mode 100644 spec/WPUP/Minimum/NoticeSpec.php delete mode 100644 spec/WPUP/Recommended/NoticeSpec.php delete mode 100644 spec/WPUpdatePhpSpec.php delete mode 100644 spec/bootstrap.php create mode 100644 tests/bootstrap.php diff --git a/.travis.yml b/.travis.yml index addfeac..56466ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,27 @@ language: php - +dist: trusty php: - - 5.2 - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - hhvm +- '7.1' +- '7.0' +- '5.6' +- '5.5' +- '5.4' + +matrix: + fast_finish: true + include: + - php: 5.2 + dist: precise + - php: 5.3 + dist: precise -before_install: - - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then `phpenv global 5.3`; fi - - composer update - - if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then `phpenv global "$TRAVIS_PHP_VERSION"`; fi -before_script: - - travis_retry composer install --prefer-source --no-interaction --dev +install: +- phpenv local 5.6 +- composer selfupdate 1.0.0 --no-interaction +- composer install --no-interaction +- if [[ "$TRAVIS_PHP_VERSION" == "5.2" ]]; then composer remove --dev phpunit/phpunit; fi +- phpenv local --unset script: - - vendor/bin/phpspec run --config=phpspec.yml --no-interaction - - phpunit52 --configuration phpunit.xml --coverage-text \ No newline at end of file +- if [[ "$TRAVIS_PHP_VERSION" == "5.2" ]]; then phpunit; else ./vendor/bin/phpunit; fi diff --git a/composer.json b/composer.json index 48a4145..c3296ab 100644 --- a/composer.json +++ b/composer.json @@ -11,19 +11,8 @@ }, "require-dev": { "phpspec/phpspec": "~2.0", - "phpunit/phpunit-php52": "dev-3.6.12-php52", - "phpunit/phpunit-mock-objects-php52": "dev-1.1.0-php52" + "phpunit/phpunit": "^3.6.12" }, - "repositories": [ - { - "type": "git", - "url": "https://github.com/garex/phpunit" - }, - { - "type": "git", - "url": "https://github.com/garex/phpunit-mock-objects" - } - ], "suggest": { "coenjacobs/mozart": "Easily wrap this library with your own prefix, to prevent collisions when multiple plugins use this library" }, diff --git a/phpspec.yml b/phpspec.yml deleted file mode 100644 index ccfd7f7..0000000 --- a/phpspec.yml +++ /dev/null @@ -1 +0,0 @@ -bootstrap: spec/bootstrap.php \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 0dcf807..e8de0ff 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ ./tests/unit/ - \ No newline at end of file + diff --git a/spec/WPUP/Minimum/NoticeSpec.php b/spec/WPUP/Minimum/NoticeSpec.php deleted file mode 100644 index c806a29..0000000 --- a/spec/WPUP/Minimum/NoticeSpec.php +++ /dev/null @@ -1,19 +0,0 @@ -beConstructedWith('5.4.0', 'Test Plugin'); - } - - function it_adds_plugin_name_to_admin_notice() - { - $this->setTranslator( new \WPUP_Translator() ); - $this->getNoticeText()->shouldMatch('/Test Plugin/i'); - } -} \ No newline at end of file diff --git a/spec/WPUP/Recommended/NoticeSpec.php b/spec/WPUP/Recommended/NoticeSpec.php deleted file mode 100644 index ef9d94f..0000000 --- a/spec/WPUP/Recommended/NoticeSpec.php +++ /dev/null @@ -1,19 +0,0 @@ -beConstructedWith('5.4.0', 'Test Plugin'); - } - - function it_adds_plugin_name_to_admin_notice() - { - $this->setTranslator( new \WPUP_Translator() ); - $this->getNoticeText()->shouldMatch('/Test Plugin/i'); - } -} \ No newline at end of file diff --git a/spec/WPUpdatePhpSpec.php b/spec/WPUpdatePhpSpec.php deleted file mode 100644 index 9c61efd..0000000 --- a/spec/WPUpdatePhpSpec.php +++ /dev/null @@ -1,27 +0,0 @@ -beConstructedWith( 'Test Plugin', '5.4.0', '5.3.0' ); - } - - function it_can_run_on_minimum_version() { - $this->does_it_meet_required_php_version( '5.4.0' )->shouldReturn( true ); - } - - function it_passes_the_recommended_version() { - $this->does_it_meet_recommended_php_version( '5.3.0' )->shouldReturn( true ); - } - - function it_will_not_run_on_old_version() { - $this->does_it_meet_required_php_version( '5.2.4' )->shouldReturn( false ); - } - - function it_fails_the_recommended_version() { - $this->does_it_meet_recommended_php_version( '5.2.9' )->shouldReturn( false ); - } -} \ No newline at end of file diff --git a/spec/bootstrap.php b/spec/bootstrap.php deleted file mode 100644 index 9bc4061..0000000 --- a/spec/bootstrap.php +++ /dev/null @@ -1,13 +0,0 @@ - Date: Fri, 25 Aug 2017 15:23:59 +0200 Subject: [PATCH 21/28] Checker class that handles all check arguments --- src/Checker.php | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/Checker.php diff --git a/src/Checker.php b/src/Checker.php new file mode 100644 index 0000000..3f0d66e --- /dev/null +++ b/src/Checker.php @@ -0,0 +1,74 @@ + array( + // // array( + // // 'version' => '3.7.1', + // // 'required' => false, + // // ), + // // array( + // // 'version' => '3.5.0', + // // 'required' => true, + // // ), + // // ), + // 'php' => array( + // array( + // 'version' => '7.0.0', + // 'required' => false, + // ), + // // array( + // // 'version' => '5.6.0', + // // 'required' => true, + // // ), + // ), + // ); + + /** @var array */ + public $arguments = array(); + + /** @var array */ + public $failures = array(); + + /** @var array */ + public $recommendations = array(); + + public function __construct($arguments = array()) + { + $this->arguments = $arguments; + } + + public function setup() + { + $this->checks = array( + new WPUP_PhpVersion($this), + new WPUP_WordPressVersion($this), + ); + + foreach($this->checks as $check) { + $check->setup(); + } + } + + public function check() + { + /** @var WPUP_Check_Interface $check */ + foreach($this->checks as $check) { + $check->check(); + } + } + + public function reportFail($failure) + { + $this->failures[] = $failure; + } + + public function reportRecommendation($recommendation) + { + $this->recommendations[] = $recommendation; + } +} From e777767757e5f4aeffc9bbde961a59e9a0152f04 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 25 Aug 2017 15:24:29 +0200 Subject: [PATCH 22/28] Implementation of basic version checks --- src/Checks/Interface.php | 8 +++++ src/Checks/PhpVersion.php | 15 +++++++++ src/Checks/VersionCheck.php | 58 +++++++++++++++++++++++++++++++++ src/Checks/WordPressVersion.php | 16 +++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/Checks/Interface.php create mode 100644 src/Checks/PhpVersion.php create mode 100644 src/Checks/VersionCheck.php create mode 100644 src/Checks/WordPressVersion.php diff --git a/src/Checks/Interface.php b/src/Checks/Interface.php new file mode 100644 index 0000000..b1a61f8 --- /dev/null +++ b/src/Checks/Interface.php @@ -0,0 +1,8 @@ +match_version = PHP_VERSION; + } +} diff --git a/src/Checks/VersionCheck.php b/src/Checks/VersionCheck.php new file mode 100644 index 0000000..af8be98 --- /dev/null +++ b/src/Checks/VersionCheck.php @@ -0,0 +1,58 @@ +arguments = $checker->arguments; + $this->checker = $checker; + } + + public function checkArguments($arguments, $key) + { + if (!isset($arguments[$key])) { + return false; + } + + if (!is_array($arguments[$key])) { + return false; + } + + return true; + } + + public function check() + { + if ( ! $this->checkArguments($this->arguments, $this->arguments_key )) { + return; + } + + $this->checkVersions($this->arguments[$this->arguments_key]); + } + + public function checkVersions($arguments) + { + foreach ($arguments as $argument) { + if (!is_array($argument)) { + continue; + } + + if (version_compare($this->match_version, $argument['version']) === -1) { + if ($argument['required'] === true) { + $this->checker->reportFail($argument); + } else { + $this->checker->reportRecommendation($argument); + } + } + } + } +} diff --git a/src/Checks/WordPressVersion.php b/src/Checks/WordPressVersion.php new file mode 100644 index 0000000..32bba85 --- /dev/null +++ b/src/Checks/WordPressVersion.php @@ -0,0 +1,16 @@ +match_version = $wp_version; + } +} From 304b7aa0402984b8cbb90a3d06f5c0c39a889a1b Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 25 Aug 2017 15:24:40 +0200 Subject: [PATCH 23/28] Tests to verify the version checks work --- tests/unit/AbstractCheckTest.php | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/unit/AbstractCheckTest.php diff --git a/tests/unit/AbstractCheckTest.php b/tests/unit/AbstractCheckTest.php new file mode 100644 index 0000000..abb185b --- /dev/null +++ b/tests/unit/AbstractCheckTest.php @@ -0,0 +1,99 @@ + array( + array( + 'version' => '5.6.0', + 'required' => true, + ), + ), + ); + $testedUnit = $this->getMock('WPUP_Checker', array()); + $testedUnit->arguments = $arguments; + + $check = new TestCheck($testedUnit); + $this->assertFalse($check->checkArguments($arguments, 'notSetKey')); + } + + /** @test */ + public function itReturnsFalseWhenKeyIsNotArray() + { + $arguments = array( + 'key' => 'dummy value' + ); + $testedUnit = $this->getMock('WPUP_Checker', array()); + $testedUnit->arguments = $arguments; + + $check = new TestCheck($testedUnit); + $this->assertFalse($check->checkArguments($arguments, 'notSetKey')); + } + + /** @test */ + public function itReturnsTrueOnProperConfig() + { + $arguments = array( + 'php' => array( + array( + 'version' => '5.6.0', + 'required' => true, + ), + ), + ); + $testedUnit = $this->getMock('WPUP_Checker', array()); + $testedUnit->arguments = $arguments; + + $check = new TestCheck($testedUnit); + $this->assertTrue($check->checkArguments($arguments, 'php')); + } + + /** @test */ + public function itReportsFailWhenVersionFails() + { + $arguments = array( + 'test' => array( + array( + 'version' => '5.6.0', + 'required' => true, + ), + ), + ); + $testedUnit = $this->getMock('WPUP_Checker', array('reportFail')); + $testedUnit->arguments = $arguments; + + $check = new TestCheck($testedUnit); + $check->match_version = '5.2.2'; + $testedUnit->expects($this->once())->method('reportFail'); + $check->check(); + } + + /** @test */ + public function itReportsRecommendationWhenVersionRecommendationIsNotMet() + { + $arguments = array( + 'test' => array( + array( + 'version' => '7.0.0', + 'required' => false, + ), + ), + ); + $testedUnit = $this->getMock('WPUP_Checker', array('reportRecommendation')); + $testedUnit->arguments = $arguments; + + $check = new TestCheck($testedUnit); + $check->match_version = '5.2.2'; + $testedUnit->expects($this->once())->method('reportRecommendation'); + $check->check(); + } +} + +class TestCheck extends WPUP_VersionCheck +{ + public $arguments_key = 'test'; + public function setup(){} +} From 612083c722729cae83a682caafdc90d27c8af44f Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 25 Aug 2017 15:25:02 +0200 Subject: [PATCH 24/28] New check method on main object to start checks --- src/WPUpdatePhp.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/WPUpdatePhp.php b/src/WPUpdatePhp.php index 4b39fe7..7cf5890 100644 --- a/src/WPUpdatePhp.php +++ b/src/WPUpdatePhp.php @@ -12,30 +12,32 @@ * WPUpdatePhp. */ class WPUpdatePhp { - /** @var string */ - private $minimum_version; - - /** @var string */ - private $recommended_version; - - /** @var string */ - private $plugin_name = ''; + /** @var string */ + private $plugin_name; /** @var WPUP_Translator */ public $translator; + /** @var WPUP_Checker */ + private $checker; + /** * @param string $plugin_name - * @param string $minimum_version Minimum version of PHP. - * @param string $recommended_version Recommended version of PHP. + * @param array $arguments */ - public function __construct( $plugin_name, $minimum_version, $recommended_version = null ) { - $this->plugin_name = $plugin_name; - $this->minimum_version = $minimum_version; - $this->recommended_version = $recommended_version; + public function __construct( $plugin_name, $arguments = array()) { + $this->plugin_name = $plugin_name; + $this->translator = new WPUP_Translator(); + $this->checker = new WPUP_Checker($arguments); } + public function check() + { + $this->checker->setup(); + $this->checker->check(); + } + /** * Check given PHP version against minimum required version. * From e79e0ab9d55455387d091ff07621f7ae0534526b Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 25 Aug 2017 15:33:11 +0200 Subject: [PATCH 25/28] Move match_version property to central version checker --- src/Checks/PhpVersion.php | 3 --- src/Checks/VersionCheck.php | 3 +++ src/Checks/WordPressVersion.php | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Checks/PhpVersion.php b/src/Checks/PhpVersion.php index a79dac7..0217b41 100644 --- a/src/Checks/PhpVersion.php +++ b/src/Checks/PhpVersion.php @@ -2,9 +2,6 @@ class WPUP_PhpVersion extends WPUP_VersionCheck { - /** @var string */ - public $match_version; - /** @var string */ public $arguments_key = 'php'; diff --git a/src/Checks/VersionCheck.php b/src/Checks/VersionCheck.php index af8be98..82de040 100644 --- a/src/Checks/VersionCheck.php +++ b/src/Checks/VersionCheck.php @@ -11,6 +11,9 @@ abstract class WPUP_VersionCheck implements WPUP_Check /** @var string */ public $arguments_key; + /** @var string */ + public $match_version; + public function __construct(WPUP_Checker $checker) { $this->arguments = $checker->arguments; diff --git a/src/Checks/WordPressVersion.php b/src/Checks/WordPressVersion.php index 32bba85..033d5cf 100644 --- a/src/Checks/WordPressVersion.php +++ b/src/Checks/WordPressVersion.php @@ -2,9 +2,6 @@ class WPUP_WordPressVersion extends WPUP_VersionCheck { - /** @var string */ - public $match_version; - /** @var string */ public $arguments_key = 'wordpress'; From 1f42bcf6a1ff3f4fc00990b5d73ef220e50d367c Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 25 Aug 2017 15:33:39 +0200 Subject: [PATCH 26/28] Remove example arguments array comments --- src/Checker.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/Checker.php b/src/Checker.php index 3f0d66e..2a88167 100644 --- a/src/Checker.php +++ b/src/Checker.php @@ -5,29 +5,6 @@ class WPUP_Checker /** @var array */ public $checks = array(); - // $arguments = array( - // // 'wordpress' => array( - // // array( - // // 'version' => '3.7.1', - // // 'required' => false, - // // ), - // // array( - // // 'version' => '3.5.0', - // // 'required' => true, - // // ), - // // ), - // 'php' => array( - // array( - // 'version' => '7.0.0', - // 'required' => false, - // ), - // // array( - // // 'version' => '5.6.0', - // // 'required' => true, - // // ), - // ), - // ); - /** @var array */ public $arguments = array(); From 97bc2c16f531147a6656ac192e71f23dfabb54c6 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 25 Aug 2017 15:40:00 +0200 Subject: [PATCH 27/28] Updated readme for new arguments and check method --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0974c68..74db7c2 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,61 @@ composer require wpupdatephp/wp-update-php Another option is to download the [class file](https://github.com/WPupdatePHP/wp-update-php/blob/master/src/WPUpdatePhp.php) manually. ## Usage -Usage of this library depends on how you start your plugin. The core `does_it_meet_required_php_version` method does all the checking for you and adds an admin notice in case the version requirement is not met. +Usage of this library depends on how you start your plugin. The core `check()` method does all the checking for you. You can output an admin notice in case the version requirement is not met. -For example, when you start your plugin by instantiating a new object, you should wrap a conditional check around it. +For example, when you start your plugin by instantiating a new object, you should wrap a conditional check around it. _Example:_ ```php -$updatePhp = new WPUpdatePhp( '5.6.0' ); - -if ( $updatePhp->does_it_meet_required_php_version() ) { +$arguments = array( + 'php' => array( + array( + 'version' => '7.0.0', + 'required' => false, + ), + array( + 'version' => '5.6.0', + 'required' => true, + ), + ), +); +$updatePhp = new WPUpdatePhp( 'Plugin Name', $arguments ); +$updatePhp->check(); + +if ( $updatePhp->passes() ) { // Instantiate new object here } -// The version check has failed, an admin notice has been thrown +// The version check has failed, an admin notice can be shown +``` + +## Available arguments +The full list of available arguments: + +```php +$arguments = array( + 'wordpress' => array( + array( + 'version' => '3.7.1', + 'required' => false, + ), + array( + 'version' => '3.5.0', + 'required' => true, + ), + ), + 'php' => array( + array( + 'version' => '7.0.0', + 'required' => false, + ), + array( + 'version' => '5.6.0', + 'required' => true, + ), + ), +); ``` ## Including the library file @@ -38,9 +79,6 @@ if ( ! class_exists( 'WPUpdatePhp' ) ) { } ``` -## Setting the name of the plugin -The notice that will be thrown can also contain the name of the plugin. Use the `set_plugin_name( $name )` method on the `WPUpdatePhp` object to provide the name. This call needs to be made before the `does_it_meet_required_php_version()` method is called to check versions. - ## License (GPLv2 license or later) From 4b5c7c09542789621015e45ce135e0f2a504c699 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Fri, 25 Aug 2017 15:42:49 +0200 Subject: [PATCH 28/28] Readme now promotes installing this library through Composer/Mozart --- README.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/README.md b/README.md index 74db7c2..970a9b7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ We recommend installing the library using [Composer](https://getcomposer.org/), composer require wpupdatephp/wp-update-php ``` -Another option is to download the [class file](https://github.com/WPupdatePHP/wp-update-php/blob/master/src/WPUpdatePhp.php) manually. +To prevent collisions, you can install this library inside your own prefixed class names (eg `CJ_WPUpdatePhp`), using [Mozart](https://github.com/coenjacobs/mozart) and we **highly recommend doing this** as it's currently the only way to prevent hard to debug conflicts. ## Usage Usage of this library depends on how you start your plugin. The core `check()` method does all the checking for you. You can output an admin notice in case the version requirement is not met. @@ -68,17 +68,6 @@ $arguments = array( ); ``` -## Including the library file -Adding the library via Composer has preference. The Composer autoloader will automatically take care of preventing including two classes with the same name. - -In case you want to include the file manually, please wrap the include or require call in a [`class_exists`](http://php.net/class_exists) conditional, like so: - -```php -if ( ! class_exists( 'WPUpdatePhp' ) ) { - // do the file include or require here -} -``` - ## License (GPLv2 license or later)