diff --git a/.phpcs.xml b/.phpcs.xml index 9032383..737399a 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -30,6 +30,7 @@ + diff --git a/README.md b/README.md index df27f02..49d355a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 { /** @@ -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 { /** diff --git a/classes/wp-async-request.php b/classes/wp-async-request.php index 0503a60..6e3a24c 100644 --- a/classes/wp-async-request.php +++ b/classes/wp-async-request.php @@ -5,6 +5,8 @@ * @package WP-Background-Processing */ +namespace WP_Background_Processing; + /** * Abstract WP_Async_Request class. * diff --git a/classes/wp-background-process.php b/classes/wp-background-process.php index 8a053d8..9c000a7 100644 --- a/classes/wp-background-process.php +++ b/classes/wp-background-process.php @@ -5,6 +5,10 @@ * @package WP-Background-Processing */ +namespace WP_Background_Processing; + +use stdClass; + /** * Abstract WP_Background_Process class. * diff --git a/tests/Test_WP_Background_Process.php b/tests/Test_WP_Background_Process.php index 19926e9..c7509b0 100644 --- a/tests/Test_WP_Background_Process.php +++ b/tests/Test_WP_Background_Process.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WP_Background_Processing\WP_Background_Process; /** * Class Test_WP_Background_Process @@ -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() ); } @@ -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 ); @@ -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' ); @@ -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' );