diff --git a/.editorconfig b/.editorconfig index 243e8a7..5d61ef1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,24 +1,24 @@ -# top-most EditorConfig file -root = true - -[*] -charset = utf-8 -end_of_line = crlf - -; temporary -trim_trailing_whitespace = true - -[*.php] -indent_style = spaces -indent_size = 4 -insert_final_newline = true - -[*.md] -indent_style = spaces -indent_size = 4 -insert_final_newline = true - -[vendor/**] -; Use editor default (possible autodetection). -indent_style = -indent_size = +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf + +; temporary +trim_trailing_whitespace = true + +[*.php] +indent_style = spaces +indent_size = 4 +insert_final_newline = true + +[*.md] +indent_style = spaces +indent_size = 4 +insert_final_newline = true + +[vendor/**] +; Use editor default (possible autodetection). +indent_style = +indent_size = diff --git a/.gitignore b/.gitignore index e96516b..41ad22c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock vendor .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache deleted file mode 100644 index 0da249f..0000000 --- a/.php-cs-fixer.cache +++ /dev/null @@ -1 +0,0 @@ -{"php":"8.1.34","version":"3.93.1:v3.93.1#b3546ab487c0762c39f308dc1ec0ea2c461fc21a","indent":" ","lineEnding":"\n","rules":{"nullable_type_declaration":true,"operator_linebreak":true,"ordered_types":true,"single_class_element_per_statement":true,"types_spaces":true,"array_indentation":true,"array_syntax":true,"attribute_block_no_spaces":true,"cast_spaces":true,"concat_space":{"spacing":"one"},"function_declaration":{"closure_fn_spacing":"none"},"method_argument_space":{"after_heredoc":true},"new_with_parentheses":{"anonymous_class":false},"single_line_empty_body":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const","const_import","do","else","elseif","enum","final","finally","for","foreach","function","function_import","if","insteadof","interface","match","named_argument","namespace","new","private","protected","public","readonly","static","switch","trait","try","type_colon","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"trailing_comma_in_multiline":{"after_heredoc":true},"binary_operator_spaces":{"operators":{"=>":"align_single_space_minimal","=":"align_single_space_minimal","!=":"align_single_space_minimal",".=":"align_single_space_minimal","+=":"align_single_space_minimal","??":"align_single_space_minimal"}},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_anonymous_functions":false,"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"modifier_keywords":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["attribute","break","case","continue","curly_brace_block","default","extra","parenthesis_brace_block","return","square_brace_block","switch","throw","use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"simple_to_complex_string_variable":true,"octal_notation":true,"clean_namespace":true,"no_unset_cast":true,"assign_null_coalescing_to_coalesce_equal":true,"normalize_index_brace":true,"heredoc_indentation":true,"no_whitespace_before_comma_in_array":{"after_heredoc":true},"list_syntax":true,"ternary_to_null_coalescing":true,"align_multiline_comment":true,"blank_line_before_statement":{"statements":["case","continue","declare","default","exit","goto","include","include_once","phpdoc","require","require_once","return","switch","throw","try","yield","yield_from"]},"class_reference_name_casing":true,"class_attributes_separation":{"elements":{"method":"one"}},"dir_constant":true,"include":true,"magic_constant_casing":true,"magic_method_casing":true,"method_chaining_indentation":true,"native_function_casing":true,"native_type_declaration_casing":true,"no_alternative_syntax":true,"no_blank_lines_after_phpdoc":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_singleline":true,"no_unneeded_control_parentheses":true,"no_useless_concat_operator":true,"no_useless_else":true,"no_unused_imports":true,"phpdoc_indent":true,"phpdoc_order":{"order":["param","return","throws"]},"phpdoc_no_package":true,"phpdoc_trim":true,"return_assignment":true,"single_line_comment_spacing":true,"single_quote":true,"trim_array_spaces":true,"type_declaration_spaces":true},"ruleCustomisationPolicyVersion":"null-policy","hashes":{"tests\/granada\/ModelPrefixingTest.php":"0013bf610a4d67c1d0edafaf8c09e4da","tests\/granada\/GranadaTest.php":"47c69dd7ad1692be451cf2342c7b283e","tests\/granada\/MultipleConnectionsTest.php":"06d11a0a9bf28c19ed0cbc07ced80038","tests\/granada\/GranadaNewTest.php":"60db643be25aed4720320d5e5d93315d","tests\/granada\/EagerTest.php":"c48760ea569c80a6a59aa43b98a03b98","tests\/orm\/QueryBuilderTest.php":"add2ef7b01aa28ae314ac375163ac2f3","tests\/orm\/CacheTest.php":"55aca553d51deddaa0a13071dfeed06c","tests\/orm\/CamelCaseTest.php":"4972bbdc0a398a1a2abf06c301ad2048","tests\/orm\/ORMTest.php":"b937bd94bef9f69e37e913b69602f921","tests\/orm\/ConfigTest.php":"1c4f86a0c1749f056907bf7065bd7ab0","tests\/orm\/MulitpleConnectionTest.php":"7866f37d72ad16631794738f1e8f0d35","tests\/orm\/QueryBuilderPsr1Test53.php":"7c34b71d95e34397c9c5bea3685e94ee","tests\/orm\/ConfigTest53.php":"cb9b141b8ba006f35b9e5f13217d8add","tests\/orm\/QueryBuilderMssqlTest.php":"feda9c7b19fc40abd854e6ad9b0a8644","tests\/orm\/IdiormResultSetTest.php":"8481a21ee86f7af76452866a33cc47d2","tests\/bootstrap.php":"d459a5280b36f8117d1422c08a383e6d","tests\/MockPDO.php":"cc6c08be358edb750e7b5c99b435a470","tests\/models.php":"2ee92b84dc50c1d5fa3a84f89a3fd5c7","src\/Granada\/Granada.php":"24c96c3dacd33c8ac810dc50ffb06da3","src\/Granada\/Orm\/Str.php":"f02d0c44266bc3e938b2df0043c1b799","src\/Granada\/Orm\/Wrapper.php":"a1f4e7ac1d2494d13f9e0e60f4afb7d2","src\/Granada\/Eager.php":"33caf4ecbc45406912b1a8557131d6bb","src\/Granada\/Model.php":"e7833839b827e9fe34b0bb526a14bc64","src\/Granada\/ResultSet.php":"9a5cb6d378a42b096562f2d7f750210d","src\/Granada\/ORM.php":"205d6e47804fbe4ab76c7a91f958f538"}} \ No newline at end of file diff --git a/src/Granada/ORM.php b/src/Granada/ORM.php index 1018e1a..3509c81 100644 --- a/src/Granada/ORM.php +++ b/src/Granada/ORM.php @@ -979,8 +979,11 @@ public function select($column, $alias = null) foreach ($columns as $column) { if ($column == '*') { if (!$this->_using_default_result_columns) { - // Put the * to the front of the list - $this->_result_columns = array_merge(['*'], $this->_result_columns); + // Check if we are already selecting '*' + if (($this->_result_columns[\array_key_first($this->_result_columns)] ?? '') != '*') { + // Put the * to the front of the list + $this->_result_columns = array_merge(['*'], $this->_result_columns); + } } } else { $column = $this->_quote_identifier($column); diff --git a/tests/orm/QueryBuilderTest.php b/tests/orm/QueryBuilderTest.php index d090a6c..caa0283 100644 --- a/tests/orm/QueryBuilderTest.php +++ b/tests/orm/QueryBuilderTest.php @@ -704,6 +704,21 @@ public function testSelectAsteriskColumn() $this->assertEquals($expected, ORM::get_last_query()); } + public function testSelectAsteriskColumnTwice() + { + ORM::for_table('widget')->select('name')->find_many(); + $expected = 'SELECT `name` FROM `widget`'; + $this->assertEquals($expected, ORM::get_last_query()); + + ORM::for_table('widget')->select('name')->select('*')->select('*')->find_many(); + $expected = 'SELECT *, `name` FROM `widget`'; + $this->assertEquals($expected, ORM::get_last_query()); + + ORM::for_table('widget')->select('*')->select('*')->find_many(); + $expected = 'SELECT * FROM `widget`'; + $this->assertEquals($expected, ORM::get_last_query()); + } + public function testSimpleResultColumn() { ORM::for_table('widget')->select('name')->find_many();