diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33f1e7b..b7a6483 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php_version: [7.4, 8.0, 8.1] + php_version: [8.0, 8.1, 8.2] composer_flags: ['', '--prefer-lowest'] steps: diff --git a/composer.json b/composer.json index 4c48cc2..dddbdb5 100644 --- a/composer.json +++ b/composer.json @@ -6,35 +6,34 @@ "php": ">=7.3||>=8.0", "php-di/php-di": "^6.4.0", "rareloop/router": "^6.0.2", - "psr/container": "^1.0", - "psr/http-message": "^1.0", - "psr/http-server-middleware": "^1.0", + "psr/container": "^1.1.2", + "psr/http-message": "^1.1", + "psr/http-server-middleware": "^1.0.2", "blast/facades": "^1.0", - "timber/timber": "^1.21.0", - "monolog/monolog": "^2.0", + "timber/timber": "^1.24.0", + "monolog/monolog": "^2.9.1", "http-interop/response-sender": "^1.0", - "symfony/debug": "^4.1", - "illuminate/collections": "^8.53.1||^9.0.0", + "symfony/debug": "^4.4.44", + "illuminate/collections": "^8.53.1||^9.52.16", "statamic/stringy": "^3.1.3", - "laminas/laminas-diactoros": "^2.4", + "laminas/laminas-diactoros": "^2.25.2", "rareloop/psr7-server-request-extension": "^2.1.0", - "mmeyer2k/dcrypt": "^8.0.1", - "spatie/macroable": "^1.0", - "mindplay/middleman": "^3.0.3", - "psr/log": "^1.1", - "laminas/laminas-zendframework-bridge": "^1.4", - "symfony/var-dumper": "^5.0||^6.0" + "mmeyer2k/dcrypt": "^8.3.1", + "spatie/macroable": "^1.0.1", + "mindplay/middleman": "^3.1.0", + "psr/log": "^1.1.4", + "laminas/laminas-zendframework-bridge": "^1.7", + "symfony/var-dumper": "^5.0||^6.3.6" }, "require-dev": { - "phpunit/phpunit": "^9.5.21", - "php-coveralls/php-coveralls": "^2.0", - "mockery/mockery": "^1.5.0", - "brain/monkey": "~2.4.2", - "squizlabs/php_codesniffer": "^3.6.0", - "php-mock/php-mock": "^2.3.1", + "phpunit/phpunit": "^9.6.13", + "php-coveralls/php-coveralls": "^2.6", + "mockery/mockery": "^1.6.6", + "brain/monkey": "^2.6.1", + "squizlabs/php_codesniffer": "^3.7.2", + "php-mock/php-mock": "^2.4.1", "mikey179/vfsstream": "1.6.11", - "antecedent/patchwork": "^2.1.21", - "dms/phpunit-arraysubset-asserts": "^0.3.0" + "dms/phpunit-arraysubset-asserts": "^0.3.1" }, "autoload": { "psr-4": { diff --git a/src/Post.php b/src/Post.php index bef9785..5a7257d 100644 --- a/src/Post.php +++ b/src/Post.php @@ -8,6 +8,7 @@ use Timber\Post as TimberPost; use Timber\Timber; +#[\AllowDynamicProperties] class Post extends TimberPost { use Macroable { @@ -46,7 +47,7 @@ public static function __callStatic($name, $arguments) return call_user_func_array([$builder, $name], $arguments); } - trigger_error('Call to undefined method '.__CLASS__.'::'.$name.'()', E_USER_ERROR); + trigger_error('Call to undefined method ' . __CLASS__ . '::' . $name . '()', E_USER_ERROR); } /** @@ -54,7 +55,7 @@ public static function __callStatic($name, $arguments) * * @return ScopedQueryBuilder */ - public static function builder() : ScopedQueryBuilder + public static function builder(): ScopedQueryBuilder { return new ScopedQueryBuilder(static::class); } diff --git a/tests/Unit/ApplicationTest.php b/tests/Unit/ApplicationTest.php index a042218..cc5f13c 100644 --- a/tests/Unit/ApplicationTest.php +++ b/tests/Unit/ApplicationTest.php @@ -552,6 +552,8 @@ public function calling_detectWhenRequestHasNotBeenHandled_adds_actions() class BootstrapperBootstrapTester { + public $callback; + public function __construct($callback) { $this->callback = $callback; @@ -560,6 +562,8 @@ public function __construct($callback) abstract class TestBootstrapperBase { + private BootstrapperBootstrapTester $tester; + public function __construct(BootstrapperBootstrapTester $tester) { $this->tester = $tester; diff --git a/tests/Unit/PostQueryBuilderTest.php b/tests/Unit/PostQueryBuilderTest.php index 32bb933..8cb501d 100644 --- a/tests/Unit/PostQueryBuilderTest.php +++ b/tests/Unit/PostQueryBuilderTest.php @@ -9,12 +9,15 @@ use Rareloop\Lumberjack\Post; use Rareloop\Lumberjack\QueryBuilder; use Rareloop\Lumberjack\ScopedQueryBuilder; +use Throwable; class PostQueryBuilderTest extends TestCase { use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration, \DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; + private Application $app; + public function setUp(): void { $this->app = new Application; @@ -48,9 +51,15 @@ public function can_create_a_builder_from_static_functions() */ public function throw_error_on_missing_static_function() { - $this->expectError(); + $errorThrown = false; + + try { + Post::missingStaticFunction(); + } catch (Throwable $e) { + $errorThrown = true; + } - Post::missingStaticFunction(); + $this->assertTrue($errorThrown); } private function assertQueryBuilder($function, $params, $postType) diff --git a/tests/Unit/Providers/RouterServiceProviderTest.php b/tests/Unit/Providers/RouterServiceProviderTest.php index 41fb1bc..780f363 100644 --- a/tests/Unit/Providers/RouterServiceProviderTest.php +++ b/tests/Unit/Providers/RouterServiceProviderTest.php @@ -124,7 +124,7 @@ public function wp_loaded_action_is_bound() $app->register($provider); $lumberjack->bootstrap(); - $this->assertTrue(has_action('wp_loaded', 'function ()')); + $this->assertNotFalse(has_action('wp_loaded', 'function ()')); } /** @test */ diff --git a/tests/Unit/Providers/WordPressControllersServiceProviderTest.php b/tests/Unit/Providers/WordPressControllersServiceProviderTest.php index ed18213..e51f0c5 100644 --- a/tests/Unit/Providers/WordPressControllersServiceProviderTest.php +++ b/tests/Unit/Providers/WordPressControllersServiceProviderTest.php @@ -32,19 +32,19 @@ class WordPressControllersServiceProviderTest extends TestCase /** @test */ public function template_include_filter_is_applied_on_boot() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $app->register($provider); $app->boot(); - $this->assertTrue(has_filter('template_include', [$provider, 'handleTemplateInclude'])); + $this->assertNotFalse(has_filter('template_include', [$provider, 'handleTemplateInclude'])); } /** @test */ public function handle_template_include_method_includes_the_requested_file() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $this->assertNotContains(__DIR__ . '/includes/single.php', get_included_files()); @@ -57,7 +57,7 @@ public function handle_template_include_method_includes_the_requested_file() /** @test */ public function handle_template_include_method_sets_details_in_container_when_controller_is_not_present() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $provider->handleTemplateInclude(__DIR__ . '/includes/single.php'); @@ -72,10 +72,10 @@ public function handle_template_include_method_sets_details_in_container_when_co public function handle_template_include_method_does_not_set_details_in_container_when_controller_is_present() { $response = new TextResponse('Testing 123', 200); - $app = Mockery::mock(Application::class.'[shutdown]', [__DIR__.'/..']); + $app = Mockery::mock(Application::class . '[shutdown]', [__DIR__ . '/..']); $app->shouldReceive('shutdown')->times(1); - $provider = Mockery::mock(WordPressControllersServiceProvider::class.'[handleRequest]', [$app]); + $provider = Mockery::mock(WordPressControllersServiceProvider::class . '[handleRequest]', [$app]); $provider->shouldReceive('handleRequest')->once()->andReturn($response); $provider->boot($app); @@ -88,7 +88,7 @@ public function handle_template_include_method_does_not_set_details_in_container /** @test */ public function can_get_name_of_controller_from_template() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $mappings = [ @@ -105,7 +105,7 @@ public function can_get_name_of_controller_from_template() /** @test */ public function can_get_special_case_name_of_404_controller_from_template() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $this->assertSame('App\\Error404Controller', $provider->getControllerClassFromTemplate(__DIR__ . 'includes/404.php')); @@ -114,7 +114,7 @@ public function can_get_special_case_name_of_404_controller_from_template() /** @test */ public function handle_template_include_applies_filters_on_controller_name_and_namespace() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); Filters\expectApplied('lumberjack_controller_name') @@ -131,7 +131,7 @@ public function handle_template_include_applies_filters_on_controller_name_and_n /** @test */ public function handle_request_returns_false_if_controller_does_not_exist() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $response = $provider->handleRequest(new ServerRequest, 'Does\\Not\\Exist', 'handle'); @@ -145,7 +145,7 @@ public function handle_request_writes_warning_to_logs_if_controller_does_not_exi $log = Mockery::mock(Logger::class); $log->shouldReceive('warning')->once()->with('Controller class `Does\Not\Exist` not found'); - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $app->bind('logger', $log); $provider = new WordPressControllersServiceProvider($app); $provider->boot(); @@ -156,7 +156,7 @@ public function handle_request_writes_warning_to_logs_if_controller_does_not_exi /** @test */ public function handle_request_will_mark_request_handled_in_app_if_controller_does_exist() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $provider->boot(); @@ -169,7 +169,7 @@ public function handle_request_will_mark_request_handled_in_app_if_controller_do /** @test */ public function handle_request_will_not_mark_request_handled_in_app_if_controller_does_not_exist() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $provider->boot(); @@ -182,7 +182,7 @@ public function handle_request_will_not_mark_request_handled_in_app_if_controlle /** @test */ public function handle_request_returns_response_when_controller_does_exist() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $provider->boot($app); @@ -195,7 +195,7 @@ public function handle_request_returns_response_when_controller_does_exist() /** @test */ public function handle_request_returns_response_when_controller_returns_a_responsable() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $provider->boot($app); @@ -209,7 +209,7 @@ public function handle_request_returns_response_when_controller_returns_a_respon /** @test */ public function handle_request_resolves_constructor_params_from_container() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $provider->boot($app); @@ -222,7 +222,7 @@ public function handle_request_resolves_constructor_params_from_container() /** @test */ public function handle_request_resolves_controller_method_params_from_container() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $provider = new WordPressControllersServiceProvider($app); $provider->boot($app); @@ -235,7 +235,7 @@ public function handle_request_resolves_controller_method_params_from_container( /** @test */ public function handle_request_supports_middleware() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $controller = new TestControllerWithMiddleware; $controller->middleware(new AddHeaderMiddleware('X-Header', 'testing123')); $app->bind(TestControllerWithMiddleware::class, $controller); @@ -252,7 +252,7 @@ public function handle_request_supports_middleware() /** @test */ public function handle_request_supports_middleware_applied_to_a_specific_method_using_only() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $controller = new TestControllerWithMiddleware; $controller->middleware(new AddHeaderMiddleware('X-Header', 'testing123'))->only('notHandle'); $app->bind(TestControllerWithMiddleware::class, $controller); @@ -268,7 +268,7 @@ public function handle_request_supports_middleware_applied_to_a_specific_method_ /** @test */ public function handle_request_supports_middleware_applied_to_a_specific_method_using_except() { - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $controller = new TestControllerWithMiddleware; $controller->middleware(new AddHeaderMiddleware('X-Header', 'testing123'))->except('handle'); $app->bind(TestControllerWithMiddleware::class, $controller); @@ -290,7 +290,7 @@ public function handle_request_supports_middleware_aliases() } }); - $app = new Application(__DIR__.'/../'); + $app = new Application(__DIR__ . '/../'); $controller = new TestControllerWithMiddleware; $controller->middleware('middleware-key'); @@ -315,10 +315,10 @@ public function handle_request_supports_middleware_aliases() public function handle_template_include_will_call_app_shutdown_when_it_has_handled_a_request() { $response = new TextResponse('Testing 123', 404); - $app = Mockery::mock(Application::class.'[shutdown]', [__DIR__.'/..']); + $app = Mockery::mock(Application::class . '[shutdown]', [__DIR__ . '/..']); $app->shouldReceive('shutdown')->times(1)->with($response); - $provider = Mockery::mock(WordPressControllersServiceProvider::class.'[handleRequest]', [$app]); + $provider = Mockery::mock(WordPressControllersServiceProvider::class . '[handleRequest]', [$app]); $provider->shouldReceive('handleRequest')->once()->andReturn($response); $provider->boot($app); @@ -328,10 +328,10 @@ public function handle_template_include_will_call_app_shutdown_when_it_has_handl /** @test */ public function handle_template_include_will_not_call_app_shutdown_when_it_has_not_handled_a_request() { - $app = Mockery::mock(Application::class.'[shutdown]', [__DIR__.'/..']); + $app = Mockery::mock(Application::class . '[shutdown]', [__DIR__ . '/..']); $app->shouldReceive('shutdown')->times(0); - $provider = Mockery::mock(WordPressControllersServiceProvider::class.'[handleRequest]', [$app]); + $provider = Mockery::mock(WordPressControllersServiceProvider::class . '[handleRequest]', [$app]); $provider->shouldReceive('handleRequest')->once()->andReturn(false); $provider->boot($app); @@ -343,7 +343,6 @@ class TestController { public function handle() { - } } @@ -351,12 +350,10 @@ class TestControllerWithConstructorParams { public function __construct(Application $app) { - } public function handle() { - } } @@ -364,13 +361,12 @@ class TestControllerWithHandleParams { public function handle(Application $app) { - } } class MyResponsable implements Responsable { - public function toResponse(RequestInterface $request) : ResponseInterface + public function toResponse(RequestInterface $request): ResponseInterface { return new TextResponse('testing123'); } @@ -388,7 +384,6 @@ class TestControllerWithMiddleware extends Controller { public function handle() { - } } @@ -403,7 +398,7 @@ public function __construct($key, $value) $this->value = $value; } - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $response = $handler->handle($request); diff --git a/tests/Unit/ScopedQueryBuilderTest.php b/tests/Unit/ScopedQueryBuilderTest.php index a5e6c31..655231f 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -10,6 +10,7 @@ use Rareloop\Lumberjack\Post; use Rareloop\Lumberjack\QueryBuilder; use Rareloop\Lumberjack\ScopedQueryBuilder; +use Throwable; use Timber\Timber; class ScopedQueryBuilderTest extends TestCase @@ -17,6 +18,8 @@ class ScopedQueryBuilderTest extends TestCase use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration, \DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; + private Application $app; + public function setUp(): void { $this->app = new Application; @@ -112,10 +115,16 @@ public function can_pass_params_into_a_query_scope_on_post_object() */ public function missing_query_scope_throws_an_error() { - $this->expectError(); + $errorThrown = false; - $builder = new ScopedQueryBuilder(PostWithQueryScope::class); - $builder->nonExistentScope(); + try { + $builder = new ScopedQueryBuilder(PostWithQueryScope::class); + $builder->nonExistentScope(); + } catch (Throwable $e) { + $errorThrown = true; + } + + $this->assertTrue($errorThrown); } /** @test */