Skip to content

Commit

Permalink
Merge pull request #39 from shimabox/drop-php7.3
Browse files Browse the repository at this point in the history
Drop php7.3
  • Loading branch information
shimabox authored Dec 12, 2022
2 parents 164e5c4 + 7c97418 commit cdb9981
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
composer.lock
vendor
.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
tests/report
19 changes: 10 additions & 9 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -33,6 +34,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.
Expand Down Expand Up @@ -61,6 +64,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.
Expand All @@ -75,8 +80,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.
Expand Down Expand Up @@ -165,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.
Expand All @@ -183,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`.
Expand Down Expand Up @@ -231,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.
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +48,9 @@ Available within PHPUnit.
```php
<?php

use App\Repositories\ExampleRepository; // example.
use Laqu\QueryAssertion;
use Tests\TestCase;

class QueryAssertionTest extends TestCase
{
Expand All @@ -68,9 +70,7 @@ class QueryAssertionTest extends TestCase
// Basic usage.
$this->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.
Expand All @@ -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
Expand Down Expand Up @@ -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 [
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
}
],
"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"
},
"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",
"mockery/mockery": "^1.4|^1.5",
"nunomaduro/larastan": "^0.7|^1.0"
"friendsofphp/php-cs-fixer": "3.4.*",
"kubawerlos/php-cs-fixer-custom-fixers": "3.7.*",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^1.0|^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/QueryAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class QueryAnalyzer
{
/**
* @param callable $queryCaller Process to execute the query.
* @param callable $queryCaller Process to execute the query.
* @return QueryList<int, Query>
*/
public function analyze(callable $queryCaller): QueryList
Expand Down
6 changes: 3 additions & 3 deletions src/Helper/QueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 11 additions & 17 deletions tests/Analyzer/QueryAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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\'';
Expand Down Expand Up @@ -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 . '\'';
Expand Down
4 changes: 1 addition & 3 deletions tests/Helper/QueryLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
36 changes: 12 additions & 24 deletions tests/QueryAssertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand All @@ -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
);
Expand Down

0 comments on commit cdb9981

Please sign in to comment.