From 6790cea51ee865381f6ac7509a9dd0ecc03f24da Mon Sep 17 00:00:00 2001 From: shimabox Date: Sat, 10 Dec 2022 19:45:48 +0900 Subject: [PATCH 01/16] :shower: Drop php7.3 --- .github/workflows/run-tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 468778d..851ec21 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 7.4, 7.3] + php: [8.0, 7.4] laravel: [8.*, 7.*, 6.*] stability: [prefer-lowest, prefer-stable] include: diff --git a/composer.json b/composer.json index 52321a2..86c2da0 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": "^7.3|^8.0", + "php": "^7.4|^8.0", "illuminate/support": "^6.0|^7.0|^8.0|^9.0", "doctrine/sql-formatter": "^1.1" }, From d0781cb690c1e11c74982dee30a5e1a7028a3694 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:10:45 +0900 Subject: [PATCH 02/16] :arrow_up: Clean up dependencies. --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 86c2da0..a926e19 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ "orchestra/testbench": "^4.0|^5.0|^6.0", "friendsofphp/php-cs-fixer": "^2.19", "kubawerlos/php-cs-fixer-custom-fixers": "^2.5", - "mockery/mockery": "^1.4|^1.5", - "nunomaduro/larastan": "^0.7|^1.0" + "mockery/mockery": "^1.5", + "nunomaduro/larastan": "^1.0|^2.0" }, "autoload": { "psr-4": { From 08d29ddc5e7073c63976fc22d905c5b93ac02783 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:36:53 +0900 Subject: [PATCH 03/16] :arrow_up: - Upgrade version of "friendsofphp/php-cs-fixer" to ^3.13 - Upgrade version of "kubawerlos/php-cs-fixer-custom-fixers to ^3.10 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a926e19..bf081fc 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ "require-dev": { "phpunit/phpunit": "^8.0|^9.0", "orchestra/testbench": "^4.0|^5.0|^6.0", - "friendsofphp/php-cs-fixer": "^2.19", - "kubawerlos/php-cs-fixer-custom-fixers": "^2.5", + "friendsofphp/php-cs-fixer": "^3.13", + "kubawerlos/php-cs-fixer-custom-fixers": "^3.10", "mockery/mockery": "^1.5", "nunomaduro/larastan": "^1.0|^2.0" }, From 87c7c952f95b9408c32e0dacb80b02a129cb9d83 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:37:06 +0900 Subject: [PATCH 04/16] :+1: Fix usage of php-cs-fixer. --- .php_cs.dist => .php-cs-fixer.dist.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename .php_cs.dist => .php-cs-fixer.dist.php (99%) diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 99% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 51bd085..e9c9309 100755 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -6,7 +6,8 @@ ->in('src') ->in('tests'); -return PhpCsFixer\Config::create() +$config = new PhpCsFixer\Config(); +return $config ->setRiskyAllowed(true) ->setRules([ // Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one. From 76a0020f68e1f763731ed5e1cf52bcf4eccb2a56 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:37:42 +0900 Subject: [PATCH 05/16] :+1: Rule "PhpCsFixerCustomFixers/internal_class_casing" is deprecated. Use "class_reference_name_casing" instead. --- .php-cs-fixer.dist.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e9c9309..5e780d1 100755 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -30,6 +30,8 @@ 'class_attributes_separation' => true, // Whitespace around the keywords of a class, trait or interfaces definition should be one space. 'class_definition' => true, + // When referencing an internal class it must be written using the correct casing. + 'class_reference_name_casing' => true, // Remove extra spaces in a nullable typehint. 'compact_nullable_typehint' => true, // Concatenation should be spaced according configuration. @@ -246,8 +248,6 @@ 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], // Comment must be surrounded by spaces. PhpCsFixerCustomFixers\Fixer\CommentSurroundedBySpacesFixer::name() => true, - // Class defined internally by an extension, or the core should be called using the correct casing. - PhpCsFixerCustomFixers\Fixer\InternalClassCasingFixer::name() => true, ]) ->registerCustomFixers( new PhpCsFixerCustomFixers\Fixers() From 73a03c2e84d9f73941e44e11887ce923c9bcccae Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:38:15 +0900 Subject: [PATCH 06/16] :+1: Fix rule name. - Rule "no_trailing_comma_in_list_call" is deprecated. Use "no_trailing_comma_in_singleline" instead. - Rule "no_trailing_comma_in_singleline_array" is deprecated. Use "no_trailing_comma_in_singleline" instead. --- .php-cs-fixer.dist.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 5e780d1..968906a 100755 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -134,10 +134,8 @@ 'no_spaces_around_offset' => true, // There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis. 'no_spaces_inside_parenthesis' => true, - // Remove trailing commas in list function calls. - 'no_trailing_comma_in_list_call' => true, - // PHP single-line arrays should not have trailing comma. - 'no_trailing_comma_in_singleline_array' => true, + // If a list of values separated by a comma is contained on a single line, then the last item MUST NOT have a trailing comma. + 'no_trailing_comma_in_singleline' => true, // Remove trailing whitespace at the end of non-blank lines. 'no_trailing_whitespace' => true, // There MUST be no trailing spaces inside comment or PHPDoc. From 27e0409e457d679c8c99f6eff34a9b5db319a759 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:38:45 +0900 Subject: [PATCH 07/16] :+1: Fix usage. --- .php-cs-fixer.dist.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 968906a..b66ccca 100755 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -36,6 +36,8 @@ 'compact_nullable_typehint' => true, // Concatenation should be spaced according configuration. 'concat_space' => ['spacing' => 'one'], + // The PHP constants `true`, `false`, and `null` MUST be in lower case. + 'constant_case' => true, // Equal sign in declare statement should be surrounded by spaces or not following configuration. 'declare_equal_normalize' => true, // Force strict types declaration in all files. Requires PHP >= 7.0. @@ -64,6 +66,8 @@ 'function_typehint_space' => true, // Configured annotations should be omitted from PHPDoc. 'general_phpdoc_annotation_remove' => ['annotations' => ['author']], + // Renames PHPDoc tags.. + 'general_phpdoc_tag_rename' => ['replacements' => ['inheritDocs' => 'inheritDoc']], // Imports or fully qualifies global classes/functions/constants. 'global_namespace_import' => true, // Include/Require and file path should be divided with a single space. File path should not be placed under brackets. @@ -78,8 +82,6 @@ 'linebreak_after_opening_tag' => true, // Cast should be written in lower case. 'lowercase_cast' => true, - // The PHP constants `true`, `false`, and `null` MUST be in lower case. - 'lowercase_constants' => true, // PHP keywords MUST be in lower case. 'lowercase_keywords' => true, // Class static references `self`, `static` and `parent` MUST be in lower case. @@ -166,16 +168,12 @@ 'ordered_imports' => true, // PHPUnit annotations should be a FQCNs including a root namespace. 'php_unit_fqcn_annotation' => true, - // Order `@covers` annotation of PHPUnit tests. - 'php_unit_ordered_covers' => true, // PHPDoc should contain `@param` for all params. 'phpdoc_add_missing_param_annotation' => ['only_untyped' => false], // All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically. 'phpdoc_align' => true, // Docblocks should have the same indentation as the documented subject. 'phpdoc_indent' => true, - // Fix PHPDoc inline tags, make `@inheritdoc` always inline. - 'phpdoc_inline_tag' => true, // `@access` annotations should be omitted from PHPDoc. 'phpdoc_no_access' => true, // `@package` and `@subpackage` annotations should be omitted from PHPDoc. @@ -184,6 +182,8 @@ 'phpdoc_no_useless_inheritdoc' => true, // Annotations in PHPDoc should be ordered so that `@param` annotations come first, then `@throws` annotations, then `@return` annotations. 'phpdoc_order' => true, + // Order phpdoc tags by value. + 'phpdoc_order_by_value' => ['annotations' => ['covers', 'group']], // The type of `@return` annotations of methods returning a reference to itself must the configured one. 'phpdoc_return_self_reference' => true, // Scalar types should always be written in the same form. `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`. @@ -232,8 +232,8 @@ 'ternary_operator_spaces' => true, // Use `null` coalescing operator `??` where possible. Requires PHP >= 7.0. 'ternary_to_null_coalescing' => true, - // PHP multi-line arrays should have a trailing comma. - 'trailing_comma_in_multiline_array' => true, + // Multi-line arrays, arguments list, parameters list and match expressions must have a trailing comma. + 'trailing_comma_in_multiline' => ['elements' => ['arrays']], // Arrays should be formatted like function/method arguments, without leading or trailing single line space. 'trim_array_spaces' => true, // Unary operators should be placed adjacent to their operands. From 350327716987a383e6ed1602f7beec48fc456b68 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:39:08 +0900 Subject: [PATCH 08/16] :+1: Fix script. --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index bf081fc..8b2fe86 100644 --- a/composer.json +++ b/composer.json @@ -42,8 +42,8 @@ } }, "scripts": { - "phpcs": "php-cs-fixer fix --dry-run --diff --diff-format udiff --config=.php_cs.dist", - "phpcs:fix": "php-cs-fixer fix --diff --diff-format udiff --config=.php_cs.dist --verbose", + "phpcs": "php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.dist.php -v", + "phpcs:fix": "php-cs-fixer fix --config=.php-cs-fixer.dist.php -v", "phpstan": "phpstan analyse --memory-limit=2G", "test": "phpunit", "ci": [ From 7c96a1665bf6f8b5fc25fe3fd1b3accb5e75c2d3 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:39:40 +0900 Subject: [PATCH 09/16] :+1: Change ignore cache file name. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7bfd85c..f0c03c1 100755 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ composer.lock vendor .phpunit.result.cache -.php_cs.cache +.php-cs-fixer.cache tests/report From 773bbd514dd7a79c85632b69c6b14b40804051d3 Mon Sep 17 00:00:00 2001 From: shimabox Date: Sun, 11 Dec 2022 16:43:19 +0900 Subject: [PATCH 10/16] :shirt: Fixed php-cs-fixer. 1) src/Helper/QueryHelper.php (unary_operator_spaces, not_operator_with_successor_space, binary_operator_spaces) 2) src/Analyzer/QueryAnalyzer.php (phpdoc_align) 3) tests/QueryAssertionTest.php (binary_operator_spaces) --- src/Analyzer/QueryAnalyzer.php | 2 +- src/Helper/QueryHelper.php | 2 +- tests/QueryAssertionTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Analyzer/QueryAnalyzer.php b/src/Analyzer/QueryAnalyzer.php index c49856f..8ac8167 100755 --- a/src/Analyzer/QueryAnalyzer.php +++ b/src/Analyzer/QueryAnalyzer.php @@ -10,7 +10,7 @@ class QueryAnalyzer { /** - * @param callable $queryCaller Process to execute the query. + * @param callable $queryCaller Process to execute the query. * @return QueryList */ public function analyze(callable $queryCaller): QueryList diff --git a/src/Helper/QueryHelper.php b/src/Helper/QueryHelper.php index 63b4c53..98f61b1 100644 --- a/src/Helper/QueryHelper.php +++ b/src/Helper/QueryHelper.php @@ -96,7 +96,7 @@ private function adjustParameters(string $rawSql, array $parameters): array && ! isset($returnParameters[$matches[0]]) && ! isset($returnParameters[$matches[1]]) ) { - $value = $returnParameters[$index]; + $value = $returnParameters[$index]; $returnParameters[$matches[1]] = $value; unset($returnParameters[$index]); } diff --git a/tests/QueryAssertionTest.php b/tests/QueryAssertionTest.php index e9906b4..bc2b1e1 100755 --- a/tests/QueryAssertionTest.php +++ b/tests/QueryAssertionTest.php @@ -61,7 +61,7 @@ public function it_can_assert_multiple_queries() $this->assertQuery( function () { - $query = 'select * from authors where name like :name'; + $query = 'select * from authors where name like :name'; $author = DB::select($query, ['name' => '%Shakespeare']); Author::destroy($author[0]->id); }, From c76ebe8c9f8dc3ac44f5363db842b57e50d79df8 Mon Sep 17 00:00:00 2001 From: shimabox Date: Mon, 12 Dec 2022 19:48:51 +0900 Subject: [PATCH 11/16] :+1: :arrow_down: Fixing the version for laravel6. larave6 asks for symfony/process version 4 series, so respond to it. ``` laravel/framework[v6.0.0, ... , v6.20.44] require symfony/process ^4.3.4 -> satisfiable by symfony/process[v4.3.4, ... , v4.4.44]. ``` friendsofphp/php-cs-fixer is version "3.4.*". kubawerlos/php-cs-fixer-custom-fixers is version "3.7.*". --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8b2fe86..e19aa0c 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ "require-dev": { "phpunit/phpunit": "^8.0|^9.0", "orchestra/testbench": "^4.0|^5.0|^6.0", - "friendsofphp/php-cs-fixer": "^3.13", - "kubawerlos/php-cs-fixer-custom-fixers": "^3.10", + "friendsofphp/php-cs-fixer": "3.4.*", + "kubawerlos/php-cs-fixer-custom-fixers": "3.7.*", "mockery/mockery": "^1.5", "nunomaduro/larastan": "^1.0|^2.0" }, From 060b3759c53b75b6928999e77c73564e5552c7ff Mon Sep 17 00:00:00 2001 From: shimabox Date: Mon, 12 Dec 2022 19:51:19 +0900 Subject: [PATCH 12/16] :+1: :arrow_down: "class_reference_name_casing" is not yet available, use "PhpCsFixerCustomFixers/internal_class_casing". --- .php-cs-fixer.dist.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index b66ccca..f0783d3 100755 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -30,8 +30,6 @@ 'class_attributes_separation' => true, // Whitespace around the keywords of a class, trait or interfaces definition should be one space. 'class_definition' => true, - // When referencing an internal class it must be written using the correct casing. - 'class_reference_name_casing' => true, // Remove extra spaces in a nullable typehint. 'compact_nullable_typehint' => true, // Concatenation should be spaced according configuration. @@ -246,6 +244,8 @@ 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], // Comment must be surrounded by spaces. PhpCsFixerCustomFixers\Fixer\CommentSurroundedBySpacesFixer::name() => true, + // Class defined internally by an extension, or the core should be called using the correct casing. + PhpCsFixerCustomFixers\Fixer\InternalClassCasingFixer::name() => true, ]) ->registerCustomFixers( new PhpCsFixerCustomFixers\Fixers() From 7601641ce480d9e1b37c67b2c5758f0876464af6 Mon Sep 17 00:00:00 2001 From: shimabox Date: Mon, 12 Dec 2022 19:56:25 +0900 Subject: [PATCH 13/16] :+1: :arrow_down: Fixed rule. Revert "no_trailing_comma_in_list_call" and "no_trailing_comma_in_singleline_array". Since "no_trailing_comma_in_singleline" is not yet present. --- .php-cs-fixer.dist.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f0783d3..d44809d 100755 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -134,8 +134,10 @@ 'no_spaces_around_offset' => true, // There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis. 'no_spaces_inside_parenthesis' => true, - // If a list of values separated by a comma is contained on a single line, then the last item MUST NOT have a trailing comma. - 'no_trailing_comma_in_singleline' => true, + // Remove trailing commas in list function calls. + 'no_trailing_comma_in_list_call' => true, + // PHP single-line arrays should not have trailing comma. + 'no_trailing_comma_in_singleline_array' => true, // Remove trailing whitespace at the end of non-blank lines. 'no_trailing_whitespace' => true, // There MUST be no trailing spaces inside comment or PHPDoc. From 4d72f35cf2a731484a93e5ab840a4d0538af4238 Mon Sep 17 00:00:00 2001 From: shimabox Date: Mon, 12 Dec 2022 19:57:59 +0900 Subject: [PATCH 14/16] :shirt: Fixed php-cs-fixer. 1) src/Helper/QueryHelper.php (unary_operator_spaces, not_operator_with_successor_space, binary_operator_spaces) 2) tests/QueryAssertionTest.php (binary_operator_spaces) --- src/Helper/QueryHelper.php | 2 +- tests/QueryAssertionTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helper/QueryHelper.php b/src/Helper/QueryHelper.php index 98f61b1..63b4c53 100644 --- a/src/Helper/QueryHelper.php +++ b/src/Helper/QueryHelper.php @@ -96,7 +96,7 @@ private function adjustParameters(string $rawSql, array $parameters): array && ! isset($returnParameters[$matches[0]]) && ! isset($returnParameters[$matches[1]]) ) { - $value = $returnParameters[$index]; + $value = $returnParameters[$index]; $returnParameters[$matches[1]] = $value; unset($returnParameters[$index]); } diff --git a/tests/QueryAssertionTest.php b/tests/QueryAssertionTest.php index bc2b1e1..e9906b4 100755 --- a/tests/QueryAssertionTest.php +++ b/tests/QueryAssertionTest.php @@ -61,7 +61,7 @@ public function it_can_assert_multiple_queries() $this->assertQuery( function () { - $query = 'select * from authors where name like :name'; + $query = 'select * from authors where name like :name'; $author = DB::select($query, ['name' => '%Shakespeare']); Author::destroy($author[0]->id); }, From 34c76f0a9e42f85eee71ac9965eb63f989b76db4 Mon Sep 17 00:00:00 2001 From: shimabox Date: Mon, 12 Dec 2022 20:35:25 +0900 Subject: [PATCH 15/16] :+1: Compatible to php7.4 --- src/Helper/QueryHelper.php | 6 ++--- tests/Analyzer/QueryAnalyzerTest.php | 28 +++++++++------------- tests/Helper/QueryLogTest.php | 4 +--- tests/QueryAssertionTest.php | 36 ++++++++++------------------ 4 files changed, 27 insertions(+), 47 deletions(-) diff --git a/src/Helper/QueryHelper.php b/src/Helper/QueryHelper.php index 63b4c53..89c99b4 100644 --- a/src/Helper/QueryHelper.php +++ b/src/Helper/QueryHelper.php @@ -74,9 +74,9 @@ public function buildedQuery(string $rawSql, array $parameters = []): string * Adjust bind parameters. * * // When using queryBuilder. - * QueryHelper::buildedQuery(function () use ($query) { - * Author::whereRaw('name like :name', ['name' => '%Shakespeare'])->get(); - * }); + * QueryHelper::buildedQuery( + * fn () => Author::whereRaw('name like :name', ['name' => '%Shakespeare'])->get() + * ); * * In the above case, parameter will be [0 => "%Shakespeare"] and query of * "select * from authors where like like: name" cannot be assembled. diff --git a/tests/Analyzer/QueryAnalyzerTest.php b/tests/Analyzer/QueryAnalyzerTest.php index ccf0f51..25d347e 100755 --- a/tests/Analyzer/QueryAnalyzerTest.php +++ b/tests/Analyzer/QueryAnalyzerTest.php @@ -19,9 +19,7 @@ class QueryAnalyzerTest extends TestCase */ public function it_can_return_a_query_instance() { - $analyzed = QueryAnalyzer::analyze(function () { - Author::where('id', '=', 1)->get(); - }); + $analyzed = QueryAnalyzer::analyze(fn () => Author::where('id', '=', 1)->get()); $this->assertCount(1, $analyzed); @@ -39,9 +37,7 @@ public function it_can_return_a_query_instance() */ public function it_can_return_a_query_after_the_build() { - $analyzed = QueryAnalyzer::analyze(function () { - Author::all(); - }); + $analyzed = QueryAnalyzer::analyze(fn () => Author::all()); $this->assertCount(1, $analyzed); @@ -74,9 +70,7 @@ public function it_can_return_queries_after_the_build() */ public function it_can_assert_question_mark_parameters_in_QueryBuilder() { - $analyzed = QueryAnalyzer::analyze(function () { - Author::where('id', '=', 1)->get(); - }); + $analyzed = QueryAnalyzer::analyze(fn () => Author::where('id', '=', 1)->get()); $actual = QueryFormatter::compress($analyzed[0]->getBuildedQuery()); $expected = 'select * from authors where id = 1'; @@ -105,12 +99,12 @@ public function it_can_assert_question_mark_parameters_in_raw_sql() */ public function it_can_assert_for_named_parameter_in_QueryBuilder() { - $analyzed = QueryAnalyzer::analyze(function () { - Author::whereRaw( + $analyzed = QueryAnalyzer::analyze( + fn () => Author::whereRaw( 'name like :name', ['name' => '%Shakespeare'] - )->get(); - }); + )->get() + ); $actual = QueryFormatter::compress($analyzed[0]->getBuildedQuery()); $expected = 'select * from authors where name like \'%Shakespeare\''; @@ -143,12 +137,12 @@ public function it_can_assert_for_named_parameter_and_question_mark_parameter_in $from = $now->copy()->subDay(); $to = $now->copy()->addDay(); - $analyzed = QueryAnalyzer::analyze(function () use ($from, $to) { - Author::whereIn('id', [1, 2]) + $analyzed = QueryAnalyzer::analyze( + fn () => Author::whereIn('id', [1, 2]) ->whereRaw('name like :name', ['name' => '%Shakespeare']) ->whereBetween('updated_at', [$from, $to]) - ->get(); - }); + ->get() + ); $actual = QueryFormatter::compress($analyzed[0]->getBuildedQuery()); $expected = 'select * from authors where id in (1, 2) and name like \'%Shakespeare\' and updated_at between \'' . $from . '\' and \'' . $to . '\''; diff --git a/tests/Helper/QueryLogTest.php b/tests/Helper/QueryLogTest.php index c4e8c17..c9f5bf5 100755 --- a/tests/Helper/QueryLogTest.php +++ b/tests/Helper/QueryLogTest.php @@ -15,9 +15,7 @@ class QueryLogTest extends TestCase */ public function it_can_get_the_results_of_laravel_query_log() { - $actual = QueryLog::getQueryLog(function () { - Author::find(1); - }); + $actual = QueryLog::getQueryLog(fn () => Author::find(1)); $expectedQuery = 'select * from authors where authors.id = ? limit 1'; $expectedBindings = [1]; diff --git a/tests/QueryAssertionTest.php b/tests/QueryAssertionTest.php index e9906b4..3ff6083 100755 --- a/tests/QueryAssertionTest.php +++ b/tests/QueryAssertionTest.php @@ -31,9 +31,7 @@ public function it_can_assert_a_simple_query() $expectedBindings = [1, 2]; $this->assertQuery( - function () { - Author::find([1, 2]); - }, + fn () => Author::find([1, 2]), $expectedQuery, $expectedBindings ); @@ -87,9 +85,7 @@ public function it_can_assert_question_mark_parameters_in_QueryBuilder() $expectedBindings = [1]; $this->assertQuery( - function () { - Author::where('id', '=', 1)->get(); - }, + fn () => Author::where('id', '=', 1)->get(), $expectedQuery, $expectedBindings ); @@ -138,12 +134,10 @@ public function it_can_assert_for_named_parameter_in_QueryBuilder() $expectedBindings = ['%Shakespeare']; $this->assertQuery( - function () { - Author::whereRaw( - 'name like :name', - ['name' => '%Shakespeare'] - )->get(); - }, + fn () => Author::whereRaw( + 'name like :name', + ['name' => '%Shakespeare'] + )->get(), $expectedQuery, $expectedBindings ); @@ -206,12 +200,10 @@ public function it_can_assert_for_named_parameter_and_question_mark_parameter_in ]; $this->assertQuery( - function () use ($from, $to) { - Author::whereIn('id', [1, 2]) - ->whereRaw('name like :name', ['name' => '%Shakespeare']) - ->whereBetween('updated_at', [$from, $to]) - ->get(); - }, + fn () => Author::whereIn('id', [1, 2]) + ->whereRaw('name like :name', ['name' => '%Shakespeare']) + ->whereBetween('updated_at', [$from, $to]) + ->get(), $expectedQuery, $expectedBindings ); @@ -298,9 +290,7 @@ public function it_can_assert_for_belongsTo() ]; $this->assertQuery( - function () { - Book::find(1)->author()->get(); - }, + fn () => Book::find(1)->author()->get(), $expectedQueries, $expectedBindings ); @@ -325,9 +315,7 @@ public function it_can_assert_for_EagerLoad() ]; $this->assertQuery( - function () { - Author::with('books')->get(); - }, + fn () => Author::with('books')->get(), $expectedQueries, $expectedBindings ); From 7c97418ddeefc15248b5344891cd6f59534867bf Mon Sep 17 00:00:00 2001 From: shimabox Date: Mon, 12 Dec 2022 20:39:28 +0900 Subject: [PATCH 16/16] :memo: Update README.md --- README.md | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1208f9a..1cfcaeb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This library is intended to be used during development. ## Requirement -- PHP 7.3+ or newer(7.3, 7.4, 8.0) +- PHP 7.4+ or newer(7.4, 8.0) - Laravel `6.x`, `7.x`, `8.x` ## Installation @@ -48,7 +48,9 @@ Available within PHPUnit. ```php assertQuery( // Pass the process in which the query will be executed in the closure. - function () { - $this->exampleRepository->findById('a123'); - }, + fn () => $this->exampleRepository->findById('a123'), // Write the expected query. 'select from user where id = ? and is_active = ?', // Define the expected bind values as an array. @@ -86,10 +86,8 @@ class QueryAssertionTest extends TestCase // but there are cases where one method executes multiple queries. // In that case, define the query and bind value as an array pair as shown below. $this->assertQuery( - function () { - // For example, if multiple queries are executed in this process - $this->exampleRepository->findAll(); - }, + // For example, if multiple queries are executed in this process + fn () => $this->exampleRepository->findAll(), // Define an array for each expected query. [ 'select from user where is_active = ?', // ※1 @@ -235,9 +233,7 @@ QueryLog is a wrap on [Basic Database Usage - Laravel - The PHP Framework For We use Laqu\Facades\QueryLog; -$queryLog = QueryLog::getQueryLog(function () { - Author::find(1); -}); +$queryLog = QueryLog::getQueryLog(fn () => Author::find(1)); /* array:1 [