Skip to content

Commit 328f8e1

Browse files
committed
Swapped options and transaction ID on middleware methods
1 parent d7a0a94 commit 328f8e1

10 files changed

+54
-54
lines changed

src/ErrorTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ trait ErrorTrait
1616
*/
1717
public function error(
1818
Throwable $throwable,
19-
array $options = [],
20-
string $transactionId = null
19+
string $transactionId,
20+
array $options = []
2121
): CancellablePromiseInterface {
2222
return reject($throwable);
2323
}

src/MiddlewareInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ interface MiddlewareInterface
2727
*/
2828
public function pre(
2929
RequestInterface $request,
30-
array $options = [],
31-
string $transactionId = null
30+
string $transactionId,
31+
array $options = []
3232
): CancellablePromiseInterface;
3333

3434
/**
@@ -41,8 +41,8 @@ public function pre(
4141
*/
4242
public function post(
4343
ResponseInterface $response,
44-
array $options = [],
45-
string $transactionId = null
44+
string $transactionId,
45+
array $options = []
4646
): CancellablePromiseInterface;
4747

4848
/**
@@ -56,7 +56,7 @@ public function post(
5656
*/
5757
public function error(
5858
Throwable $throwable,
59-
array $options = [],
60-
string $transactionId = null
59+
string $transactionId,
60+
array $options = []
6161
): CancellablePromiseInterface;
6262
}

src/MiddlewareRunner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function pre(
6262
foreach ($middlewares as $middleware) {
6363
$requestMiddleware = $middleware;
6464
$promise = $promise->then(function (RequestInterface $request) use ($requestMiddleware) {
65-
return $requestMiddleware->pre($request, $this->options, $this->id);
65+
return $requestMiddleware->pre($request, $this->id, $this->options);
6666
});
6767
}
6868

@@ -84,7 +84,7 @@ public function post(
8484
foreach ($middlewares as $middleware) {
8585
$responseMiddleware = $middleware;
8686
$promise = $promise->then(function (ResponseInterface $response) use ($responseMiddleware) {
87-
return $responseMiddleware->post($response, $this->options, $this->id);
87+
return $responseMiddleware->post($response, $this->id, $this->options);
8888
});
8989
}
9090

@@ -106,7 +106,7 @@ public function error(
106106
foreach ($middlewares as $middleware) {
107107
$errorMiddleware = $middleware;
108108
$promise = $promise->then(null, function (Throwable $throwable) use ($errorMiddleware) {
109-
return reject($errorMiddleware->error($throwable, $this->options, $this->id));
109+
return reject($errorMiddleware->error($throwable, $this->id, $this->options));
110110
});
111111
}
112112

src/PostTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ trait PostTrait
1515
*/
1616
public function post(
1717
ResponseInterface $response,
18-
array $options = [],
19-
string $transactionId = null
18+
string $transactionId,
19+
array $options = []
2020
): CancellablePromiseInterface {
2121
return resolve($response);
2222
}

src/PreTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ trait PreTrait
1515
*/
1616
public function pre(
1717
RequestInterface $request,
18-
array $options = [],
19-
string $transactionId = null
18+
string $transactionId,
19+
array $options = []
2020
): CancellablePromiseInterface {
2121
return resolve($request);
2222
}

tests/DummyMiddlewareTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testPre()
1818
$this->assertSame(
1919
$request,
2020
await(
21-
$middleware->pre($request),
21+
$middleware->pre($request, 'abc'),
2222
Factory::create()
2323
)
2424
);
@@ -31,7 +31,7 @@ public function testPost()
3131
$this->assertSame(
3232
$response,
3333
await(
34-
$middleware->post($response),
34+
$middleware->post($response, 'abc'),
3535
Factory::create()
3636
)
3737
);
@@ -44,7 +44,7 @@ public function testError()
4444
self::expectException(Exception::class);
4545
self::expectExceptionMessage('Throwable or anything extending it');
4646
await(
47-
$middleware->error($exception),
47+
$middleware->error($exception, 'abc'),
4848
Factory::create()
4949
);
5050
}

tests/MiddlewareRunnerTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ public function testAll()
4444
return $executioner->id;
4545
}, null, MiddlewareRunner::class)($executioner);
4646

47-
Phake::when($middlewareOne)->pre($request, $options, $id)->thenReturn(resolve($request));
48-
Phake::when($middlewareOne)->post($response, $options, $id)->thenReturn(resolve($response));
49-
Phake::when($middlewareOne)->error($exception, $options, $id)->thenReturn(reject($exception));
47+
Phake::when($middlewareOne)->pre($request, $id, $options)->thenReturn(resolve($request));
48+
Phake::when($middlewareOne)->post($response, $id, $options)->thenReturn(resolve($response));
49+
Phake::when($middlewareOne)->error($exception, $id, $options)->thenReturn(reject($exception));
5050

51-
Phake::when($middlewareTwo)->pre($request, $options, $id)->thenReturn(resolve($request));
52-
Phake::when($middlewareTwo)->post($response, $options, $id)->thenReturn(resolve($response));
53-
Phake::when($middlewareTwo)->error($exception, $options, $id)->thenReturn(reject($exception));
51+
Phake::when($middlewareTwo)->pre($request, $id, $options)->thenReturn(resolve($request));
52+
Phake::when($middlewareTwo)->post($response, $id, $options)->thenReturn(resolve($response));
53+
Phake::when($middlewareTwo)->error($exception, $id, $options)->thenReturn(reject($exception));
5454

