From 7e0174884e604c6d33bc18057e9b6e2fac1df439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 23 Dec 2019 08:59:23 -0500 Subject: [PATCH 01/20] add interfaces --- src/EventManagerAwareSubscriberInterface.php | 18 ++++++++++ src/SubscriberInterface.php | 38 ++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/EventManagerAwareSubscriberInterface.php create mode 100644 src/SubscriberInterface.php diff --git a/src/EventManagerAwareSubscriberInterface.php b/src/EventManagerAwareSubscriberInterface.php new file mode 100644 index 0000000..6955180 --- /dev/null +++ b/src/EventManagerAwareSubscriberInterface.php @@ -0,0 +1,18 @@ + 'method_name') + * * array('event_name' => array('method_name', $priority)) + * * array('event_name' => array('method_name', $priority, $accepted_args)) + * * array('event_name' => array(array('method_name_1', $priority_1, $accepted_args_1)), array('method_name_2', $priority_2, $accepted_args_2))) + * + * @return array + */ + public static function getSubscribedEvents(); +} From 7bdf7154481f66a443c77c6ded2e347045820fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 23 Dec 2019 08:59:31 -0500 Subject: [PATCH 02/20] add PluginApiManager --- src/PluginApiManager.php | 102 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/PluginApiManager.php diff --git a/src/PluginApiManager.php b/src/PluginApiManager.php new file mode 100644 index 0000000..7937473 --- /dev/null +++ b/src/PluginApiManager.php @@ -0,0 +1,102 @@ + Date: Mon, 23 Dec 2019 08:59:35 -0500 Subject: [PATCH 03/20] add EventManager --- src/EventManager.php | 135 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/EventManager.php diff --git a/src/EventManager.php b/src/EventManager.php new file mode 100644 index 0000000..169e7bd --- /dev/null +++ b/src/EventManager.php @@ -0,0 +1,135 @@ +plugin_api_manager = $plugin_api_manager; + } + + /** + * Adds the given event listener to the list of event listeners + * + * @param string $event_name Name of the event. + * @param callable $listener Listener Callback function. + * @param int $priority Priority. + * @param int $accepted_args Number of arguments. + */ + public function addListener($event_name, $listener, $priority = 10, $accepted_args = 1) + { + $this->plugin_api_manager->addCallback($event_name, $listener, $priority, $accepted_args); + } + + /** + * Adds an event subscriber. + * + * The event manager adds the given subscriber to the list of event listeners + * for all the events that it wants to listen to. + * + * @param SubscriberInterface $subscriber SubscriberInterface implementation. + */ + public function addSubscriber(SubscriberInterface $subscriber) + { + if ($subscriber instanceof EventManagerAwareSubscriberInterface) { + $subscriber->setEventManager($this); + } + foreach ($subscriber->getSubscribedEvents() as $event_name => $parameters) { + $this->addSubscriberListener($subscriber, $event_name, $parameters); + } + } + + /** + * Removes the given event listener from the list of event listeners + * that listen to the given event. + * + * @param string $event_name Event name. + * @param callable $callback Callback. + * @param int $priority Priority. + * + * @return bool + */ + public function removeListener($event_name, $callback, $priority = 10) + { + return $this->plugin_api_manager->removeCallback($event_name, $callback, $priority); + } + + /** + * Removes an event subscriber. + * + * The event manager removes the given subscriber from the list of event listeners + * for all the events that it wants to listen to. + * + * @param SubscriberInterface $subscriber SubscriberInterface implementation. + */ + public function removeSubscriber(SubscriberInterface $subscriber) + { + foreach ($subscriber->getSubscribedEvents() as $event_name => $parameters) { + $this->removeSubscriberListener($subscriber, $event_name, $parameters); + } + } + + /** + * Adds the given subscriber listener to the list of event listeners + * that listen to the given event. + * + * @param SubscriberInterface $subscriber SubscriberInterface implementation. + * @param string $event_name Event name. + * @param mixed $parameters Parameters, can be a string, an array or a multidimensional array. + */ + private function addSubscriberListener(SubscriberInterface $subscriber, $event_name, $parameters) + { + if (is_string($parameters)) { + $this->addListener($event_name, [ $subscriber, $parameters ]); + } elseif (is_array($parameters) && count($parameters) !== count($parameters, COUNT_RECURSIVE)) { + foreach ($parameters as $parameter) { + $this->addSubscriberListener($subscriber, $event_name, $parameter); + } + } elseif (is_array($parameters) && isset($parameters[0])) { + $this->addListener($event_name, [ $subscriber, $parameters[0] ], isset($parameters[1]) ? $parameters[1] : 10, isset($parameters[2]) ? $parameters[2] : 1); + } + } + + /** + * Removes the given subscriber listener to the list of event listeners + * that listen to the given event. + * + * @param SubscriberInterface $subscriber SubscriberInterface implementation. + * @param string $event_name Event name. + * @param mixed $parameters Parameters, can be a string, an array or a multidimensional array. + */ + private function removeSubscriberListener(SubscriberInterface $subscriber, $event_name, $parameters) + { + if (is_string($parameters)) { + $this->removeCallback($event_name, [ $subscriber, $parameters ]); + } elseif (is_array($parameters) && count($parameters) !== count($parameters, COUNT_RECURSIVE)) { + foreach ($parameters as $parameter) { + $this->removeSubscriberCallback($subscriber, $event_name, $parameter); + } + } elseif (is_array($parameters) && isset($parameters[0])) { + $this->removeCallback($event_name, [ $subscriber, $parameters[0] ], isset($parameters[1]) ? $parameters[1] : 10); + } + } +} From 0d063e877ea160a88400d2348b4919b229717e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 24 Dec 2019 11:52:54 -0500 Subject: [PATCH 04/20] fix tests path for autoloading --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8c7ed7c..9b46be4 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,8 @@ }, "autoload-dev": { "psr-4": { - "WP_Media\\EventManager\\Tests\\Unit\\": "test/Unit", - "WP_Media\\EventManager\\Tests\\Integration\\": "test/Integration" + "WP_Media\\EventManager\\Tests\\Unit\\": "tests/Unit", + "WP_Media\\EventManager\\Tests\\Integration\\": "tests/Integration" } }, "scripts": { From ff1ff717593bb4e1fc6a6b795a1a993a7b302269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Thu, 26 Dec 2019 11:18:55 -0500 Subject: [PATCH 05/20] add unit tests initial setup --- tests/TestCaseTrait.php | 59 ++++++++++++++++++++++++++++++ tests/Unit/TestCase.php | 67 +++++++++++++++++++++++++++++++++++ tests/Unit/bootstrap.php | 13 +++++++ tests/Unit/phpunit.xml.dist | 28 +++++++++++++++ tests/bootstrap-functions.php | 48 +++++++++++++++++++++++++ 5 files changed, 215 insertions(+) create mode 100644 tests/TestCaseTrait.php create mode 100644 tests/Unit/TestCase.php create mode 100644 tests/Unit/bootstrap.php create mode 100644 tests/Unit/phpunit.xml.dist create mode 100644 tests/bootstrap-functions.php diff --git a/tests/TestCaseTrait.php b/tests/TestCaseTrait.php new file mode 100644 index 0000000..f039818 --- /dev/null +++ b/tests/TestCaseTrait.php @@ -0,0 +1,59 @@ +getMethod( $method_name ); + $method->setAccessible( true ); + return $method; + } + + /** + * Get reflective access to the private/protected property. + * + * @param string $property Property name for which to gain access. + * @param string|mixed $class Class name or instance. + * + * @return \ReflectionProperty|string + * @throws \ReflectionException Throws an exception if property does not exist. + */ + protected function get_reflective_property( $property, $class ) { + $class = new \ReflectionClass( $class ); + $property = $class->getProperty( $property ); + $property->setAccessible( true ); + return $property; + } + + /** + * Set the value of a property or private property. + * + * @param mixed $value The value to set for the property. + * @param string $property Property name for which to gain access. + * @param mixed $instance Instance of the target object. + * + * @return \ReflectionProperty|string + * @throws \ReflectionException Throws an exception if property does not exist. + */ + protected function set_reflective_property( $value, $property, $instance ) { + $property = $this->get_reflective_property( $property, $instance ); + $property->setValue( $instance, $value ); + $property->setAccessible( false ); + return $property; + } +} diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php new file mode 100644 index 0000000..1cf265b --- /dev/null +++ b/tests/Unit/TestCase.php @@ -0,0 +1,67 @@ +echoArg(); + } + } +} diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php new file mode 100644 index 0000000..a0df3b5 --- /dev/null +++ b/tests/Unit/bootstrap.php @@ -0,0 +1,13 @@ + + + + + + . + TestCase.php + + + + + + . + + + \ No newline at end of file diff --git a/tests/bootstrap-functions.php b/tests/bootstrap-functions.php new file mode 100644 index 0000000..999d6a7 --- /dev/null +++ b/tests/bootstrap-functions.php @@ -0,0 +1,48 @@ + Date: Thu, 26 Dec 2019 11:19:15 -0500 Subject: [PATCH 06/20] add unit tests for the PluginApiManager methods --- .../Unit/PluginApiManager/TestAddCallback.php | 37 ++++++++++++ tests/Unit/PluginApiManager/TestExecute.php | 26 +++++++++ tests/Unit/PluginApiManager/TestFilter.php | 26 +++++++++ .../Unit/PluginApiManager/TestHasCallback.php | 56 ++++++++++++++++++ .../PluginApiManager/TestRemoveCallback.php | 58 +++++++++++++++++++ 5 files changed, 203 insertions(+) create mode 100644 tests/Unit/PluginApiManager/TestAddCallback.php create mode 100644 tests/Unit/PluginApiManager/TestExecute.php create mode 100644 tests/Unit/PluginApiManager/TestFilter.php create mode 100644 tests/Unit/PluginApiManager/TestHasCallback.php create mode 100644 tests/Unit/PluginApiManager/TestRemoveCallback.php diff --git a/tests/Unit/PluginApiManager/TestAddCallback.php b/tests/Unit/PluginApiManager/TestAddCallback.php new file mode 100644 index 0000000..2a6ff72 --- /dev/null +++ b/tests/Unit/PluginApiManager/TestAddCallback.php @@ -0,0 +1,37 @@ +with('strtolower', 10, 1); + + $plugin_api_manager = new PluginApiManager(); + $plugin_api_manager->addCallback('the_content', 'strtolower'); + } + + /** + * Test should add a new filter with a priority 100 and 3 arguments + */ + public function testShouldAddNewFilterWithAllParameters() { + Filters\expectAdded('the_content') + ->with('strtolower', 100, 3); + + $plugin_api_manager = new PluginApiManager(); + $plugin_api_manager->addCallback('the_content', 'strtolower', 100, 3); + } +} diff --git a/tests/Unit/PluginApiManager/TestExecute.php b/tests/Unit/PluginApiManager/TestExecute.php new file mode 100644 index 0000000..d43ba4b --- /dev/null +++ b/tests/Unit/PluginApiManager/TestExecute.php @@ -0,0 +1,26 @@ +execute('my_action'); + + $this->assertSame(1, did_action('my_action')); + } +} diff --git a/tests/Unit/PluginApiManager/TestFilter.php b/tests/Unit/PluginApiManager/TestFilter.php new file mode 100644 index 0000000..ee090be --- /dev/null +++ b/tests/Unit/PluginApiManager/TestFilter.php @@ -0,0 +1,26 @@ +filter('my_filter', 'filter value'); + + $this->assertTrue(Filters\applied('my_filter') > 0); + } +} diff --git a/tests/Unit/PluginApiManager/TestHasCallback.php b/tests/Unit/PluginApiManager/TestHasCallback.php new file mode 100644 index 0000000..a542f5a --- /dev/null +++ b/tests/Unit/PluginApiManager/TestHasCallback.php @@ -0,0 +1,56 @@ +assertFalse($plugin_api_manager->hasCallback('the_content')); + } + + /** + * Test should return true when a callback is attached to the given hook. + */ + public function testShouldReturnTrueWhenCallbackAttached() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertTrue($plugin_api_manager->hasCallback('the_content', null)); + } + + /** + * Test should return false when the given callback is not attached to the given hook. + */ + public function testShouldReturnFalseWhenCallbackNotAttached() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertFalse($plugin_api_manager->hasCallback('the_content', 'strtoupper')); + } + + /** + * Test should return true when the given callback is attached to the given hook. + */ + public function testShouldReturnPriorityIntWhenCallbackAttached() { + add_filter('the_content', 'strtolower', 11); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertTrue($plugin_api_manager->hasCallback('the_content', 'strtolower')); + } +} diff --git a/tests/Unit/PluginApiManager/TestRemoveCallback.php b/tests/Unit/PluginApiManager/TestRemoveCallback.php new file mode 100644 index 0000000..8771832 --- /dev/null +++ b/tests/Unit/PluginApiManager/TestRemoveCallback.php @@ -0,0 +1,58 @@ +assertTrue($plugin_api_manager->removeCallback('the_content', 'strtolower')); + } + + /** + * Test should return false when the given callback doesn't exist for the given hook + */ + public function testShouldReturnFalseWhenCallbackDoesNotExist() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertFalse($plugin_api_manager->removeCallback('the_content', 'strtoupper')); + } + + /** + * Test should return false when the given callback priority doesn't match with the priority when added + */ + public function testShouldReturnFalseWhenPriorityDoesNotMatch() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertFalse($plugin_api_manager->removeCallback('the_content', 'strtolower', 100)); + } + + /** + * Test should return true when the given callback priority matches with the priority when added + */ + public function testShouldReturnTrueWhenPriorityMatches() { + add_filter('the_content', 'strtolower', 100); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertTrue($plugin_api_manager->removeCallback('the_content', 'strtolower', 100)); + } +} From b6aea37f04c0c8d90911f3a6fec19ea0a2c05000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 15:26:51 -0500 Subject: [PATCH 07/20] add fixtures autoload --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9b46be4..624f71b 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "autoload-dev": { "psr-4": { "WP_Media\\EventManager\\Tests\\Unit\\": "tests/Unit", - "WP_Media\\EventManager\\Tests\\Integration\\": "tests/Integration" + "WP_Media\\EventManager\\Tests\\Integration\\": "tests/Integration", + "WP_Media\\EventManager\\Tests\\Fixtures\\": "tests/Fixtures" } }, "scripts": { From c6bf48374860b33d3e518f5a0e6ec28d2c96a696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 15:27:09 -0500 Subject: [PATCH 08/20] fix methods names --- src/EventManager.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/EventManager.php b/src/EventManager.php index 169e7bd..5e06d21 100644 --- a/src/EventManager.php +++ b/src/EventManager.php @@ -56,6 +56,7 @@ public function addSubscriber(SubscriberInterface $subscriber) if ($subscriber instanceof EventManagerAwareSubscriberInterface) { $subscriber->setEventManager($this); } + foreach ($subscriber->getSubscribedEvents() as $event_name => $parameters) { $this->addSubscriberListener($subscriber, $event_name, $parameters); } @@ -123,13 +124,13 @@ private function addSubscriberListener(SubscriberInterface $subscriber, $event_n private function removeSubscriberListener(SubscriberInterface $subscriber, $event_name, $parameters) { if (is_string($parameters)) { - $this->removeCallback($event_name, [ $subscriber, $parameters ]); + $this->removeListener($event_name, [ $subscriber, $parameters ]); } elseif (is_array($parameters) && count($parameters) !== count($parameters, COUNT_RECURSIVE)) { foreach ($parameters as $parameter) { - $this->removeSubscriberCallback($subscriber, $event_name, $parameter); + $this->removeSubscriberListener($subscriber, $event_name, $parameter); } } elseif (is_array($parameters) && isset($parameters[0])) { - $this->removeCallback($event_name, [ $subscriber, $parameters[0] ], isset($parameters[1]) ? $parameters[1] : 10); + $this->removeListener($event_name, [ $subscriber, $parameters[0] ], isset($parameters[1]) ? $parameters[1] : 10); } } } From 06e82c7b95ba608656c62e02b86c58a4b380ed9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 15:27:20 -0500 Subject: [PATCH 09/20] add dummy subscriber for tests --- tests/Fixtures/DummySubscriber.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/Fixtures/DummySubscriber.php diff --git a/tests/Fixtures/DummySubscriber.php b/tests/Fixtures/DummySubscriber.php new file mode 100644 index 0000000..7513e20 --- /dev/null +++ b/tests/Fixtures/DummySubscriber.php @@ -0,0 +1,22 @@ + 'bar', + 'foofoo' => [ 'barbar', 20 ], + 'foobar' => [ 'foobarbar', 50, 3 ], + 'barfoo' => [ + [ 'filter_this' ], + [ 'filter_that', 10, 2 ], + ], + ]; + } +} From 8bce359d99eda9209cd3216eda4b8ce2d3fbae88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 15:27:51 -0500 Subject: [PATCH 10/20] add event manager tests --- tests/Unit/EventManager/addSubscriber.php | 29 ++++++++++++++++++++ tests/Unit/EventManager/removeSubscriber.php | 29 ++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/Unit/EventManager/addSubscriber.php create mode 100644 tests/Unit/EventManager/removeSubscriber.php diff --git a/tests/Unit/EventManager/addSubscriber.php b/tests/Unit/EventManager/addSubscriber.php new file mode 100644 index 0000000..fc9ed35 --- /dev/null +++ b/tests/Unit/EventManager/addSubscriber.php @@ -0,0 +1,29 @@ +shouldReceive('addCallback') + ->times(5); + + $manager = new EventManager($plugin_api_manager); + + $manager->addSubscriber(new DummySubscriber()); + } +} diff --git a/tests/Unit/EventManager/removeSubscriber.php b/tests/Unit/EventManager/removeSubscriber.php new file mode 100644 index 0000000..255941e --- /dev/null +++ b/tests/Unit/EventManager/removeSubscriber.php @@ -0,0 +1,29 @@ +shouldReceive('removeCallback') + ->times(5); + + $manager = new EventManager($plugin_api_manager); + + $manager->removeSubscriber(new DummySubscriber()); + } +} From 1819383cb3b5704614f24a86deea0d3f44f1e33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 15:29:50 -0500 Subject: [PATCH 11/20] rename classes and files --- tests/Integration/TestCase.php | 31 ++++++++++ tests/Integration/bootstrap.php | 62 +++++++++++++++++++ tests/Integration/phpunit.xml.dist | 22 +++++++ .../{TestAddCallback.php => addCallback.php} | 2 +- .../{TestExecute.php => execute.php} | 2 +- .../{TestFilter.php => filter.php} | 2 +- .../{TestHasCallback.php => hasCallback.php} | 2 +- ...tRemoveCallback.php => removeCallback.php} | 2 +- 8 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 tests/Integration/TestCase.php create mode 100644 tests/Integration/bootstrap.php create mode 100644 tests/Integration/phpunit.xml.dist rename tests/Unit/PluginApiManager/{TestAddCallback.php => addCallback.php} (96%) rename tests/Unit/PluginApiManager/{TestExecute.php => execute.php} (94%) rename tests/Unit/PluginApiManager/{TestFilter.php => filter.php} (94%) rename tests/Unit/PluginApiManager/{TestHasCallback.php => hasCallback.php} (97%) rename tests/Unit/PluginApiManager/{TestRemoveCallback.php => removeCallback.php} (97%) diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php new file mode 100644 index 0000000..6ca14ba --- /dev/null +++ b/tests/Integration/TestCase.php @@ -0,0 +1,31 @@ + + + + + + . + TestCase.php + + + \ No newline at end of file diff --git a/tests/Unit/PluginApiManager/TestAddCallback.php b/tests/Unit/PluginApiManager/addCallback.php similarity index 96% rename from tests/Unit/PluginApiManager/TestAddCallback.php rename to tests/Unit/PluginApiManager/addCallback.php index 2a6ff72..cb03004 100644 --- a/tests/Unit/PluginApiManager/TestAddCallback.php +++ b/tests/Unit/PluginApiManager/addCallback.php @@ -12,7 +12,7 @@ * @covers WP_Media\EventManager\PluginApiManager::addCallback * @group PluginApiManager */ -class TestAddCallback extends TestCase { +class Test_AddCallback extends TestCase { /** * Test should add a new filter with default priority and arguments */ diff --git a/tests/Unit/PluginApiManager/TestExecute.php b/tests/Unit/PluginApiManager/execute.php similarity index 94% rename from tests/Unit/PluginApiManager/TestExecute.php rename to tests/Unit/PluginApiManager/execute.php index d43ba4b..17baca9 100644 --- a/tests/Unit/PluginApiManager/TestExecute.php +++ b/tests/Unit/PluginApiManager/execute.php @@ -12,7 +12,7 @@ * @covers WP_Media\EventManager\PluginApiManager::execute * @group PluginApiManager */ -class TestExecute extends TestCase { +class Test_Execute extends TestCase { /** * Test should assert the given action was fired once */ diff --git a/tests/Unit/PluginApiManager/TestFilter.php b/tests/Unit/PluginApiManager/filter.php similarity index 94% rename from tests/Unit/PluginApiManager/TestFilter.php rename to tests/Unit/PluginApiManager/filter.php index ee090be..d99b6fc 100644 --- a/tests/Unit/PluginApiManager/TestFilter.php +++ b/tests/Unit/PluginApiManager/filter.php @@ -12,7 +12,7 @@ * @covers WP_Media\EventManager\PluginApiManager::filter * @group PluginApiManager */ -class TestFilter extends TestCase { +class Test_Filter extends TestCase { /** * Test should assert the given filter was fired at least once */ diff --git a/tests/Unit/PluginApiManager/TestHasCallback.php b/tests/Unit/PluginApiManager/hasCallback.php similarity index 97% rename from tests/Unit/PluginApiManager/TestHasCallback.php rename to tests/Unit/PluginApiManager/hasCallback.php index a542f5a..c9833b9 100644 --- a/tests/Unit/PluginApiManager/TestHasCallback.php +++ b/tests/Unit/PluginApiManager/hasCallback.php @@ -11,7 +11,7 @@ * @covers WP_Media\EventManager\PluginApiManager::hasCallback * @group PluginApiManager */ -class TestHasCallback extends TestCase { +class Test_HasCallback extends TestCase { /** * Test should return false when no callback is attached to the given hook. */ diff --git a/tests/Unit/PluginApiManager/TestRemoveCallback.php b/tests/Unit/PluginApiManager/removeCallback.php similarity index 97% rename from tests/Unit/PluginApiManager/TestRemoveCallback.php rename to tests/Unit/PluginApiManager/removeCallback.php index 8771832..9dac439 100644 --- a/tests/Unit/PluginApiManager/TestRemoveCallback.php +++ b/tests/Unit/PluginApiManager/removeCallback.php @@ -11,7 +11,7 @@ * @covers WP_Media\EventManager\PluginApiManager::removeCallback * @group PluginApiManager */ -class TestRemoveCallback extends TestCase { +class Test_RemoveCallback extends TestCase { /** * Test should return true when the given callback is removed from the given hook */ From ef9347831664d07640e5ffcafc95b0465601e432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 16:04:35 -0500 Subject: [PATCH 12/20] remove unnecessary code --- tests/Integration/bootstrap.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/Integration/bootstrap.php b/tests/Integration/bootstrap.php index f677be4..17367e2 100644 --- a/tests/Integration/bootstrap.php +++ b/tests/Integration/bootstrap.php @@ -45,16 +45,7 @@ function get_wp_tests_dir() { function bootstrap_integration_suite( $wp_tests_dir ) { // Give access to tests_add_filter() function. require_once $wp_tests_dir . '/includes/functions.php'; - // Manually load the plugin being tested. - tests_add_filter( - 'muplugins_loaded', - function() { - // Load fixture for WC_Rocket() function. - require ROCKETVERSIONUPDATE_PLUGIN_ROOT . '/tests/Fixtures/WC_Rocket/functions.php'; - // Load the plugin. - require ROCKETVERSIONUPDATE_PLUGIN_ROOT . '/rocket-version-updater.php'; - } - ); + // Start up the WP testing environment. require_once $wp_tests_dir . '/includes/bootstrap.php'; } From 24ed0e13d9a1057746c51aee248b0fe1a0bde483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 16:04:42 -0500 Subject: [PATCH 13/20] add integration tests --- .../EventManager/addSubscriber.php | 47 +++++++++++++++ .../EventManager/removeSubscriber.php | 33 +++++++++++ .../PluginApiManager/addCallback.php | 39 ++++++++++++ .../Integration/PluginApiManager/execute.php | 26 ++++++++ tests/Integration/PluginApiManager/filter.php | 31 ++++++++++ .../PluginApiManager/hasCallback.php | 59 +++++++++++++++++++ .../PluginApiManager/removeCallback.php | 58 ++++++++++++++++++ 7 files changed, 293 insertions(+) create mode 100644 tests/Integration/EventManager/addSubscriber.php create mode 100644 tests/Integration/EventManager/removeSubscriber.php create mode 100644 tests/Integration/PluginApiManager/addCallback.php create mode 100644 tests/Integration/PluginApiManager/execute.php create mode 100644 tests/Integration/PluginApiManager/filter.php create mode 100644 tests/Integration/PluginApiManager/hasCallback.php create mode 100644 tests/Integration/PluginApiManager/removeCallback.php diff --git a/tests/Integration/EventManager/addSubscriber.php b/tests/Integration/EventManager/addSubscriber.php new file mode 100644 index 0000000..faf0262 --- /dev/null +++ b/tests/Integration/EventManager/addSubscriber.php @@ -0,0 +1,47 @@ +addSubscriber($subscriber); + + $this->assertSame( + 10, + has_filter('foo', [ $subscriber, 'bar' ]) + ); + $this->assertSame( + 20, + has_filter('foofoo', [ $subscriber, 'barbar' ]) + ); + $this->assertSame( + 50, + has_filter('foobar', [ $subscriber, 'foobarbar' ]) + ); + $this->assertSame( + 10, + has_filter('barfoo', [ $subscriber, 'filter_this' ]) + ); + $this->assertSame( + 10, + has_filter('barfoo', [ $subscriber, 'filter_that' ]) + ); + } +} diff --git a/tests/Integration/EventManager/removeSubscriber.php b/tests/Integration/EventManager/removeSubscriber.php new file mode 100644 index 0000000..c6b48e5 --- /dev/null +++ b/tests/Integration/EventManager/removeSubscriber.php @@ -0,0 +1,33 @@ +addSubscriber($subscriber); + $manager->removeSubscriber($subscriber); + + $this->assertFalse(has_filter('foo', [ $subscriber, 'bar' ])); + $this->assertFalse(has_filter('foofoo', [ $subscriber, 'barbar' ])); + $this->assertFalse(has_filter('foobar', [ $subscriber, 'foobarbar' ])); + $this->assertFalse(has_filter('barfoo', [ $subscriber, 'filter_this' ])); + $this->assertFalse(has_filter('barfoo', [ $subscriber, 'filter_that' ])); + } +} diff --git a/tests/Integration/PluginApiManager/addCallback.php b/tests/Integration/PluginApiManager/addCallback.php new file mode 100644 index 0000000..74ce87f --- /dev/null +++ b/tests/Integration/PluginApiManager/addCallback.php @@ -0,0 +1,39 @@ +addCallback('the_content', 'strtolower'); + + $this->assertSame( + 10, + has_filter('the_content', 'strtolower') + ); + } + + /** + * Test should add a new filter with a priority 100 and 3 arguments + */ + public function testShouldAddNewFilterWithAllParameters() { + $plugin_api_manager = new PluginApiManager(); + $plugin_api_manager->addCallback('the_content', 'strtolower', 100, 3); + + $this->assertSame( + 100, + has_filter('the_content', 'strtolower') + ); + } +} diff --git a/tests/Integration/PluginApiManager/execute.php b/tests/Integration/PluginApiManager/execute.php new file mode 100644 index 0000000..193f591 --- /dev/null +++ b/tests/Integration/PluginApiManager/execute.php @@ -0,0 +1,26 @@ +execute('my_action'); + + $this->assertSame(1, did_action('my_action')); + } +} \ No newline at end of file diff --git a/tests/Integration/PluginApiManager/filter.php b/tests/Integration/PluginApiManager/filter.php new file mode 100644 index 0000000..512727e --- /dev/null +++ b/tests/Integration/PluginApiManager/filter.php @@ -0,0 +1,31 @@ +filter('my_filter', 'filter value'); + + add_filter('my_filter', 'strtoupper'); + + $this->assertSame( + 10, + has_filter('my_filter', 'strtoupper') + ); + } +} diff --git a/tests/Integration/PluginApiManager/hasCallback.php b/tests/Integration/PluginApiManager/hasCallback.php new file mode 100644 index 0000000..bc25421 --- /dev/null +++ b/tests/Integration/PluginApiManager/hasCallback.php @@ -0,0 +1,59 @@ +assertFalse($plugin_api_manager->hasCallback('my_custom_filter')); + } + + /** + * Test should return true when a callback is attached to the given hook. + */ + public function testShouldReturnTrueWhenCallbackAttached() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertTrue($plugin_api_manager->hasCallback('the_content')); + } + + /** + * Test should return false when the given callback is not attached to the given hook. + */ + public function testShouldReturnFalseWhenCallbackNotAttached() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertFalse($plugin_api_manager->hasCallback('the_content', 'strtoupper')); + } + + /** + * Test should return true when the given callback is attached to the given hook. + */ + public function testShouldReturnPriorityIntWhenCallbackAttached() { + add_filter('the_content', 'strtolower', 11); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertSame( + 11, + $plugin_api_manager->hasCallback('the_content', 'strtolower') + ); + } +} diff --git a/tests/Integration/PluginApiManager/removeCallback.php b/tests/Integration/PluginApiManager/removeCallback.php new file mode 100644 index 0000000..e79f739 --- /dev/null +++ b/tests/Integration/PluginApiManager/removeCallback.php @@ -0,0 +1,58 @@ +assertTrue($plugin_api_manager->removeCallback('the_content', 'strtolower')); + } + + /** + * Test should return false when the given callback doesn't exist for the given hook + */ + public function testShouldReturnFalseWhenCallbackDoesNotExist() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertFalse($plugin_api_manager->removeCallback('the_content', 'strtoupper')); + } + + /** + * Test should return false when the given callback priority doesn't match with the priority when added + */ + public function testShouldReturnFalseWhenPriorityDoesNotMatch() { + add_filter('the_content', 'strtolower'); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertFalse($plugin_api_manager->removeCallback('the_content', 'strtolower', 100)); + } + + /** + * Test should return true when the given callback priority matches with the priority when added + */ + public function testShouldReturnTrueWhenPriorityMatches() { + add_filter('the_content', 'strtolower', 100); + + $plugin_api_manager = new PluginApiManager(); + + $this->assertTrue($plugin_api_manager->removeCallback('the_content', 'strtolower', 100)); + } +} From 4f6da3db1cc42b1b290aef43c6b938fe80f63f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 16:19:19 -0500 Subject: [PATCH 14/20] remove unnecessary method --- tests/Unit/TestCase.php | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index 1cf265b..e29e143 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -30,38 +30,4 @@ protected function tearDown() { Monkey\tearDown(); parent::tearDown(); } - - /** - * Mock common WP functions. - * - * @author Grégory Viguier - * @access protected - */ - protected function mockCommonWpFunctions() { - Monkey\Functions\stubs( - [ - '__', - 'esc_attr__', - 'esc_html__', - '_x', - 'esc_attr_x', - 'esc_html_x', - '_n', - '_nx', - 'esc_attr', - 'esc_html', - 'esc_textarea', - 'esc_url', - ] - ); - $functions = [ - '_e', - 'esc_attr_e', - 'esc_html_e', - '_ex', - ]; - foreach ( $functions as $function ) { - Monkey\Functions\when( $function )->echoArg(); - } - } } From 697095f3e5481bef464ac26f5ad99d0c31cb915a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Tue, 7 Jan 2020 16:24:31 -0500 Subject: [PATCH 15/20] missing wp tests shell script --- bin/install-wp-tests.sh | 152 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 bin/install-wp-tests.sh diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh new file mode 100644 index 0000000..878881f --- /dev/null +++ b/bin/install-wp-tests.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash + +if [ $# -lt 3 ]; then + echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + exit 1 +fi + +DB_NAME=$1 +DB_USER=$2 +DB_PASS=$3 +DB_HOST=${4-localhost} +WP_VERSION=${5-latest} +SKIP_DB_CREATE=${6-false} + +TMPDIR=${TMPDIR-/tmp} +TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") +WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} +WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} + +download() { + if [ `which curl` ]; then + curl -s "$1" > "$2"; + elif [ `which wget` ]; then + wget -nv -O "$2" "$1" + fi +} + +if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then + WP_TESTS_TAG="branches/$WP_VERSION" +elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + WP_TESTS_TAG="tags/${WP_VERSION%??}" + else + WP_TESTS_TAG="tags/$WP_VERSION" + fi +elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + WP_TESTS_TAG="trunk" +else + # http serves a single offer, whereas https serves multiple. we only want one + download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json + grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json + LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') + if [[ -z "$LATEST_VERSION" ]]; then + echo "Latest WordPress version could not be found" + exit 1 + fi + WP_TESTS_TAG="tags/$LATEST_VERSION" +fi + +set -ex + +install_wp() { + + if [ -d $WP_CORE_DIR ]; then + return; + fi + + mkdir -p $WP_CORE_DIR + + if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + mkdir -p $TMPDIR/wordpress-nightly + download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip + unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/ + mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR + else + if [ $WP_VERSION == 'latest' ]; then + local ARCHIVE_NAME='latest' + elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then + # https serves multiple offers, whereas http serves single. + download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + LATEST_VERSION=${WP_VERSION%??} + else + # otherwise, scan the releases and get the most up to date minor version of the major release + local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'` + LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) + fi + if [[ -z "$LATEST_VERSION" ]]; then + local ARCHIVE_NAME="wordpress-$WP_VERSION" + else + local ARCHIVE_NAME="wordpress-$LATEST_VERSION" + fi + else + local ARCHIVE_NAME="wordpress-$WP_VERSION" + fi + download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz + tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR + fi + + download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php +} + +install_test_suite() { + # portable in-place argument for both GNU sed and Mac OSX sed + if [[ $(uname -s) == 'Darwin' ]]; then + local ioption='-i .bak' + else + local ioption='-i' + fi + + # set up testing suite if it doesn't yet exist + if [ ! -d $WP_TESTS_DIR ]; then + # 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 + + 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 + # 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 + sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + fi + +} + +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]}; + local DB_SOCK_OR_PORT=${PARTS[1]}; + local EXTRA="" + + if ! [ -z $DB_HOSTNAME ] ; then + if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then + EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" + elif ! [ -z $DB_SOCK_OR_PORT ] ; then + EXTRA=" --socket=$DB_SOCK_OR_PORT" + elif ! [ -z $DB_HOSTNAME ] ; then + EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + fi + fi + + # create database + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA +} + +install_wp +install_test_suite +install_db From 16e02c284b871891dcaa5b24f01e60e059d4bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 13 Jan 2020 13:23:42 -0500 Subject: [PATCH 16/20] update autoload config --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 624f71b..3efdfba 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "autoload": { "psr-4": { - "WP_Media\\EventManager\\": "src/" + "WP_Media\\EventManager\\": "/" } }, "autoload-dev": { From 50bb38e3bd74590fd058cc5d60535897060423e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 13 Jan 2020 13:23:49 -0500 Subject: [PATCH 17/20] move files in the root directory --- src/EventManager.php => EventManager.php | 0 ...riberInterface.php => EventManagerAwareSubscriberInterface.php | 0 src/PluginApiManager.php => PluginApiManager.php | 0 src/SubscriberInterface.php => SubscriberInterface.php | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/EventManager.php => EventManager.php (100%) rename src/EventManagerAwareSubscriberInterface.php => EventManagerAwareSubscriberInterface.php (100%) rename src/PluginApiManager.php => PluginApiManager.php (100%) rename src/SubscriberInterface.php => SubscriberInterface.php (100%) diff --git a/src/EventManager.php b/EventManager.php similarity index 100% rename from src/EventManager.php rename to EventManager.php diff --git a/src/EventManagerAwareSubscriberInterface.php b/EventManagerAwareSubscriberInterface.php similarity index 100% rename from src/EventManagerAwareSubscriberInterface.php rename to EventManagerAwareSubscriberInterface.php diff --git a/src/PluginApiManager.php b/PluginApiManager.php similarity index 100% rename from src/PluginApiManager.php rename to PluginApiManager.php diff --git a/src/SubscriberInterface.php b/SubscriberInterface.php similarity index 100% rename from src/SubscriberInterface.php rename to SubscriberInterface.php From d445c525245104621851eb80ace163be8076c250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 13 Jan 2020 13:24:32 -0500 Subject: [PATCH 18/20] add gitattributes configuration --- .gitattributes | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..03efbe6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +tests export-ignore +bin export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +phpcs.xml export-ignore +README.md export-ignore +LICENSE export-ignore \ No newline at end of file From df57c1c901ddc9a1e1e2cb9a5496dad16a503d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 13 Jan 2020 13:34:24 -0500 Subject: [PATCH 19/20] update autoload config for root directory --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3efdfba..fb90de9 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "autoload": { "psr-4": { - "WP_Media\\EventManager\\": "/" + "WP_Media\\EventManager\\": "" } }, "autoload-dev": { From 99f96334ade87cf69eba4aaacdafb29a2068233e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 13 Jan 2020 13:36:36 -0500 Subject: [PATCH 20/20] remove underscore in vendor name --- EventManager.php | 4 ++-- EventManagerAwareSubscriberInterface.php | 4 ++-- PluginApiManager.php | 4 ++-- SubscriberInterface.php | 4 ++-- composer.json | 8 ++++---- tests/Fixtures/DummySubscriber.php | 4 ++-- tests/Integration/EventManager/addSubscriber.php | 12 ++++++------ tests/Integration/EventManager/removeSubscriber.php | 12 ++++++------ tests/Integration/PluginApiManager/addCallback.php | 8 ++++---- tests/Integration/PluginApiManager/execute.php | 8 ++++---- tests/Integration/PluginApiManager/filter.php | 8 ++++---- tests/Integration/PluginApiManager/hasCallback.php | 8 ++++---- .../Integration/PluginApiManager/removeCallback.php | 8 ++++---- tests/Integration/TestCase.php | 6 +++--- tests/Integration/bootstrap.php | 8 ++++---- tests/TestCaseTrait.php | 4 ++-- tests/Unit/EventManager/addSubscriber.php | 12 ++++++------ tests/Unit/EventManager/removeSubscriber.php | 12 ++++++------ tests/Unit/PluginApiManager/addCallback.php | 8 ++++---- tests/Unit/PluginApiManager/execute.php | 8 ++++---- tests/Unit/PluginApiManager/filter.php | 8 ++++---- tests/Unit/PluginApiManager/hasCallback.php | 8 ++++---- tests/Unit/PluginApiManager/removeCallback.php | 8 ++++---- tests/Unit/TestCase.php | 6 +++--- tests/Unit/bootstrap.php | 6 +++--- tests/bootstrap-functions.php | 4 ++-- 26 files changed, 95 insertions(+), 95 deletions(-) diff --git a/EventManager.php b/EventManager.php index 5e06d21..16f190b 100644 --- a/EventManager.php +++ b/EventManager.php @@ -3,10 +3,10 @@ * Event Manager for events and listeners. * Based on https://carlalexander.ca/designing-system-wordpress-event-management/ * - * @package WP_Media\EventManager + * @package WPMedia\EventManager */ -namespace WP_Media\EventManager; +namespace WPMedia\EventManager; /** * The event manager manages events using the WordPress plugin API. diff --git a/EventManagerAwareSubscriberInterface.php b/EventManagerAwareSubscriberInterface.php index 6955180..4b02709 100644 --- a/EventManagerAwareSubscriberInterface.php +++ b/EventManagerAwareSubscriberInterface.php @@ -2,10 +2,10 @@ /** * Interface for subscribers who need access to the event manager object * - * @package WP_Media\EventManager + * @package WPMedia\EventManager */ -namespace WP_Media\EventManager; +namespace WPMedia\EventManager; interface EventManagerAwareSubscriberInterface extends SubscriberInterface { diff --git a/PluginApiManager.php b/PluginApiManager.php index 7937473..788f1c4 100644 --- a/PluginApiManager.php +++ b/PluginApiManager.php @@ -2,10 +2,10 @@ /** * Based on https://carlalexander.ca/designing-system-wordpress-event-management/ * - * @package WP_Media\EventManager + * @package WPMedia\EventManager */ -namespace WP_Media\EventManager; +namespace WPMedia\EventManager; /** * Wrapper class around the WordPress plugin API diff --git a/SubscriberInterface.php b/SubscriberInterface.php index 855a0ea..6a7b4ee 100644 --- a/SubscriberInterface.php +++ b/SubscriberInterface.php @@ -2,10 +2,10 @@ /** * Interface for subscribers * - * @package WP_Media\EventManager + * @package WPMedia\EventManager */ -namespace WP_Media\EventManager; +namespace WPMedia\EventManager; /** * A Subscriber knows what specific WordPress events it wants to listen to. diff --git a/composer.json b/composer.json index fb90de9..a83fe78 100644 --- a/composer.json +++ b/composer.json @@ -31,14 +31,14 @@ }, "autoload": { "psr-4": { - "WP_Media\\EventManager\\": "" + "WPMedia\\EventManager\\": "" } }, "autoload-dev": { "psr-4": { - "WP_Media\\EventManager\\Tests\\Unit\\": "tests/Unit", - "WP_Media\\EventManager\\Tests\\Integration\\": "tests/Integration", - "WP_Media\\EventManager\\Tests\\Fixtures\\": "tests/Fixtures" + "WPMedia\\EventManager\\Tests\\Unit\\": "tests/Unit", + "WPMedia\\EventManager\\Tests\\Integration\\": "tests/Integration", + "WPMedia\\EventManager\\Tests\\Fixtures\\": "tests/Fixtures" } }, "scripts": { diff --git a/tests/Fixtures/DummySubscriber.php b/tests/Fixtures/DummySubscriber.php index 7513e20..31f5a44 100644 --- a/tests/Fixtures/DummySubscriber.php +++ b/tests/Fixtures/DummySubscriber.php @@ -1,8 +1,8 @@