Skip to content

Commit e7a37e6

Browse files
committed
Added more kernel tests, cleaned up config, and updated schema.
1 parent d9f193f commit e7a37e6

23 files changed

+2268
-34
lines changed

.ahoy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ commands:
9393
if [[ "$COVERAGE_CHECK_VERSION" == *"PHPUnit Coverage Check 1"* ]]; then
9494
COVERAGE_CHECK_COMMAND="coverage:check"
9595
fi
96-
vendor/bin/coverage-check ${COVERAGE_CHECK_COMMAND:-} ../.logs/coverage/phpunit/clover.xml 50
96+
vendor/bin/coverage-check ${COVERAGE_CHECK_COMMAND:-} ../.logs/coverage/phpunit/clover.xml 90
9797
popd >/dev/null || exit 1
9898
9999
reset:

.github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,14 @@ jobs:
160160

161161
- name: Check code coverage
162162
working-directory: build
163-
run: vendor/bin/coverage-check ${CI_CHECK_COVERAGE_EXTRA:-} ${CI_CHECK_COVERAGE_COMMAND:-} ../.logs/coverage/phpunit/clover.xml "${CI_CHECK_COVERAGE_THRESHOLD:-50}" || [ "${CI_CHECK_COVERAGE_IGNORE_FAILURE:-0}" -eq 1 ]
163+
run: vendor/bin/coverage-check ${CI_CHECK_COVERAGE_EXTRA:-} ${CI_CHECK_COVERAGE_COMMAND:-} ../.logs/coverage/phpunit/clover.xml "${CI_CHECK_COVERAGE_THRESHOLD:-90}" || [ "${CI_CHECK_COVERAGE_IGNORE_FAILURE:-0}" -eq 1 ]
164164
if: always()
165165
env:
166166
# Drupal 10 uses older version of coverage-check which requires an extra param.
167167
CI_CHECK_COVERAGE_COMMAND: ${{ contains(matrix.name, 'd10') && 'coverage:check' || '' }}
168168
CI_CHECK_COVERAGE_EXTRA: ${{ contains(matrix.name, 'd10') && '--no-ansi' || '' }}
169-
# TODO: Increase the threshold to 80-90% when we have enough tests.
170-
CI_CHECK_COVERAGE_THRESHOLD: ${{ vars.CI_CHECK_COVERAGE_THRESHOLD || 50 }}
171-
# Temporarily accept code coverage check failure.
172-
CI_CHECK_COVERAGE_IGNORE_FAILURE: ${{ vars.CI_CHECK_COVERAGE_IGNORE_FAILURE || 1}}
169+
CI_CHECK_COVERAGE_THRESHOLD: ${{ vars.CI_CHECK_COVERAGE_THRESHOLD || 90 }}
170+
CI_CHECK_COVERAGE_IGNORE_FAILURE: ${{ vars.CI_CHECK_COVERAGE_IGNORE_FAILURE || 0 }}
173171

174172
- name: Upload test results as an artifact
175173
uses: actions/upload-artifact@v4

.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ variables:
7979
if [[ "$COVERAGE_CHECK_VERSION" == *"PHPUnit Coverage Check 1"* ]]; then
8080
COVERAGE_CHECK_COMMAND="coverage:check"
8181
fi
82-
vendor/bin/coverage-check ${COVERAGE_CHECK_COMMAND:-} $CI_PROJECT_DIR/$_WEB_ROOT/.logs/coverage/phpunit/clover.xml 50 || true
82+
vendor/bin/coverage-check ${COVERAGE_CHECK_COMMAND:-} $CI_PROJECT_DIR/$_WEB_ROOT/.logs/coverage/phpunit/clover.xml ${CI_CHECK_COVERAGE_THRESHOLD:-90}
8383
# Capture line coverage counts for GitLab UI display.
8484
coverage: /^\s*Lines:\s*\d+.\d+\%/
8585
artifacts:
@@ -89,7 +89,8 @@ variables:
8989
coverage_report:
9090
coverage_format: cobertura
9191
path: $CI_PROJECT_DIR/$_WEB_ROOT/.logs/coverage/phpunit/cobertura.xml
92-
92+
variables:
93+
CI_CHECK_COVERAGE_THRESHOLD: 90
9394

9495
phpunit (previous major):
9596
variables:

