/**
  * @return TodoReminder
  */
 public function reminder()
 {
     if (!$this->reminder) {
         $this->reminder = TodoReminder::fromString($this->payload['reminder'], $this->payload['reminder_status']);
     }
     return $this->reminder;
 }
 /**
  * @return TodoReminder
  */
 public function reminder()
 {
     if (!$this->reminder) {
         $this->reminder = TodoReminder::fromString($this->payload['reminder'], TodoReminderStatus::OPEN);
     }
     return $this->reminder;
 }
 public function it_returns_a_new_reminder_with_status_closed_when_closed()
 {
     $reminder = TodoReminder::fromString('2047-02-01 10:00:00', TodoReminderStatus::OPEN);
     $reminderClosed = $reminder->close();
     $this->assertNotEquals($reminder, $reminderClosed);
     $this->assertFalse($reminderClosed->isOpen());
 }
Example #4
0
 /**
  * @test
  * @dataProvider getReminders
  *
  * @param $reminder
  * @param $inThePast
  */
 public function it_correctly_validates_the_reminder($reminder, $inThePast)
 {
     $reminder = TodoReminder::fromString($reminder);
     $reminderInThePast = $reminder->isInThePast();
     if ($inThePast) {
         $this->assertTrue($reminderInThePast);
     } else {
         $this->assertFalse($reminderInThePast);
     }
 }
Example #5
0
 /**
  * @param TodoReminder $reminder
  * @throws Exception\InvalidReminder
  */
 public function remindAssignee(TodoReminder $reminder)
 {
     if ($this->status->isDone()) {
         throw Exception\TodoNotOpen::triedToAddReminder($reminder, $this->status);
     }
     if (!$this->reminder->equals($reminder)) {
         throw Exception\InvalidReminder::reminderNotCurrent($this->reminder, $reminder);
     }
     if (!$this->reminder->isOpen()) {
         throw Exception\InvalidReminder::alreadyReminded();
     }
     if ($reminder->isInTheFuture()) {
         throw Exception\InvalidReminder::reminderInTheFuture($reminder);
     }
     $this->recordThat(TodoAssigneeWasReminded::forAssignee($this->todoId, $this->assigneeId, $reminder->close()));
 }
 /**
  * @return TodoReminder
  */
 public function reminder()
 {
     return TodoReminder::fromString($this->payload['reminder'], $this->payload['reminder_status']);
 }
<?php

/**
 * This script looks for todos with open reminders and reminds the assignees
 */
namespace {
    use Prooph\ProophessorDo\Model\Todo\Command\RemindTodoAssignee;
    use Prooph\ProophessorDo\Model\Todo\TodoId;
    use Prooph\ProophessorDo\Model\Todo\TodoReminder;
    use Prooph\ProophessorDo\Projection\Todo\TodoReminderFinder;
    use Prooph\ServiceBus\CommandBus;
    chdir(dirname(__DIR__));
    // Setup autoloading
    require 'vendor/autoload.php';
    $container = (require 'config/container.php');
    $commandBus = $container->get(CommandBus::class);
    $todoReminderFinder = $container->get(TodoReminderFinder::class);
    $todoReminder = $todoReminderFinder->findOpen();
    if (!$todoReminder) {
        echo "Nothing to do. Exiting.\n";
        exit;
    }
    foreach ($todoReminder as $reminder) {
        echo "Send reminder for Todo with id {$reminder->todo_id}.\n";
        $commandBus->dispatch(RemindTodoAssignee::forTodo(TodoId::fromString($reminder->todo_id), TodoReminder::fromString($reminder->reminder, $reminder->status)));
    }
    echo "Done!\n";
}
Example #8
0
 /**
  * @return Todo
  */
 private function todoWithReminderInThePast()
 {
     $userId = UserId::generate();
     $todoId = TodoId::generate();
     $reminder = TodoReminder::fromString('2000-12-11 12:00:00', TodoReminderStatus::OPEN);
     $events = [TodoWasPosted::byUser($userId, 'test', $todoId, TodoStatus::open()), ReminderWasAddedToTodo::byUserToDate($todoId, $userId, $reminder)];
     return $this->reconstituteAggregateFromHistory(Todo::class, $events);
 }
Example #9
0
 /**
  * @param UserId $userId
  * @param TodoReminder $reminder
  * @return void
  * @throws Exception\InvalidReminder
  */
 public function addReminder(UserId $userId, TodoReminder $reminder)
 {
     if (!$this->assigneeId()->sameValueAs($userId)) {
         throw Exception\InvalidReminder::userIsNotAssignee($userId, $this->assigneeId());
     }
     if ($reminder->isInThePast()) {
         throw Exception\InvalidReminder::reminderInThePast($reminder);
     }
     if ($this->status->isDone()) {
         throw Exception\TodoNotOpen::triedToAddReminder($reminder, $this->status);
     }
     $this->recordThat(ReminderWasAddedToTodo::byUserToDate($this->todoId, $this->assigneeId, $reminder));
 }
Example #10
0
 /**
  * @param TodoReminder $reminder
  * @param TodoStatus $status
  * @return TodoNotOpen
  */
 public static function triedToSendReminder(TodoReminder $reminder, TodoStatus $status)
 {
     return new self(sprintf('Tried to send a reminder %s for a todo with status %s.', $reminder->toString(), $status->toString()));
 }
Example #11
0
 /**
  * @test
  * @param Todo $todo
  * @depends it_adds_a_reminder_to_todo
  */
 public function it_throws_an_exception_if_todo_is_closed_while_setting_a_reminder(Todo $todo)
 {
     $todo->markAsDone();
     $this->setExpectedException(TodoNotOpen::class);
     $todo->addReminder($todo->assigneeId(), TodoReminder::fromString('2047-12-11 12:00:00'));
 }
 /**
  * @return TodoReminder
  */
 public function reminder()
 {
     return TodoReminder::fromString($this->payload['reminder'], TodoReminderStatus::OPEN);
 }
Example #13
0
 /**
  * @param TodoReminder $reminder
  * @return InvalidReminder
  */
 public static function reminderInThePast(TodoReminder $reminder)
 {
     return new self(sprintf('Provided reminder %s is in the past from %s', $reminder->toString(), $reminder->createdOn()));
 }
 /**
  * @param TodoReminder $expected
  * @param TodoReminder $actual
  * @return InvalidReminder
  */
 public static function reminderNotCurrent(TodoReminder $expected, TodoReminder $actual)
 {
     return new self(sprintf('Notification for reminder %s can not be send, because %s is the current one.', $actual->toString(), $expected->toString()));
 }