55-
Phake::when($middlewareThree)->pre($request, $options, $id)->thenReturn(resolve($request));
56-
Phake::when($middlewareThree)->post($response, $options, $id)->thenReturn(resolve($response));
57-
Phake::when($middlewareThree)->error($exception, $options, $id)->thenReturn(reject($exception));
55+
Phake::when($middlewareThree)->pre($request, $id, $options)->thenReturn(resolve($request));
56+
Phake::when($middlewareThree)->post($response, $id, $options)->thenReturn(resolve($response));
57+
Phake::when($middlewareThree)->error($exception, $id, $options)->thenReturn(reject($exception));
5858

5959
self::assertSame($request, await($executioner->pre($request), $loop));
6060
self::assertSame($response, await($executioner->post($response), $loop));
@@ -65,15 +65,15 @@ public function testAll()
6565
}
6666

6767
Phake::inOrder(
68-
Phake::verify($middlewareThree)->pre($request, $options, $id),
69-
Phake::verify($middlewareOne)->pre($request, $options, $id),
70-
Phake::verify($middlewareTwo)->pre($request, $options, $id),
71-
Phake::verify($middlewareThree)->post($response, $options, $id),
72-
Phake::verify($middlewareOne)->post($response, $options, $id),
73-
Phake::verify($middlewareTwo)->post($response, $options, $id),
74-
Phake::verify($middlewareThree)->error($exception, $options, $id),
75-
Phake::verify($middlewareOne)->error($exception, $options, $id),
76-
Phake::verify($middlewareTwo)->error($exception, $options, $id)
68+
Phake::verify($middlewareThree)->pre($request, $id, $options),
69+
Phake::verify($middlewareOne)->pre($request, $id, $options),
70+
Phake::verify($middlewareTwo)->pre($request, $id, $options),
71+
Phake::verify($middlewareThree)->post($response, $id, $options),
72+
Phake::verify($middlewareOne)->post($response, $id, $options),
73+
Phake::verify($middlewareTwo)->post($response, $id, $options),
74+
Phake::verify($middlewareThree)->error($exception, $id, $options),
75+
Phake::verify($middlewareOne)->error($exception, $id, $options),
76+
Phake::verify($middlewareTwo)->error($exception, $id, $options)
7777
);
7878
}
7979

tests/TestMiddlewares/OneMiddleware.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function getCalls(): array
3232
*/
3333
public function pre(
3434
RequestInterface $request,
35-
array $options = [],
36-
string $transactionId = null
35+
string $transactionId,
36+
array $options = []
3737
): CancellablePromiseInterface {
3838
usleep(100);
3939
$this->calls[(string)microtime(true)] = __CLASS__ . ':pre';
@@ -49,8 +49,8 @@ public function pre(
4949
*/
5050
public function post(
5151
ResponseInterface $response,
52-
array $options = [],
53-
string $transactionId = null
52+
string $transactionId,
53+
array $options = []
5454
): CancellablePromiseInterface {
5555
usleep(100);
5656
$this->calls[(string)microtime(true)] = __CLASS__ . ':post';
@@ -66,8 +66,8 @@ public function post(
6666
*/
6767
public function error(
6868
Throwable $throwable,
69-
array $options = [],
70-
string $transactionId = null
69+
string $transactionId,
70+
array $options = []
7171
): CancellablePromiseInterface {
7272
usleep(100);
7373
$this->calls[(string)microtime(true)] = __CLASS__ . ':error';

tests/TestMiddlewares/ThreeMiddleware.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function getCalls(): array
3333
*/
3434
public function pre(
3535
RequestInterface $request,
36-
array $options = [],
37-
string $transactionId = null
36+
string $transactionId,
37+
array $options = []
3838
): CancellablePromiseInterface {
3939
usleep(100);
4040
$this->calls[(string)microtime(true)] = __CLASS__ . ':pre';
@@ -50,8 +50,8 @@ public function pre(
5050
*/
5151
public function post(
5252
ResponseInterface $response,
53-
array $options = [],
54-
string $transactionId = null
53+
string $transactionId,
54+
array $options = []
5555
): CancellablePromiseInterface {
5656
usleep(100);
5757
$this->calls[(string)microtime(true)] = __CLASS__ . ':post';
@@ -67,8 +67,8 @@ public function post(
6767
*/
6868
public function error(
6969
Throwable $throwable,
70-
array $options = [],
71-
string $transactionId = null
70+
string $transactionId,
71+
array $options = []
7272
): CancellablePromiseInterface {
7373
usleep(100);
7474
$this->calls[(string)microtime(true)] = __CLASS__ . ':error';

tests/TestMiddlewares/TwoMiddleware.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function getCalls(): array
2929
*/
3030
public function pre(
3131
RequestInterface $request,
32-
array $options = [],
33-
string $transactionId = null
32+
string $transactionId,
33+
array $options = []
3434
): CancellablePromiseInterface {
3535
usleep(100);
3636
$this->calls[(string)microtime(true)] = __CLASS__ . ':pre';
@@ -45,8 +45,8 @@ public function pre(
4545
*/
4646
public function post(
4747
ResponseInterface $response,
48-
array $options = [],
49-
string $transactionId = null
48+
string $transactionId,
49+
array $options = []
5050
): CancellablePromiseInterface {
5151
usleep(100);
5252
$this->calls[(string)microtime(true)] = __CLASS__ . ':post';
@@ -61,8 +61,8 @@ public function post(
6161
*/
6262
public function error(
6363
Throwable $throwable,
64-
array $options = [],
65-
string $transactionId = null
64+
string $transactionId,
65+
array $options = []
6666
): CancellablePromiseInterface {
6767
usleep(100);
6868
$this->calls[(string)microtime(true)] = __CLASS__ . ':error';

0 commit comments

Comments
 (0)