src/Plugin/WebformHandler/OpenFiscaJourneyHandler.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class OpenFiscaJourneyHandler extends WebformHandlerBase {
5151
*/
5252
protected RacContentHelperInterface $racContentHelper;
5353

54+
/**
55+
* The debug data from the last API call to OpenFisca.
56+
*
57+
* @var array<string, \Drupal\webform_openfisca\OpenFisca\Payload>
58+
*/
59+
protected array $recentDebugData = [];
60+
5461
/**
5562
* {@inheritdoc}
5663
*/
@@ -83,7 +90,9 @@ public function submitForm(array &$form, FormStateInterface $form_state, Webform
8390
public function alterElement(array &$element, FormStateInterface $form_state, array $context) : void {
8491
$form_object = $form_state->getFormObject();
8592
if (!$form_object instanceof WebformSubmissionForm) {
93+
// @codeCoverageIgnoreStart
8694
return;
95+
// @codeCoverageIgnoreEnd
8796
}
8897
if ($form_object->getOperation() !== 'add') {
8998
return;
@@ -157,7 +166,7 @@ public function requestOpenFiscaImmediateResponse(array $form, FormStateInterfac
157166
}
158167
else {
159168
$triggering_element = $form_state->getTriggeringElement();
160-
if (isset($values[$triggering_element['#name']])) {
169+
if (isset($triggering_element['#name'], $values[$triggering_element['#name']])) {
161170
$data = [
162171
'name' => $triggering_element['#name'],
163172
'webform' => $triggering_element['#webform'] ?? $webform->id(),
@@ -260,7 +269,9 @@ protected function prepareOpenfiscaPayload(WebformSubmissionInterface $webform_s
260269
$role = $fisca_entity_role['role'] ?? NULL;
261270
$is_array = $fisca_entity_role['is_array'] ?? FALSE;
262271
if (empty($role)) {
272+
// @codeCoverageIgnoreStart
263273
continue;
274+
// @codeCoverageIgnoreEnd
264275
}
265276
// The role will be in the format
266277
// group_entity.group_entity_key.role.entity_key
@@ -350,7 +361,10 @@ protected function determineBenefits(RequestPayload $request_payload, ?ResponseP
350361
foreach ($fisca_field_mappings as $webform_key => $openfisca_key) {
351362
// Always ignore period key.
352363
if ($webform_key === 'period') {
364+
// @codeCoverageIgnoreStart
365+
// Period should be alread unset while being prepared.
353366
continue;
367+
// @codeCoverageIgnoreEnd
354368
}
355369
if ($openfisca_key !== '_nil') {
356370
// The openfisca_key will be in the format
@@ -461,6 +475,15 @@ protected function overrideConfirmationUrl(ResponsePayload $response_payload) :
461475
public function logDebug(RequestPayload $request_payload, ?ResponsePayload $response_payload, bool $show_message = TRUE) : void {
462476
$webform = $this->getWebform();
463477
$openfisca_settings = WebformOpenFiscaSettings::load($webform);
478+
479+
// Set the debug data.
480+
if ($openfisca_settings->isDebugEnabled()) {
481+
$this->recentDebugData = [
482+
'request' => $request_payload,
483+
'response' => $response_payload,
484+
];
485+
}
486+
464487
if (!$openfisca_settings->isDebugEnabled() && !$openfisca_settings->isLoggingEnabled()) {
465488
return;
466489
}
@@ -554,4 +577,16 @@ public function logDebug(RequestPayload $request_payload, ?ResponsePayload $resp
554577
}
555578
}
556579

580+
/**
581+
* Return the debug data from the last API call to OpenFisca.
582+
*
583+
* @return \Drupal\webform_openfisca\OpenFisca\Payload[]
584+
* The data array with 2 keys if debug mode is enabled:
585+
* - request
586+
* - response
587+
*/
588+
public function getRecentDebugData() : array {
589+
return $this->recentDebugData;
590+
}
591+
557592
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"defaultValue": 0,
3+
"definitionPeriod": "DAY",
4+
"description": "Disability allowance eligibility amount",
5+
"entity": "person",
6+
"formulas": {
7+
"0001-01-01": {
8+
"content": "def formula(person, period, parameters):\n \"\"\"Calculate Disability Allowance eligibility amount.\"\"\"\n # Retrieve the values of the input variables\n disability_allowance_eligible = person(\"disability_allowance_eligible\", period)\n\n # Retrieve the values of the parameters\n disability_allowance_benefit = parameters(period).disability_allowance_benefit\n\n # Return the benefit amount if eligible, 0 otherwise\n return where(disability_allowance_eligible, disability_allowance_benefit, 0)\n",
9+
"documentation": "Calculate Disability Allowance eligibility amount.",
10+
"source": "https://github.com/openfisca/country-template/blob/0.0.1/openfisca_rules/variables/disability_allowance.py#L109-L118"
11+
}
12+
},
13+
"id": "disability_allowance_benefit",
14+
"references": [
15+
"https://law.gov.example/disability_allowance_benefit"
16+
],
17+
"source": "https://github.com/openfisca/country-template/blob/0.0.1/openfisca_rules/variables/disability_allowance.py#L101-L117",
18+
"valueType": "Float"
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"defaultValue": false,
3+
"definitionPeriod": "DAY",
4+
"description": "Eligibility for immediate exit",
5+
"entity": "person",
6+
"formulas": {
7+
"0001-01-01": {
8+
"content": "def formula(person, period):\n \"\"\"Calculate the eligibility for immediate exit.\"\"\"\n # Retrieve the values of the input variables\n australian_citizen_or_permanent_resident = person(\"australian_citizen_or_permanent_resident\", period)\n has_disability = person(\"has_disability\", period)\n giving_care_to_disabled = person(\"giving_care_to_disabled\", period)\n meets_pension_age = person(\"meets_pension_age\", period)\n dependant_children = person(\"dependant_children\", period)\n looking_for_work_unable_to_work = person(\"looking_for_work_unable_to_work\", period)\n currently_studying = person(\"currently_studying\", period)\n\n # Check if any condition is met for eligibility\n eligible_conditions = (\n has_disability | giving_care_to_disabled | meets_pension_age | dependant_children | looking_for_work_unable_to_work | currently_studying\n )\n\n # Determine eligibility\n return select(\n [\n australian_citizen_or_permanent_resident & eligible_conditions,\n logical_not(australian_citizen_or_permanent_resident),\n ],\n [\n True,\n True,\n ],\n )\n",
9+
"documentation": "Calculate the eligibility for immediate exit.",
10+
"source": "https://github.com/openfisca/country-template/blob/0.0.1/openfisca_rules/variables/sa.py#L343-L369"
11+
}
12+
},
13+
"id": "exit",
14+
"source": "https://github.com/openfisca/country-template/blob/0.0.1/openfisca_rules/variables/sa.py#L335-L368",
15+
"valueType": "Boolean"
16+
}

tests/fixtures/api.openfisca.test/__GET/variables.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
"description": "Disability allowance eligibility",
3636
"href": "https://api.openfisca.test/variable/disability_allowance_eligible"
3737
},
38+
"exit": {
39+
"description": "Eligibility for immediate exit",
40+
"href": "https://api.openfisca.test/variable/exit"
41+
},
3842
"has_disability": {
3943
"description": "I <do/do not> have a disability",
4044
"href": "https://api.openfisca.test/variable/has_disability"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"persons": {
3+
"personA": {
4+
"aus_citizen": {
5+
"2025-01-01": true
6+
},
7+
"disability_allowance_benefit": {
8+
"2025-01-01": 1
9+
},
10+
"disability_allowance_eligible": {
11+
"2025-01-01": true
12+
},
13+
"has_disability": {
14+
"2025-01-01": true
15+
},
16+
"monthly_income": {
17+
"2025-01-01": "100"
18+
},
19+
"monthly_income_exceeds_limit": {
20+
"2025-01-01": false
21+
},
22+
"requires_ongoing_supervision_or_treatment": {
23+
"2025-01-01": true
24+
},
25+
"requires_ongoing_support": {
26+
"2025-01-01": true
27+
}
28+
}
29+
}
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"persons": {
3+
"personA": {
4+
"aus_citizen": {
5+
"2025-01-01": false
6+
},
7+
"disability_allowance_benefit": {
8+
"2025-01-01": 0
9+
},
10+
"disability_allowance_eligible": {
11+
"2025-01-01": false
12+
},
13+
"has_disability": {
14+
"2025-01-01": null
15+
},
16+
"monthly_income": {
17+
"2025-01-01": null
18+
},
19+
"monthly_income_exceeds_limit": {
20+
"2025-01-01": null
21+
},
22+
"requires_ongoing_supervision_or_treatment": {
23+
"2025-01-01": null
24+
},
25+
"requires_ongoing_support": {
26+
"2025-01-01": null
27+
},
28+
"exit": {
29+
"2025-01-01": true
30+
}
31+
}
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"persons": {
3+
"personA": {
4+
"aus_citizen": {
5+
"2025-01-01": true
6+
},
7+
"disability_allowance_benefit": {
8+
"2025-01-01": 0
9+
},
10+
"disability_allowance_eligible": {
11+
"2025-01-01": false
12+
},
13+
"has_disability": {
14+
"2025-01-01": true
15+
},
16+
"monthly_income": {
17+
"2025-01-01": "500"
18+
},
19+
"monthly_income_exceeds_limit": {
20+
"2025-01-01": true
21+
},
22+
"requires_ongoing_supervision_or_treatment": {
23+
"2025-01-01": true
24+
},
25+
"requires_ongoing_support": {
26+
"2025-01-01": true
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)