Skip to content

Commit

Permalink
Merge pull request #180 from calvinalkan/master
Browse files Browse the repository at this point in the history
fix(kernel,better-wp-cli-testing): fix #178 and #179
  • Loading branch information
calvinalkan committed May 7, 2023
2 parents 006ec76 + ff42483 commit 87b9fde
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 36 deletions.
Expand Up @@ -9,14 +9,19 @@
use Snicco\Component\HttpRouting\Middleware\Middleware;
use Snicco\Component\HttpRouting\Middleware\NextMiddleware;

use const SEEK_END;

final class MiddlewareOne extends Middleware
{
protected function handle(Request $request, NextMiddleware $next): ResponseInterface
{
$response = $next($request);

$response->getBody()
->write(':middleware_one');
$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':middleware_one');

return $response;
}
Expand Down
Expand Up @@ -15,8 +15,11 @@ protected function handle(Request $request, NextMiddleware $next): ResponseInter
{
$response = $next($request);

$response->getBody()
->write(':middleware_three');
$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':middleware_three');

return $response;
}
Expand Down
Expand Up @@ -15,8 +15,11 @@ protected function handle(Request $request, NextMiddleware $next): ResponseInter
{
$response = $next($request);

$response->getBody()
->write(':middleware_two');
$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':middleware_two');

return $response;
}
Expand Down
Expand Up @@ -28,6 +28,8 @@
use Snicco\Component\HttpRouting\Tests\helpers\CreateTestPsr17Factories;
use Snicco\Component\Psr7ErrorHandler\HttpErrorHandler;

use const SEEK_END;

/**
* @internal
*/
Expand Down Expand Up @@ -177,10 +179,11 @@ public function middleware_can_break_out_of_the_middleware_stack(): void
*/
public function middleware_can_be_resolved_from_the_container(): void
{
$this->pimple[MiddlewareWithDependencies::class] = fn (): MiddlewareWithDependencies => new MiddlewareWithDependencies(
new Foo('FOO'),
new Bar('BAR')
);
$this->pimple[MiddlewareWithDependencies::class] =
fn (): MiddlewareWithDependencies => new MiddlewareWithDependencies(
new Foo('FOO'),
new Bar('BAR')
);

$response = $this->pipeline
->send($this->request)
Expand Down Expand Up @@ -348,8 +351,12 @@ public function __construct(string $value_to_add = 'foo')
protected function handle(Request $request, NextMiddleware $next): ResponseInterface
{
$response = $next($request->withAttribute(self::ATTRIBUTE, $this->value_to_add));
$response->getBody()
->write(':pm1');

$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':pm1');

return $response;
}
Expand All @@ -372,8 +379,12 @@ public function __construct(string $value_to_add = 'bar')
protected function handle(Request $request, NextMiddleware $next): ResponseInterface
{
$response = $next->process($request->withAttribute(self::ATTRIBUTE, $this->value_to_add), $next);
$response->getBody()
->write(':pm2');

$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':pm2');

return $response;
}
Expand Down
Expand Up @@ -18,6 +18,8 @@
use Snicco\Component\HttpRouting\Tests\fixtures\TestDependencies\Foo;
use Snicco\Component\HttpRouting\Tests\HttpRunnerTestCase;

use const SEEK_END;

/**
* @internal
*/
Expand Down Expand Up @@ -159,8 +161,11 @@ protected function handle(Request $request, NextMiddleware $next): ResponseInter
{
$response = $next($request);

$response->getBody()
->write(':' . $this->foo->value . $this->bar->value . $this->baz . $this->biz);
$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':' . $this->foo->value . $this->bar->value . $this->baz . $this->biz);

return $response;
}
Expand Down
Expand Up @@ -7,6 +7,7 @@
use Psr\Http\Message\ResponseInterface;
use Snicco\Component\HttpRouting\Http\Psr7\Request;
use Snicco\Component\HttpRouting\Middleware\Middleware;
use Snicco\Component\HttpRouting\Middleware\NextMiddleware;

final class BarMiddleware extends Middleware
{
Expand All @@ -17,12 +18,15 @@ public function __construct(string $bar = 'bar_middleware')
$this->bar = $bar;
}

protected function handle(Request $request, $next): ResponseInterface
protected function handle(Request $request, NextMiddleware $next): ResponseInterface
{
$response = $next($request);

$response->getBody()
->write(':' . $this->bar);
$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':' . $this->bar);

return $response;
}
Expand Down
Expand Up @@ -7,6 +7,7 @@
use Psr\Http\Message\ResponseInterface;
use Snicco\Component\HttpRouting\Http\Psr7\Request;
use Snicco\Component\HttpRouting\Middleware\Middleware;
use Snicco\Component\HttpRouting\Middleware\NextMiddleware;

final class BazMiddleware extends Middleware
{
Expand All @@ -17,12 +18,14 @@ public function __construct(string $baz = 'baz_middleware')
$this->baz = $baz;
}

