Skip to content

Commit

Permalink
fixed #522 avoiding $emailAddress property accessed before initializa…
Browse files Browse the repository at this point in the history
…tion error.
  • Loading branch information
lesstif committed Sep 26, 2023
1 parent 35be23f commit 25f83be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Issue/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Reporter implements \JsonSerializable

public ?string $name;

public ?string $emailAddress;
public ?string $emailAddress = null;

public array $avatarUrls;

Expand Down
16 changes: 16 additions & 0 deletions test-data/reporter-no-email-address.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"reporter": {
"self": "https://jira.example.com/rest/api/2/user?username=lesstif",
"name": "lesstif",
"key": "lesstif",
"avatarUrls": {
"48x48": "https://secure.gravatar.com/avatar/9f1705ef1d8c977eba04f00556e02922?d=mm&s=48",
"24x24": "https://secure.gravatar.com/avatar/9f1705ef1d8c977eba04f00556e02922?d=mm&s=24",
"16x16": "https://secure.gravatar.com/avatar/9f1705ef1d8c977eba04f00556e02922?d=mm&s=16",
"32x32": "https://secure.gravatar.com/avatar/9f1705ef1d8c977eba04f00556e02922?d=mm&s=32"
},
"displayName": "정광섭",
"active": true,
"timeZone": "Asia/Seoul"
}
}
15 changes: 14 additions & 1 deletion tests/MapperTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace JiraRestApi\Test;

Expand Down Expand Up @@ -89,4 +89,17 @@ public function testIssue()

}

public function testReporterField()
{
$ret = file_get_contents('test-data/reporter-no-email-address.json');

$reporter = $this->mapper->map(
json_decode($ret), new Reporter()
);

$this->assertInstanceOf(Reporter::class, $reporter);

$this->assertEquals('[email protected]', $reporter->emailAddress);
}

}

0 comments on commit 25f83be

Please sign in to comment.