diff --git a/.gitattributes b/.gitattributes index 7b964c51..05fc1b50 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,15 +1,17 @@ /tests export-ignore -/tests-php8 export-ignore +/tests-deprecated export-ignore /demo export-ignore -/vendor-bin export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.scrutinizer.yml export-ignore +/codecov.yml export-ignore +/composer-require-checker.json export-ignore /phpcs.xml export-ignore /phpmd.xml export-ignore /phpstan.neon export-ignore /phpunit.xml.dist export-ignore /psalm.xml export-ignore +/rector.php export-ignore å # Configure diff output for .php and .phar files. *.php diff=php diff --git a/composer-require-checker.json b/composer-require-checker.json index 3eb309b9..a484094c 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -4,7 +4,6 @@ "static", "self", "parent", "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "Attribute", "ReflectionAttribute", "Stringable", - "BEAR\\Resource\\HalLink", "BEAR\\Resource\\NullReverseLink", "BEAR\\Resource\\ReverseLinkInterface", "BEAR\\Resource\\Module\\AnnotationModule", - "Doctrine\\Common\\Annotations\\Reader", "Doctrine\\Common\\Annotations\\AnnotationReader" + "BEAR\\Resource\\HalLink", "BEAR\\Resource\\NullReverseLink", "BEAR\\Resource\\ReverseLinkInterface", "BEAR\\Resource\\Module\\AnnotationModule" ] } diff --git a/composer.json b/composer.json index 64eb0b18..da704d28 100644 --- a/composer.json +++ b/composer.json @@ -55,12 +55,12 @@ "psr-4": { "BEAR\\Resource\\": [ "tests/", - "tests-php8/", - "tests/Fake/" + "tests/Fake/", + "tests-deprecated" ], "FakeVendor\\Sandbox\\": "tests/Fake/FakeVendor/Sandbox/", "FakeVendor\\Blog\\": "tests/Fake/FakeVendor/Blog/src", - "FakeVendor\\News\\": "tests-php8/Fake/News/src" + "FakeVendor\\News\\": "tests/Fake/FakeVendor/News/src" }, "files": ["tests/Fake/AppInjector.php"] }, diff --git a/phpstan.neon b/phpstan.neon index 89d07a43..9ed99839 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,7 +7,5 @@ parameters: - '%currentWorkingDirectory%/tests/tmp/*' - '%currentWorkingDirectory%/tests/Module/tmp/*' - '%currentWorkingDirectory%/tests/Fake/*' - - tests/HttpResourceObjectTest.php - - tests/HalLinkerTest.php ignoreErrors: - '#Access to an undefined property#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 933ae401..f227f0bf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,6 @@ tests - tests-php8 diff --git a/psalm.xml b/psalm.xml index 727599d1..23ca3862 100644 --- a/psalm.xml +++ b/psalm.xml @@ -13,7 +13,6 @@ - diff --git a/src-deprecated/JsonSchemalModule.php b/src-deprecated/Module/JsonSchemalModule.php similarity index 100% rename from src-deprecated/JsonSchemalModule.php rename to src-deprecated/Module/JsonSchemalModule.php diff --git a/src/JsonSchema/Module/JsonSchemaModule.php b/src/JsonSchema/Module/JsonSchemaModule.php index 26d61b80..c76740a2 100644 --- a/src/JsonSchema/Module/JsonSchemaModule.php +++ b/src/JsonSchema/Module/JsonSchemaModule.php @@ -12,7 +12,7 @@ use BEAR\Resource\ResourceObject; use Ray\Di\AbstractModule; -final class JsonSchemaModule extends AbstractModule +class JsonSchemaModule extends AbstractModule { /** * @param string $jsonSchemaDir Json-schema json file directory diff --git a/tests/HalLinkTest.php b/tests-deprecated/HalLinkTest.php similarity index 100% rename from tests/HalLinkTest.php rename to tests-deprecated/HalLinkTest.php diff --git a/tests/HalLinkerTest.php b/tests-deprecated/HalLinkerTest.php similarity index 100% rename from tests/HalLinkerTest.php rename to tests-deprecated/HalLinkerTest.php diff --git a/src-deprecated/JsonSchemalModuleTest.php b/tests-deprecated/Module/JsonSchemalModuleTest.php similarity index 92% rename from src-deprecated/JsonSchemalModuleTest.php rename to tests-deprecated/Module/JsonSchemalModuleTest.php index 1ad4c6db..596899dd 100644 --- a/src-deprecated/JsonSchemalModuleTest.php +++ b/tests-deprecated/Module/JsonSchemalModuleTest.php @@ -55,7 +55,7 @@ public function testBCValidateException() public function testBCValidateErrorException(JsonSchemaException $e) { $expected = '[age] Must have a minimum value of 20'; - $this->assertContains($expected, $e->getMessage()); + $this->assertStringContainsString($expected, $e->getMessage()); } public function testException() @@ -114,9 +114,9 @@ private function getFakeUsers() : FakeUsers private function getRo(string $class) { - $jsonSchema = dirname(__DIR__) . '/Fake/json_schema'; - $jsonValidate = dirname(__DIR__) . '/Fake/json_validate'; - $ro = (new Injector(new JsonSchemalModule($jsonSchema, $jsonValidate), $_ENV['TMP_DIR']))->getInstance($class); + $jsonSchema = dirname(__DIR__) . '/../tests/Fake/json_schema'; + $jsonValidate = dirname(__DIR__) . '/../tests/Fake/json_validate'; + $ro = (new Injector(new JsonSchemalModule($jsonSchema, $jsonValidate)))->getInstance($class); /* @var $ro FakeUser */ $ro->uri = new Uri('app://self/user?id=1'); diff --git a/tests-php8/tmp/.gitkeep b/tests-php8/tmp/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/tests-php8/AttrNamedParameterTest.php b/tests/AttrNamedParameterTest.php similarity index 67% rename from tests-php8/AttrNamedParameterTest.php rename to tests/AttrNamedParameterTest.php index 661d3d2d..a182d939 100644 --- a/tests-php8/AttrNamedParameterTest.php +++ b/tests/AttrNamedParameterTest.php @@ -5,48 +5,43 @@ namespace BEAR\Resource; use BEAR\Resource\Exception\ParameterException; -use Doctrine\Common\Cache\ArrayCache; use FakeVendor\News\Resource\App\AttrWebContext; -use Koriym\Attributes\AttributeReader; use PHPUnit\Framework\TestCase; use Ray\Di\Injector; -use Ray\ServiceLocator\ServiceLocator; - -use function call_user_func_array; class AttrNamedParameterTest extends TestCase { private NamedParameter $params; - /** @var FakeAttrContext */ - private $ro; - protected function setUp(): void { parent::setUp(); - $this->params = new NamedParameter(new NamedParamMetas(new AttributeReader()), new Injector()); - $this->ro = new AttrWebContext(); + + $this->params = new NamedParameter(new NamedParamMetas(), new Injector()); } public function testGetParameters(): void { + $object = new AttrWebContext(); $namedArgs = ['id' => 1, 'name' => 'koriym']; - $args = $this->params->getParameters([$this->ro, 'onGet'], $namedArgs); + $args = $this->params->getParameters([$object, 'onGet'], $namedArgs); $this->assertSame(['id' => 1, 'name' => 'koriym'], $args); } public function testDefaultValue(): void { + $object = new AttrWebContext(); $namedArgs = ['id' => 1]; - $args = $this->params->getParameters([$this->ro, 'onGet'], $namedArgs); + $args = $this->params->getParameters([$object, 'onGet'], $namedArgs); $this->assertSame(['id' => 1, 'name' => 'koriym'], $args); } public function testParameterException(): void { + $object = new AttrWebContext(); $this->expectException(ParameterException::class); $namedArgs = []; - $this->params->getParameters([$this->ro, 'onGet'], $namedArgs); + $this->params->getParameters([$object, 'onGet'], $namedArgs); } public function testParameterWebContext(): void @@ -64,9 +59,10 @@ public function testParameterWebContext(): void 'env' => 'env_val', 'form' => 'post_val', 'query' => 'get_val', - 'server' => 'server_val' + 'server' => 'server_val', ]; - $args = $this->params->getParameters([$this->ro, 'onPost'], []); + $object = new AttrWebContext(); + $args = $this->params->getParameters([$object, 'onPost'], []); $this->assertSame($expected, $args); } @@ -74,7 +70,8 @@ public function testParameterWebContextNotExits(): void { $this->expectException(ParameterException::class); AssistedWebContextParam::setSuperGlobalsOnlyForTestingPurpose([]); - $this->params->getParameters([$this->ro, 'onPut'], ['cookie' => 1]); // should be ignored + $object = new AttrWebContext(); + $this->params->getParameters([$object, 'onPut'], ['cookie' => 1]); // should be ignored } public function testParameterWebContextDefault(): void @@ -82,9 +79,10 @@ public function testParameterWebContextDefault(): void AssistedWebContextParam::setSuperGlobalsOnlyForTestingPurpose([]); $expected = [ 'a' => 1, - 'cookie' => 'default' + 'cookie' => 'default', ]; - $args = $this->params->getParameters([$this->ro, 'onDelete'], ['a' => 1]); + $object = new AttrWebContext(); + $args = $this->params->getParameters([$object, 'onDelete'], ['a' => 1]); $this->assertSame($expected, $args); } @@ -92,8 +90,7 @@ public function testParameterWebContexRequiredNotGiven(): void { $this->expectException(ParameterException::class); AssistedWebContextParam::setSuperGlobalsOnlyForTestingPurpose([]); - $this->ro = new FakeParamResource(); - $this->params->getParameters([$this->ro, 'onDelete'], []); + $object = new FakeParamResource(); + $this->params->getParameters([$object, 'onDelete'], []); } - } diff --git a/tests-php8/AttributeTest.php b/tests/AttributeTest.php similarity index 81% rename from tests-php8/AttributeTest.php rename to tests/AttributeTest.php index 8a57931f..e04ad447 100644 --- a/tests-php8/AttributeTest.php +++ b/tests/AttributeTest.php @@ -4,33 +4,22 @@ namespace BEAR\Resource; -use BEAR\Resource\Exception\MethodNotAllowedException; -use BEAR\Resource\Module\HalModule; use BEAR\Resource\Module\ResourceModule; -use Doctrine\Common\Annotations\AnnotationReader; -use FakeVendor\News\Resource\App\Event; use FakeVendor\News\Resource\App\News; use FakeVendor\News\Resource\App\WebParam; -use FakeVendor\Sandbox\Resource\App\Blog; -use FakeVendor\Sandbox\Resource\App\Href\Hasembed; -use FakeVendor\Sandbox\Resource\App\Href\Origin; -use FakeVendor\Sandbox\Resource\App\Href\Target; -use FakeVendor\Sandbox\Resource\Page\Index; use PHPUnit\Framework\TestCase; use Ray\Di\Injector; -use Ray\Di\NullModule; use function assert; -use function var_dump; -use function var_export; class AttributeTest extends TestCase { - private \BEAR\Resource\ResourceInterface $resource; + private ResourceInterface $resource; - protected function setUp() : void + protected function setUp(): void { parent::setUp(); + $injector = new Injector(new ResourceModule('FakeVendor\News'), __DIR__ . '/tmp'); $this->resource = $injector->getInstance(ResourceInterface::class); } @@ -44,9 +33,7 @@ public function testNewInstance(): News return $instance; } - /** - * @depends testNewInstance - */ + /** @depends testNewInstance */ public function testEmbeded(News $news): void { $ro = $news->onGet('2021/7/23'); @@ -55,7 +42,6 @@ public function testEmbeded(News $news): void /** * @depends testNewInstance - * * @see ResourceTest::testLinkSelf() */ public function testLink(News $news): void @@ -66,6 +52,7 @@ public function testLink(News $news): void $this->assertSame(LinkType::SELF_LINK, $request->links[0]->type); $ro = $request(); $this->assertSame(200, $ro->code); + $this->assertIsArray($ro->body); $this->assertArrayHasKey('event', $ro->body); $this->assertSame('2021/7/23', $ro->body['event']); } diff --git a/tests-php8/Fake/News/src/Resource/App/AttrWebContext.php b/tests/Fake/FakeVendor/News/src/Resource/App/AttrWebContext.php similarity index 100% rename from tests-php8/Fake/News/src/Resource/App/AttrWebContext.php rename to tests/Fake/FakeVendor/News/src/Resource/App/AttrWebContext.php diff --git a/tests-php8/Fake/News/src/Resource/App/Event.php b/tests/Fake/FakeVendor/News/src/Resource/App/Event.php similarity index 100% rename from tests-php8/Fake/News/src/Resource/App/Event.php rename to tests/Fake/FakeVendor/News/src/Resource/App/Event.php diff --git a/tests-php8/Fake/News/src/Resource/App/Greeting.php b/tests/Fake/FakeVendor/News/src/Resource/App/Greeting.php similarity index 100% rename from tests-php8/Fake/News/src/Resource/App/Greeting.php rename to tests/Fake/FakeVendor/News/src/Resource/App/Greeting.php diff --git a/tests-php8/Fake/News/src/Resource/App/Login.php b/tests/Fake/FakeVendor/News/src/Resource/App/Login.php similarity index 100% rename from tests-php8/Fake/News/src/Resource/App/Login.php rename to tests/Fake/FakeVendor/News/src/Resource/App/Login.php diff --git a/tests-php8/Fake/News/src/Resource/App/News.php b/tests/Fake/FakeVendor/News/src/Resource/App/News.php similarity index 100% rename from tests-php8/Fake/News/src/Resource/App/News.php rename to tests/Fake/FakeVendor/News/src/Resource/App/News.php diff --git a/tests-php8/Fake/News/src/Resource/App/Weather.php b/tests/Fake/FakeVendor/News/src/Resource/App/Weather.php similarity index 100% rename from tests-php8/Fake/News/src/Resource/App/Weather.php rename to tests/Fake/FakeVendor/News/src/Resource/App/Weather.php diff --git a/tests-php8/Fake/News/src/Resource/App/WebParam.php b/tests/Fake/FakeVendor/News/src/Resource/App/WebParam.php similarity index 100% rename from tests-php8/Fake/News/src/Resource/App/WebParam.php rename to tests/Fake/FakeVendor/News/src/Resource/App/WebParam.php diff --git a/tests-php8/Fake/News/var/tmp/.placefolder b/tests/Fake/FakeVendor/News/var/tmp/.placefolder similarity index 100% rename from tests-php8/Fake/News/var/tmp/.placefolder rename to tests/Fake/FakeVendor/News/var/tmp/.placefolder diff --git a/tests/NamedParameterTest.php b/tests/NamedParameterTest.php index 722cb6a8..158df760 100644 --- a/tests/NamedParameterTest.php +++ b/tests/NamedParameterTest.php @@ -112,7 +112,6 @@ public function testCameCaseParam(): void $this->assertSame(['userId' => 'koriym', 'userRole' => 'lead'], (array) $ro->body); } - /** @requires PHP >= 8.1 */ public function testEnumParam(): void { $ro = new EnumParam(); @@ -130,7 +129,6 @@ public function testEnumParam(): void ); } - /** @requires PHP >= 8.1 */ public function testEnumInvlidType(): void { $this->expectException(ParameterEnumTypeException::class); @@ -140,7 +138,6 @@ public function testEnumInvlidType(): void $this->params->getParameters([$ro, 'onGet'], $params); } - /** @requires PHP >= 8.1 */ public function testWithResourceClient(): void { $resource = (new Injector(new ResourceModule('FakeVendor\Sandbox')))->getInstance(ResourceInterface::class); @@ -150,7 +147,6 @@ public function testWithResourceClient(): void $this->assertSame(['stringBacked' => 'foo', 'intBacked' => 1], $body); } - /** @requires PHP >= 8.1 */ public function testEnumParamWithResourceClient(): void { $this->expectException(ParameterInvalidEnumException::class); @@ -160,7 +156,6 @@ public function testEnumParamWithResourceClient(): void $resource->get('page://self/enum-param', $params); } - /** @requires PHP >= 8.1 */ public function testNotBackedEnumParamWithResourceClient(): void { $this->expectException(NotBackedEnumException::class); diff --git a/tests/ShortSyntaxTest.php b/tests/ShortSyntaxTest.php index 0422e7e4..cd0fea54 100644 --- a/tests/ShortSyntaxTest.php +++ b/tests/ShortSyntaxTest.php @@ -21,7 +21,6 @@ protected function setUp(): void $this->resource = $injector->getInstance(ResourceInterface::class); } - /** @requires PHP 7.0.0 */ public function testShortSyntax(): void { $ro = $this->resource->get('page://self/index', ['id' => 'koriym']); @@ -29,7 +28,6 @@ public function testShortSyntax(): void $this->assertSame('koriym', $ro->body); } - /** @requires PHP 7.0.0 */ public function testShortSyntaxWithQuery(): void { $ro = $this->resource->get->uri('page://self/index?id=koriym')(); @@ -63,7 +61,6 @@ public function testShortSyntaxReuseRequest(AbstractRequest $index): void $this->assertSame('bear', $ro->body); } - /** @requires PHP 7.0.0 */ public function testShortSyntaxFunctionWithDefaultGetMethod(): void { $ro = $this->resource->uri('page://self/index')();