Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test suite and add dummy #[PHP8] attribute #225

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 17 additions & 145 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ public function __invoke(): ResponseInterface
}
};

$fn = null;
$fn = $data = null;
$fn = #[PHP8] fn(mixed $data = 42) => new Response(200, [], (string) json_encode($data)); // @phpstan-ignore-line
$container = new Container([
ResponseInterface::class => $fn,
Expand Down Expand Up @@ -1269,17 +1269,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesUnknow
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1301,17 +1293,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesRecurs
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1333,17 +1317,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesString
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class('') {
/** @var string */
private $data;

public function __construct(string $stdClass)
{
$this->data = $stdClass;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert(is_string($stdClass));
}
};

Expand All @@ -1367,17 +1343,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesVariab
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1402,17 +1370,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesObject
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1435,17 +1395,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesString
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1468,17 +1420,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesIntVar
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1501,17 +1445,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesFloatV
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1534,17 +1470,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesBoolVa
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1567,17 +1495,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesClassN
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1597,17 +1517,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesNullab
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var ?\stdClass */
private $data;

public function __construct(?\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1627,17 +1539,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesClassN
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1657,17 +1561,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesClassN
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1687,17 +1583,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesNullab
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var ?\stdClass */
private $data;

public function __construct(?\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1717,17 +1605,9 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryReferencesClassM
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class(new \stdClass()) {
/** @var \stdClass */
private $data;

public function __construct(\stdClass $data)
{
$this->data = $data;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert($data instanceof \stdClass);
}
};

Expand All @@ -1747,17 +1627,9 @@ public function testCallableReturnsCallableThatThrowsWhenConstructorWithoutFacto
$request = new ServerRequest('GET', 'http://example.com/');

$controller = new class('Alice') {
/** @var string */
private $data;

public function __construct(string $name)
{
$this->data = $name;
}

public function __invoke(ServerRequestInterface $request): Response
{
return new Response(200, [], (string) json_encode($this->data));
assert(is_string($name));
}
};

Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/InvalidConstructorIntersection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace FrameworkX\Tests\Fixtures;

use FrameworkX\Tests\PHP8;

/** PHP 8.1+ **/
class InvalidConstructorIntersection
{
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/InvalidConstructorUnion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace FrameworkX\Tests\Fixtures;

use FrameworkX\Tests\PHP8;

/** PHP 8.0+ **/
class InvalidConstructorUnion
{
Expand Down
13 changes: 13 additions & 0 deletions tests/PHP8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace FrameworkX\Tests;

/** Dummy attribute used to comment out code for PHP < 8 to ensure compatibility across test matrix */
#[\Attribute]
class PHP8
{
public function __construct()
{
assert(\PHP_VERSION_ID >= 80000);
}
}