Skip to content

Commit

Permalink
Tests for Notification entity
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Oct 20, 2024
1 parent fe322bc commit 5960523
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/Notifications/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ class Notification

/**
* Indicate that the notification gives information about a successful operation.
*
* @return $this
*/
public function success()
public function success(): self
{
$this->level = 'success';

Expand All @@ -54,10 +52,8 @@ public function success()

/**
* Indicate that the notification gives information about an error.
*
* @return $this
*/
public function error()
public function error(): self
{
$this->level = 'error';

Expand All @@ -66,18 +62,15 @@ public function error()

/**
* Set the "level" of the notification (success, error, etc.).
*
* @return $this
*/
public function level(string $level)
public function level(string $level): self
{
$this->level = $level;

return $this;
}

/** @return $this */
public function message(string $message)
public function message(string $message): self
{
$this->message = $message;

Expand All @@ -86,18 +79,16 @@ public function message(string $message)

/**
* Configure the "call to action" button.
*
* @return $this
*/
public function action(string $text, string $url)
public function action(string $text, string $url): self
{
$this->actionText = $text;
$this->actionUrl = $url;

return $this;
}

public function to(mixed $user): Notification
public function to(mixed $user): self
{
$this->user = $user;

Expand Down
55 changes: 55 additions & 0 deletions tests/Feature/Notifications/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use Doctrine\ORM\EntityManagerInterface;
use Mockery\Mock;
use PHPUnit\Framework\TestCase;

class NotificationTest extends TestCase
{
/**
* @var Mock
*/
private $registry;

/**
* @var Mock
*/
private $em;

public function setUp(): void
{
$this->em = Mockery::spy(EntityManagerInterface::class);
}

public function testClassFunctions()
{
$entity = new \LaravelDoctrine\ORM\Notifications\Notification();

$entity->success();
$this->assertEquals('success', $entity->getLevel());

$entity->error();
$this->assertEquals('error', $entity->getLevel());

$entity->level('custom');
$this->assertEquals('custom', $entity->getLevel());

$entity->message('custom');
$this->assertEquals('custom', $entity->getMessage());

$entity->action('custom', 'url');
$this->assertEquals('custom', $entity->getActionText());
$this->assertEquals('url', $entity->getActionUrl());

$user = new stdClass();
$entity->to($user);
$this->assertSame($user, $entity->getUser());

$reflection = new ReflectionClass($entity);
$property = $reflection->getProperty('id');
$property->setAccessible(true);
$property->setValue($entity, 1);

$entity->getId();
}
}

0 comments on commit 5960523

Please sign in to comment.