diff --git a/src/Event.php b/src/Event.php index 2a2e7f2..3019f9c 100644 --- a/src/Event.php +++ b/src/Event.php @@ -33,7 +33,7 @@ class Event extends Component * * @var string */ - protected $_expression = '* * * * * *'; + protected $_expression = '* * * * *'; /** * The timezone the date should be evaluated on. * diff --git a/tests/FrequencyTest.php b/tests/FrequencyTest.php index 40478b9..dd59f2a 100644 --- a/tests/FrequencyTest.php +++ b/tests/FrequencyTest.php @@ -7,113 +7,118 @@ class FrequencyTest extends \PHPUnit_Framework_TestCase { /* - * @var Event + * @var yii\mutex\Mutex */ - protected $event; + protected $mutex; protected function setUp() { - $this->event = new Event( - $this->getMock('yii\mutex\Mutex'), - 'php foo' + $this->mutex = $this->getMock('yii\mutex\Mutex'); + } + + protected function getEvent() + { + return new Event( + $this->mutex, + '' ); } public function testEveryMinute() { - $this->assertSame('* * * * *', $this->event->getExpression()); - $this->assertSame('* * * * *', $this->event->everyMinute()->getExpression()); + $this->assertSame('* * * * *', $this->getEvent()->getExpression()); + $this->assertSame('* * * * *', $this->getEvent()->everyMinute()->getExpression()); } public function testEveryFiveMinutes() { - $this->assertSame('*/5 * * * *', $this->event->everyFiveMinutes()->getExpression()); + $this->assertSame('*/5 * * * *', $this->getEvent()->everyFiveMinutes()->getExpression()); } public function testDaily() { - $this->assertSame('0 0 * * *', $this->event->daily()->getExpression()); + $this->assertSame('0 0 * * *', $this->getEvent()->daily()->getExpression()); } public function testTwiceDaily() { - $this->assertSame('0 3,15 * * *', $this->event->twiceDaily(3, 15)->getExpression()); + $this->assertSame('0 3,15 * * *', $this->getEvent()->twiceDaily(3, 15)->getExpression()); } public function testOverrideWithHourly() { - $this->assertSame('0 * * * *', $this->event->everyFiveMinutes()->hourly()->getExpression()); - $this->assertSame('37 * * * *', $this->event->hourlyAt(37)->getExpression()); - $this->assertSame('15,30,45 * * * *', $this->event->hourlyAt([15, 30, 45])->getExpression()); + $this->assertSame('0 * * * *', $this->getEvent()->everyFiveMinutes()->hourly()->getExpression()); + $this->assertSame('37 * * * *', $this->getEvent()->hourlyAt(37)->getExpression()); + $this->assertSame('15,30,45 * * * *', $this->getEvent()->hourlyAt([15, 30, 45])->getExpression()); } public function testMonthlyOn() { - $this->assertSame('0 15 4 * *', $this->event->monthlyOn(4, '15:00')->getExpression()); + $this->assertSame('0 15 4 * *', $this->getEvent()->monthlyOn(4, '15:00')->getExpression()); } public function testTwiceMonthly() { - $this->assertSame('0 0 1,16 * *', $this->event->twiceMonthly(1, 16)->getExpression()); + $this->assertSame('0 0 1,16 * *', $this->getEvent()->twiceMonthly(1, 16)->getExpression()); } public function testMonthlyOnWithMinutes() { - $this->assertSame('15 15 4 * *', $this->event->monthlyOn(4, '15:15')->getExpression()); + $this->assertSame('15 15 4 * *', $this->getEvent()->monthlyOn(4, '15:15')->getExpression()); } public function testWeekdaysDaily() { - $this->assertSame('0 0 * * 1-5', $this->event->weekdays()->daily()->getExpression()); + $this->assertSame('0 0 * * 1-5', $this->getEvent()->weekdays()->daily()->getExpression()); } public function testWeekdaysHourly() { - $this->assertSame('0 * * * 1-5', $this->event->weekdays()->hourly()->getExpression()); + $this->assertSame('0 * * * 1-5', $this->getEvent()->weekdays()->hourly()->getExpression()); } public function testWeekdays() { - $this->assertSame('* * * * 1-5', $this->event->weekdays()->getExpression()); + $this->assertSame('* * * * 1-5', $this->getEvent()->weekdays()->getExpression()); } public function testSundays() { - $this->assertSame('* * * * 0', $this->event->sundays()->getExpression()); + $this->assertSame('* * * * 0', $this->getEvent()->sundays()->getExpression()); } public function testMondays() { - $this->assertSame('* * * * 1', $this->event->mondays()->getExpression()); + $this->assertSame('* * * * 1', $this->getEvent()->mondays()->getExpression()); } public function testTuesdays() { - $this->assertSame('* * * * 2', $this->event->tuesdays()->getExpression()); + $this->assertSame('* * * * 2', $this->getEvent()->tuesdays()->getExpression()); } public function testWednesdays() { - $this->assertSame('* * * * 3', $this->event->wednesdays()->getExpression()); + $this->assertSame('* * * * 3', $this->getEvent()->wednesdays()->getExpression()); } public function testThursdays() { - $this->assertSame('* * * * 4', $this->event->thursdays()->getExpression()); + $this->assertSame('* * * * 4', $this->getEvent()->thursdays()->getExpression()); } public function testFridays() { - $this->assertSame('* * * * 5', $this->event->fridays()->getExpression()); + $this->assertSame('* * * * 5', $this->getEvent()->fridays()->getExpression()); } public function testSaturdays() { - $this->assertSame('* * * * 6', $this->event->saturdays()->getExpression()); + $this->assertSame('* * * * 6', $this->getEvent()->saturdays()->getExpression()); } public function testQuarterly() { - $this->assertSame('0 0 1 1-12/3 *', $this->event->quarterly()->getExpression()); + $this->assertSame('0 0 1 1-12/3 *', $this->getEvent()->quarterly()->getExpression()); } }