returnArg(); Functions\when('sanitize_title')->returnArg(); $this->policies = Mockery::mock(PolicyRepository::class); $this->service = Mockery::mock(PolicyService::class); $this->endpoint = new PolicyEndpoint( $this->policies, Mockery::mock(PolicyVersionRepository::class), $this->service, ); } public function testCreateRejectsTitleLongerThanColumnLimit(): void { $this->service->shouldNotReceive('createPolicy'); $request = new \WP_REST_Request([ 'title' => str_repeat('a', Policy::MAX_TITLE_LENGTH + 1), ]); $response = $this->endpoint->create($request); self::assertInstanceOf(\WP_Error::class, $response); self::assertSame(400, $response->error_data['invalid_policy']['status']); } public function testCreateRejectsSlugLongerThanColumnLimit(): void { $this->service->shouldNotReceive('createPolicy'); $request = new \WP_REST_Request([ 'title' => 'Cancellation', 'slug' => str_repeat('a', Policy::MAX_SLUG_LENGTH + 1), ]); $response = $this->endpoint->create($request); self::assertInstanceOf(\WP_Error::class, $response); self::assertSame(400, $response->error_data['invalid_policy']['status']); } }