Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmajkl committed Oct 5, 2022
1 parent e7cf884 commit d590334
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/Lemon/Debug/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Lemon\Debug;

use Closure;
use Lemon\Contracts\Config\Config;
use Lemon\Contracts\Debug\Dumper as DumperContract;
use Lemon\Debug\Exceptions\DebugerException;
use Closure;

class Dumper implements DumperContract
{
Expand Down Expand Up @@ -102,13 +102,14 @@ private function parseObject(object $object): string
$class = $object::class;
$result = '<div class="ldg-object"><details open><summary>'.$class.' [</summary>';

// This allows us to get private properties in dumped object.
// This allows us to get private properties in dumped object.
// Don't use this exploit in production.
$result .= Closure::fromCallable(function(Dumper $dumper) {
$result .= Closure::fromCallable(function (Dumper $dumper) {
$result = '';
foreach (get_class_vars($this::class) as $property => $_) {
$result .= '<span class="ldg-property"><span class="ldg-property-name">'.$property.'</span> => '.$dumper->resolve($this->{$property} ?? null).'</span>';
}

return $result;
})->call($object, $this);

Expand Down
2 changes: 1 addition & 1 deletion src/Lemon/Http/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public function __construct(
public readonly int $error,
public readonly int $size
) {

}

public function read(): string
Expand All @@ -24,6 +23,7 @@ public function read(): string
public function copy(string $new): static
{
copy($this->tmp_path, $new);

return $this;
}
}
4 changes: 2 additions & 2 deletions src/Lemon/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function capture(): self
getallheaders(),
file_get_contents('php://input'),
$_COOKIE,
array_map(fn($item) => new File(...$item), $_FILES)
array_map(fn ($item) => new File(...$item), $_FILES)
);
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public function cookies()
public function file(string $name): ?File
{
return $this->files[$name] ?? null;
}
}

public function hasFile(string $name): bool
{
Expand Down
3 changes: 2 additions & 1 deletion src/Lemon/Kernel/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class Application extends Container
/**
* Current Lemon version.
*/
public const VERSION = '3.6.1';
public const VERSION = '3.6.4';

/**
* Default units with aliases.
Expand Down Expand Up @@ -84,6 +84,7 @@ public function __get(string $name): object
if (!$this->has($name)) {
throw new Exception('Undefined property: '.self::class.'::$'.$name);
}

return $this->get($name);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Lemon/Testing/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ class Mock

public function __construct(string $class)
{
/** @phpstan-ignore-next-line */
// @phpstan-ignore-next-line
$this->mock = Mockery::mock($class);
}

public function expect(callable ...$methods): MockInterface
{
foreach ($methods as $method => $action) {
/** @phpstan-ignore-next-line */
// @phpstan-ignore-next-line
$this->mock->shouldReceive($method)
->andReturnUsing($action)
->andReturnUsing($action)
;
}

return $this->mock;
}
}
2 changes: 1 addition & 1 deletion src/Lemon/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function mock(string $class, string ...$aliases): Mock
}

return $mock;
}
}

public function request(string $path, string $method = 'GET', array $headers = [], array $cookies = [], string $body = '', array $files = []): TestResponse
{
Expand Down
7 changes: 7 additions & 0 deletions src/Lemon/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ public function __construct(
public function assertStatus(int $expected): self
{
$this->testCase->assertSame($expected, $this->response->code());

return $this;
}

public function assertOK(): self
{
$this->assertStatus(200);

return $this;
}

public function assertBody(mixed $expected): self
{
$this->testCase->assertSame($expected, $this->response->body);

return $this;
}

Expand All @@ -44,18 +47,21 @@ public function assertTemplate(string $expected_name): self
$path = $this->factory->getRawPath($expected_name);

$this->testCase->assertSame($path, $this->response->body->raw_path);

return $this;
}

public function assertHeader(string $header, string $expected): self
{
$this->testCase->assertSame($expected, $this->response->header($header));

return $this;
}

public function assertLocation(string $expected): self
{
$this->assertHeader('Location', $expected);

return $this;
}

Expand All @@ -65,6 +71,7 @@ public function assertCookie(string $cookie, string $expected): self
$expected,
array_filter($this->response->cookies(), fn ($item) => $item[0] === $cookie)[0][1] ?? null
);

return $this;
}
}
2 changes: 1 addition & 1 deletion tests/Testing/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testRequest()
public function testMock()
{
$this->mock(Foo::class, 'foo')
->expect(bar: fn() => 'cs')
->expect(bar: fn () => 'cs')
;

$this->assertSame('cs', $this->application->get(Foo::class)->bar());
Expand Down

0 comments on commit d590334

Please sign in to comment.