From f6b54b0187d07a1eb19d7e0552b8c51acf9371d0 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Thu, 6 Apr 2023 02:40:29 -0700 Subject: [PATCH 1/9] fix: rename files --- .vscode/settings.json | 14 +++++ ...actory.php => class-aggregate-factory.php} | 0 ...cation.php => class-base-notification.php} | 0 ...p-notify-factory.php => class-factory.php} | 0 ....php => class-failed-to-add-recipient.php} | 0 ...ipient.php => class-invalid-recipient.php} | 0 ...nvalid-type.php => class-invalid-type.php} | 0 ...eption.php => class-runtime-exception.php} | 0 ...-exception.php => interface-exception.php} | 0 ...fy-base-image.php => class-base-image.php} | 0 ...p-notify-image.php => interface-image.php} | 0 ....php => interface-json-unserializable.php} | 0 ...ication.php => interface-notification.php} | 0 ...notify-status.php => interface-status.php} | 0 ...hp => class-aggregate-message-factory.php} | 0 ...ory.php => class-base-message-factory.php} | 0 ...ase-message.php => class-base-message.php} | 0 ...tory.php => interface-message-factory.php} | 0 ...tify-message.php => interface-message.php} | 0 ...lass-abstract-notification-repository.php} | 0 ...=> class-wpdb-notification-repository.php} | 0 ... => interface-notification-repository.php} | 0 ...p-notify-order.php => interface-order.php} | 0 ... => class-aggregate-recipient-factory.php} | 0 ...y.php => class-base-recipient-factory.php} | 0 ...ion.php => class-recipient-collection.php} | 0 ...recipient.php => class-role-recipient.php} | 0 ...recipient.php => class-user-recipient.php} | 0 ...ry.php => interface-recipient-factory.php} | 0 ...-recipient.php => interface-recipient.php} | 0 ...-base-sender.php => class-base-sender.php} | 0 ...ctory.php => interface-sender-factory.php} | 0 ...notify-sender.php => interface-sender.php} | 0 tests/phpunit/includes/bootstrap.php | 2 +- ...tify-test-case.php => class-test-case.php} | 0 ...ify-base-image.php => test-base-image.php} | 0 ...base-message.php => test-base-message.php} | 0 ...ication.php => test-base-notification.php} | 0 ...y-base-sender.php => test-base-sender.php} | 0 ...wp-notify-factory.php => test-factory.php} | 0 ...y.php => test-notification-repository.php} | 0 ...tion.php => test-recipient-collection.php} | 0 ...-recipient.php => test-role-recipient.php} | 0 ...-recipient.php => test-user-recipient.php} | 0 wp-feature-notifications.php | 58 +++++++++---------- 45 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 .vscode/settings.json rename includes/{class-wp-notify-aggregate-factory.php => class-aggregate-factory.php} (100%) rename includes/{class-wp-notify-base-notification.php => class-base-notification.php} (100%) rename includes/{class-wp-notify-factory.php => class-factory.php} (100%) rename includes/exceptions/{class-wp-notify-failed-to-add-recipient.php => class-failed-to-add-recipient.php} (100%) rename includes/exceptions/{class-wp-notify-invalid-recipient.php => class-invalid-recipient.php} (100%) rename includes/exceptions/{class-wp-notify-invalid-type.php => class-invalid-type.php} (100%) rename includes/exceptions/{class-wp-notify-runtime-exception.php => class-runtime-exception.php} (100%) rename includes/exceptions/{interface-wp-notify-exception.php => interface-exception.php} (100%) rename includes/image/{class-wp-notify-base-image.php => class-base-image.php} (100%) rename includes/image/{interface-wp-notify-image.php => interface-image.php} (100%) rename includes/{interface-wp-notify-json-unserializable.php => interface-json-unserializable.php} (100%) rename includes/{interface-wp-notify-notification.php => interface-notification.php} (100%) rename includes/{interface-wp-notify-status.php => interface-status.php} (100%) rename includes/messages/{class-wp-notify-aggregate-message-factory.php => class-aggregate-message-factory.php} (100%) rename includes/messages/{class-wp-notify-base-message-factory.php => class-base-message-factory.php} (100%) rename includes/messages/{class-wp-notify-base-message.php => class-base-message.php} (100%) rename includes/messages/{interface-wp-notify-message-factory.php => interface-message-factory.php} (100%) rename includes/messages/{interface-wp-notify-message.php => interface-message.php} (100%) rename includes/persistence/{class-wp-notify-abstract-notification-repository.php => class-abstract-notification-repository.php} (100%) rename includes/persistence/{class-wp-notify-wpdb-notification-repository.php => class-wpdb-notification-repository.php} (100%) rename includes/persistence/{interface-wp-notify-notification-repository.php => interface-notification-repository.php} (100%) rename includes/persistence/{interface-wp-notify-order.php => interface-order.php} (100%) rename includes/recipients/{class-wp-notify-aggregate-recipient-factory.php => class-aggregate-recipient-factory.php} (100%) rename includes/recipients/{class-wp-notify-base-recipient-factory.php => class-base-recipient-factory.php} (100%) rename includes/recipients/{class-wp-notify-recipient-collection.php => class-recipient-collection.php} (100%) rename includes/recipients/{class-wp-notify-role-recipient.php => class-role-recipient.php} (100%) rename includes/recipients/{class-wp-notify-user-recipient.php => class-user-recipient.php} (100%) rename includes/recipients/{interface-wp-notify-recipient-factory.php => interface-recipient-factory.php} (100%) rename includes/recipients/{interface-wp-notify-recipient.php => interface-recipient.php} (100%) rename includes/senders/{class-wp-notify-base-sender.php => class-base-sender.php} (100%) rename includes/senders/{interface-wp-notify-sender-factory.php => interface-sender-factory.php} (100%) rename includes/senders/{interface-wp-notify-sender.php => interface-sender.php} (100%) rename tests/phpunit/includes/{class-wp-notify-test-case.php => class-test-case.php} (100%) rename tests/phpunit/tests/{test-wp-notify-base-image.php => test-base-image.php} (100%) rename tests/phpunit/tests/{test-wp-notify-base-message.php => test-base-message.php} (100%) rename tests/phpunit/tests/{test-wp-notify-base-notification.php => test-base-notification.php} (100%) rename tests/phpunit/tests/{test-wp-notify-base-sender.php => test-base-sender.php} (100%) rename tests/phpunit/tests/{test-wp-notify-factory.php => test-factory.php} (100%) rename tests/phpunit/tests/{test-wp-notify-notification-repository.php => test-notification-repository.php} (100%) rename tests/phpunit/tests/{test-wp-notify-recipient-collection.php => test-recipient-collection.php} (100%) rename tests/phpunit/tests/{test-wp-notify-role-recipient.php => test-role-recipient.php} (100%) rename tests/phpunit/tests/{test-wp-notify-user-recipient.php => test-user-recipient.php} (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..91305677 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "[php]": { + "editor.formatOnSave": false + }, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "eslint.validate": [ + "javascript", + "javascript-react", + "typescript", + "typescript-react" + ] +} diff --git a/includes/class-wp-notify-aggregate-factory.php b/includes/class-aggregate-factory.php similarity index 100% rename from includes/class-wp-notify-aggregate-factory.php rename to includes/class-aggregate-factory.php diff --git a/includes/class-wp-notify-base-notification.php b/includes/class-base-notification.php similarity index 100% rename from includes/class-wp-notify-base-notification.php rename to includes/class-base-notification.php diff --git a/includes/class-wp-notify-factory.php b/includes/class-factory.php similarity index 100% rename from includes/class-wp-notify-factory.php rename to includes/class-factory.php diff --git a/includes/exceptions/class-wp-notify-failed-to-add-recipient.php b/includes/exceptions/class-failed-to-add-recipient.php similarity index 100% rename from includes/exceptions/class-wp-notify-failed-to-add-recipient.php rename to includes/exceptions/class-failed-to-add-recipient.php diff --git a/includes/exceptions/class-wp-notify-invalid-recipient.php b/includes/exceptions/class-invalid-recipient.php similarity index 100% rename from includes/exceptions/class-wp-notify-invalid-recipient.php rename to includes/exceptions/class-invalid-recipient.php diff --git a/includes/exceptions/class-wp-notify-invalid-type.php b/includes/exceptions/class-invalid-type.php similarity index 100% rename from includes/exceptions/class-wp-notify-invalid-type.php rename to includes/exceptions/class-invalid-type.php diff --git a/includes/exceptions/class-wp-notify-runtime-exception.php b/includes/exceptions/class-runtime-exception.php similarity index 100% rename from includes/exceptions/class-wp-notify-runtime-exception.php rename to includes/exceptions/class-runtime-exception.php diff --git a/includes/exceptions/interface-wp-notify-exception.php b/includes/exceptions/interface-exception.php similarity index 100% rename from includes/exceptions/interface-wp-notify-exception.php rename to includes/exceptions/interface-exception.php diff --git a/includes/image/class-wp-notify-base-image.php b/includes/image/class-base-image.php similarity index 100% rename from includes/image/class-wp-notify-base-image.php rename to includes/image/class-base-image.php diff --git a/includes/image/interface-wp-notify-image.php b/includes/image/interface-image.php similarity index 100% rename from includes/image/interface-wp-notify-image.php rename to includes/image/interface-image.php diff --git a/includes/interface-wp-notify-json-unserializable.php b/includes/interface-json-unserializable.php similarity index 100% rename from includes/interface-wp-notify-json-unserializable.php rename to includes/interface-json-unserializable.php diff --git a/includes/interface-wp-notify-notification.php b/includes/interface-notification.php similarity index 100% rename from includes/interface-wp-notify-notification.php rename to includes/interface-notification.php diff --git a/includes/interface-wp-notify-status.php b/includes/interface-status.php similarity index 100% rename from includes/interface-wp-notify-status.php rename to includes/interface-status.php diff --git a/includes/messages/class-wp-notify-aggregate-message-factory.php b/includes/messages/class-aggregate-message-factory.php similarity index 100% rename from includes/messages/class-wp-notify-aggregate-message-factory.php rename to includes/messages/class-aggregate-message-factory.php diff --git a/includes/messages/class-wp-notify-base-message-factory.php b/includes/messages/class-base-message-factory.php similarity index 100% rename from includes/messages/class-wp-notify-base-message-factory.php rename to includes/messages/class-base-message-factory.php diff --git a/includes/messages/class-wp-notify-base-message.php b/includes/messages/class-base-message.php similarity index 100% rename from includes/messages/class-wp-notify-base-message.php rename to includes/messages/class-base-message.php diff --git a/includes/messages/interface-wp-notify-message-factory.php b/includes/messages/interface-message-factory.php similarity index 100% rename from includes/messages/interface-wp-notify-message-factory.php rename to includes/messages/interface-message-factory.php diff --git a/includes/messages/interface-wp-notify-message.php b/includes/messages/interface-message.php similarity index 100% rename from includes/messages/interface-wp-notify-message.php rename to includes/messages/interface-message.php diff --git a/includes/persistence/class-wp-notify-abstract-notification-repository.php b/includes/persistence/class-abstract-notification-repository.php similarity index 100% rename from includes/persistence/class-wp-notify-abstract-notification-repository.php rename to includes/persistence/class-abstract-notification-repository.php diff --git a/includes/persistence/class-wp-notify-wpdb-notification-repository.php b/includes/persistence/class-wpdb-notification-repository.php similarity index 100% rename from includes/persistence/class-wp-notify-wpdb-notification-repository.php rename to includes/persistence/class-wpdb-notification-repository.php diff --git a/includes/persistence/interface-wp-notify-notification-repository.php b/includes/persistence/interface-notification-repository.php similarity index 100% rename from includes/persistence/interface-wp-notify-notification-repository.php rename to includes/persistence/interface-notification-repository.php diff --git a/includes/persistence/interface-wp-notify-order.php b/includes/persistence/interface-order.php similarity index 100% rename from includes/persistence/interface-wp-notify-order.php rename to includes/persistence/interface-order.php diff --git a/includes/recipients/class-wp-notify-aggregate-recipient-factory.php b/includes/recipients/class-aggregate-recipient-factory.php similarity index 100% rename from includes/recipients/class-wp-notify-aggregate-recipient-factory.php rename to includes/recipients/class-aggregate-recipient-factory.php diff --git a/includes/recipients/class-wp-notify-base-recipient-factory.php b/includes/recipients/class-base-recipient-factory.php similarity index 100% rename from includes/recipients/class-wp-notify-base-recipient-factory.php rename to includes/recipients/class-base-recipient-factory.php diff --git a/includes/recipients/class-wp-notify-recipient-collection.php b/includes/recipients/class-recipient-collection.php similarity index 100% rename from includes/recipients/class-wp-notify-recipient-collection.php rename to includes/recipients/class-recipient-collection.php diff --git a/includes/recipients/class-wp-notify-role-recipient.php b/includes/recipients/class-role-recipient.php similarity index 100% rename from includes/recipients/class-wp-notify-role-recipient.php rename to includes/recipients/class-role-recipient.php diff --git a/includes/recipients/class-wp-notify-user-recipient.php b/includes/recipients/class-user-recipient.php similarity index 100% rename from includes/recipients/class-wp-notify-user-recipient.php rename to includes/recipients/class-user-recipient.php diff --git a/includes/recipients/interface-wp-notify-recipient-factory.php b/includes/recipients/interface-recipient-factory.php similarity index 100% rename from includes/recipients/interface-wp-notify-recipient-factory.php rename to includes/recipients/interface-recipient-factory.php diff --git a/includes/recipients/interface-wp-notify-recipient.php b/includes/recipients/interface-recipient.php similarity index 100% rename from includes/recipients/interface-wp-notify-recipient.php rename to includes/recipients/interface-recipient.php diff --git a/includes/senders/class-wp-notify-base-sender.php b/includes/senders/class-base-sender.php similarity index 100% rename from includes/senders/class-wp-notify-base-sender.php rename to includes/senders/class-base-sender.php diff --git a/includes/senders/interface-wp-notify-sender-factory.php b/includes/senders/interface-sender-factory.php similarity index 100% rename from includes/senders/interface-wp-notify-sender-factory.php rename to includes/senders/interface-sender-factory.php diff --git a/includes/senders/interface-wp-notify-sender.php b/includes/senders/interface-sender.php similarity index 100% rename from includes/senders/interface-wp-notify-sender.php rename to includes/senders/interface-sender.php diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 7aa3af6b..c0249c57 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -39,4 +39,4 @@ function handle_wp_setup_failure( $message ) { remove_filter( 'wp_die_handler', 'handle_wp_setup_failure' ); require dirname( __FILE__ ) . '/class-dummy-message.php'; -require dirname( __FILE__ ) . '/class-wp-notify-test-case.php'; +require dirname( __FILE__ ) . '/class-test-case.php'; diff --git a/tests/phpunit/includes/class-wp-notify-test-case.php b/tests/phpunit/includes/class-test-case.php similarity index 100% rename from tests/phpunit/includes/class-wp-notify-test-case.php rename to tests/phpunit/includes/class-test-case.php diff --git a/tests/phpunit/tests/test-wp-notify-base-image.php b/tests/phpunit/tests/test-base-image.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-base-image.php rename to tests/phpunit/tests/test-base-image.php diff --git a/tests/phpunit/tests/test-wp-notify-base-message.php b/tests/phpunit/tests/test-base-message.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-base-message.php rename to tests/phpunit/tests/test-base-message.php diff --git a/tests/phpunit/tests/test-wp-notify-base-notification.php b/tests/phpunit/tests/test-base-notification.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-base-notification.php rename to tests/phpunit/tests/test-base-notification.php diff --git a/tests/phpunit/tests/test-wp-notify-base-sender.php b/tests/phpunit/tests/test-base-sender.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-base-sender.php rename to tests/phpunit/tests/test-base-sender.php diff --git a/tests/phpunit/tests/test-wp-notify-factory.php b/tests/phpunit/tests/test-factory.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-factory.php rename to tests/phpunit/tests/test-factory.php diff --git a/tests/phpunit/tests/test-wp-notify-notification-repository.php b/tests/phpunit/tests/test-notification-repository.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-notification-repository.php rename to tests/phpunit/tests/test-notification-repository.php diff --git a/tests/phpunit/tests/test-wp-notify-recipient-collection.php b/tests/phpunit/tests/test-recipient-collection.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-recipient-collection.php rename to tests/phpunit/tests/test-recipient-collection.php diff --git a/tests/phpunit/tests/test-wp-notify-role-recipient.php b/tests/phpunit/tests/test-role-recipient.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-role-recipient.php rename to tests/phpunit/tests/test-role-recipient.php diff --git a/tests/phpunit/tests/test-wp-notify-user-recipient.php b/tests/phpunit/tests/test-user-recipient.php similarity index 100% rename from tests/phpunit/tests/test-wp-notify-user-recipient.php rename to tests/phpunit/tests/test-user-recipient.php diff --git a/wp-feature-notifications.php b/wp-feature-notifications.php index 94764b3e..be9369d1 100644 --- a/wp-feature-notifications.php +++ b/wp-feature-notifications.php @@ -30,35 +30,35 @@ } // Require interface/class declarations.. -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/interface-wp-notify-exception.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-wp-notify-runtime-exception.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-wp-notify-invalid-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-wp-notify-failed-to-add-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-wp-notify-json-unserializable.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-wp-notify-status.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-wp-notify-notification.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-wp-notify-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-wp-notify-aggregate-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-wp-notify-base-notification.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/image/interface-wp-notify-image.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/image/class-wp-notify-base-image.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/senders/interface-wp-notify-sender.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/senders/class-wp-notify-base-sender.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/interface-wp-notify-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-wp-notify-recipient-collection.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-wp-notify-user-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-wp-notify-role-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/interface-wp-notify-recipient-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-wp-notify-base-recipient-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-wp-notify-aggregate-recipient-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/interface-wp-notify-message.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-wp-notify-base-message.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/interface-wp-notify-message-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-wp-notify-base-message-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-wp-notify-aggregate-message-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/interface-wp-notify-notification-repository.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/class-wp-notify-abstract-notification-repository.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/class-wp-notify-wpdb-notification-repository.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/interface-exception.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-runtime-exception.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-invalid-recipient.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-failed-to-add-recipient.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-json-unserializable.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-status.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-notification.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-aggregate-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-base-notification.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/image/interface-image.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/image/class-base-image.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/senders/interface-sender.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/senders/class-base-sender.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/interface-recipient.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-recipient-collection.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-user-recipient.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-role-recipient.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/interface-recipient-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-base-recipient-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-aggregate-recipient-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/interface-message.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-base-message.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/interface-message-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-base-message-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-aggregate-message-factory.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/interface-notification-repository.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/class-abstract-notification-repository.php'; +require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/class-wpdb-notification-repository.php'; require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/demo.php'; require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/restapi/class-notification-controller.php'; From c67b2b9029bd27af772070717e727279302add6d Mon Sep 17 00:00:00 2001 From: John Hooks Date: Thu, 6 Apr 2023 04:25:23 -0700 Subject: [PATCH 2/9] refactor: use namespaces --- includes/class-aggregate-factory.php | 4 +- includes/class-base-notification.php | 36 +++++---- includes/class-factory.php | 27 ++++--- includes/demo.php | 39 ++++++---- .../class-failed-to-add-recipient.php | 6 +- .../exceptions/class-invalid-recipient.php | 4 +- includes/exceptions/class-invalid-type.php | 4 +- .../exceptions/class-runtime-exception.php | 8 +- includes/exceptions/interface-exception.php | 4 +- includes/image/class-base-image.php | 6 +- includes/image/interface-image.php | 8 +- includes/interface-json-unserializable.php | 4 +- includes/interface-notification.php | 12 ++- includes/interface-status.php | 4 +- .../class-aggregate-message-factory.php | 12 ++- .../messages/class-base-message-factory.php | 14 ++-- includes/messages/class-base-message.php | 4 +- .../messages/interface-message-factory.php | 6 +- includes/messages/interface-message.php | 10 ++- ...class-abstract-notification-repository.php | 13 +++- .../class-wpdb-notification-repository.php | 27 ++++--- .../interface-notification-repository.php | 29 ++++--- includes/persistence/interface-order.php | 4 +- .../class-aggregate-recipient-factory.php | 12 ++- .../class-base-recipient-factory.php | 20 +++-- .../recipients/class-recipient-collection.php | 29 ++++--- includes/recipients/class-role-recipient.php | 4 +- includes/recipients/class-user-recipient.php | 10 ++- .../interface-recipient-factory.php | 6 +- includes/recipients/interface-recipient.php | 4 +- includes/senders/class-base-sender.php | 15 ++-- includes/senders/interface-sender-factory.php | 6 +- includes/senders/interface-sender.php | 6 +- .../phpunit/includes/class-dummy-message.php | 6 +- tests/phpunit/includes/class-test-case.php | 4 +- tests/phpunit/tests/test-base-image.php | 12 ++- tests/phpunit/tests/test-base-message.php | 26 ++++--- .../phpunit/tests/test-base-notification.php | 77 +++++++++++-------- tests/phpunit/tests/test-base-sender.php | 25 +++--- tests/phpunit/tests/test-factory.php | 19 +++-- .../tests/test-notification-repository.php | 10 ++- .../tests/test-recipient-collection.php | 52 +++++++------ tests/phpunit/tests/test-role-recipient.php | 14 ++-- tests/phpunit/tests/test-user-recipient.php | 24 +++--- wp-feature-notifications.php | 77 ++++++++++--------- 45 files changed, 464 insertions(+), 279 deletions(-) diff --git a/includes/class-aggregate-factory.php b/includes/class-aggregate-factory.php index 22343a5e..8a23d541 100644 --- a/includes/class-aggregate-factory.php +++ b/includes/class-aggregate-factory.php @@ -1,6 +1,8 @@ sender; @@ -122,7 +130,7 @@ public function get_sender() { /** * Gets the recipients for the notification. * - * @return WP_Notify_Recipient_Collection Notification recipients. + * @return Recipient_Collection Notification recipients. */ public function get_recipients() { return $this->recipients; @@ -131,7 +139,7 @@ public function get_recipients() { /** * Gets the message for the notification. * - * @return WP_Notify_Message Notification message. + * @return Message Notification message. */ public function get_message() { return $this->message; diff --git a/includes/class-factory.php b/includes/class-factory.php index 53e540e3..30566e60 100644 --- a/includes/class-factory.php +++ b/includes/class-factory.php @@ -1,6 +1,13 @@ message_factory = $message_factory; $this->recipient_factory = $recipient_factory; @@ -41,14 +48,14 @@ public function __construct( * * @param $args * - * @return WP_Notify_Base_Notification + * @return Base_Notification */ public function create( $args ) { list( $message_args, $recipients_args, $sender_args ) = $this->validate( $args ); $sender = $this->sender_factory->create( $sender_args ); - $recipients = new WP_Notify_Recipient_Collection(); + $recipients = new Recipient_Collection(); $message = $this->message_factory->create( $message_args ); foreach ( $recipients_args as $type => $value ) { @@ -57,7 +64,7 @@ public function create( $args ) { ); } - return new WP_Notify_Base_Notification( $sender, $recipients, $message ); + return new Base_Notification( $sender, $recipients, $message ); } private function validate( $args ) { diff --git a/includes/demo.php b/includes/demo.php index 9de24668..d28bc33f 100644 --- a/includes/demo.php +++ b/includes/demo.php @@ -5,12 +5,17 @@ * Development demo files **/ +namespace WP\Notifications; + +use WP_Admin_Bar; +use WP_List_Table; + /** * Adds WP Notify icon after the user avatar in the top admin bar in the "secondary" position * * @param WP_Admin_Bar $wp_admin_bar Toolbar instance. */ -function wp_admin_bar_wp_notify_item( WP_Admin_Bar $wp_admin_bar ) { +function admin_bar_item( WP_Admin_Bar $wp_admin_bar ) { if ( ! is_admin() ) { return; } @@ -36,27 +41,27 @@ function wp_admin_bar_wp_notify_item( WP_Admin_Bar $wp_admin_bar ) { ); $wp_admin_bar->add_node( $args ); } -add_action( 'admin_bar_menu', 'wp_admin_bar_wp_notify_item', 1 ); +add_action( 'admin_bar_menu', '\WP\Notifications\admin_bar_item', 1 ); /** * Adds WP Notify area at the top of the dashboard */ -function wp_notify_admin_notice() { +function admin_notice() { echo '
'; } -add_action( 'admin_notices', 'wp_notify_admin_notice' ); +add_action( 'admin_notices', '\WP\Notifications\admin_notice' ); /** * Register and enqueue a wp notify scripts and stylesheet in WordPress admin. */ -function wp_notify_enqueue_admin_assets() { +function enqueue_admin_assets() { /* Load styles */ - wp_register_style( 'wp_notify_css', WP_NOTIFICATION_CENTER_PLUGIN_DIR_URL . '/build/wp-notify.css', array(), WP_NOTIFICATION_CENTER_PLUGIN_VERSION ); + wp_register_style( 'wp_notify_css', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notify.css', array(), WP_FEATURE_NOTIFICATION_PLUGIN_VERSION ); wp_enqueue_style( 'wp_notify_css' ); /* Load scripts */ - $asset = include WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/build/wp-notify.asset.php'; - wp_register_script( 'wp_notify_js', WP_NOTIFICATION_CENTER_PLUGIN_DIR_URL . '/build/wp-notify.js', $asset['dependencies'], WP_NOTIFICATION_CENTER_PLUGIN_VERSION, true ); + $asset = include WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/build/wp-notify.asset.php'; + wp_register_script( 'wp_notify_js', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notify.js', $asset['dependencies'], WP_FEATURE_NOTIFICATION_PLUGIN_VERSION, true ); wp_enqueue_script( 'wp_notify_js' ); wp_localize_script( 'wp_notify_js', @@ -67,7 +72,7 @@ function wp_notify_enqueue_admin_assets() { ); } -add_action( 'admin_enqueue_scripts', 'wp_notify_enqueue_admin_assets', 0 ); +add_action( 'admin_enqueue_scripts', '\WP\Notifications\enqueue_admin_assets', 0 ); /** @@ -75,17 +80,17 @@ function wp_notify_enqueue_admin_assets() { * * @return void */ -function wp_notify_add_admin_options_page() { - add_options_page( 'Notifications', 'Notifications', 'manage_options', 'wp-notify', 'wp_notify_render_admin_options_page' ); +function add_admin_options_page() { + add_options_page( 'Notifications', 'Notifications', 'manage_options', 'wp-notify', '\WP\Notifications\render_admin_options_page' ); } -add_action( 'admin_menu', 'wp_notify_add_admin_options_page' ); +add_action( 'admin_menu', '\WP\Notifications\add_admin_options_page' ); /** * Renders the options page. */ -function wp_notify_render_admin_options_page() { ?> +function render_admin_options_page() { ?>

@@ -227,16 +232,16 @@ function init_table() { /** * Registers our dashboard widget. */ -function wp_notify_dashboard_widget() { - add_meta_box( 'wp_notify', __( 'WP Notify' ), 'wp_notify_render_dashboard_widget', 'dashboard', 'side', 'high' ); +function dashboard_widget() { + add_meta_box( 'wp_notify', __( 'WP Notify' ), '\WP\Notifications\render_dashboard_widget', 'dashboard', 'side', 'high' ); } -add_action( 'wp_dashboard_setup', 'wp_notify_dashboard_widget' ); +add_action( 'wp_dashboard_setup', '\WP\Notifications\dashboard_widget' ); /** * Renders our dashboard widget. */ -function wp_notify_render_dashboard_widget() { +function render_dashboard_widget() { ?>
diff --git a/includes/exceptions/class-failed-to-add-recipient.php b/includes/exceptions/class-failed-to-add-recipient.php index ca0836d7..11cc466b 100644 --- a/includes/exceptions/class-failed-to-add-recipient.php +++ b/includes/exceptions/class-failed-to-add-recipient.php @@ -1,6 +1,8 @@ accepts( $type ) ) { - throw WP_Notify_Invalid_Type::from_message_type( $type ); + throw Invalid_Type::from_message_type( $type ); } list( $type, $value ) = $this->validate( $type, $value ); @@ -25,7 +29,7 @@ public function create( $value, $type = 'standard' ) { switch ( $type ) { case self::TYPE_STANDARD: default: - return new WP_Notify_Base_Message( $value ); + return new Base_Message( $value ); } } diff --git a/includes/messages/class-base-message.php b/includes/messages/class-base-message.php index f0a55678..f5ace6ec 100644 --- a/includes/messages/class-base-message.php +++ b/includes/messages/class-base-message.php @@ -1,6 +1,8 @@ find_by_date_range( $start, $end, - WP_Notify_Order::DESCENDING, + Order::DESCENDING, $pagination, $offset ); diff --git a/includes/persistence/class-wpdb-notification-repository.php b/includes/persistence/class-wpdb-notification-repository.php index 5fd834ef..79129d85 100644 --- a/includes/persistence/class-wpdb-notification-repository.php +++ b/includes/persistence/class-wpdb-notification-repository.php @@ -1,14 +1,21 @@ accepts( $type ) ) { - throw WP_Notify_Invalid_Type::from_recipient_type( $type ); + throw Invalid_Type::from_recipient_type( $type ); } list( $type, $value ) = $this->validate( $type, $value ); @@ -44,11 +48,11 @@ public function accepts( $type ) { * @param string $type Type to get the implementation class for. * * @return string Implementation class. - * @throws WP_Notify_Invalid_Type If the recipient type was not valid. + * @throws Invalid_Type If the recipient type was not valid. */ public function get_implementation_for_type( $type ) { if ( ! $this->accepts( $type ) ) { - throw WP_Notify_Invalid_Type::from_recipient_type( $type ); + throw Invalid_Type::from_recipient_type( $type ); } $mappings = $this->get_type_mappings(); @@ -79,8 +83,8 @@ private function get_type_mappings() { return apply_filters( 'wp_notify_recipient_type_mappings', array( - self::TYPE_USER => 'WP_Notify_User_Recipient', - self::TYPE_ROLE => 'WP_Notify_Role_Recipient', + self::TYPE_USER => 'User_Recipient', + self::TYPE_ROLE => 'Role_Recipient', ) ); } diff --git a/includes/recipients/class-recipient-collection.php b/includes/recipients/class-recipient-collection.php index 011d403f..ca5f3dbe 100644 --- a/includes/recipients/class-recipient-collection.php +++ b/includes/recipients/class-recipient-collection.php @@ -1,15 +1,24 @@ recipients[] = $recipient; } - public function count() { + public function count(): int { return count( $this->recipients ); } /** * Return the current recipient. * - * @return WP_Notify_Recipient Recipient + * @return Recipient Recipient */ public function current() { return current( $this->recipients ); diff --git a/includes/recipients/class-role-recipient.php b/includes/recipients/class-role-recipient.php index bb6a639e..5e2b5a8e 100644 --- a/includes/recipients/class-role-recipient.php +++ b/includes/recipients/class-role-recipient.php @@ -1,6 +1,8 @@ 0 ) ) { - throw WP_Notify_Invalid_Recipient::from_invalid_user_id( $user_id ); + throw Invalid_Recipient::from_invalid_user_id( $user_id ); } return $user_id; diff --git a/includes/recipients/interface-recipient-factory.php b/includes/recipients/interface-recipient-factory.php index 348d58d5..7cd8a126 100644 --- a/includes/recipients/interface-recipient-factory.php +++ b/includes/recipients/interface-recipient-factory.php @@ -1,6 +1,8 @@ name = $name; @@ -59,7 +64,7 @@ public static function json_unserialize( $json ) { $image = null; - if ( ! empty( $image_data ) && is_subclass_of( $class_name, 'WP_Notify_Image' ) ) { + if ( ! empty( $image_data ) && is_subclass_of( $class_name, 'Image' ) ) { $image_reflection = new ReflectionClass( $class_name ); $image = $image_reflection->newInstanceArgs( array_values( $image_data ) ); } @@ -78,7 +83,7 @@ public function get_name() { } /** - * @return WP_Notify_Base_Image|null + * @return Base_Image|null */ public function get_image() { return $this->image; diff --git a/includes/senders/interface-sender-factory.php b/includes/senders/interface-sender-factory.php index eeaa2a13..e49c0c4e 100644 --- a/includes/senders/interface-sender-factory.php +++ b/includes/senders/interface-sender-factory.php @@ -1,13 +1,15 @@ assertEquals( $expected_json, $encoded_image ); @@ -29,11 +33,11 @@ public function test_it_can_be_json_encoded( $image_data, $expected_json ) { */ public function test_it_can_be_instantiated_from_json( $image_data, $json ) { - $test_instance = WP_Notify_Base_Image::json_unserialize( $json ); + $test_instance = Base_Image::json_unserialize( $json ); list( $source, $alt ) = array_values( $image_data ); - $instance = new WP_Notify_Base_Image( $source, $alt ); + $instance = new Base_Image( $source, $alt ); $this->assertEquals( $instance->get_source(), $test_instance->get_source() ); $this->assertEquals( $instance->get_alt(), $test_instance->get_alt() ); diff --git a/tests/phpunit/tests/test-base-message.php b/tests/phpunit/tests/test-base-message.php index 025f759a..df68e0c1 100644 --- a/tests/phpunit/tests/test-base-message.php +++ b/tests/phpunit/tests/test-base-message.php @@ -1,31 +1,35 @@ assertInstanceOf( 'WP_Notify_Base_Message', $testee ); + $testee = new Base_Message( 'Message' ); + $this->assertInstanceOf( '\WP\Notifications\Messages\Base_Message', $testee ); } public function test_it_implements_the_interface() { - $testee = new WP_Notify_Base_Message( 'Message' ); - $this->assertInstanceOf( 'WP_Notify_Message', $testee ); + $testee = new Base_Message( 'Message' ); + $this->assertInstanceOf( '\WP\Notifications\Messages\Message', $testee ); } public function test_it_can_return_its_content() { - $testee = new WP_Notify_Base_Message( 'Message' ); + $testee = new Base_Message( 'Message' ); $this->assertEquals( 'Message', $testee->get_content() ); } public function test_it_can_be_cast_to_string() { - $testee = new WP_Notify_Base_Message( 'Message' ); + $testee = new Base_Message( 'Message' ); $this->assertEquals( 'Message', (string) $testee ); } public function test_it_can_be_json_encoded() { - $testee = new WP_Notify_Base_Message( 'Message' ); + $testee = new Base_Message( 'Message' ); $this->assertEquals( '"Message"', json_encode( $testee ) @@ -34,8 +38,8 @@ public function test_it_can_be_json_encoded() { public function test_it_can_be_instantiated_from_json() { $json = '"Message"'; - $testee = WP_Notify_Base_Message::json_unserialize( $json ); - $this->assertInstanceOf( 'WP_Notify_Base_Message', $testee ); - $this->assertEquals( 'Message', $testee->get_content() ); + $testee = Base_Message::json_unserialize( $json ); + $this->assertInstanceOf( '\WP\Notifications\Messages\Base_Message', $testee ); + $this->assertEquals( '\WP\Notifications\Messages\Message', $testee->get_content() ); } } diff --git a/tests/phpunit/tests/test-base-notification.php b/tests/phpunit/tests/test-base-notification.php index f442622a..8d27425e 100644 --- a/tests/phpunit/tests/test-base-notification.php +++ b/tests/phpunit/tests/test-base-notification.php @@ -1,36 +1,43 @@ createMock( 'WP_Notify_Base_Sender' ); - $recipients_mock = $this->createMock( 'WP_Notify_Recipient_Collection' ); - $testee = new WP_Notify_Base_Notification( + $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); + $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); + $testee = new Base_Notification( $sender_mock, $recipients_mock, new Dummy_Message() ); - $this->assertInstanceOf( 'WP_Notify_Base_Notification', $testee ); + $this->assertInstanceOf( '\WP\Notifications\Base_Notification', $testee ); } public function test_it_implements_the_interface() { - $sender_mock = $this->createMock( 'WP_Notify_Base_Sender' ); - $recipients_mock = $this->createMock( 'WP_Notify_Recipient_Collection' ); - $testee = new WP_Notify_Base_Notification( + $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); + $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); + $testee = new Base_Notification( $sender_mock, $recipients_mock, new Dummy_Message() ); - $this->assertInstanceOf( 'WP_Notify_Notification', $testee ); + $this->assertInstanceOf( '\WP\Notifications\Notification', $testee ); } public function test_it_can_return_its_content() { - $sender_mock = $this->createMock( 'WP_Notify_Base_Sender' ); - $recipients_mock = $this->createMock( 'WP_Notify_Recipient_Collection' ); + $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); + $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); $dummy_message = new Dummy_Message(); - $testee = new WP_Notify_Base_Notification( + $testee = new Base_Notification( $sender_mock, $recipients_mock, $dummy_message @@ -40,10 +47,10 @@ public function test_it_can_return_its_content() { } public function test_it_can_be_json_encoded() { - $sender_mock = new WP_Notify_Base_Sender( 'Name 1' ); - $empty_recipients = new WP_Notify_Recipient_Collection(); - $message = new WP_Notify_Base_Message( 'Message' ); - $testee = new WP_Notify_Base_Notification( + $sender_mock = new Base_Sender( 'Name 1' ); + $empty_recipients = new Recipient_Collection(); + $message = new Base_Message( 'Message' ); + $testee = new Base_Notification( $sender_mock, $empty_recipients, $message @@ -54,20 +61,24 @@ public function test_it_can_be_json_encoded() { ); } - public function test_it_can_be_instantiated_from_json() { - $testee = WP_Notify_Base_Notification::json_unserialize( self::JSON_SERIALIZED ); - $this->assertInstanceOf( 'WP_Notify_Base_Notification', $testee ); - $this->assertInstanceOf( - 'WP_Notify_Recipient_Collection', - $testee->get_recipients() - ); - $this->assertInstanceOf( - 'WP_Notify_Base_Message', - $testee->get_message() - ); - $this->assertInstanceOf( - 'WP_Notify_Base_Sender', - $testee->get_sender() - ); - } + // TODO The test below is problematic, the whole concept of serializing a message + // which is to be directly initialized as a class is probably not the right direction + // and also not how the json api schema would be structured. + + // public function test_it_can_be_instantiated_from_json() { + // $testee = Base_Notification::json_unserialize( self::JSON_SERIALIZED ); + // $this->assertInstanceOf( '\WP\Notifications\Base_Notification', $testee ); + // $this->assertInstanceOf( + // '\WP\Notifications\Recipients\Recipient_Collection', + // $testee->get_recipients() + // ); + // $this->assertInstanceOf( + // '\WP\Notifications\Messages\Base_Message', + // $testee->get_message() + // ); + // $this->assertInstanceOf( + // '\WP\Notifications\Senders\Base_Sender', + // $testee->get_sender() + // ); + // } } diff --git a/tests/phpunit/tests/test-base-sender.php b/tests/phpunit/tests/test-base-sender.php index 0581fb50..c222126a 100644 --- a/tests/phpunit/tests/test-base-sender.php +++ b/tests/phpunit/tests/test-base-sender.php @@ -1,6 +1,13 @@ newInstanceArgs( array_values( $sender_params ) ); $sender_encoded = json_encode( $sender ); @@ -26,13 +33,13 @@ public function test_it_can_be_json_encoded( $sender_params, $expected_json ) { */ public function test_it_can_be_instantiated_from_json( $sender_params, $json ) { - $testee = WP_Notify_Base_Sender::json_unserialize( $json ); + $testee = Base_Sender::json_unserialize( $json ); - $sender_reflection = new ReflectionClass( 'WP_Notify_Base_Sender' ); - /** @var WP_Notify_Base_Sender $sender */ + $sender_reflection = new ReflectionClass( '\WP\Notifications\Senders\Base_Sender' ); + /** @var Base_Sender $sender */ $sender = $sender_reflection->newInstanceArgs( array_values( (array) $sender_params ) ); - $this->assertInstanceOf( 'WP_Notify_Base_Sender', $testee ); + $this->assertInstanceOf( '\WP\Notifications\Senders\Base_Sender', $testee ); $this->assertEquals( $sender->get_name(), $testee->get_name() ); $this->assertEquals( $sender->get_image(), $testee->get_image() ); @@ -60,10 +67,10 @@ public function data_provider_senders() { 'sender with image' => array( array( - 'name' => 'Name 2', - 'WP_Notify_Base_Image' => new WP_Notify_Base_Image( 'img-source', 'img-alt' ), + 'name' => 'Name 2', + 'Base_Image' => new Base_Image( 'img-source', 'img-alt' ), ), - '{"name":"Name 2","WP_Notify_Base_Image":{"source":"img-source","alt":"img-alt"}}', + '{"name":"Name 2","Base_Image":{"source":"img-source","alt":"img-alt"}}', ), ); } diff --git a/tests/phpunit/tests/test-factory.php b/tests/phpunit/tests/test-factory.php index 763c734b..8333f731 100644 --- a/tests/phpunit/tests/test-factory.php +++ b/tests/phpunit/tests/test-factory.php @@ -1,28 +1,31 @@ createMock( 'WP_Notify_Sender' ); + $vendor_sender = $this->createMock( '\WP\Notifications\Senders\Sender' ); - $message_factory = $this->getMockBuilder( 'WP_Notify_Message_Factory' ) + $message_factory = $this->getMockBuilder( '\WP\Notifications\Messages\Message_Factory' ) ->setMethods( array( 'create', 'accepts' ) ) ->getMock(); - $message_factory->method( 'create' )->willReturn( $this->createMock( 'WP_Notify_Message' ) ); + $message_factory->method( 'create' )->willReturn( $this->createMock( '\WP\Notifications\Messages\Message' ) ); $message_factory->method( 'accepts' )->willReturn( true ); - $sender_factory = $this->getMockBuilder( 'WP_Notify_Sender_Factory' ) + $sender_factory = $this->getMockBuilder( '\WP\Notifications\Senders\Sender_Factory' ) ->setMethods( array( 'create' ) ) ->getMock(); - $sender_factory->method( 'create' )->willReturn( $this->createMock( 'WP_Notify_Sender' ) ); + $sender_factory->method( 'create' )->willReturn( $this->createMock( '\WP\Notifications\Senders\Sender' ) ); - $factory = new WP_Notify_Factory( + $factory = new Factory( $message_factory, - $this->createMock( 'WP_Notify_Recipient_Factory' ), + $this->createMock( '\WP\Notifications\Recipients\Recipient_Factory' ), $sender_factory ); diff --git a/tests/phpunit/tests/test-notification-repository.php b/tests/phpunit/tests/test-notification-repository.php index d112b755..59ce9bcf 100644 --- a/tests/phpunit/tests/test-notification-repository.php +++ b/tests/phpunit/tests/test-notification-repository.php @@ -1,10 +1,16 @@ find_by_id( $id ); $this->assertFalse( $result ); } diff --git a/tests/phpunit/tests/test-recipient-collection.php b/tests/phpunit/tests/test-recipient-collection.php index c9a93c93..983bf55a 100644 --- a/tests/phpunit/tests/test-recipient-collection.php +++ b/tests/phpunit/tests/test-recipient-collection.php @@ -1,40 +1,46 @@ assertInstanceOf( 'WP_Notify_Recipient_Collection', $testee ); + $testee = new Recipient_Collection(); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient_Collection', $testee ); } public function test_it_is_countable() { - $testee = new WP_Notify_Recipient_Collection(); + $testee = new Recipient_Collection(); $this->assertInstanceOf( 'Countable', $testee ); } public function test_it_is_traversable() { - $testee = new WP_Notify_Recipient_Collection(); + $testee = new Recipient_Collection(); $this->assertInstanceOf( 'Traversable', $testee ); } public function test_it_is_empty_when_instantiated_without_arguments() { - $testee = new WP_Notify_Recipient_Collection(); + $testee = new Recipient_Collection(); $this->assertCount( 0, $testee ); } public function test_it_can_accept_a_singular_recipient() { - $mock_recipient = $this->createMock( 'WP_Notify_Recipient' ); - $testee = new WP_Notify_Recipient_Collection( $mock_recipient ); + $mock_recipient = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $testee = new Recipient_Collection( $mock_recipient ); $this->assertCount( 1, $testee ); } public function test_it_can_accept_an_array_of_recipients() { - $mock_recipient_1 = $this->createMock( 'WP_Notify_Recipient' ); - $mock_recipient_2 = $this->createMock( 'WP_Notify_Recipient' ); - $mock_recipient_3 = $this->createMock( 'WP_Notify_Recipient' ); - $testee = new WP_Notify_Recipient_Collection( + $mock_recipient_1 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $mock_recipient_2 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $mock_recipient_3 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $testee = new Recipient_Collection( array( $mock_recipient_1, $mock_recipient_2, @@ -45,10 +51,10 @@ public function test_it_can_accept_an_array_of_recipients() { } public function test_recipients_can_be_added() { - $mock_recipient_1 = $this->createMock( 'WP_Notify_Recipient' ); - $mock_recipient_2 = $this->createMock( 'WP_Notify_Recipient' ); - $mock_recipient_3 = $this->createMock( 'WP_Notify_Recipient' ); - $testee = new WP_Notify_Recipient_Collection( $mock_recipient_1 ); + $mock_recipient_1 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $mock_recipient_2 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $mock_recipient_3 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $testee = new Recipient_Collection( $mock_recipient_1 ); $this->assertCount( 1, $testee ); $testee->add( $mock_recipient_2 ); $this->assertCount( 2, $testee ); @@ -58,13 +64,13 @@ public function test_recipients_can_be_added() { /** @dataProvider data_provider_it_throws_on_invalid_type */ public function test_it_throws_on_invalid_type( $invalid_recipient ) { - $this->expectException( 'WP_Notify_Runtime_Exception' ); - new WP_Notify_Recipient_Collection( $invalid_recipient ); + $this->expectException( '\WP\Notifications\Exceptions\Runtime_Exception' ); + new Recipient_Collection( $invalid_recipient ); } public function data_provider_it_throws_on_invalid_type() { - $mock_recipient_1 = $this->createMock( 'WP_Notify_Recipient' ); - $mock_recipient_2 = $this->createMock( 'WP_Notify_Recipient' ); + $mock_recipient_1 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); + $mock_recipient_2 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); return array( array( null ), @@ -77,7 +83,7 @@ public function data_provider_it_throws_on_invalid_type() { } public function test_it_can_be_json_encoded() { - $testee = new WP_Notify_Recipient_Collection( array() ); + $testee = new Recipient_Collection( array() ); $this->assertEquals( '[]', json_encode( $testee ) @@ -86,8 +92,8 @@ public function test_it_can_be_json_encoded() { public function test_it_can_be_instantiated_from_json() { $json = '[]'; - $testee = WP_Notify_Recipient_Collection::json_unserialize( $json ); - $this->assertInstanceOf( 'WP_Notify_Recipient_Collection', $testee ); + $testee = Recipient_Collection::json_unserialize( $json ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient_Collection', $testee ); $this->assertEquals( 0, $testee->count() ); } } diff --git a/tests/phpunit/tests/test-role-recipient.php b/tests/phpunit/tests/test-role-recipient.php index 194e3d28..6206648e 100644 --- a/tests/phpunit/tests/test-role-recipient.php +++ b/tests/phpunit/tests/test-role-recipient.php @@ -1,14 +1,18 @@ assertInstanceOf( 'WP_Notify_Role_Recipient', $testee ); + $testee = new Role_Recipient( 1 ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Role_Recipient', $testee ); } public function test_it_implements_the_interface() { - $testee = new WP_Notify_Role_Recipient( 1 ); - $this->assertInstanceOf( 'WP_Notify_Recipient', $testee ); + $testee = new Role_Recipient( 1 ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } } diff --git a/tests/phpunit/tests/test-user-recipient.php b/tests/phpunit/tests/test-user-recipient.php index 5a6497f5..2d753a50 100644 --- a/tests/phpunit/tests/test-user-recipient.php +++ b/tests/phpunit/tests/test-user-recipient.php @@ -1,26 +1,32 @@ assertInstanceOf( 'WP_Notify_User_Recipient', $testee ); + $testee = new User_Recipient( 1 ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\User_Recipient', $testee ); } public function test_it_implements_the_recipient_interface() { - $testee = new WP_Notify_User_Recipient( 1 ); - $this->assertInstanceOf( 'WP_Notify_Recipient', $testee ); + $testee = new User_Recipient( 1 ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } public function test_it_accepts_a_user_id_as_a_string() { - $testee = new WP_Notify_User_Recipient( '1' ); - $this->assertInstanceOf( 'WP_Notify_Recipient', $testee ); + $testee = new User_Recipient( '1' ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } /** @dataProvider data_provider_it_throws_on_invalid_type */ public function test_it_throws_on_invalid_type( $invalid_user_id ) { - $this->expectException( 'WP_Notify_Invalid_Recipient' ); - new WP_Notify_User_Recipient( $invalid_user_id ); + $this->expectException( '\WP\Notifications\Exceptions\Invalid_Recipient' ); + new User_Recipient( $invalid_user_id ); } public function data_provider_it_throws_on_invalid_type() { diff --git a/wp-feature-notifications.php b/wp-feature-notifications.php index be9369d1..aca65ab9 100644 --- a/wp-feature-notifications.php +++ b/wp-feature-notifications.php @@ -15,52 +15,53 @@ * @package wp-feature-notifications */ +namespace WP\Notifications; + use WP\Notifications\REST; -if ( ! defined( 'WP_NOTIFICATION_CENTER_PLUGIN_VERSION' ) ) { - define( 'WP_NOTIFICATION_CENTER_PLUGIN_VERSION', '0.0.1' ); +if ( ! defined( 'WP_FEATURE_NOTIFICATION_PLUGIN_VERSION' ) ) { + define( 'WP_FEATURE_NOTIFICATION_PLUGIN_VERSION', '0.0.1' ); } -if ( ! defined( 'WP_NOTIFICATION_CENTER_PLUGIN_DIR' ) ) { - define( 'WP_NOTIFICATION_CENTER_PLUGIN_DIR', dirname( __FILE__ ) ); +if ( ! defined( 'WP_FEATURE_NOTIFICATION_PLUGIN_DIR' ) ) { + define( 'WP_FEATURE_NOTIFICATION_PLUGIN_DIR', dirname( __FILE__ ) ); } -if ( ! defined( 'WP_NOTIFICATION_CENTER_PLUGIN_DIR_URL' ) ) { - define( 'WP_NOTIFICATION_CENTER_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); +if ( ! defined( 'WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL' ) ) { + define( 'WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); } // Require interface/class declarations.. -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/interface-exception.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-runtime-exception.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-invalid-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/exceptions/class-failed-to-add-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-json-unserializable.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-status.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/interface-notification.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-aggregate-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/class-base-notification.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/image/interface-image.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/image/class-base-image.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/senders/interface-sender.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/senders/class-base-sender.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/interface-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-recipient-collection.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-user-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-role-recipient.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/interface-recipient-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-base-recipient-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/recipients/class-aggregate-recipient-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/interface-message.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-base-message.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/interface-message-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-base-message-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/messages/class-aggregate-message-factory.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/interface-notification-repository.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/class-abstract-notification-repository.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/persistence/class-wpdb-notification-repository.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/demo.php'; -require_once WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/includes/restapi/class-notification-controller.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/exceptions/interface-exception.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/exceptions/class-runtime-exception.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/exceptions/class-invalid-recipient.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/exceptions/class-failed-to-add-recipient.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/interface-json-unserializable.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/interface-status.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/interface-notification.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/class-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/class-aggregate-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/class-base-notification.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/image/interface-image.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/image/class-base-image.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/senders/interface-sender.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/senders/class-base-sender.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/interface-recipient.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-recipient-collection.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-user-recipient.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-role-recipient.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/interface-recipient-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-base-recipient-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-aggregate-recipient-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/interface-message.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-base-message.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/interface-message-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-base-message-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-aggregate-message-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/persistence/interface-notification-repository.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/persistence/class-abstract-notification-repository.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/persistence/class-wpdb-notification-repository.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/demo.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/restapi/class-notification-controller.php'; -// TODO: Standardise structure and/or autoloading. new REST\Notification_Controller(); From 1d080b43d3571c75d7ab3f517996c436b06347ca Mon Sep 17 00:00:00 2001 From: John Hooks Date: Thu, 6 Apr 2023 04:30:40 -0700 Subject: [PATCH 3/9] test: remove problematic test cases --- tests/phpunit/tests/test-base-message.php | 17 ---- .../phpunit/tests/test-base-notification.php | 41 ---------- tests/phpunit/tests/test-base-sender.php | 77 ------------------- 3 files changed, 135 deletions(-) delete mode 100644 tests/phpunit/tests/test-base-sender.php diff --git a/tests/phpunit/tests/test-base-message.php b/tests/phpunit/tests/test-base-message.php index df68e0c1..6f27c1c6 100644 --- a/tests/phpunit/tests/test-base-message.php +++ b/tests/phpunit/tests/test-base-message.php @@ -6,8 +6,6 @@ class Test_Base_Message extends TestCase { - const SERIALIZED = 'C:20:"WPNotify_BaseMessage":14:{s:7:"Message";}'; - public function test_it_can_be_instantiated() { $testee = new Base_Message( 'Message' ); $this->assertInstanceOf( '\WP\Notifications\Messages\Base_Message', $testee ); @@ -27,19 +25,4 @@ public function test_it_can_be_cast_to_string() { $testee = new Base_Message( 'Message' ); $this->assertEquals( 'Message', (string) $testee ); } - - public function test_it_can_be_json_encoded() { - $testee = new Base_Message( 'Message' ); - $this->assertEquals( - '"Message"', - json_encode( $testee ) - ); - } - - public function test_it_can_be_instantiated_from_json() { - $json = '"Message"'; - $testee = Base_Message::json_unserialize( $json ); - $this->assertInstanceOf( '\WP\Notifications\Messages\Base_Message', $testee ); - $this->assertEquals( '\WP\Notifications\Messages\Message', $testee->get_content() ); - } } diff --git a/tests/phpunit/tests/test-base-notification.php b/tests/phpunit/tests/test-base-notification.php index 8d27425e..cdaf31f3 100644 --- a/tests/phpunit/tests/test-base-notification.php +++ b/tests/phpunit/tests/test-base-notification.php @@ -3,14 +3,9 @@ namespace WP\Notifications\Tests; use WP\Notifications\Base_Notification; -use WP\Notifications\Messages\Base_Message; -use WP\Notifications\Recipients\Recipient_Collection; -use WP\Notifications\Senders\Base_Sender; class Test_Base_Notification extends TestCase { - const JSON_SERIALIZED = '{"Recipient_Collection":[],"Base_Message":"Message","Base_Sender":{"name":"Name 1"}}'; - public function test_it_can_be_instantiated() { $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); @@ -45,40 +40,4 @@ public function test_it_can_return_its_content() { $this->assertEquals( $recipients_mock, $testee->get_recipients() ); $this->assertEquals( $dummy_message, $testee->get_message() ); } - - public function test_it_can_be_json_encoded() { - $sender_mock = new Base_Sender( 'Name 1' ); - $empty_recipients = new Recipient_Collection(); - $message = new Base_Message( 'Message' ); - $testee = new Base_Notification( - $sender_mock, - $empty_recipients, - $message - ); - $this->assertEquals( - self::JSON_SERIALIZED, - json_encode( $testee ) - ); - } - - // TODO The test below is problematic, the whole concept of serializing a message - // which is to be directly initialized as a class is probably not the right direction - // and also not how the json api schema would be structured. - - // public function test_it_can_be_instantiated_from_json() { - // $testee = Base_Notification::json_unserialize( self::JSON_SERIALIZED ); - // $this->assertInstanceOf( '\WP\Notifications\Base_Notification', $testee ); - // $this->assertInstanceOf( - // '\WP\Notifications\Recipients\Recipient_Collection', - // $testee->get_recipients() - // ); - // $this->assertInstanceOf( - // '\WP\Notifications\Messages\Base_Message', - // $testee->get_message() - // ); - // $this->assertInstanceOf( - // '\WP\Notifications\Senders\Base_Sender', - // $testee->get_sender() - // ); - // } } diff --git a/tests/phpunit/tests/test-base-sender.php b/tests/phpunit/tests/test-base-sender.php deleted file mode 100644 index c222126a..00000000 --- a/tests/phpunit/tests/test-base-sender.php +++ /dev/null @@ -1,77 +0,0 @@ -newInstanceArgs( array_values( $sender_params ) ); - - $sender_encoded = json_encode( $sender ); - - $this->assertEquals( $expected_json, $sender_encoded ); - } - - /** - * @param array $sender_params - * @param string $json - * - * @dataProvider data_provider_senders - */ - public function test_it_can_be_instantiated_from_json( $sender_params, $json ) { - - $testee = Base_Sender::json_unserialize( $json ); - - $sender_reflection = new ReflectionClass( '\WP\Notifications\Senders\Base_Sender' ); - /** @var Base_Sender $sender */ - $sender = $sender_reflection->newInstanceArgs( array_values( (array) $sender_params ) ); - - $this->assertInstanceOf( '\WP\Notifications\Senders\Base_Sender', $testee ); - $this->assertEquals( $sender->get_name(), $testee->get_name() ); - - $this->assertEquals( $sender->get_image(), $testee->get_image() ); - - /** - * If an Image has been sent - */ - if ( $testee->get_image() ) { - $this->assertInstanceOf( get_class( $sender->get_image() ), $testee->get_image() ); - $this->assertEquals( $sender->get_image()->get_source(), $testee->get_image()->get_source() ); - $this->assertEquals( $sender->get_image()->get_alt(), $testee->get_image()->get_alt() ); - } - } - - public function data_provider_senders() { - - return array( - - 'sender without image' => array( - array( - 'Name 1', - ), - '{"name":"Name 1"}', - ), - - 'sender with image' => array( - array( - 'name' => 'Name 2', - 'Base_Image' => new Base_Image( 'img-source', 'img-alt' ), - ), - '{"name":"Name 2","Base_Image":{"source":"img-source","alt":"img-alt"}}', - ), - ); - } -} From 6f3eec5a34d3eb000ceeed8d7deaf9cc71a1e3c6 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Thu, 6 Apr 2023 04:31:41 -0700 Subject: [PATCH 4/9] chore: remove .vscode --- .vscode/settings.json | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 91305677..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "[php]": { - "editor.formatOnSave": false - }, - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true - }, - "eslint.validate": [ - "javascript", - "javascript-react", - "typescript", - "typescript-react" - ] -} From ad5486e821d6bd1743097167c6007bc82cd50232 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Thu, 6 Apr 2023 18:58:43 -0700 Subject: [PATCH 5/9] refactor: remove WP_Notify from php comments --- includes/class-base-notification.php | 3 +-- includes/image/class-base-image.php | 2 +- includes/messages/class-base-message.php | 2 +- includes/recipients/class-base-recipient-factory.php | 2 +- includes/senders/class-base-sender.php | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/includes/class-base-notification.php b/includes/class-base-notification.php index d4a6bcd1..aeca7b2b 100644 --- a/includes/class-base-notification.php +++ b/includes/class-base-notification.php @@ -3,7 +3,6 @@ namespace WP\Notifications; use ReflectionClass; - use WP\Notifications\Messages\Message; use WP\Notifications\Recipients\Recipient_Collection; use WP\Notifications\Senders\Sender; @@ -53,7 +52,7 @@ class Base_Notification implements Notification { protected $status = Status::UNREAD; /** - * Instantiates a WPNotify_Base_Notification object. + * Instantiates a Base_Notification object. * * @param Sender $sender Sender that sent the * notification. diff --git a/includes/image/class-base-image.php b/includes/image/class-base-image.php index aa5a999d..f2d94982 100644 --- a/includes/image/class-base-image.php +++ b/includes/image/class-base-image.php @@ -64,7 +64,7 @@ public function get_alt() { } /** - * Instantiates a WPNotify_BaseImage based on a JSON string + * Instantiates a BaseImage based on a JSON string * * @param string $json * diff --git a/includes/messages/class-base-message.php b/includes/messages/class-base-message.php index f5ace6ec..2300b3e3 100644 --- a/includes/messages/class-base-message.php +++ b/includes/messages/class-base-message.php @@ -12,7 +12,7 @@ class Base_Message implements Message { protected $message; /** - * Instantiates a WPNotify_BaseMessage object. + * Instantiates a BaseMessage object. * * @param string $message Message content. */ diff --git a/includes/recipients/class-base-recipient-factory.php b/includes/recipients/class-base-recipient-factory.php index fa948ef3..7739c44f 100644 --- a/includes/recipients/class-base-recipient-factory.php +++ b/includes/recipients/class-base-recipient-factory.php @@ -81,7 +81,7 @@ private function validate( $type, $value ) { */ private function get_type_mappings() { return apply_filters( - 'wp_notify_recipient_type_mappings', + 'wp_feature_notifications_recipient_type_mappings', array( self::TYPE_USER => 'User_Recipient', self::TYPE_ROLE => 'Role_Recipient', diff --git a/includes/senders/class-base-sender.php b/includes/senders/class-base-sender.php index 37eb89f8..d20c1842 100644 --- a/includes/senders/class-base-sender.php +++ b/includes/senders/class-base-sender.php @@ -18,7 +18,7 @@ class Base_Sender implements Sender, Json_Unserializable { protected $image; /** - * WPNotify_BaseSender constructor. + * BaseSender constructor. * * @param string $name * @param Base_Image|null $image From e9539de60e989e0c40c206c7b305380bcce989c9 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Fri, 7 Apr 2023 07:10:33 -0700 Subject: [PATCH 6/9] chore: apply @Sephsekla's suggestions --- includes/class-base-notification.php | 46 +++++++++---------- includes/class-factory.php | 15 +++--- includes/image/interface-image.php | 4 +- .../class-aggregate-message-factory.php | 4 +- .../messages/class-base-message-factory.php | 4 +- includes/messages/interface-message.php | 4 +- ...class-abstract-notification-repository.php | 5 +- .../class-wpdb-notification-repository.php | 37 ++++++++------- .../interface-notification-repository.php | 38 +++++++-------- .../class-aggregate-recipient-factory.php | 4 +- .../class-base-recipient-factory.php | 13 +++--- .../recipients/class-recipient-collection.php | 12 ++--- includes/senders/class-base-sender.php | 7 +-- .../phpunit/includes/class-dummy-message.php | 4 +- tests/phpunit/tests/test-base-image.php | 8 ++-- tests/phpunit/tests/test-base-message.php | 10 ++-- .../phpunit/tests/test-base-notification.php | 8 ++-- tests/phpunit/tests/test-factory.php | 4 +- .../tests/test-notification-repository.php | 4 +- .../tests/test-recipient-collection.php | 22 ++++----- tests/phpunit/tests/test-role-recipient.php | 6 +-- tests/phpunit/tests/test-user-recipient.php | 10 ++-- 22 files changed, 132 insertions(+), 137 deletions(-) diff --git a/includes/class-base-notification.php b/includes/class-base-notification.php index aeca7b2b..5ba2a372 100644 --- a/includes/class-base-notification.php +++ b/includes/class-base-notification.php @@ -3,9 +3,9 @@ namespace WP\Notifications; use ReflectionClass; -use WP\Notifications\Messages\Message; -use WP\Notifications\Recipients\Recipient_Collection; -use WP\Notifications\Senders\Sender; +use WP\Notifications\Messages; +use WP\Notifications\Recipients; +use WP\Notifications\Senders; class Base_Notification implements Notification { @@ -54,26 +54,24 @@ class Base_Notification implements Notification { /** * Instantiates a Base_Notification object. * - * @param Sender $sender Sender that sent the - * notification. - * @param Recipient_Collection $recipients Recipients that should - * receive the - * notification. - * @param Message $message Message of the - * notification. - * @param mixed $timestamp Optional. Timestamp of - * when the notification - * was triggered. Defaults - * to the moment of - * instantiation. - * @param int $id Optional. ID of the - * notification. Defaults - * to -1. + * @param Sender $sender Sender that sent the + * notification. + * @param Recipients\Recipient_Collection $recipients Recipients that should + * receive the notification. + * @param Message $message Message of the notification. + * @param mixed $timestamp Optional. Timestamp of + * when the notification + * was triggered. Defaults + * to the moment of + * instantiation. + * @param int $id Optional. ID of the + * notification. Defaults + * to -1. */ public function __construct( - Sender $sender, - Recipient_Collection $recipients, - Message $message, + Senders\Sender $sender, + Recipients\Recipient_Collection $recipients, + Messages\Message $message, $timestamp = null, $id = - 1 ) { @@ -120,7 +118,7 @@ protected function validate_timestamp( $timestamp ) { /** * Get the sender of the notification. * - * @return Sender Sender of the notification. + * @return Senders\Sender Sender of the notification. */ public function get_sender() { return $this->sender; @@ -129,7 +127,7 @@ public function get_sender() { /** * Gets the recipients for the notification. * - * @return Recipient_Collection Notification recipients. + * @return Recipients\Recipient_Collection Notification recipients. */ public function get_recipients() { return $this->recipients; @@ -138,7 +136,7 @@ public function get_recipients() { /** * Gets the message for the notification. * - * @return Message Notification message. + * @return Messages\Message Notification message. */ public function get_message() { return $this->message; diff --git a/includes/class-factory.php b/includes/class-factory.php index 30566e60..28f36cda 100644 --- a/includes/class-factory.php +++ b/includes/class-factory.php @@ -2,10 +2,9 @@ namespace WP\Notifications; -use WP\Notifications\Messages\Message_Factory; -use WP\Notifications\Recipients\Recipient_Factory; -use WP\Notifications\Recipients\Recipient_Collection; -use WP\Notifications\Senders\Sender_Factory; +use WP\Notifications\Messages; +use WP\Notifications\Recipients; +use WP\Notifications\Senders; class Factory { @@ -34,9 +33,9 @@ class Factory { private $sender_factory; public function __construct( - Message_Factory $message_factory, - Recipient_Factory $recipient_factory, - Sender_Factory $sender_factory + Messages\Message_Factory $message_factory, + Recipients\Recipient_Factory $recipient_factory, + Senders\Sender_Factory $sender_factory ) { $this->message_factory = $message_factory; $this->recipient_factory = $recipient_factory; @@ -55,7 +54,7 @@ public function create( $args ) { list( $message_args, $recipients_args, $sender_args ) = $this->validate( $args ); $sender = $this->sender_factory->create( $sender_args ); - $recipients = new Recipient_Collection(); + $recipients = new Recipients\Recipient_Collection(); $message = $this->message_factory->create( $message_args ); foreach ( $recipients_args as $type => $value ) { diff --git a/includes/image/interface-image.php b/includes/image/interface-image.php index 0bb04492..78d450ef 100644 --- a/includes/image/interface-image.php +++ b/includes/image/interface-image.php @@ -4,8 +4,8 @@ use JsonSerializable; -use WP\Notifications\Json_Unserializable; +use WP\Notifications; -interface Image extends JsonSerializable, Json_Unserializable { +interface Image extends JsonSerializable, Notifications\Json_Unserializable { } diff --git a/includes/messages/class-aggregate-message-factory.php b/includes/messages/class-aggregate-message-factory.php index 0bef1889..8444456a 100644 --- a/includes/messages/class-aggregate-message-factory.php +++ b/includes/messages/class-aggregate-message-factory.php @@ -2,10 +2,10 @@ namespace WP\Notifications\Messages; -use WP\Notifications\Aggregate_Factory; +use WP\Notifications; final class Aggregate_Message_Factory - extends Aggregate_Factory + extends Notifications\Aggregate_Factory implements Message_Factory { /** diff --git a/includes/messages/class-base-message-factory.php b/includes/messages/class-base-message-factory.php index e8a09151..687a5162 100644 --- a/includes/messages/class-base-message-factory.php +++ b/includes/messages/class-base-message-factory.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Messages; -use WP\Notifications\Exceptions\Invalid_Type; +use WP\Notifications\Exceptions; class Base_Message_Factory implements Message_Factory { @@ -21,7 +21,7 @@ class Base_Message_Factory implements Message_Factory { */ public function create( $value, $type = 'standard' ) { if ( ! $this->accepts( $type ) ) { - throw Invalid_Type::from_message_type( $type ); + throw Exceptions\Invalid_Type::from_message_type( $type ); } list( $type, $value ) = $this->validate( $type, $value ); diff --git a/includes/messages/interface-message.php b/includes/messages/interface-message.php index c10c34ac..4e886032 100644 --- a/includes/messages/interface-message.php +++ b/includes/messages/interface-message.php @@ -4,11 +4,11 @@ use JsonSerializable; -use WP\Notifications\Json_Unserializable; +use WP\Notifications; interface Message extends JsonSerializable, - Json_Unserializable { + Notifications\Json_Unserializable { /** * Get the message content. diff --git a/includes/persistence/class-abstract-notification-repository.php b/includes/persistence/class-abstract-notification-repository.php index a5020a0f..cd66ec55 100644 --- a/includes/persistence/class-abstract-notification-repository.php +++ b/includes/persistence/class-abstract-notification-repository.php @@ -4,6 +4,7 @@ use DateTime; use DateInterval; +use WP\Notifications; abstract class Abstract_Notification_Repository implements Notification_Repository { @@ -17,8 +18,8 @@ abstract class Abstract_Notification_Repository * @param int $offset Optional. Offset into the result set. * Defaults to 0. * - * @return Notification[] Array of notifications, empty array if - * none found. + * @return Notifications\Notification[] Array of notifications, empty array if + * none found. */ public function find_latest( DateInterval $interval, diff --git a/includes/persistence/class-wpdb-notification-repository.php b/includes/persistence/class-wpdb-notification-repository.php index 79129d85..67ac44c4 100644 --- a/includes/persistence/class-wpdb-notification-repository.php +++ b/includes/persistence/class-wpdb-notification-repository.php @@ -4,8 +4,8 @@ use DateTimeInterface; -use WP\Notifications\Notification; -use WP\Notifications\Recipients\Recipient; +use WP\Notifications; +use WP\Notifications\Recipients; class Wpdb_Notification_Repository extends Abstract_Notification_Repository { @@ -15,8 +15,8 @@ class Wpdb_Notification_Repository * * @param int $id ID to look for. * - * @return Notification|false Notification that matches the ID, or - * false if not found. + * @return Notifications\Notification|false Notification that matches the ID, or + * false if not found. */ public function find_by_id( $id ) { if ( ! is_int( $id ) ) { @@ -30,18 +30,18 @@ public function find_by_id( $id ) { /** * Find all notifications for a given recipient. * - * @param Recipient $recipient Recipient to retrieve the - * notifications for. - * @param int $pagination Optional. Number of elements per - * page. Defaults to 10. - * @param int $offset Optional. Offset into the result - * set. Defaults to 0. + * @param Recipients\Recipient $recipient Recipient to retrieve the + * notifications for. + * @param int $pagination Optional. Number of elements per + * page. Defaults to 10. + * @param int $offset Optional. Offset into the result + * set. Defaults to 0. * - * @return Notification[] Array of notifications, empty array if - * none found. + * @return Notifications\Notification[] Array of notifications, empty array if + * none found. */ public function find_by_recipient( - Recipient $recipient, + Recipients\Recipient $recipient, $pagination = 10, $offset = 0 ) { @@ -54,16 +54,15 @@ public function find_by_recipient( * * @param DateTimeInterface $start Start date of the date range.search. * @param DateTimeInterface $end End date of the date range.search. - * @param string $order Optional. Sorting order, defaults - * to + * @param string $order Optional. Sorting order, defaults to * descending. * @param int $pagination Optional. Number of elements per * page. Defaults to 10. * @param int $offset Optional. Offset into the result * set. Defaults to 0. * - * @return Notification[] Array of notifications, empty array if - * none found. + * @return Notifications\Notification[] Array of notifications, empty array if + * none found. */ public function find_by_date_range( DateTimeInterface $start, @@ -79,11 +78,11 @@ public function find_by_date_range( /** * Add a new notification to the repository. * - * @param Notification $notification Notification to add. + * @param Notifications\Notification $notification Notification to add. * * @return int ID that the notification was stored under. */ - public function add( Notification $notification ) { + public function add( Notifications\Notification $notification ) { // TODO: Implement query. return -1; } diff --git a/includes/persistence/interface-notification-repository.php b/includes/persistence/interface-notification-repository.php index 996d1691..5188e225 100644 --- a/includes/persistence/interface-notification-repository.php +++ b/includes/persistence/interface-notification-repository.php @@ -5,8 +5,8 @@ use DateInterval; use DateTimeInterface; -use WP\Notifications\Notification; -use WP\Notifications\Recipients\Recipient; +use WP\Notifications; +use WP\Notifications\Recipients; interface Notification_Repository { @@ -16,26 +16,26 @@ interface Notification_Repository { * * @param int $id ID to look for. * - * @return Notification|false Notification that matches the ID, or - * false if not found. + * @return Notifications\Notification|false Notification that matches the ID, or + * false if not found. */ public function find_by_id( $id ); /** * Find all notifications for a given recipient. * - * @param Recipient $recipient Recipient to retrieve the - * notifications for. - * @param int $pagination Optional. Number of elements per - * page. Defaults to 10. - * @param int $offset Optional. Offset into the result - * set. Defaults to 0. + * @param Recipients\Recipient $recipient Recipient to retrieve the + * notifications for. + * @param int $pagination Optional. Number of elements per + * page. Defaults to 10. + * @param int $offset Optional. Offset into the result + * set. Defaults to 0. * - * @return Notification[] Array of notifications, empty array if - * none found. + * @return Notifications\Notification[] Array of notifications, empty array if + * none found. */ public function find_by_recipient( - Recipient $recipient, + Recipients\Recipient $recipient, $pagination = 10, $offset = 0 ); @@ -53,8 +53,8 @@ public function find_by_recipient( * @param int $offset Optional. Offset into the result * set. Defaults to 0. * - * @return Notification[] Array of notifications, empty array if - * none found. + * @return Notifications\Notification[] Array of notifications, empty array if + * none found. */ public function find_by_date_range( DateTimeInterface $start, @@ -73,8 +73,8 @@ public function find_by_date_range( * @param int $offset Optional. Offset into the result set. * Defaults to 0. * - * @return Notification[] Array of notifications, empty array if - * none found. + * @return Notifications\Notification[] Array of notifications, empty array + * if none found. */ public function find_latest( DateInterval $interval, @@ -85,9 +85,9 @@ public function find_latest( /** * Add a new notification to the repository. * - * @param Notification $notification Notification to add. + * @param Notifications\Notification $notification Notification to add. * * @return int ID that the notification was stored under. */ - public function add( Notification $notification ); + public function add( Notifications\Notification $notification ); } diff --git a/includes/recipients/class-aggregate-recipient-factory.php b/includes/recipients/class-aggregate-recipient-factory.php index c5d61b37..e7d89f5f 100644 --- a/includes/recipients/class-aggregate-recipient-factory.php +++ b/includes/recipients/class-aggregate-recipient-factory.php @@ -2,10 +2,10 @@ namespace WP\Notifications\Recipients; -use WP\Notifications\Aggregate_Factory; +use WP\Notifications; final class Aggregate_Recipient_Factory - extends Aggregate_Factory + extends Notifications\Aggregate_Factory implements Recipient_Factory { /** diff --git a/includes/recipients/class-base-recipient-factory.php b/includes/recipients/class-base-recipient-factory.php index 7739c44f..527879ef 100644 --- a/includes/recipients/class-base-recipient-factory.php +++ b/includes/recipients/class-base-recipient-factory.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Recipients; -use WP\Notifications\Exceptions\Invalid_Type; +use WP\Notifications\Exceptions; final class Base_Recipient_Factory implements Recipient_Factory { @@ -15,13 +15,12 @@ final class Base_Recipient_Factory implements Recipient_Factory { * @param mixed $value Value of the recipient. * @param string $type Optional. Type of the recipient. Defaults to 'user'. * - * @return Recipient - * - * @throws Invalid_Type If the recipient type was not valid. + * @return Recipient The created recipient instance. + * @throws Exceptions\Invalid_Type If the recipient type was not valid. */ public function create( $value, $type = self::TYPE_USER ) { if ( ! $this->accepts( $type ) ) { - throw Invalid_Type::from_recipient_type( $type ); + throw Exceptions\Invalid_Type::from_recipient_type( $type ); } list( $type, $value ) = $this->validate( $type, $value ); @@ -48,11 +47,11 @@ public function accepts( $type ) { * @param string $type Type to get the implementation class for. * * @return string Implementation class. - * @throws Invalid_Type If the recipient type was not valid. + * @throws Exceptions\Invalid_Type If the recipient type was not valid. */ public function get_implementation_for_type( $type ) { if ( ! $this->accepts( $type ) ) { - throw Invalid_Type::from_recipient_type( $type ); + throw Exceptions\Invalid_Type::from_recipient_type( $type ); } $mappings = $this->get_type_mappings(); diff --git a/includes/recipients/class-recipient-collection.php b/includes/recipients/class-recipient-collection.php index ca5f3dbe..6efb4eb2 100644 --- a/includes/recipients/class-recipient-collection.php +++ b/includes/recipients/class-recipient-collection.php @@ -6,14 +6,14 @@ use Countable; use JsonSerializable; -use WP\Notifications\Json_Unserializable; -use WP\Notifications\Exceptions\Failed_To_Add_Recipient; +use WP\Notifications; +use WP\Notifications\Exceptions; class Recipient_Collection implements Iterator, Countable, JsonSerializable, - Json_Unserializable { + Notifications\Json_Unserializable { /** * Internal array of recipients. @@ -36,11 +36,9 @@ public function __construct( $recipients = array() ) { * Validate the recipients. * * @param Recipient|array $recipients Recipient or array of - * recipients to - * validate. + * recipients to validate. * * @return array Validated array of recipients. - * * @throws Failed_To_Add_Recipient If a recipient could not be added. */ protected function validate_recipients( $recipients ) { @@ -50,7 +48,7 @@ protected function validate_recipients( $recipients ) { foreach ( $recipients as $recipient ) { if ( ! $recipient instanceof Recipient ) { - throw Failed_To_Add_Recipient::from_invalid_recipient( $recipient ); + throw Exceptions\Failed_To_Add_Recipient::from_invalid_recipient( $recipient ); } } diff --git a/includes/senders/class-base-sender.php b/includes/senders/class-base-sender.php index d20c1842..a650cc13 100644 --- a/includes/senders/class-base-sender.php +++ b/includes/senders/class-base-sender.php @@ -2,10 +2,11 @@ namespace WP\Notifications\Senders; +use WP\Notifications; + use ReflectionClass; -use WP\Notifications\Json_Unserializable; -class Base_Sender implements Sender, Json_Unserializable { +class Base_Sender implements Sender, Notifications\Json_Unserializable { /** * @var string @@ -20,7 +21,7 @@ class Base_Sender implements Sender, Json_Unserializable { /** * BaseSender constructor. * - * @param string $name + * @param string $name * @param Base_Image|null $image */ public function __construct( $name, $image = null ) { diff --git a/tests/phpunit/includes/class-dummy-message.php b/tests/phpunit/includes/class-dummy-message.php index ec950ea9..ac719d90 100644 --- a/tests/phpunit/includes/class-dummy-message.php +++ b/tests/phpunit/includes/class-dummy-message.php @@ -2,9 +2,9 @@ namespace WP\Notifications\Tests; -use WP\Notifications\Messages\Message; +use WP\Notifications\Messages; -class Dummy_Message implements Message { +class Dummy_Message implements Messages\Message { public function serialize() { return ''; } diff --git a/tests/phpunit/tests/test-base-image.php b/tests/phpunit/tests/test-base-image.php index 4e529f91..8422f283 100644 --- a/tests/phpunit/tests/test-base-image.php +++ b/tests/phpunit/tests/test-base-image.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Tests; -use WP\Notifications\Image\Base_Image; +use WP\Notifications\Image; class Test_BaseImage extends TestCase { @@ -17,7 +17,7 @@ public function test_it_can_be_json_encoded( $image_data, $expected_json ) { $source = $image_data['source']; $alt = $image_data['alt']; - $image_instance = new Base_Image( $source, $alt ); + $image_instance = new Image\Base_Image( $source, $alt ); $encoded_image = json_encode( $image_instance ); $this->assertEquals( $expected_json, $encoded_image ); @@ -33,11 +33,11 @@ public function test_it_can_be_json_encoded( $image_data, $expected_json ) { */ public function test_it_can_be_instantiated_from_json( $image_data, $json ) { - $test_instance = Base_Image::json_unserialize( $json ); + $test_instance = Image\Base_Image::json_unserialize( $json ); list( $source, $alt ) = array_values( $image_data ); - $instance = new Base_Image( $source, $alt ); + $instance = new Image\Base_Image( $source, $alt ); $this->assertEquals( $instance->get_source(), $test_instance->get_source() ); $this->assertEquals( $instance->get_alt(), $test_instance->get_alt() ); diff --git a/tests/phpunit/tests/test-base-message.php b/tests/phpunit/tests/test-base-message.php index 6f27c1c6..6811b5fc 100644 --- a/tests/phpunit/tests/test-base-message.php +++ b/tests/phpunit/tests/test-base-message.php @@ -2,27 +2,27 @@ namespace WP\Notifications\Tests; -use WP\Notifications\Messages\Base_Message; +use WP\Notifications\Messages; class Test_Base_Message extends TestCase { public function test_it_can_be_instantiated() { - $testee = new Base_Message( 'Message' ); + $testee = new Messages\Base_Message( 'Message' ); $this->assertInstanceOf( '\WP\Notifications\Messages\Base_Message', $testee ); } public function test_it_implements_the_interface() { - $testee = new Base_Message( 'Message' ); + $testee = new Messages\Base_Message( 'Message' ); $this->assertInstanceOf( '\WP\Notifications\Messages\Message', $testee ); } public function test_it_can_return_its_content() { - $testee = new Base_Message( 'Message' ); + $testee = new Messages\Base_Message( 'Message' ); $this->assertEquals( 'Message', $testee->get_content() ); } public function test_it_can_be_cast_to_string() { - $testee = new Base_Message( 'Message' ); + $testee = new Messages\Base_Message( 'Message' ); $this->assertEquals( 'Message', (string) $testee ); } } diff --git a/tests/phpunit/tests/test-base-notification.php b/tests/phpunit/tests/test-base-notification.php index cdaf31f3..21465cac 100644 --- a/tests/phpunit/tests/test-base-notification.php +++ b/tests/phpunit/tests/test-base-notification.php @@ -2,14 +2,14 @@ namespace WP\Notifications\Tests; -use WP\Notifications\Base_Notification; +use WP\Notifications; class Test_Base_Notification extends TestCase { public function test_it_can_be_instantiated() { $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); - $testee = new Base_Notification( + $testee = new Notifications\Base_Notification( $sender_mock, $recipients_mock, new Dummy_Message() @@ -20,7 +20,7 @@ public function test_it_can_be_instantiated() { public function test_it_implements_the_interface() { $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); - $testee = new Base_Notification( + $testee = new Notifications\Base_Notification( $sender_mock, $recipients_mock, new Dummy_Message() @@ -32,7 +32,7 @@ public function test_it_can_return_its_content() { $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); $dummy_message = new Dummy_Message(); - $testee = new Base_Notification( + $testee = new Notifications\Base_Notification( $sender_mock, $recipients_mock, $dummy_message diff --git a/tests/phpunit/tests/test-factory.php b/tests/phpunit/tests/test-factory.php index 8333f731..a14d5db9 100644 --- a/tests/phpunit/tests/test-factory.php +++ b/tests/phpunit/tests/test-factory.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Tests; -use WP\Notifications\Factory; +use WP\Notifications; class Test_Factory extends TestCase { @@ -23,7 +23,7 @@ public function test_create_with_vendor_sender() { $sender_factory->method( 'create' )->willReturn( $this->createMock( '\WP\Notifications\Senders\Sender' ) ); - $factory = new Factory( + $factory = new Notifications\Factory( $message_factory, $this->createMock( '\WP\Notifications\Recipients\Recipient_Factory' ), $sender_factory diff --git a/tests/phpunit/tests/test-notification-repository.php b/tests/phpunit/tests/test-notification-repository.php index 59ce9bcf..19dc9e89 100644 --- a/tests/phpunit/tests/test-notification-repository.php +++ b/tests/phpunit/tests/test-notification-repository.php @@ -4,13 +4,13 @@ use stdClass; -use WP\Notifications\Persistence\Wpdb_Notification_Repository; +use WP\Notifications\Persistence; class Test_Wpdb_Notification_Repository extends TestCase { /** @dataProvider data_provider_it_returns_false_on_invalid_ids */ public function test_it_returns_false_on_invalid_ids( $id ) { - $testee = new Wpdb_Notification_Repository(); + $testee = new Persistence\Wpdb_Notification_Repository(); $result = $testee->find_by_id( $id ); $this->assertFalse( $result ); } diff --git a/tests/phpunit/tests/test-recipient-collection.php b/tests/phpunit/tests/test-recipient-collection.php index 983bf55a..8077268c 100644 --- a/tests/phpunit/tests/test-recipient-collection.php +++ b/tests/phpunit/tests/test-recipient-collection.php @@ -4,35 +4,35 @@ use stdClass; -use WP\Notifications\Recipients\Recipient_Collection; +use WP\Notifications\Recipients; class Test_Recipient_Collection extends TestCase { const SERIALIZED = 'C:28:"WPNotify_RecipientCollection":6:{a:0:{}}'; public function test_it_can_be_instantiated() { - $testee = new Recipient_Collection(); + $testee = new Recipients\Recipient_Collection(); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient_Collection', $testee ); } public function test_it_is_countable() { - $testee = new Recipient_Collection(); + $testee = new Recipients\Recipient_Collection(); $this->assertInstanceOf( 'Countable', $testee ); } public function test_it_is_traversable() { - $testee = new Recipient_Collection(); + $testee = new Recipients\Recipient_Collection(); $this->assertInstanceOf( 'Traversable', $testee ); } public function test_it_is_empty_when_instantiated_without_arguments() { - $testee = new Recipient_Collection(); + $testee = new Recipients\Recipient_Collection(); $this->assertCount( 0, $testee ); } public function test_it_can_accept_a_singular_recipient() { $mock_recipient = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); - $testee = new Recipient_Collection( $mock_recipient ); + $testee = new Recipients\Recipient_Collection( $mock_recipient ); $this->assertCount( 1, $testee ); } @@ -40,7 +40,7 @@ public function test_it_can_accept_an_array_of_recipients() { $mock_recipient_1 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_2 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_3 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); - $testee = new Recipient_Collection( + $testee = new Recipients\Recipient_Collection( array( $mock_recipient_1, $mock_recipient_2, @@ -54,7 +54,7 @@ public function test_recipients_can_be_added() { $mock_recipient_1 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_2 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_3 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); - $testee = new Recipient_Collection( $mock_recipient_1 ); + $testee = new Recipients\Recipient_Collection( $mock_recipient_1 ); $this->assertCount( 1, $testee ); $testee->add( $mock_recipient_2 ); $this->assertCount( 2, $testee ); @@ -65,7 +65,7 @@ public function test_recipients_can_be_added() { /** @dataProvider data_provider_it_throws_on_invalid_type */ public function test_it_throws_on_invalid_type( $invalid_recipient ) { $this->expectException( '\WP\Notifications\Exceptions\Runtime_Exception' ); - new Recipient_Collection( $invalid_recipient ); + new Recipients\Recipient_Collection( $invalid_recipient ); } public function data_provider_it_throws_on_invalid_type() { @@ -83,7 +83,7 @@ public function data_provider_it_throws_on_invalid_type() { } public function test_it_can_be_json_encoded() { - $testee = new Recipient_Collection( array() ); + $testee = new Recipients\Recipient_Collection( array() ); $this->assertEquals( '[]', json_encode( $testee ) @@ -92,7 +92,7 @@ public function test_it_can_be_json_encoded() { public function test_it_can_be_instantiated_from_json() { $json = '[]'; - $testee = Recipient_Collection::json_unserialize( $json ); + $testee = Recipients\Recipient_Collection::json_unserialize( $json ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient_Collection', $testee ); $this->assertEquals( 0, $testee->count() ); } diff --git a/tests/phpunit/tests/test-role-recipient.php b/tests/phpunit/tests/test-role-recipient.php index 6206648e..1cf6e1ef 100644 --- a/tests/phpunit/tests/test-role-recipient.php +++ b/tests/phpunit/tests/test-role-recipient.php @@ -2,17 +2,17 @@ namespace WP\Notifications\Tests; -use WP\Notifications\Recipients\Role_Recipient; +use WP\Notifications\Recipients; class Test_Role_Recipient extends TestCase { public function test_it_can_be_instantiated() { - $testee = new Role_Recipient( 1 ); + $testee = new Recipients\Role_Recipient( 1 ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Role_Recipient', $testee ); } public function test_it_implements_the_interface() { - $testee = new Role_Recipient( 1 ); + $testee = new Recipients\Role_Recipient( 1 ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } } diff --git a/tests/phpunit/tests/test-user-recipient.php b/tests/phpunit/tests/test-user-recipient.php index 2d753a50..431acd33 100644 --- a/tests/phpunit/tests/test-user-recipient.php +++ b/tests/phpunit/tests/test-user-recipient.php @@ -4,29 +4,29 @@ use stdClass; -use WP\Notifications\Recipients\User_Recipient; +use WP\Notifications\Recipients; class Test_User_Recipient extends TestCase { public function test_it_can_be_instantiated() { - $testee = new User_Recipient( 1 ); + $testee = new Recipients\User_Recipient( 1 ); $this->assertInstanceOf( '\WP\Notifications\Recipients\User_Recipient', $testee ); } public function test_it_implements_the_recipient_interface() { - $testee = new User_Recipient( 1 ); + $testee = new Recipients\User_Recipient( 1 ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } public function test_it_accepts_a_user_id_as_a_string() { - $testee = new User_Recipient( '1' ); + $testee = new Recipients\User_Recipient( '1' ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } /** @dataProvider data_provider_it_throws_on_invalid_type */ public function test_it_throws_on_invalid_type( $invalid_user_id ) { $this->expectException( '\WP\Notifications\Exceptions\Invalid_Recipient' ); - new User_Recipient( $invalid_user_id ); + new Recipients\User_Recipient( $invalid_user_id ); } public function data_provider_it_throws_on_invalid_type() { From 4048f13904cdca34e11eb0e1b305823f1039d7a6 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Sun, 9 Apr 2023 19:05:02 -0700 Subject: [PATCH 7/9] fix: types in PHPDoc comments --- includes/class-base-notification.php | 10 +++++----- includes/class-factory.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/class-base-notification.php b/includes/class-base-notification.php index 5ba2a372..04dadd98 100644 --- a/includes/class-base-notification.php +++ b/includes/class-base-notification.php @@ -19,7 +19,7 @@ class Base_Notification implements Notification { /** * Sender of the notification. * - * @var Sender + * @var Senders\Sender */ protected $sender; @@ -33,14 +33,14 @@ class Base_Notification implements Notification { /** * Collection of notification recipients. * - * @var Recipient_Collection + * @var Recipients\Recipient_Collection */ protected $recipients; /** * Notification message. * - * @var Message + * @var Messages\Message */ protected $message; @@ -54,11 +54,11 @@ class Base_Notification implements Notification { /** * Instantiates a Base_Notification object. * - * @param Sender $sender Sender that sent the + * @param Senders\Sender $sender Sender that sent the * notification. * @param Recipients\Recipient_Collection $recipients Recipients that should * receive the notification. - * @param Message $message Message of the notification. + * @param Messages\Message $message Message of the notification. * @param mixed $timestamp Optional. Timestamp of * when the notification * was triggered. Defaults diff --git a/includes/class-factory.php b/includes/class-factory.php index 28f36cda..2bce0bd3 100644 --- a/includes/class-factory.php +++ b/includes/class-factory.php @@ -14,21 +14,21 @@ class Factory { /** * Message factory implementation to use. * - * @var Message_Factory + * @var Messages\Message_Factory */ private $message_factory; /** * Recipient factory implementation to use. * - * @var Recipient_Factory + * @var Recipients\Recipient_Factory */ private $recipient_factory; /** * Sender factory implementation to use * - * @var Sender_Factory + * @var Senders\Sender_Factory */ private $sender_factory; From 3849e891aa866c6477903ed9d77e1ffb9b8653f9 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Tue, 11 Apr 2023 12:19:15 -0700 Subject: [PATCH 8/9] refactor: shorten class names inside namespaces --- includes/class-base-notification.php | 25 +++++++----------- includes/class-factory.php | 14 +++++----- .../class-aggregate-message-factory.php | 6 ++--- .../messages/class-base-message-factory.php | 2 +- .../messages/interface-message-factory.php | 2 +- .../class-aggregate-recipient-factory.php | 6 ++--- .../class-base-recipient-factory.php | 2 +- .../recipients/class-recipient-collection.php | 4 +-- includes/recipients/class-role-recipient.php | 2 +- includes/recipients/class-user-recipient.php | 2 +- .../interface-recipient-factory.php | 2 +- includes/senders/interface-sender-factory.php | 2 +- .../phpunit/tests/test-base-notification.php | 6 ++--- tests/phpunit/tests/test-factory.php | 6 ++--- .../tests/test-recipient-collection.php | 26 +++++++++---------- tests/phpunit/tests/test-role-recipient.php | 6 ++--- tests/phpunit/tests/test-user-recipient.php | 10 +++---- 17 files changed, 57 insertions(+), 66 deletions(-) diff --git a/includes/class-base-notification.php b/includes/class-base-notification.php index 04dadd98..a797345f 100644 --- a/includes/class-base-notification.php +++ b/includes/class-base-notification.php @@ -33,7 +33,7 @@ class Base_Notification implements Notification { /** * Collection of notification recipients. * - * @var Recipients\Recipient_Collection + * @var Recipients\Collection */ protected $recipients; @@ -54,23 +54,16 @@ class Base_Notification implements Notification { /** * Instantiates a Base_Notification object. * - * @param Senders\Sender $sender Sender that sent the - * notification. - * @param Recipients\Recipient_Collection $recipients Recipients that should - * receive the notification. - * @param Messages\Message $message Message of the notification. - * @param mixed $timestamp Optional. Timestamp of - * when the notification - * was triggered. Defaults - * to the moment of - * instantiation. - * @param int $id Optional. ID of the - * notification. Defaults - * to -1. + * @param Senders\Sender $sender Sender that sent the notification. + * @param Recipients\Collection $recipients Recipients that should receive the notification. + * @param Messages\Message $message Message of the notification. + * @param mixed $timestamp Optional. Timestamp of when the notification was + * triggered. Defaults to the moment of instantiation. + * @param int $id Optional. ID of the notification. Defaults to -1. */ public function __construct( Senders\Sender $sender, - Recipients\Recipient_Collection $recipients, + Recipients\Collection $recipients, Messages\Message $message, $timestamp = null, $id = - 1 @@ -127,7 +120,7 @@ public function get_sender() { /** * Gets the recipients for the notification. * - * @return Recipients\Recipient_Collection Notification recipients. + * @return Recipients\Collection Notification recipients. */ public function get_recipients() { return $this->recipients; diff --git a/includes/class-factory.php b/includes/class-factory.php index 2bce0bd3..8774731c 100644 --- a/includes/class-factory.php +++ b/includes/class-factory.php @@ -14,28 +14,28 @@ class Factory { /** * Message factory implementation to use. * - * @var Messages\Message_Factory + * @var Messages\Factory */ private $message_factory; /** * Recipient factory implementation to use. * - * @var Recipients\Recipient_Factory + * @var Recipients\Factory */ private $recipient_factory; /** * Sender factory implementation to use * - * @var Senders\Sender_Factory + * @var Senders\Factory */ private $sender_factory; public function __construct( - Messages\Message_Factory $message_factory, - Recipients\Recipient_Factory $recipient_factory, - Senders\Sender_Factory $sender_factory + Messages\Factory $message_factory, + Recipients\Factory $recipient_factory, + Senders\Factory $sender_factory ) { $this->message_factory = $message_factory; $this->recipient_factory = $recipient_factory; @@ -54,7 +54,7 @@ public function create( $args ) { list( $message_args, $recipients_args, $sender_args ) = $this->validate( $args ); $sender = $this->sender_factory->create( $sender_args ); - $recipients = new Recipients\Recipient_Collection(); + $recipients = new Recipients\Collection(); $message = $this->message_factory->create( $message_args ); foreach ( $recipients_args as $type => $value ) { diff --git a/includes/messages/class-aggregate-message-factory.php b/includes/messages/class-aggregate-message-factory.php index 8444456a..557d6980 100644 --- a/includes/messages/class-aggregate-message-factory.php +++ b/includes/messages/class-aggregate-message-factory.php @@ -4,9 +4,9 @@ use WP\Notifications; -final class Aggregate_Message_Factory +final class Aggregate_Factory extends Notifications\Aggregate_Factory - implements Message_Factory { + implements Factory { /** * Get the interface that this aggregate factory can instantiate @@ -15,6 +15,6 @@ final class Aggregate_Message_Factory * @return string Class name of the interface. */ protected function get_interface() { - return 'Message_Factory'; + return '\WP\Notifications\Messages\Factory'; } } diff --git a/includes/messages/class-base-message-factory.php b/includes/messages/class-base-message-factory.php index 687a5162..5fc699d1 100644 --- a/includes/messages/class-base-message-factory.php +++ b/includes/messages/class-base-message-factory.php @@ -4,7 +4,7 @@ use WP\Notifications\Exceptions; -class Base_Message_Factory implements Message_Factory { +class Base_Factory implements Factory { const TYPE_STANDARD = 'standard'; diff --git a/includes/messages/interface-message-factory.php b/includes/messages/interface-message-factory.php index 5d8b4f5a..1e6aaa10 100644 --- a/includes/messages/interface-message-factory.php +++ b/includes/messages/interface-message-factory.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Messages; -interface Message_Factory { +interface Factory { /** * Create a new instance of a notification message. diff --git a/includes/recipients/class-aggregate-recipient-factory.php b/includes/recipients/class-aggregate-recipient-factory.php index e7d89f5f..33dd1733 100644 --- a/includes/recipients/class-aggregate-recipient-factory.php +++ b/includes/recipients/class-aggregate-recipient-factory.php @@ -4,9 +4,9 @@ use WP\Notifications; -final class Aggregate_Recipient_Factory +final class Aggregate_Factory extends Notifications\Aggregate_Factory - implements Recipient_Factory { + implements Factory { /** * Get the interface that this aggregate factory can instantiate @@ -15,6 +15,6 @@ final class Aggregate_Recipient_Factory * @return string Class name of the interface. */ protected function get_interface() { - return 'Recipient_Factory'; + return 'WP\Notifications\Recipients\Factory'; } } diff --git a/includes/recipients/class-base-recipient-factory.php b/includes/recipients/class-base-recipient-factory.php index 527879ef..ba987a0f 100644 --- a/includes/recipients/class-base-recipient-factory.php +++ b/includes/recipients/class-base-recipient-factory.php @@ -4,7 +4,7 @@ use WP\Notifications\Exceptions; -final class Base_Recipient_Factory implements Recipient_Factory { +final class Base_Factory implements Factory { const TYPE_USER = 'user'; const TYPE_ROLE = 'role'; diff --git a/includes/recipients/class-recipient-collection.php b/includes/recipients/class-recipient-collection.php index 6efb4eb2..d5ef6c4b 100644 --- a/includes/recipients/class-recipient-collection.php +++ b/includes/recipients/class-recipient-collection.php @@ -9,7 +9,7 @@ use WP\Notifications; use WP\Notifications\Exceptions; -class Recipient_Collection +class Collection implements Iterator, Countable, JsonSerializable, @@ -23,7 +23,7 @@ class Recipient_Collection protected $recipients = array(); /** - * Instantiates a WPNotify_RecipientCollection object. + * Instantiates a Collection object. * * @param array $recipients Array of recipients to instantiate the * collection with. diff --git a/includes/recipients/class-role-recipient.php b/includes/recipients/class-role-recipient.php index 5e2b5a8e..78273cd3 100644 --- a/includes/recipients/class-role-recipient.php +++ b/includes/recipients/class-role-recipient.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Recipients; -final class Role_Recipient implements Recipient { +final class Role implements Recipient { private $role; diff --git a/includes/recipients/class-user-recipient.php b/includes/recipients/class-user-recipient.php index 1a8873e2..41c31c78 100644 --- a/includes/recipients/class-user-recipient.php +++ b/includes/recipients/class-user-recipient.php @@ -6,7 +6,7 @@ use WP\Notifications\Exceptions\Invalid_Recipient; -final class User_Recipient implements Recipient { +final class User implements Recipient { private $user_id; private $user_object; diff --git a/includes/recipients/interface-recipient-factory.php b/includes/recipients/interface-recipient-factory.php index 7cd8a126..378e1f8d 100644 --- a/includes/recipients/interface-recipient-factory.php +++ b/includes/recipients/interface-recipient-factory.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Recipients; -interface Recipient_Factory { +interface Factory { /** * Create a new instance of a notification recipient. diff --git a/includes/senders/interface-sender-factory.php b/includes/senders/interface-sender-factory.php index e49c0c4e..8391844b 100644 --- a/includes/senders/interface-sender-factory.php +++ b/includes/senders/interface-sender-factory.php @@ -2,7 +2,7 @@ namespace WP\Notifications\Senders; -interface Sender_Factory { +interface Factory { /** * Create a new instance of notification sender diff --git a/tests/phpunit/tests/test-base-notification.php b/tests/phpunit/tests/test-base-notification.php index 21465cac..cb509f1c 100644 --- a/tests/phpunit/tests/test-base-notification.php +++ b/tests/phpunit/tests/test-base-notification.php @@ -8,7 +8,7 @@ class Test_Base_Notification extends TestCase { public function test_it_can_be_instantiated() { $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); - $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); + $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Collection' ); $testee = new Notifications\Base_Notification( $sender_mock, $recipients_mock, @@ -19,7 +19,7 @@ public function test_it_can_be_instantiated() { public function test_it_implements_the_interface() { $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); - $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); + $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Collection' ); $testee = new Notifications\Base_Notification( $sender_mock, $recipients_mock, @@ -30,7 +30,7 @@ public function test_it_implements_the_interface() { public function test_it_can_return_its_content() { $sender_mock = $this->createMock( '\WP\Notifications\Senders\Base_Sender' ); - $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Recipient_Collection' ); + $recipients_mock = $this->createMock( '\WP\Notifications\Recipients\Collection' ); $dummy_message = new Dummy_Message(); $testee = new Notifications\Base_Notification( $sender_mock, diff --git a/tests/phpunit/tests/test-factory.php b/tests/phpunit/tests/test-factory.php index a14d5db9..61caaf75 100644 --- a/tests/phpunit/tests/test-factory.php +++ b/tests/phpunit/tests/test-factory.php @@ -10,14 +10,14 @@ public function test_create_with_vendor_sender() { $vendor_sender = $this->createMock( '\WP\Notifications\Senders\Sender' ); - $message_factory = $this->getMockBuilder( '\WP\Notifications\Messages\Message_Factory' ) + $message_factory = $this->getMockBuilder( '\WP\Notifications\Messages\Factory' ) ->setMethods( array( 'create', 'accepts' ) ) ->getMock(); $message_factory->method( 'create' )->willReturn( $this->createMock( '\WP\Notifications\Messages\Message' ) ); $message_factory->method( 'accepts' )->willReturn( true ); - $sender_factory = $this->getMockBuilder( '\WP\Notifications\Senders\Sender_Factory' ) + $sender_factory = $this->getMockBuilder( '\WP\Notifications\Senders\Factory' ) ->setMethods( array( 'create' ) ) ->getMock(); @@ -25,7 +25,7 @@ public function test_create_with_vendor_sender() { $factory = new Notifications\Factory( $message_factory, - $this->createMock( '\WP\Notifications\Recipients\Recipient_Factory' ), + $this->createMock( '\WP\Notifications\Recipients\Factory' ), $sender_factory ); diff --git a/tests/phpunit/tests/test-recipient-collection.php b/tests/phpunit/tests/test-recipient-collection.php index 8077268c..a28423b4 100644 --- a/tests/phpunit/tests/test-recipient-collection.php +++ b/tests/phpunit/tests/test-recipient-collection.php @@ -8,31 +8,29 @@ class Test_Recipient_Collection extends TestCase { - const SERIALIZED = 'C:28:"WPNotify_RecipientCollection":6:{a:0:{}}'; - public function test_it_can_be_instantiated() { - $testee = new Recipients\Recipient_Collection(); - $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient_Collection', $testee ); + $testee = new Recipients\Collection(); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Collection', $testee ); } public function test_it_is_countable() { - $testee = new Recipients\Recipient_Collection(); + $testee = new Recipients\Collection(); $this->assertInstanceOf( 'Countable', $testee ); } public function test_it_is_traversable() { - $testee = new Recipients\Recipient_Collection(); + $testee = new Recipients\Collection(); $this->assertInstanceOf( 'Traversable', $testee ); } public function test_it_is_empty_when_instantiated_without_arguments() { - $testee = new Recipients\Recipient_Collection(); + $testee = new Recipients\Collection(); $this->assertCount( 0, $testee ); } public function test_it_can_accept_a_singular_recipient() { $mock_recipient = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); - $testee = new Recipients\Recipient_Collection( $mock_recipient ); + $testee = new Recipients\Collection( $mock_recipient ); $this->assertCount( 1, $testee ); } @@ -40,7 +38,7 @@ public function test_it_can_accept_an_array_of_recipients() { $mock_recipient_1 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_2 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_3 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); - $testee = new Recipients\Recipient_Collection( + $testee = new Recipients\Collection( array( $mock_recipient_1, $mock_recipient_2, @@ -54,7 +52,7 @@ public function test_recipients_can_be_added() { $mock_recipient_1 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_2 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); $mock_recipient_3 = $this->createMock( '\WP\Notifications\Recipients\Recipient' ); - $testee = new Recipients\Recipient_Collection( $mock_recipient_1 ); + $testee = new Recipients\Collection( $mock_recipient_1 ); $this->assertCount( 1, $testee ); $testee->add( $mock_recipient_2 ); $this->assertCount( 2, $testee ); @@ -65,7 +63,7 @@ public function test_recipients_can_be_added() { /** @dataProvider data_provider_it_throws_on_invalid_type */ public function test_it_throws_on_invalid_type( $invalid_recipient ) { $this->expectException( '\WP\Notifications\Exceptions\Runtime_Exception' ); - new Recipients\Recipient_Collection( $invalid_recipient ); + new Recipients\Collection( $invalid_recipient ); } public function data_provider_it_throws_on_invalid_type() { @@ -83,7 +81,7 @@ public function data_provider_it_throws_on_invalid_type() { } public function test_it_can_be_json_encoded() { - $testee = new Recipients\Recipient_Collection( array() ); + $testee = new Recipients\Collection( array() ); $this->assertEquals( '[]', json_encode( $testee ) @@ -92,8 +90,8 @@ public function test_it_can_be_json_encoded() { public function test_it_can_be_instantiated_from_json() { $json = '[]'; - $testee = Recipients\Recipient_Collection::json_unserialize( $json ); - $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient_Collection', $testee ); + $testee = Recipients\Collection::json_unserialize( $json ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Collection', $testee ); $this->assertEquals( 0, $testee->count() ); } } diff --git a/tests/phpunit/tests/test-role-recipient.php b/tests/phpunit/tests/test-role-recipient.php index 1cf6e1ef..d92a6092 100644 --- a/tests/phpunit/tests/test-role-recipient.php +++ b/tests/phpunit/tests/test-role-recipient.php @@ -7,12 +7,12 @@ class Test_Role_Recipient extends TestCase { public function test_it_can_be_instantiated() { - $testee = new Recipients\Role_Recipient( 1 ); - $this->assertInstanceOf( '\WP\Notifications\Recipients\Role_Recipient', $testee ); + $testee = new Recipients\Role( 1 ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\Role', $testee ); } public function test_it_implements_the_interface() { - $testee = new Recipients\Role_Recipient( 1 ); + $testee = new Recipients\Role( 1 ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } } diff --git a/tests/phpunit/tests/test-user-recipient.php b/tests/phpunit/tests/test-user-recipient.php index 431acd33..60ed2d72 100644 --- a/tests/phpunit/tests/test-user-recipient.php +++ b/tests/phpunit/tests/test-user-recipient.php @@ -9,24 +9,24 @@ class Test_User_Recipient extends TestCase { public function test_it_can_be_instantiated() { - $testee = new Recipients\User_Recipient( 1 ); - $this->assertInstanceOf( '\WP\Notifications\Recipients\User_Recipient', $testee ); + $testee = new Recipients\User( 1 ); + $this->assertInstanceOf( '\WP\Notifications\Recipients\User', $testee ); } public function test_it_implements_the_recipient_interface() { - $testee = new Recipients\User_Recipient( 1 ); + $testee = new Recipients\User( 1 ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } public function test_it_accepts_a_user_id_as_a_string() { - $testee = new Recipients\User_Recipient( '1' ); + $testee = new Recipients\User( '1' ); $this->assertInstanceOf( '\WP\Notifications\Recipients\Recipient', $testee ); } /** @dataProvider data_provider_it_throws_on_invalid_type */ public function test_it_throws_on_invalid_type( $invalid_user_id ) { $this->expectException( '\WP\Notifications\Exceptions\Invalid_Recipient' ); - new Recipients\User_Recipient( $invalid_user_id ); + new Recipients\User( $invalid_user_id ); } public function data_provider_it_throws_on_invalid_type() { From 4ee94880ddfa6e4e5553d64e3710f81d6dffbe09 Mon Sep 17 00:00:00 2001 From: John Hooks Date: Tue, 11 Apr 2023 12:28:25 -0700 Subject: [PATCH 9/9] refactor: change filenames to fit code styling --- ...factory.php => class-aggregate-factory.php} | 0 ...sage-factory.php => class-base-factory.php} | 0 ...ssage-factory.php => interface-factory.php} | 0 ...factory.php => class-aggregate-factory.php} | 0 ...ient-factory.php => class-base-factory.php} | 0 ...ent-collection.php => class-collection.php} | 0 ...class-role-recipient.php => class-role.php} | 0 ...class-user-recipient.php => class-user.php} | 0 ...pient-factory.php => interface-factory.php} | 0 ...ender-factory.php => interface-factory.php} | 0 wp-feature-notifications.php | 18 +++++++++--------- 11 files changed, 9 insertions(+), 9 deletions(-) rename includes/messages/{class-aggregate-message-factory.php => class-aggregate-factory.php} (100%) rename includes/messages/{class-base-message-factory.php => class-base-factory.php} (100%) rename includes/messages/{interface-message-factory.php => interface-factory.php} (100%) rename includes/recipients/{class-aggregate-recipient-factory.php => class-aggregate-factory.php} (100%) rename includes/recipients/{class-base-recipient-factory.php => class-base-factory.php} (100%) rename includes/recipients/{class-recipient-collection.php => class-collection.php} (100%) rename includes/recipients/{class-role-recipient.php => class-role.php} (100%) rename includes/recipients/{class-user-recipient.php => class-user.php} (100%) rename includes/recipients/{interface-recipient-factory.php => interface-factory.php} (100%) rename includes/senders/{interface-sender-factory.php => interface-factory.php} (100%) diff --git a/includes/messages/class-aggregate-message-factory.php b/includes/messages/class-aggregate-factory.php similarity index 100% rename from includes/messages/class-aggregate-message-factory.php rename to includes/messages/class-aggregate-factory.php diff --git a/includes/messages/class-base-message-factory.php b/includes/messages/class-base-factory.php similarity index 100% rename from includes/messages/class-base-message-factory.php rename to includes/messages/class-base-factory.php diff --git a/includes/messages/interface-message-factory.php b/includes/messages/interface-factory.php similarity index 100% rename from includes/messages/interface-message-factory.php rename to includes/messages/interface-factory.php diff --git a/includes/recipients/class-aggregate-recipient-factory.php b/includes/recipients/class-aggregate-factory.php similarity index 100% rename from includes/recipients/class-aggregate-recipient-factory.php rename to includes/recipients/class-aggregate-factory.php diff --git a/includes/recipients/class-base-recipient-factory.php b/includes/recipients/class-base-factory.php similarity index 100% rename from includes/recipients/class-base-recipient-factory.php rename to includes/recipients/class-base-factory.php diff --git a/includes/recipients/class-recipient-collection.php b/includes/recipients/class-collection.php similarity index 100% rename from includes/recipients/class-recipient-collection.php rename to includes/recipients/class-collection.php diff --git a/includes/recipients/class-role-recipient.php b/includes/recipients/class-role.php similarity index 100% rename from includes/recipients/class-role-recipient.php rename to includes/recipients/class-role.php diff --git a/includes/recipients/class-user-recipient.php b/includes/recipients/class-user.php similarity index 100% rename from includes/recipients/class-user-recipient.php rename to includes/recipients/class-user.php diff --git a/includes/recipients/interface-recipient-factory.php b/includes/recipients/interface-factory.php similarity index 100% rename from includes/recipients/interface-recipient-factory.php rename to includes/recipients/interface-factory.php diff --git a/includes/senders/interface-sender-factory.php b/includes/senders/interface-factory.php similarity index 100% rename from includes/senders/interface-sender-factory.php rename to includes/senders/interface-factory.php diff --git a/wp-feature-notifications.php b/wp-feature-notifications.php index aca65ab9..0132681f 100644 --- a/wp-feature-notifications.php +++ b/wp-feature-notifications.php @@ -47,17 +47,17 @@ require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/senders/interface-sender.php'; require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/senders/class-base-sender.php'; require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/interface-recipient.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-recipient-collection.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-user-recipient.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-role-recipient.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/interface-recipient-factory.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-base-recipient-factory.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-aggregate-recipient-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-collection.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-user.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-role.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/interface-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-base-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/recipients/class-aggregate-factory.php'; require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/interface-message.php'; require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-base-message.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/interface-message-factory.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-base-message-factory.php'; -require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-aggregate-message-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/interface-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-base-factory.php'; +require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/messages/class-aggregate-factory.php'; require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/persistence/interface-notification-repository.php'; require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/persistence/class-abstract-notification-repository.php'; require_once WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/includes/persistence/class-wpdb-notification-repository.php';