protected function handle(Request $request, $next): ResponseInterface
protected function handle(Request $request, NextMiddleware $next): ResponseInterface
{
$response = $next($request);

$response->getBody()
->write(':' . $this->baz);
$body = $response->getBody();
$body->seek(0, SEEK_END);

$body->write(':' . $this->baz);

return $response;
}
Expand Down
Expand Up @@ -22,8 +22,10 @@ protected function handle(Request $request, NextMiddleware $next): ResponseInter
{
$response = $next($request);

$response->getBody()
->write(':' . $this->val);
$body = $response->getBody();
$body->seek(0, SEEK_END);

$body->write(':' . $this->val);

return $response;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Snicco/Component/http-routing/tests/fixtures/FooMiddleware.php
Expand Up @@ -8,6 +8,10 @@
use Snicco\Component\HttpRouting\Http\Psr7\Request;
use Snicco\Component\HttpRouting\Middleware\Middleware;

use Snicco\Component\HttpRouting\Middleware\NextMiddleware;

use const SEEK_END;

final class FooMiddleware extends Middleware
{
public string $foo;
Expand All @@ -17,12 +21,15 @@ public function __construct(string $foo = 'foo_middleware')
$this->foo = $foo;
}

protected function handle(Request $request, $next): ResponseInterface
protected function handle(Request $request, NextMiddleware $next): ResponseInterface
{
$response = $next($request);

$response->getBody()
->write(':' . $this->foo);
$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':' . $this->foo);

return $response;
}
Expand Down
Expand Up @@ -8,6 +8,10 @@
use Snicco\Component\HttpRouting\Http\Psr7\Request;
use Snicco\Component\HttpRouting\Middleware\Middleware;

use Snicco\Component\HttpRouting\Middleware\NextMiddleware;

use const SEEK_END;

final class FoobarMiddleware extends Middleware
{
private string $val;
Expand All @@ -21,12 +25,14 @@ public function __construct(string $foo = null, string $bar = null)
}
}

protected function handle(Request $request, $next): ResponseInterface
protected function handle(Request $request, NextMiddleware $next): ResponseInterface
{
$response = $next($request);

$response->getBody()
->write(':' . $this->val);
$body = $response->getBody();
$body->seek(0, SEEK_END);

$body->write(':' . $this->val);

return $response;
}
Expand Down
Expand Up @@ -22,8 +22,11 @@ protected function handle(Request $request, NextMiddleware $next): ResponseInter
{
$response = $next($request);

$response->getBody()
->write(':' . $this->val);
$body = $response->getBody();

$body->seek(0, SEEK_END);

$body->write(':' . $this->val);

return $response;
}
Expand Down
Expand Up @@ -11,6 +11,8 @@
use Snicco\Component\HttpRouting\Tests\fixtures\TestDependencies\Bar;
use Snicco\Component\HttpRouting\Tests\fixtures\TestDependencies\Foo;

use const SEEK_END;

final class MiddlewareWithDependencies extends Middleware
{
public Foo $foo;
Expand All @@ -27,8 +29,9 @@ protected function handle(Request $request, NextMiddleware $next): ResponseInter
{
$response = $next($request);

$response->getBody()
->write(':' . $this->foo->value . $this->bar->value);
$body = $response->getBody();
$body->seek(0, SEEK_END);
$body->write(':' . $this->foo->value . $this->bar->value);

return $response;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Snicco/Component/kernel/src/ValueObject/Directories.php
Expand Up @@ -7,6 +7,7 @@
use Webmozart\Assert\Assert;

use function sprintf;

use const DIRECTORY_SEPARATOR;

/**
Expand Down Expand Up @@ -36,7 +37,7 @@ public function __construct(string $base_directory, string $config_dir, string $
Assert::writable($cache_dir, sprintf('$cache_dir [%s] is not writable.', $cache_dir));

Assert::readable($log_dir, sprintf('$log_dir [%s] is not readable.', $log_dir));
Assert::writable($cache_dir, sprintf('$log_dir [%s] is not writable.', $cache_dir));
Assert::writable($log_dir, sprintf('$log_dir [%s] is not writable.', $log_dir));

$this->config_dir = rtrim($config_dir, DIRECTORY_SEPARATOR);
$this->cache_dir = rtrim($cache_dir, DIRECTORY_SEPARATOR);
Expand Down
2 changes: 1 addition & 1 deletion src/Snicco/Testing/better-wp-cli/src/CommandTester.php
Expand Up @@ -125,7 +125,7 @@ public function run(array $positional_args = [], array $associative_args = [], a
$command::synopsis(),
$positional_args,
$associative_args,
$this->getInMemoryStream('r+', $this->options['input'] ?? []),
$this->getInMemoryStream('r+', $options['input'] ?? []),
$options[self::INTERACTIVE] ?? false,
);

Expand Down

0 comments on commit 87b9fde

Please sign in to comment.