@@ -15,12 +15,12 @@ CLASS y_check_db_access_in_ut DEFINITION PUBLIC INHERITING FROM y_check_base CRE
15
15
DATA tokens_not_allowed TYPE y_char255_tab.
16
16
DATA has_framework TYPE abap_bool .
17
17
18
- METHODS inspect_class_definition IMPORTING method TYPE sstruc.
18
+ METHODS inspect_class_definition IMPORTING class_implementation TYPE sstruc.
19
19
20
20
METHODS is_persistent_object IMPORTING obj_name TYPE string
21
21
RETURNING VALUE (result ) TYPE abap_bool .
22
22
23
- METHODS consolidade_tokens IMPORTING statement TYPE sstmnt
23
+ METHODS consolidade_tokens IMPORTING statement TYPE sstmnt
24
24
RETURNING VALUE (result ) TYPE string .
25
25
26
26
METHODS has_ddic_itab_same_syntax IMPORTING token TYPE char255
@@ -32,7 +32,8 @@ CLASS y_check_db_access_in_ut DEFINITION PUBLIC INHERITING FROM y_check_base CRE
32
32
ENDCLASS .
33
33
34
34
35
- CLASS y_check_db_access_in_ut IMPLEMENTATION .
35
+
36
+ CLASS Y_CHECK_DB_ACCESS_IN_UT IMPLEMENTATION .
36
37
37
38
38
39
METHOD constructor .
@@ -47,7 +48,7 @@ CLASS y_check_db_access_in_ut IMPLEMENTATION.
47
48
settings-apply_on_test_code = abap_true .
48
49
settings-documentation = | { c_docs_path-checks } db-access-in-ut.md| .
49
50
50
- relevant_statement_types = VALUE #( ( scan_struc_stmnt_type-method ) ).
51
+ relevant_statement_types = VALUE #( ( scan_struc_stmnt_type-class_implementation ) ).
51
52
relevant_structure_types = VALUE #( ).
52
53
53
54
set_check_message( 'Database access(es) within a Unit-Test should be removed!' ).
@@ -85,9 +86,10 @@ CLASS y_check_db_access_in_ut IMPLEMENTATION.
85
86
ENDIF .
86
87
87
88
raise_error( statement_level = statement-level
88
- statement_index = index
89
- statement_from = statement-from
90
- error_priority = check_configuration-prio ).
89
+ statement_index = index
90
+ statement_from = statement-from
91
+ error_priority = check_configuration-prio ).
92
+
91
93
ENDLOOP .
92
94
ENDMETHOD .
93
95
@@ -102,18 +104,21 @@ CLASS y_check_db_access_in_ut IMPLEMENTATION.
102
104
METHOD inspect_class_definition .
103
105
DATA test_risk_level TYPE string .
104
106
105
- CLEAR has_framework.
106
-
107
107
TRY .
108
- DATA (class_implementation ) = ref_scan_manager->structures[ method-back ].
109
108
DATA (class_definition ) = ref_scan_manager->structures[ class_implementation-back ].
110
109
CATCH cx_sy_itab_line_not_found.
111
110
RETURN .
112
111
ENDTRY .
113
112
113
+ has_framework = abap_false .
114
+
114
115
LOOP AT ref_scan_manager->statements ASSIGNING FIELD-SYMBOL (<statement> )
115
- FROM class_definition-stmnt_from TO class_definition-stmnt_to.
116
- IF is_in_scope( <statement> ) = abap_false .
116
+ FROM class_definition-stmnt_from TO class_definition-stmnt_to.
117
+
118
+ IF is_in_scope( <statement> ) = abap_false
119
+ OR test_risk_level IS NOT INITIAL
120
+ OR has_framework EQ abap_true .
121
+
117
122
CONTINUE .
118
123
ENDIF .
119
124
@@ -143,7 +148,7 @@ CLASS y_check_db_access_in_ut IMPLEMENTATION.
143
148
144
149
METHOD consolidade_tokens .
145
150
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL (<token> )
146
- FROM statement-from TO statement-to.
151
+ FROM statement-from TO statement-to.
147
152
result = COND #( WHEN result IS INITIAL THEN condense ( <token> -str )
148
153
ELSE | { result } { condense( <token>-str ) } | ).
149
154
ENDLOOP .
@@ -159,12 +164,11 @@ CLASS y_check_db_access_in_ut IMPLEMENTATION.
159
164
160
165
METHOD is_internal_table .
161
166
DATA (second_token ) = get_token_abs( statement-from + 1 ).
162
- DATA (tirth_token ) = get_token_abs( statement-from + 2 ).
167
+ DATA (third_token ) = get_token_abs( statement-from + 2 ).
163
168
164
- DATA (table ) = COND #( WHEN second_token = 'FROM' THEN tirth_token
169
+ DATA (table ) = COND #( WHEN second_token = 'FROM' THEN third_token
165
170
ELSE second_token ).
166
171
167
172
result = xsdbool ( is_persistent_object( table ) = abap_false ).
168
173
ENDMETHOD .
169
-
170
174
ENDCLASS .
0 commit comments