From a7a9ce95bb606172c2dec39639859b2391126ad8 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Fri, 1 Mar 2024 19:38:29 -0500 Subject: [PATCH] Debugging leaky queue test failure (#503) * Debug message to help with testing * Fixing one-off issue with tests * Use the term attribute to save the terms, remove date for leaky tests * Fix deprecated error --- src/mantle/application/autoload.php | 4 ++-- .../model/registration/trait-register-meta.php | 2 +- .../queue/providers/wordpress/class-provider.php | 13 +++---------- .../testing/concerns/trait-interacts-with-cron.php | 2 +- tests/Events/EventDispatcherTest.php | 6 ++++++ 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/mantle/application/autoload.php b/src/mantle/application/autoload.php index e7d49d7d4..5cf7ecbf9 100644 --- a/src/mantle/application/autoload.php +++ b/src/mantle/application/autoload.php @@ -25,10 +25,10 @@ */ function app( string $abstract = null, array $parameters = [] ) { if ( empty( $abstract ) ) { - return Application::getInstance(); + return Application::get_instance(); } - return Application::getInstance()->make( $abstract, $parameters ); + return Application::get_instance()->make( $abstract, $parameters ); } } diff --git a/src/mantle/database/model/registration/trait-register-meta.php b/src/mantle/database/model/registration/trait-register-meta.php index f61b2b8d6..cea8925ba 100644 --- a/src/mantle/database/model/registration/trait-register-meta.php +++ b/src/mantle/database/model/registration/trait-register-meta.php @@ -81,7 +81,7 @@ public static function register_meta( string $meta_key, array $args = [] ): bool * @return string|null */ public static function get_object_type(): ?string { - $parent = get_parent_class(); + $parent = get_parent_class( static::class ); if ( Model\Post::class === $parent ) { return 'post'; diff --git a/src/mantle/queue/providers/wordpress/class-provider.php b/src/mantle/queue/providers/wordpress/class-provider.php index 1fa4e6d89..c50d5f07c 100644 --- a/src/mantle/queue/providers/wordpress/class-provider.php +++ b/src/mantle/queue/providers/wordpress/class-provider.php @@ -144,16 +144,10 @@ public function push( mixed $job ): bool { $object->post_date = Carbon::createFromTimestamp( $delay, wp_timezone() )->toDateTimeString(); } - $object->save(); + // Set the queue term for the job. + $object->terms->{static::OBJECT_NAME} = static::get_queue_term_id( $queue ); - // TODO: Convert this to a queued term setter like we do with meta. - $object->set_terms( - [ - static::OBJECT_NAME => static::get_queue_term_id( $queue ), - ] - ); - - return true; + return $object->save(); } /** @@ -224,7 +218,6 @@ protected function query( string $queue = null ): Post_Query_Builder { */ public function in_queue( mixed $job, string $queue = null ): bool { return Queue_Record::where( 'post_status', Post_Status::PENDING->value ) - ->whereDate( now()->toDateTimeString(), '>=' ) ->whereTerm( static::get_queue_term_id( $queue ), static::OBJECT_NAME ) ->whereMeta( Meta_Key::JOB->value, maybe_serialize( $job ) ) ->exists(); diff --git a/src/mantle/testing/concerns/trait-interacts-with-cron.php b/src/mantle/testing/concerns/trait-interacts-with-cron.php index 484da62b6..93b027f37 100644 --- a/src/mantle/testing/concerns/trait-interacts-with-cron.php +++ b/src/mantle/testing/concerns/trait-interacts-with-cron.php @@ -119,7 +119,7 @@ public function assertJobQueued( $job, array $args = [], string $queue = null ): PHPUnit::assertTrue( $provider->in_queue( $job, $queue ), - "Job [{$job_name}] is not in the queue.", + "Job [{$job_name}] is not in the queue [{$queue}] for " . $provider::class, ); } diff --git a/tests/Events/EventDispatcherTest.php b/tests/Events/EventDispatcherTest.php index de5a9077a..01c4e80dd 100644 --- a/tests/Events/EventDispatcherTest.php +++ b/tests/Events/EventDispatcherTest.php @@ -9,6 +9,12 @@ * @group events */ class EventDispatcherTest extends \Mockery\Adapter\Phpunit\MockeryTestCase { + public function setUp(): void { + parent::setUp(); + + app()->singleton_if( 'events', fn ( $app ) => new Dispatcher( $app ) ); + } + public function testBasicEventExecution() { unset( $_SERVER['__event.test'] ); $d = new Dispatcher();