From 3fd53e58c8e6d5c56a990b8ab5e8e709bf79d376 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 11:06:46 +0900 Subject: [PATCH 01/20] Support mobiledetect v3 --- composer.json | 2 +- src/MobileTemplateFinder.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f5f2cf8..593b8d3 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "bear/sunday": "^1.2", "bear/app-meta": "^1.1", "twig/twig": "^2.15.3 || ^v3.4.3", - "mobiledetect/mobiledetectlib": "^2.7", + "mobiledetect/mobiledetectlib": "^2.7 || ^3.74", "ray/di": "^2.7", "doctrine/annotations": "^1.13.3" }, diff --git a/src/MobileTemplateFinder.php b/src/MobileTemplateFinder.php index 14acc92..c558fcf 100644 --- a/src/MobileTemplateFinder.php +++ b/src/MobileTemplateFinder.php @@ -4,8 +4,8 @@ namespace Madapaja\TwigModule; +use Detection\MobileDetect; use Madapaja\TwigModule\Annotation\TwigPaths; -use Mobile_Detect; use function file_exists; use function sprintf; @@ -29,7 +29,8 @@ public function __construct( public function __invoke(string $name): string { $templatePath = ($this->templateFinder)($name); - $detect = new Mobile_Detect(null, $this->userAgent); + $isMobileDetectV3 = class_exists(MobileDetect::class); + $detect = $isMobileDetectV3 ? new MobileDetect(null, $this->userAgent) : new \Mobile_Detect(null, $this->userAgent); $isMobile = $detect->isMobile() && ! $detect->isTablet(); if ($isMobile) { $mobilePath = str_replace(TwigRenderer::EXT, '.mobile.twig', $templatePath); From dd65fbc35c56c6d02c1a8661a708d363a7812386 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 11:07:01 +0900 Subject: [PATCH 02/20] Support doctrine/annotation v2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 593b8d3..a9937e0 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "twig/twig": "^2.15.3 || ^v3.4.3", "mobiledetect/mobiledetectlib": "^2.7 || ^3.74", "ray/di": "^2.7", - "doctrine/annotations": "^1.13.3" + "doctrine/annotations": "^1.13.3 || ^2.0" }, "require-dev": { "phpunit/phpunit": "^9.5.21", From ea4f1e6f245653eab4f397028f5858b8b55a960c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 11:47:36 +0900 Subject: [PATCH 03/20] Refactor: Use same param name with interface --- src/TemplateFinder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TemplateFinder.php b/src/TemplateFinder.php index 3763899..f84bfc5 100644 --- a/src/TemplateFinder.php +++ b/src/TemplateFinder.php @@ -13,10 +13,10 @@ class TemplateFinder implements TemplateFinderInterface /** * {@inheritdoc} */ - public function __invoke(string $resourceFilePath): string + public function __invoke(string $name): string { - $pos = strpos($resourceFilePath, '/Resource/'); - $relativePath = substr($resourceFilePath, $pos + 10); + $pos = strpos($name, '/Resource/'); + $relativePath = substr($name, $pos + 10); return str_replace('.php', TwigRenderer::EXT, $relativePath); } From 2fa21a68374f937dd7d4b3360be6e5bd57a3ebbf Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 15:52:41 +0900 Subject: [PATCH 04/20] Create MobileDetect on invoke User-Agent should be retrieved every time --- composer.json | 4 ++-- psalm.xml | 7 +++++++ src/MobileTemplateFinder.php | 19 ++++++++++++------- src/MobileTwigModule.php | 1 + tests/MobileTemplateFinderTest.php | 20 +++++++++++++++----- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index a9937e0..cfc2377 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ ], "require": { "php": "^8.0", - "bear/resource": "^1.15.2", + "bear/resource": "^1.20", "bear/sunday": "^1.2", - "bear/app-meta": "^1.1", + "bear/app-meta": "^1.8", "twig/twig": "^2.15.3 || ^v3.4.3", "mobiledetect/mobiledetectlib": "^2.7 || ^3.74", "ray/di": "^2.7", diff --git a/psalm.xml b/psalm.xml index b8a42df..50b16d2 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,6 +5,13 @@ xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" > + + + + + + + diff --git a/src/MobileTemplateFinder.php b/src/MobileTemplateFinder.php index c558fcf..695a2b0 100644 --- a/src/MobileTemplateFinder.php +++ b/src/MobileTemplateFinder.php @@ -6,21 +6,23 @@ use Detection\MobileDetect; use Madapaja\TwigModule\Annotation\TwigPaths; +use Mobile_Detect; +use Ray\Di\Di\Named; +use function class_alias; +use function class_exists; use function file_exists; use function sprintf; use function str_replace; class MobileTemplateFinder implements TemplateFinderInterface { - private TemplateFinder $templateFinder; - public function __construct( - private mixed $userAgent = '', #[TwigPaths] - private array $paths = [], + private array $paths, + #[Named('original')] + private TemplateFinderInterface $templateFinder, ) { - $this->templateFinder = new TemplateFinder(); } /** @@ -28,9 +30,12 @@ public function __construct( */ public function __invoke(string $name): string { + if (! class_exists(MobileDetect::class)) { + class_alias(Mobile_Detect::class, MobileDetect::class); + } + + $detect = new MobileDetect(); $templatePath = ($this->templateFinder)($name); - $isMobileDetectV3 = class_exists(MobileDetect::class); - $detect = $isMobileDetectV3 ? new MobileDetect(null, $this->userAgent) : new \Mobile_Detect(null, $this->userAgent); $isMobile = $detect->isMobile() && ! $detect->isTablet(); if ($isMobile) { $mobilePath = str_replace(TwigRenderer::EXT, '.mobile.twig', $templatePath); diff --git a/src/MobileTwigModule.php b/src/MobileTwigModule.php index 95491f1..c61389a 100644 --- a/src/MobileTwigModule.php +++ b/src/MobileTwigModule.php @@ -14,5 +14,6 @@ class MobileTwigModule extends AbstractModule protected function configure() { $this->bind(TemplateFinderInterface::class)->to(MobileTemplateFinder::class); + $this->bind(TemplateFinderInterface::class)->annotatedWith('original')->to(TemplateFinder::class); } } diff --git a/tests/MobileTemplateFinderTest.php b/tests/MobileTemplateFinderTest.php index cb464a0..4eb9dfc 100644 --- a/tests/MobileTemplateFinderTest.php +++ b/tests/MobileTemplateFinderTest.php @@ -4,7 +4,10 @@ namespace Madapaja\TwigModule; +use BEAR\AppMeta\AbstractAppMeta; +use BEAR\AppMeta\Meta; use PHPUnit\Framework\TestCase; +use Ray\Di\AbstractModule; use Ray\Di\Injector; class MobileTemplateFinderTest extends TestCase @@ -13,14 +16,21 @@ class MobileTemplateFinderTest extends TestCase public function setUp(): void { - $this->injector = new Injector(new MobileTwigModule()); + $module = new MobileTwigModule(new TwigModule()); + $module->install(new class extends AbstractModule{ + protected function configure(): void + { + $this->bind(AbstractAppMeta::class)->toInstance(new Meta(__NAMESPACE__)); + } + }); + $this->injector = new Injector($module); } public function testMobileTemplate(): void { - $iphone = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25'; + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25'; $paths = [$_ENV['TEST_DIR'] . '/Fake/src/Resource']; - $templateFinder = new MobileTemplateFinder($iphone, $paths); + $templateFinder = new MobileTemplateFinder($paths, new TemplateFinder()); $file = ($templateFinder)($_ENV['TEST_DIR'] . '/Resource/Page/Index.php'); $expected = 'Page/Index.mobile.twig'; $this->assertSame($expected, $file); @@ -28,9 +38,9 @@ public function testMobileTemplate(): void public function testPcTemplate(): void { - $pc = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'; + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'; $paths = [$_ENV['TEST_DIR'] . '/Fake/src/Resource']; - $templateFinder = new MobileTemplateFinder($pc, $paths); + $templateFinder = new MobileTemplateFinder($paths, new TemplateFinder()); $file = ($templateFinder)($_ENV['TEST_DIR'] . '/Resource/Page/Index.php'); $expected = 'Page/Index.html.twig'; $this->assertSame($expected, $file); From 0a83e7873b932fa46af71c2d170d46bab16cf309 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 16:11:08 +0900 Subject: [PATCH 05/20] Update doctrine coding standard v12 --- composer.json | 2 +- src/AppPathProvider.php | 2 +- src/MobileTemplateFinder.php | 2 +- src/MobileTwigModule.php | 2 +- src/OptionProvider.php | 2 +- src/TemplateFinder.php | 2 +- src/TwigErrorHandler.php | 4 ++-- src/TwigErrorPageHandler.php | 4 ++-- src/TwigErrorPageModule.php | 2 +- src/TwigModule.php | 2 +- src/TwigRenderer.php | 2 +- tests/AppPathProviderTestModule.php | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index cfc2377..965a122 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "phpmd/phpmd": "^2.6", "rector/rector": "^0.15.3", "ray/rector-ray": "^1.0", - "doctrine/coding-standard": "^11.1", + "doctrine/coding-standard": "^12.0", "vimeo/psalm": "^5.4" }, "autoload":{ diff --git a/src/AppPathProvider.php b/src/AppPathProvider.php index 91e2bd1..51fa85b 100644 --- a/src/AppPathProvider.php +++ b/src/AppPathProvider.php @@ -16,7 +16,7 @@ public function __construct( } /** - * {@inheritdoc} + * {@inheritDoc} */ public function get(): array { diff --git a/src/MobileTemplateFinder.php b/src/MobileTemplateFinder.php index 695a2b0..44fd9c3 100644 --- a/src/MobileTemplateFinder.php +++ b/src/MobileTemplateFinder.php @@ -26,7 +26,7 @@ public function __construct( } /** - * {@inheritdoc} + * {@inheritDoc} */ public function __invoke(string $name): string { diff --git a/src/MobileTwigModule.php b/src/MobileTwigModule.php index c61389a..de88467 100644 --- a/src/MobileTwigModule.php +++ b/src/MobileTwigModule.php @@ -9,7 +9,7 @@ class MobileTwigModule extends AbstractModule { /** - * {@inheritdoc} + * {@inheritDoc} */ protected function configure() { diff --git a/src/OptionProvider.php b/src/OptionProvider.php index e55da26..4f00718 100644 --- a/src/OptionProvider.php +++ b/src/OptionProvider.php @@ -24,7 +24,7 @@ public function __construct( } /** - * {@inheritdoc} + * {@inheritDoc} */ public function get() { diff --git a/src/TemplateFinder.php b/src/TemplateFinder.php index f84bfc5..423cccc 100644 --- a/src/TemplateFinder.php +++ b/src/TemplateFinder.php @@ -11,7 +11,7 @@ class TemplateFinder implements TemplateFinderInterface { /** - * {@inheritdoc} + * {@inheritDoc} */ public function __invoke(string $name): string { diff --git a/src/TwigErrorHandler.php b/src/TwigErrorHandler.php index 4d09c3f..3776925 100644 --- a/src/TwigErrorHandler.php +++ b/src/TwigErrorHandler.php @@ -26,7 +26,7 @@ public function __construct( } /** - * {@inheritdoc} + * {@inheritDoc} */ public function handle(Throwable $e, Request $request) { @@ -56,7 +56,7 @@ public function handle(Throwable $e, Request $request) } /** - * {@inheritdoc} + * {@inheritDoc} */ public function transfer() { diff --git a/src/TwigErrorPageHandler.php b/src/TwigErrorPageHandler.php index f3cf3f6..0d30a09 100644 --- a/src/TwigErrorPageHandler.php +++ b/src/TwigErrorPageHandler.php @@ -28,7 +28,7 @@ public function __construct( } /** - * {@inheritdoc} + * {@inheritDoc} */ public function handle(Throwable $e, Request $request) { @@ -55,7 +55,7 @@ public function handle(Throwable $e, Request $request) } /** - * {@inheritdoc} + * {@inheritDoc} */ public function transfer() { diff --git a/src/TwigErrorPageModule.php b/src/TwigErrorPageModule.php index 36919a7..e64d8b9 100644 --- a/src/TwigErrorPageModule.php +++ b/src/TwigErrorPageModule.php @@ -12,7 +12,7 @@ class TwigErrorPageModule extends AbstractModule { /** - * {@inheritdoc} + * {@inheritDoc} */ protected function configure() { diff --git a/src/TwigModule.php b/src/TwigModule.php index c4e5721..98c8833 100644 --- a/src/TwigModule.php +++ b/src/TwigModule.php @@ -35,7 +35,7 @@ public function __construct( } /** - * {@inheritdoc} + * {@inheritDoc} */ protected function configure() { diff --git a/src/TwigRenderer.php b/src/TwigRenderer.php index 2317180..9602791 100644 --- a/src/TwigRenderer.php +++ b/src/TwigRenderer.php @@ -40,7 +40,7 @@ public function __construct( } /** - * {@inheritdoc} + * {@inheritDoc} */ public function render(ResourceObject $ro) { diff --git a/tests/AppPathProviderTestModule.php b/tests/AppPathProviderTestModule.php index 873312d..a9a8d99 100644 --- a/tests/AppPathProviderTestModule.php +++ b/tests/AppPathProviderTestModule.php @@ -12,7 +12,7 @@ class AppPathProviderTestModule extends AbstractModule { /** - * {@inheritdoc} + * {@inheritDoc} */ protected function configure() { From 4fcb8357d15aeab710b56eecafaa177f1c38b6d5 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 16:25:05 +0900 Subject: [PATCH 06/20] Add return type --- src/TwigModule.php | 2 +- src/TwigRenderer.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TwigModule.php b/src/TwigModule.php index 98c8833..7d87381 100644 --- a/src/TwigModule.php +++ b/src/TwigModule.php @@ -116,7 +116,7 @@ private function bindTwigRedirectPath(): void $this->bind()->annotatedWith(TwigRedirectPath::class)->toInstance('/redirect/redirect.html.twig'); } - private function isNotEmpty($var) + private function isNotEmpty($var): bool { return is_array($var) && ! empty($var); } diff --git a/src/TwigRenderer.php b/src/TwigRenderer.php index 9602791..d7a8a6d 100644 --- a/src/TwigRenderer.php +++ b/src/TwigRenderer.php @@ -72,14 +72,14 @@ private function setContentType(ResourceObject $ro): void $ro->headers['Content-Type'] = 'text/html; charset=utf-8'; } - private function renderView(ResourceObject $ro) + private function renderView(ResourceObject $ro): string { $template = $this->load($ro); return $template ? $template->render($this->buildBody($ro)) : ''; } - private function renderRedirectView(ResourceObject $ro) + private function renderRedirectView(ResourceObject $ro): string { try { return $this->twig->render($this->redirectPage, ['url' => $ro->headers['Location']]); From d107971d8e13a48a9585acd1d23fc2c26b1d26a4 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 18:55:23 +0900 Subject: [PATCH 07/20] Add TwigErrorPage --- tests/TwigErrorPageModuleTest.php | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/TwigErrorPageModuleTest.php diff --git a/tests/TwigErrorPageModuleTest.php b/tests/TwigErrorPageModuleTest.php new file mode 100644 index 0000000..675fda2 --- /dev/null +++ b/tests/TwigErrorPageModuleTest.php @@ -0,0 +1,39 @@ +install(new class extends AbstractModule{ + protected function configure(): void + { + $this->bind(LoggerInterface::class)->to(NullLogger::class); + $this->bind(TransferInterface::class)->to(FakeTransfer::class); + } + }); + $injector = (new Injector($module)); + $error = $injector->getInstance(ErrorInterface::class); + assert($error instanceof ErrorInterface); + $error->handle(new RuntimeException(), new RouterMatch())->transfer(); + $this->assertArrayHasKey('status', FakeTransfer::$ro->body); + $this->assertArrayHasKey('e', FakeTransfer::$ro->body); + $this->assertArrayHasKey('logref', FakeTransfer::$ro->body); + } +} From 82344f3d0e98e523d504258ebfbf99074beb4ed6 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 18:55:57 +0900 Subject: [PATCH 08/20] Add redirect with no template test --- tests/Fake/src/FakeTransfer.php | 15 +++++++++++ .../Page/RedirectNoTemplate.php | 25 +++++++++++++++++++ tests/FileLoaderTest.php | 12 +++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/Fake/src/FakeTransfer.php create mode 100644 tests/Fake/src/ResourceNoTemplate/Page/RedirectNoTemplate.php diff --git a/tests/Fake/src/FakeTransfer.php b/tests/Fake/src/FakeTransfer.php new file mode 100644 index 0000000..7a565f3 --- /dev/null +++ b/tests/Fake/src/FakeTransfer.php @@ -0,0 +1,15 @@ + 'text/html; charset=SJIS' + ]; + + public function onPost() + { + $this->code = Code::FOUND; + $this->headers['Location'] = '/path/to/baz'; + + return $this; + } +} diff --git a/tests/FileLoaderTest.php b/tests/FileLoaderTest.php index 1cbc1ec..1bd6b4d 100644 --- a/tests/FileLoaderTest.php +++ b/tests/FileLoaderTest.php @@ -6,6 +6,7 @@ use BEAR\Resource\Code; use Madapaja\TwigModule\Exception\TemplateNotFound; +use Madapaja\TwigModule\Fake\src\ResourceNoTemplate\Page\RedirectNoTemplate; use Madapaja\TwigModule\Resource\Page\Index; use Madapaja\TwigModule\Resource\Page\NoTemplate; use Madapaja\TwigModule\Resource\Page\Page; @@ -144,4 +145,15 @@ public function testRedirectOnPost(): void $this->assertSame('/path/to/baz', $ro->headers['Location']); $this->assertMatchesRegularExpression('#^.*Redirecting to /path/to/baz.*$#s', trim((string) $ro)); } + + public function testRedirectOnPostNoRedirectTemplate(): void + { + $injector = new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/ResourceNoTemplate'])); + $ro = $injector->getInstance(RedirectNoTemplate::class); + $ro->onPost(); + (string) $ro; + $this->assertSame(Code::FOUND, $ro->code); + $this->assertSame('/path/to/baz', $ro->headers['Location']); + $this->assertSame('', $ro->view); + } } From 5bf0f14e636a3e25ec91526a5296850eb5e8fcad Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 19:22:11 +0900 Subject: [PATCH 09/20] Add TwigErrorPage serialize test --- tests/TwigErrorPageModuleTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/TwigErrorPageModuleTest.php b/tests/TwigErrorPageModuleTest.php index 675fda2..6cf97ff 100644 --- a/tests/TwigErrorPageModuleTest.php +++ b/tests/TwigErrorPageModuleTest.php @@ -15,13 +15,15 @@ use Ray\Di\Injector; use function assert; +use function serialize; +use function unserialize; class TwigErrorPageModuleTest extends TestCase { public function testError(): void { $module = new TwigErrorPageModule(new TwigModule()); - $module->install(new class extends AbstractModule{ + $module->install(new class extends AbstractModule { protected function configure(): void { $this->bind(LoggerInterface::class)->to(NullLogger::class); @@ -36,4 +38,10 @@ protected function configure(): void $this->assertArrayHasKey('e', FakeTransfer::$ro->body); $this->assertArrayHasKey('logref', FakeTransfer::$ro->body); } + + public function testSerializeTwigErrorPage(): void + { + $errorPage = unserialize(serialize(new TwigErrorPage())); + $this->assertInstanceOf(TwigErrorPage::class, $errorPage); + } } From 589ed03e622b757a9c97c4146c63108dd185de51 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 19:39:15 +0900 Subject: [PATCH 10/20] Remove TwigErrorPageHandler Use TwigErrorHandler --- src/TwigErrorPageHandler.php | 73 ------------------------------------ 1 file changed, 73 deletions(-) delete mode 100644 src/TwigErrorPageHandler.php diff --git a/src/TwigErrorPageHandler.php b/src/TwigErrorPageHandler.php deleted file mode 100644 index 0d30a09..0000000 --- a/src/TwigErrorPageHandler.php +++ /dev/null @@ -1,73 +0,0 @@ -isCodeExists($e) ? $e->getCode() : 503; - if ($code >= 500) { - $eStr = (string) $e; - $this->logger->error(sprintf('logref:%s %s', crc32($eStr), $eStr)); - } - - $this->errorPage->code = $code; - $this->errorPage->body = [ - 'status' => [ - 'code' => $code, - 'message' => (new Code())->statusText[$code], - ], - 'e' => [ - 'code' => $e->getCode(), - 'message' => $e->getMessage(), - ], - ]; - - return $this; - } - - /** - * {@inheritDoc} - */ - public function transfer() - { - ($this->transfer)($this->errorPage, []); - } - - private function isCodeExists(Throwable $e): bool - { - if (! ($e instanceof NotFound) && ! ($e instanceof BadRequest) && ! ($e instanceof ServerError)) { - return false; - } - - return array_key_exists($e->getCode(), (new Code())->statusText); - } -} From acdfff3f45cb1a35042e96f5558cd8955e40577b Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 20:14:10 +0900 Subject: [PATCH 11/20] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5a3f380..b75d795 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /composer.lock /.php_cs.cache /.phpunit.result.cache +/.phpcs-cache From 5ada0b51d4efaf49533bb26a97dc08085b0e9ba8 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 20:14:20 +0900 Subject: [PATCH 12/20] Code coverage 100% --- src/MobileTemplateFinder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MobileTemplateFinder.php b/src/MobileTemplateFinder.php index 44fd9c3..9fcc51f 100644 --- a/src/MobileTemplateFinder.php +++ b/src/MobileTemplateFinder.php @@ -31,7 +31,9 @@ public function __construct( public function __invoke(string $name): string { if (! class_exists(MobileDetect::class)) { + // @codeCoverageIgnoreStart class_alias(Mobile_Detect::class, MobileDetect::class); + // @codeCoverageIgnoreEnd } $detect = new MobileDetect(); From 6efa58056d0875931c9a41fb6b4a7b6edf7bf5ef Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 22:41:36 +0900 Subject: [PATCH 13/20] Change doctrine/annotations optional --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 965a122..e56914e 100644 --- a/composer.json +++ b/composer.json @@ -21,16 +21,19 @@ "twig/twig": "^2.15.3 || ^v3.4.3", "mobiledetect/mobiledetectlib": "^2.7 || ^3.74", "ray/di": "^2.7", - "doctrine/annotations": "^1.13.3 || ^2.0" + "ray/aop": "^2.13", + "psr/log": "^3.0" }, "require-dev": { + "doctrine/annotations": "^1.13.3 || ^2.0", "phpunit/phpunit": "^9.5.21", "squizlabs/php_codesniffer": "^3.7", "phpmd/phpmd": "^2.6", "rector/rector": "^0.15.3", "ray/rector-ray": "^1.0", "doctrine/coding-standard": "^12.0", - "vimeo/psalm": "^5.4" + "vimeo/psalm": "^5.4", + "phpstan/phpstan": "^1.10" }, "autoload":{ "psr-4":{ From dfbcc270164795b99679514a95e6f372f4acb1b9 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 23:28:09 +0900 Subject: [PATCH 14/20] Update composer script --- composer.json | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index e56914e..f9bfd70 100644 --- a/composer.json +++ b/composer.json @@ -49,13 +49,12 @@ } }, "scripts": { - "test": ["@setup", "vendor/bin/phpunit"], - "test74": ["/usr/local/Cellar/php@7.4/7.4.14/bin/php vendor/bin/phpunit"], - "tests": ["@cs", "phpstan analyse -l max src tests -c phpstan.neon --no-progress", "@test"], - "coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"], - "cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=phpcs.xml src;"], + "test": ["phpunit"], + "tests": ["@cs", "@sa", "@test"], + "coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage phpunit --coverage-text --coverage-html=build/coverage"], + "cs": ["phpcs --standard=phpcs.xml src"], "cs-fix": ["phpcbf src tests"], - "sa": "psalm" + "sa": ["psalm", "phpstan"] }, "config": { "allow-plugins": { From 7a36c7237c74df7d1192dca0e6c14e9e2badd1b3 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 23:28:44 +0900 Subject: [PATCH 15/20] Soothe phpstan --- phpstan.neon | 9 +++++++++ src/ErrorPagerRenderer.php | 4 ++++ src/MobileTemplateFinder.php | 3 ++- src/TemplateFinder.php | 3 +++ src/TwigErrorPage.php | 10 +++++++--- src/TwigModule.php | 6 +++--- src/TwigRenderer.php | 9 +++++++-- tests/ArrayLoaderTest.php | 6 +++++- .../Page/RedirectNoTemplate.php | 3 ++- tests/FileLoaderTest.php | 18 +++++++++++++----- tests/OptionProviderTest.php | 2 +- tests/TwigErrorPageHandlerTest.php | 4 +--- tests/TwigErrorPageModuleTest.php | 2 ++ 13 files changed, 59 insertions(+), 20 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index e69de29..6acfdee 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + level: max + paths: + - src + - tests + excludePaths: + - */tests/tmp/* + - */tests/Fake/* + ignoreErrors: diff --git a/src/ErrorPagerRenderer.php b/src/ErrorPagerRenderer.php index facb77d..e4fa4ff 100644 --- a/src/ErrorPagerRenderer.php +++ b/src/ErrorPagerRenderer.php @@ -12,6 +12,9 @@ use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; +use function assert; +use function is_array; + class ErrorPagerRenderer implements RenderInterface { public function __construct( @@ -28,6 +31,7 @@ public function __construct( */ public function render(ResourceObject $ro): string { + assert(is_array($ro->body)); $ro->view = $this->twig->render($this->errorPage, $ro->body); return $ro->view; diff --git a/src/MobileTemplateFinder.php b/src/MobileTemplateFinder.php index 9fcc51f..227c754 100644 --- a/src/MobileTemplateFinder.php +++ b/src/MobileTemplateFinder.php @@ -17,6 +17,7 @@ class MobileTemplateFinder implements TemplateFinderInterface { + /** @param array $paths */ public function __construct( #[TwigPaths] private array $paths, @@ -32,7 +33,7 @@ public function __invoke(string $name): string { if (! class_exists(MobileDetect::class)) { // @codeCoverageIgnoreStart - class_alias(Mobile_Detect::class, MobileDetect::class); + class_alias(Mobile_Detect::class, MobileDetect::class); // @phpstan-ignore-line // @codeCoverageIgnoreEnd } diff --git a/src/TemplateFinder.php b/src/TemplateFinder.php index 423cccc..273e69d 100644 --- a/src/TemplateFinder.php +++ b/src/TemplateFinder.php @@ -4,6 +4,8 @@ namespace Madapaja\TwigModule; +use function assert; +use function is_int; use function str_replace; use function strpos; use function substr; @@ -16,6 +18,7 @@ class TemplateFinder implements TemplateFinderInterface public function __invoke(string $name): string { $pos = strpos($name, '/Resource/'); + assert(is_int($pos)); $relativePath = substr($name, $pos + 10); return str_replace('.php', TwigRenderer::EXT, $relativePath); diff --git a/src/TwigErrorPage.php b/src/TwigErrorPage.php index 4637762..6cd469b 100644 --- a/src/TwigErrorPage.php +++ b/src/TwigErrorPage.php @@ -11,8 +11,10 @@ class TwigErrorPage extends ResourceObject { - /** @var array */ + /** @var array */ public $headers = ['content-type' => 'text/html; charset=utf-8']; + + /** @var RenderInterface */ protected $renderer; public function __sleep() @@ -23,12 +25,14 @@ public function __sleep() /** * @Inject * @Named("error_page") + * {@inheritDoc} */ #[Inject] - #[Named('error_page')] - public function setRenderer(RenderInterface $renderer): void + public function setRenderer(RenderInterface $renderer) { $this->renderer = $renderer; + + return $this; } } diff --git a/src/TwigModule.php b/src/TwigModule.php index 7d87381..c48fb07 100644 --- a/src/TwigModule.php +++ b/src/TwigModule.php @@ -20,8 +20,8 @@ class TwigModule extends AbstractModule { /** - * @param array $paths Twig template paths - * @param array $options Twig_Environment options + * @param array $paths Twig template paths + * @param array $options Twig_Environment options * @param AbstractModule|null $module * * @see http://twig.sensiolabs.org/api/master/Twig_Environment.html @@ -116,7 +116,7 @@ private function bindTwigRedirectPath(): void $this->bind()->annotatedWith(TwigRedirectPath::class)->toInstance('/redirect/redirect.html.twig'); } - private function isNotEmpty($var): bool + private function isNotEmpty(mixed $var): bool { return is_array($var) && ! empty($var); } diff --git a/src/TwigRenderer.php b/src/TwigRenderer.php index d7a8a6d..e2d63d4 100644 --- a/src/TwigRenderer.php +++ b/src/TwigRenderer.php @@ -121,7 +121,7 @@ private function loadTemplate(ResourceObject $ro): TemplateWrapper { $loader = $this->twig->getLoader(); if ($loader instanceof FilesystemLoader) { - $classFile = $this->getReflection($ro)->getFileName(); + $classFile = (string) $this->getReflection($ro)->getFileName(); $templateFile = ($this->templateFinder)($classFile); return $this->twig->load($templateFile); @@ -130,15 +130,20 @@ private function loadTemplate(ResourceObject $ro): TemplateWrapper return $this->twig->load($this->getReflection($ro)->name . self::EXT); } + /** @return ReflectionClass */ private function getReflection(ResourceObject $ro): ReflectionClass { if ($ro instanceof WeavedInterface) { - return (new ReflectionClass($ro))->getParentClass(); + /** @var ReflectionClass $ref */ + $ref = (new ReflectionClass($ro))->getParentClass(); + + return $ref; } return new ReflectionClass($ro); } + /** @return array */ private function buildBody(ResourceObject $ro): array { $body = is_array($ro->body) ? $ro->body : []; diff --git a/tests/ArrayLoaderTest.php b/tests/ArrayLoaderTest.php index 5a59a90..bd9939d 100644 --- a/tests/ArrayLoaderTest.php +++ b/tests/ArrayLoaderTest.php @@ -12,6 +12,8 @@ use Ray\Di\Injector; use ReflectionClass; +use function assert; + class ArrayLoaderTest extends TestCase { private Injector $injector; @@ -50,7 +52,9 @@ public function testTemplateNotFoundException(): void $ro = $this->injector->getInstance(NoTemplate::class); $prop = (new ReflectionClass($ro))->getProperty('renderer'); $prop->setAccessible(true); - $prop->getValue($ro)->render($ro); + $roValue = $prop->getValue($ro); + assert($roValue instanceof TwigRenderer); + $roValue->render($ro); } public function testPage(): void diff --git a/tests/Fake/src/ResourceNoTemplate/Page/RedirectNoTemplate.php b/tests/Fake/src/ResourceNoTemplate/Page/RedirectNoTemplate.php index 4fc3447..4692f0f 100644 --- a/tests/Fake/src/ResourceNoTemplate/Page/RedirectNoTemplate.php +++ b/tests/Fake/src/ResourceNoTemplate/Page/RedirectNoTemplate.php @@ -4,7 +4,8 @@ * * @license http://opensource.org/licenses/MIT MIT */ -namespace Madapaja\TwigModule\Fake\src\ResourceNotemplate\Page; + +namespace Madapaja\TwigModule\ResourceNoTemplate\Page; use BEAR\Resource\Code; use BEAR\Resource\ResourceObject; diff --git a/tests/FileLoaderTest.php b/tests/FileLoaderTest.php index 1bd6b4d..991b8d3 100644 --- a/tests/FileLoaderTest.php +++ b/tests/FileLoaderTest.php @@ -6,15 +6,16 @@ use BEAR\Resource\Code; use Madapaja\TwigModule\Exception\TemplateNotFound; -use Madapaja\TwigModule\Fake\src\ResourceNoTemplate\Page\RedirectNoTemplate; use Madapaja\TwigModule\Resource\Page\Index; use Madapaja\TwigModule\Resource\Page\NoTemplate; use Madapaja\TwigModule\Resource\Page\Page; use Madapaja\TwigModule\Resource\Page\Redirect; +use Madapaja\TwigModule\ResourceNoTemplate\Page\RedirectNoTemplate; use PHPUnit\Framework\TestCase; use Ray\Di\Injector; use ReflectionClass; +use function assert; use function trim; class FileLoaderTest extends TestCase @@ -76,7 +77,9 @@ public function testTemplateNotFoundException(): void $ro = $injector->getInstance(NoTemplate::class); $prop = (new ReflectionClass($ro))->getProperty('renderer'); $prop->setAccessible(true); - $prop->getValue($ro)->render($ro); + $renderer = $prop->getValue($ro); + assert($renderer instanceof TwigRenderer); + $renderer->render($ro); } public function testNoViewWhenCode301(): void @@ -86,7 +89,9 @@ public function testNoViewWhenCode301(): void $ro->code = 303; $prop = (new ReflectionClass($ro))->getProperty('renderer'); $prop->setAccessible(true); - $view = $prop->getValue($ro)->render($ro); + $renderer = $prop->getValue($ro); + assert($renderer instanceof TwigRenderer); + $view = $renderer->render($ro); $this->assertSame('', $view); } @@ -97,7 +102,9 @@ public function testNoContent(): void $ro->code = Code::NO_CONTENT; $prop = (new ReflectionClass($ro))->getProperty('renderer'); $prop->setAccessible(true); - $view = $prop->getValue($ro)->render($ro); + $renderer = $prop->getValue($ro); + assert($renderer instanceof TwigRenderer); + $view = $renderer->render($ro); $this->assertSame('', $view); } @@ -151,9 +158,10 @@ public function testRedirectOnPostNoRedirectTemplate(): void $injector = new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/ResourceNoTemplate'])); $ro = $injector->getInstance(RedirectNoTemplate::class); $ro->onPost(); - (string) $ro; + $view = (string) $ro; $this->assertSame(Code::FOUND, $ro->code); $this->assertSame('/path/to/baz', $ro->headers['Location']); $this->assertSame('', $ro->view); + $this->assertSame('', $view); } } diff --git a/tests/OptionProviderTest.php b/tests/OptionProviderTest.php index 9abc26e..3039a5f 100644 --- a/tests/OptionProviderTest.php +++ b/tests/OptionProviderTest.php @@ -12,7 +12,7 @@ class OptionProviderTest extends TestCase { - public $tmpDir; + public string $tmpDir; public function setUp(): void { diff --git a/tests/TwigErrorPageHandlerTest.php b/tests/TwigErrorPageHandlerTest.php index ff669b2..c24e070 100644 --- a/tests/TwigErrorPageHandlerTest.php +++ b/tests/TwigErrorPageHandlerTest.php @@ -32,7 +32,7 @@ public function setUp(): void ); } - public function testHandle() + public function testHandle(): void { $request = new RouterMatch(); $request->method = 'get'; @@ -40,8 +40,6 @@ public function testHandle() $request->query = []; $handler = $this->handler->handle(new NotFound(), $request); $this->assertInstanceOf(TwigErrorHandler::class, $handler); - - return $handler; } /** @depends testHandle */ diff --git a/tests/TwigErrorPageModuleTest.php b/tests/TwigErrorPageModuleTest.php index 6cf97ff..61b379b 100644 --- a/tests/TwigErrorPageModuleTest.php +++ b/tests/TwigErrorPageModuleTest.php @@ -15,6 +15,7 @@ use Ray\Di\Injector; use function assert; +use function is_array; use function serialize; use function unserialize; @@ -34,6 +35,7 @@ protected function configure(): void $error = $injector->getInstance(ErrorInterface::class); assert($error instanceof ErrorInterface); $error->handle(new RuntimeException(), new RouterMatch())->transfer(); + assert(is_array(FakeTransfer::$ro->body)); $this->assertArrayHasKey('status', FakeTransfer::$ro->body); $this->assertArrayHasKey('e', FakeTransfer::$ro->body); $this->assertArrayHasKey('logref', FakeTransfer::$ro->body); From cc97393adf0f8ab1c567175b8173d99d3381fc7b Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 23:29:34 +0900 Subject: [PATCH 16/20] Update CI --- .github/workflows/coding-standards.yml | 12 ++++++++++++ .github/workflows/static-analysis.yml | 13 +++++++++++++ .../update-copyright-years-in-license-file.yml | 2 +- composer-require-checker.json | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/coding-standards.yml create mode 100644 .github/workflows/static-analysis.yml create mode 100644 composer-require-checker.json diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 0000000..aa14250 --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,12 @@ +name: Coding Standards + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + cs: + uses: ray-di/.github/.github/workflows/coding-standards.yml@v1 + with: + php_version: 8.1 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..19eda0c --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,13 @@ +name: Static Analysis + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + sa: + uses: ray-di/.github/.github/workflows/static-analysis.yml@v1 + with: + php_version: 8.1 + has_crc_config: true diff --git a/.github/workflows/update-copyright-years-in-license-file.yml b/.github/workflows/update-copyright-years-in-license-file.yml index fc00479..f432106 100644 --- a/.github/workflows/update-copyright-years-in-license-file.yml +++ b/.github/workflows/update-copyright-years-in-license-file.yml @@ -1,4 +1,4 @@ -name: Update copyright year(s) in license file +name: Update copyright year in license file on: workflow_dispatch: diff --git a/composer-require-checker.json b/composer-require-checker.json new file mode 100644 index 0000000..ad6a80c --- /dev/null +++ b/composer-require-checker.json @@ -0,0 +1,18 @@ +{ + "symbol-whitelist" : [ + "Mobile_Detect" + ], + "php-core-extensions" : [ + "Core", + "date", + "json", + "hash", + "pcre", + "Phar", + "Reflection", + "SPL", + "random", + "standard" + ], + "scan-files" : [] +} \ No newline at end of file From 84097b418f215f9c5bf0295c0ffa965249b7d927 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 23:32:26 +0900 Subject: [PATCH 17/20] Soohte phpmd --- src/TwigModule.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TwigModule.php b/src/TwigModule.php index c48fb07..c166a9d 100644 --- a/src/TwigModule.php +++ b/src/TwigModule.php @@ -17,6 +17,7 @@ use function is_array; +/** @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class TwigModule extends AbstractModule { /** From 015019686d612bb87f0777653af9cd10478e137f Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 23:39:16 +0900 Subject: [PATCH 18/20] Remove tests/bootstrap.php --- phpunit.xml | 2 +- tests/ExtensionTest.php | 2 +- tests/FileLoaderTest.php | 8 ++++---- tests/MobileTemplateFinderTest.php | 8 ++++---- tests/WeavedResourceTest.php | 2 +- tests/bootstrap.php | 20 -------------------- 6 files changed, 11 insertions(+), 31 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/phpunit.xml b/phpunit.xml index 839e7d3..8dd2640 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + src diff --git a/tests/ExtensionTest.php b/tests/ExtensionTest.php index 5aa2a40..353568c 100644 --- a/tests/ExtensionTest.php +++ b/tests/ExtensionTest.php @@ -17,7 +17,7 @@ class ExtensionTest extends TestCase public function setUp(): void { - $this->injector = new Injector(new TwigExtensionTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource/'])); + $this->injector = new Injector(new TwigExtensionTestModule([__DIR__ . '/Fake/src/Resource/'])); } public function testTwigFilter(): void diff --git a/tests/FileLoaderTest.php b/tests/FileLoaderTest.php index 991b8d3..61664dd 100644 --- a/tests/FileLoaderTest.php +++ b/tests/FileLoaderTest.php @@ -22,7 +22,7 @@ class FileLoaderTest extends TestCase { public function getInjector(): Injector { - return new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource'])); + return new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/Resource'])); } public function testRenderer(): void @@ -38,11 +38,11 @@ public function testRenderer(): void public function testTwigOptions(): void { /** @var TwigRenderer $renderer */ - $renderer = (new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource'], ['debug' => true])))->getInstance(TwigRenderer::class); + $renderer = (new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/Resource'], ['debug' => true])))->getInstance(TwigRenderer::class); $this->assertTrue($renderer->twig->isDebug()); /** @var TwigRenderer $renderer */ - $renderer = (new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource'], ['debug' => false])))->getInstance(TwigRenderer::class); + $renderer = (new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/Resource'], ['debug' => false])))->getInstance(TwigRenderer::class); $this->assertFalse($renderer->twig->isDebug()); } @@ -155,7 +155,7 @@ public function testRedirectOnPost(): void public function testRedirectOnPostNoRedirectTemplate(): void { - $injector = new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/ResourceNoTemplate'])); + $injector = new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/ResourceNoTemplate'])); $ro = $injector->getInstance(RedirectNoTemplate::class); $ro->onPost(); $view = (string) $ro; diff --git a/tests/MobileTemplateFinderTest.php b/tests/MobileTemplateFinderTest.php index 4eb9dfc..635bd3c 100644 --- a/tests/MobileTemplateFinderTest.php +++ b/tests/MobileTemplateFinderTest.php @@ -29,9 +29,9 @@ protected function configure(): void public function testMobileTemplate(): void { $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25'; - $paths = [$_ENV['TEST_DIR'] . '/Fake/src/Resource']; + $paths = [__DIR__ . '/Fake/src/Resource']; $templateFinder = new MobileTemplateFinder($paths, new TemplateFinder()); - $file = ($templateFinder)($_ENV['TEST_DIR'] . '/Resource/Page/Index.php'); + $file = ($templateFinder)(__DIR__ . '/Resource/Page/Index.php'); $expected = 'Page/Index.mobile.twig'; $this->assertSame($expected, $file); } @@ -39,9 +39,9 @@ public function testMobileTemplate(): void public function testPcTemplate(): void { $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'; - $paths = [$_ENV['TEST_DIR'] . '/Fake/src/Resource']; + $paths = [__DIR__ . '/Fake/src/Resource']; $templateFinder = new MobileTemplateFinder($paths, new TemplateFinder()); - $file = ($templateFinder)($_ENV['TEST_DIR'] . '/Resource/Page/Index.php'); + $file = ($templateFinder)(__DIR__ . '/Resource/Page/Index.php'); $expected = 'Page/Index.html.twig'; $this->assertSame($expected, $file); } diff --git a/tests/WeavedResourceTest.php b/tests/WeavedResourceTest.php index bf7298e..64b5a6f 100644 --- a/tests/WeavedResourceTest.php +++ b/tests/WeavedResourceTest.php @@ -17,7 +17,7 @@ class WeavedResourceTest extends TestCase public function setUp(): void { - $this->injector = new Injector(new TwigWeavedResourceTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource'])); + $this->injector = new Injector(new TwigWeavedResourceTestModule([__DIR__ . '/Fake/src/Resource'])); } public function testRenderer(): void diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 3002bb2..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,20 +0,0 @@ -addPsr4('Madapaja\TwigModule\\', [__DIR__]); -$_ENV['TEST_DIR'] = __DIR__; -$_ENV['TMP_DIR'] = __DIR__ . '/tmp'; -// no annotation in PHP 8 -if (PHP_MAJOR_VERSION >= 8) { - ServiceLocator::setReader(new AttributeReader()); -} From 82a8a638d9c6f681c37de4e5daabbf38f9510d24 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 23:39:28 +0900 Subject: [PATCH 19/20] Update depreated AppMeta --- tests/AppPathProviderTestModule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/AppPathProviderTestModule.php b/tests/AppPathProviderTestModule.php index a9a8d99..8e65012 100644 --- a/tests/AppPathProviderTestModule.php +++ b/tests/AppPathProviderTestModule.php @@ -5,7 +5,7 @@ namespace Madapaja\TwigModule; use BEAR\AppMeta\AbstractAppMeta; -use BEAR\AppMeta\AppMeta; +use BEAR\AppMeta\Meta; use Madapaja\TwigModule\Annotation\TwigPaths; use Ray\Di\AbstractModule; @@ -16,7 +16,7 @@ class AppPathProviderTestModule extends AbstractModule */ protected function configure() { - $this->bind(AbstractAppMeta::class)->toInstance(new AppMeta('Madapaja\TwigModule')); + $this->bind(AbstractAppMeta::class)->toInstance(new Meta('Madapaja\TwigModule')); $this->install(new TwigModule()); $this->bind()->annotatedWith(TwigPaths::class)->toProvider(AppPathProvider::class); } From 7264080c681122728f5a5bc207999f46802efb3c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 3 Sep 2023 23:41:48 +0900 Subject: [PATCH 20/20] Rename phpunit.xml --- phpunit.xml => phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename phpunit.xml => phpunit.xml.dist (88%) diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 88% rename from phpunit.xml rename to phpunit.xml.dist index 8dd2640..b3cf599 100644 --- a/phpunit.xml +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ - tests + tests