Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-----

* Added `FlattenExceptionNormalizer` to give more information about the exception on Messenger background processes. The `FlattenExceptionNormalizer` has a higher priority than `ProblemNormalizer` and it is only used when the Messenger serialization context is set.
* Added factory methods to `DelayStamp`.

5.1.0
-----
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Messenger/Stamp/DelayStamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public function getDelay(): int
{
return $this->delay;
}

public static function delayForSeconds(int $seconds): self
{
return new self($seconds * 1000);
}

public static function delayForMinutes(int $minutes): self
{
return self::delayForSeconds($minutes * 60);
}

public static function delayForHours(int $hours): self
{
return self::delayForMinutes($hours * 60);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not converting hours to milliseconds directly rather than chaining 3 method calls ?

}
}
39 changes: 39 additions & 0 deletions src/Symfony/Component/Messenger/Tests/Stamp/DelayStampTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Messenger\Tests\Stamp;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Stamp\DelayStamp;

/**
* @author Yanick Witschi <yanick.witschi@terminal42.ch>
*/
class DelayStampTest extends TestCase
{
public function testSeconds()
{
$stamp = DelayStamp::delayForSeconds(30);
$this->assertSame(30000, $stamp->getDelay());
}

public function testMinutes()
{
$stamp = DelayStamp::delayForMinutes(30);
$this->assertSame(1800000, $stamp->getDelay());
}

public function testHours()
{
$stamp = DelayStamp::delayForHours(30);
$this->assertSame(108000000, $stamp->getDelay());
}
}