Skip to content

Commit

Permalink
Merge pull request #15 from oat-sa/feat/tr5026/acs_action_update
Browse files Browse the repository at this point in the history
Feat/tr5026/acs action update
  • Loading branch information
poyuki authored Jan 24, 2023
2 parents 7b09e47 + 209cadb commit 792a0e4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
include:
- php: 8.0
coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8
- php: 8.1
coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8
- php: 8.2
coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8

steps:
- name: Checkout
Expand All @@ -39,7 +43,7 @@ jobs:
- name: Psalm
run: |
./vendor/bin/psalm --shepherd
- name: Coveralls
if: ${{ matrix.coverage == 'true' }}
env:
Expand Down
11 changes: 6 additions & 5 deletions src/Factory/AcsControlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public function create(array $data): AcsControlInterface
[
'title' => $resourceLinkData['title'] ?? null,
'text' => $resourceLinkData['description'] ?? null,
]);
]
);

$userData = $data['user'] ?? null;

Expand Down Expand Up @@ -94,8 +95,8 @@ public function create(array $data): AcsControlInterface
throw new InvalidArgumentException('Missing mandatory incident_time');
}

$extraTime = $data['extra_time'] ?? null;
$incidentSeverity = $data['incident_severity'] ?? null;
$extraTime = isset($data['extra_time']) ? (int)$data['extra_time'] : null;
$incidentSeverity = isset($data['incident_severity']) ? (float)$data['incident_severity'] : null;

return new AcsControl(
$resourceLink,
Expand All @@ -104,8 +105,8 @@ public function create(array $data): AcsControlInterface
new Carbon($incidentTime),
$attemptNumber,
$issuerIdentifier,
$extraTime ? intval($extraTime) : null,
$incidentSeverity ? floatval($incidentSeverity) : null,
$extraTime,
$incidentSeverity,
$data['reason_code'] ?? null,
$data['reason_msg'] ?? null
);
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/AcsControlResultFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function create(array $data): AcsControlResultInterface
throw new LtiException('Cannot create ACS control result: Invalid status');
}

$extraTime = $data['extra_time'] ?? null;
$extraTime = isset($data['extra_time']) ? (int)$data['extra_time'] : null;

return new AcsControlResult($status, $extraTime ? intval($extraTime) : null);
return new AcsControlResult($status, $extraTime);
}
}
5 changes: 4 additions & 1 deletion src/Model/AcsControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ public function jsonSerialize(): array
'incident_severity' => $this->incidentSeverity,
'reason_code' => $this->reasonCode,
'reason_msg' => $this->reasonMessage,
]
],
static function ($element) {
return $element !== null;
}
);
}
}
5 changes: 4 additions & 1 deletion src/Model/AcsControlResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public function jsonSerialize(): array
[
'status' => $this->status,
'extra_time' => $this->extraTime,
]
],
static function($element) {
return $element !== null;
}
);
}
}
80 changes: 80 additions & 0 deletions tests/Unit/Factory/AcsControlFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,86 @@ public function testCreateSuccess(): void
$this->assertEquals('message', $result->getReasonMessage());
}

public function testCreateSuccessWithZeroExtraTimeAndIncidentSeverity(): void
{
$date = Carbon::now();

$result = $this->subject->create(
[
'user' => [
'iss' => 'issuerIdentifier',
'sub' => 'userIdentifier',
],
'resource_link' => [
'id' => 'resourceLinkIdentifier',
'title' => 'resourceLinkTitle',
'description' => 'resourceLinkDescription',
],
'attempt_number' => 1,
'action' => AcsControlInterface::ACTION_UPDATE,
'extra_time' => 0,
'incident_time' => $date->format(DATE_ATOM),
'incident_severity' => 0,
'reason_code' => 'code',
'reason_msg' => 'message',
]
);

$this->assertInstanceOf(AcsControlInterface::class, $result);

$this->assertEquals('resourceLinkIdentifier', $result->getResourceLink()->getIdentifier());
$this->assertEquals('resourceLinkTitle', $result->getResourceLink()->getTitle());
$this->assertEquals('resourceLinkDescription', $result->getResourceLink()->getText());
$this->assertEquals('issuerIdentifier', $result->getIssuerIdentifier());
$this->assertEquals('userIdentifier', $result->getUserIdentifier());
$this->assertEquals(1, $result->getAttemptNumber());
$this->assertEquals(AcsControlInterface::ACTION_UPDATE, $result->getAction());
$this->assertEquals(0, $result->getExtraTime());
$this->assertEquals($date->format(DATE_ATOM), $result->getIncidentTime()->format(DATE_ATOM));
$this->assertEquals(0, $result->getIncidentSeverity());
$this->assertEquals('code', $result->getReasonCode());
$this->assertEquals('message', $result->getReasonMessage());
}

public function testCreateSuccessWithoutExtraTimeAndIncidentSeverity(): void
{
$date = Carbon::now();

$result = $this->subject->create(
[
'user' => [
'iss' => 'issuerIdentifier',
'sub' => 'userIdentifier',
],
'resource_link' => [
'id' => 'resourceLinkIdentifier',
'title' => 'resourceLinkTitle',
'description' => 'resourceLinkDescription',
],
'attempt_number' => 1,
'action' => AcsControlInterface::ACTION_UPDATE,
'incident_time' => $date->format(DATE_ATOM),
'reason_code' => 'code',
'reason_msg' => 'message',
]
);

$this->assertInstanceOf(AcsControlInterface::class, $result);

$this->assertEquals('resourceLinkIdentifier', $result->getResourceLink()->getIdentifier());
$this->assertEquals('resourceLinkTitle', $result->getResourceLink()->getTitle());
$this->assertEquals('resourceLinkDescription', $result->getResourceLink()->getText());
$this->assertEquals('issuerIdentifier', $result->getIssuerIdentifier());
$this->assertEquals('userIdentifier', $result->getUserIdentifier());
$this->assertEquals(1, $result->getAttemptNumber());
$this->assertEquals(AcsControlInterface::ACTION_UPDATE, $result->getAction());
$this->assertEquals(null, $result->getExtraTime());
$this->assertEquals($date->format(DATE_ATOM), $result->getIncidentTime()->format(DATE_ATOM));
$this->assertEquals(null, $result->getIncidentSeverity());
$this->assertEquals('code', $result->getReasonCode());
$this->assertEquals('message', $result->getReasonMessage());
}

/**
* @dataProvider provideFailingData
*/
Expand Down

0 comments on commit 792a0e4

Please sign in to comment.