Skip to content

Commit

Permalink
Add test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Jan 8, 2022
1 parent 3def306 commit b25fcc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -27,7 +27,6 @@
},
"require-dev": {
"codeigniter4/codeigniter4": "dev-develop",
"tatter/imposter": "^1.0",
"tatter/tools": "^1.15"
},
"autoload": {
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/Email.php
Expand Up @@ -3,6 +3,7 @@
namespace Tatter\Outbox\Entities;

use CodeIgniter\Entity\Entity;
use RuntimeException;

class Email extends Entity
{
Expand Down Expand Up @@ -58,11 +59,13 @@ public function getRecipients(): array
* Helper function to return attachments or recipients.
*
* @param string $target Object/table/model to request
*
* @throws RuntimeException
*/
protected function getRelatedItems(string $target): array
{
if (empty($this->id)) {
throw new \RuntimeException('Object must be created before getting relations.');
throw new RuntimeException('Object must be created before getting relations.');
}

$property = $target . 's';
Expand Down
10 changes: 10 additions & 0 deletions tests/entities/EmailTest.php
Expand Up @@ -57,4 +57,14 @@ public function testGetRecipients()
$this->assertInstanceOf(Recipient::class, $result[0]);
$this->assertSame('to@example.com', $result[0]->email);
}

public function testGetRelatedUncreatedThrows()
{
$email = new Email();

$this->expectException('RuntimeException');
$this->expectExceptionMessage('Object must be created before getting relations.');

$email->getRecipients();
}
}

0 comments on commit b25fcc0

Please sign in to comment.