Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WP_Background_Processing namespace to classes #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<rule ref="WordPress">
<!-- Unable to fix -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound"/>
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching"/>
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The recommended way to install this library in your project is by loading it thr
composer require deliciousbrains/wp-background-processing
```

It is highly recommended to prefix wrap the library class files using [the Mozart package](https://packagist.org/packages/coenjacobs/mozart), to prevent collisions with other projects using this same library.
It is highly recommended to prefix wrap the library class files using [PHP-Scoper](https://packagist.org/packages/humbug/php-scoper), to prevent collisions with other projects using this same library.

## Usage

Expand All @@ -25,6 +25,8 @@ Async requests are useful for pushing slow one-off tasks such as sending emails
Extend the `WP_Async_Request` class:

```php
use My_Plugin\PHP_Scoped\Namespace\WP_Background_Processing;

class WP_Example_Request extends WP_Async_Request {

/**
Expand Down Expand Up @@ -99,6 +101,8 @@ Queues work on a first in first out basis, which allows additional items to be p
Extend the `WP_Background_Process` class:

```php
use My_Plugin\PHP_Scoped\Namespace\WP_Background_Processing;

class WP_Example_Process extends WP_Background_Process {

/**
Expand Down
2 changes: 2 additions & 0 deletions classes/wp-async-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package WP-Background-Processing
*/

namespace WP_Background_Processing;

/**
* Abstract WP_Async_Request class.
*
Expand Down
4 changes: 4 additions & 0 deletions classes/wp-background-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* @package WP-Background-Processing
*/

namespace WP_Background_Processing;

use stdClass;

/**
* Abstract WP_Background_Process class.
*
Expand Down
9 changes: 5 additions & 4 deletions tests/Test_WP_Background_Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use PHPUnit\Framework\MockObject\MockObject;
use WP_Background_Processing\WP_Background_Process;

/**
* Class Test_WP_Background_Process
Expand Down Expand Up @@ -42,7 +43,7 @@ public function setUp(): void {
*/
private function getWPBPProperty( string $name ) {
try {
$property = new ReflectionProperty( 'WP_Background_Process', $name );
$property = new ReflectionProperty( 'WP_Background_Processing\WP_Background_Process', $name );
} catch ( Exception $e ) {
return new WP_Error( $e->getCode(), $e->getMessage() );
}
Expand All @@ -61,7 +62,7 @@ private function getWPBPProperty( string $name ) {
*/
private function executeWPBPMethod( string $name, ...$args ) {
try {
$method = new ReflectionMethod( 'WP_Background_Process', $name );
$method = new ReflectionMethod( 'WP_Background_Processing\WP_Background_Process', $name );
$method->setAccessible( true );

return $method->invoke( $this->wpbp, ...$args );
Expand All @@ -76,7 +77,7 @@ private function executeWPBPMethod( string $name, ...$args ) {
* @return void
*/
public function test_push_to_queue() {
$this->assertClassHasAttribute( 'data', 'WP_Background_Process', 'class has data property' );
$this->assertClassHasAttribute( 'data', 'WP_Background_Processing\WP_Background_Process', 'class has data property' );
$this->assertEmpty( $this->getWPBPProperty( 'data' ) );

$this->wpbp->push_to_queue( 'wibble' );
Expand All @@ -93,7 +94,7 @@ public function test_push_to_queue() {
* @return void
*/
public function test_save() {
$this->assertClassHasAttribute( 'data', 'WP_Background_Process', 'class has data property' );
$this->assertClassHasAttribute( 'data', 'WP_Background_Processing\WP_Background_Process', 'class has data property' );
$this->assertEmpty( $this->getWPBPProperty( 'data' ) );
$this->assertEmpty( $this->wpbp->get_batches(), 'no batches until save' );

Expand Down