Skip to content

Job WithoutOverlapping Middleware not working #41968

@anabeto93

Description

@anabeto93
  • Laravel Version: 9.8.1
  • PHP Version: 8.1.2
  • Database Driver & Version: sqlite

Description:

The middleware() method on jobs not getting called. Have tried to dd() and it does not work unlike uniqueId() method when implementing the ShouldBeUnique interface.

Steps To Reproduce:

On a clean laravel app,

  1. Create a job, that simply logs any string
  2. Inlcude the middleware() method and include the WithoutOverlapping middleware, defining a key for it.
  3. Test it using phpunit or postman making sure to dd() in the middleware

Below are some screenshots to better explain

  1. Route endpoint
    route_endpoint
Route::get('log', function() {
    DB::beginTransaction();

    SimpleLogJob::dispatch()->afterCommit()->afterResponse();

    User::create([
        'email' => 'test@mailinator.com',
        'password' => 'unhashedpassword',
        'name' => 'Testing Commit',
    ]);

    DB::commit();

    return response()->json(['message' => "Logging works."]);
});

job_function

  1. Tests
    test_endpoint
public function test_job_dispatched_after_response()
    {
        $response = $this->json('GET', 'api/log');

        $response->assertStatus(200)->assertJson([
            'message' => 'Logging works.'
        ]);

        $users = User::get();

        $this->assertCount(1, $users);
    }
  1. Result
    test_result

Should've died and dumped the result some_middleware when the tests run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions