Skip to content

Commit

Permalink
Implemented detection of duplicate task name
Browse files Browse the repository at this point in the history
  • Loading branch information
stekycz committed Feb 7, 2016
1 parent 4a73792 commit ff2ef03
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Cronner/Cronner.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ public function addTasks($tasks)
$methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if (!Strings::startsWith($method->getName(), '__') && $method->hasAnnotation(Parameters::TASK)) {
$this->tasks[] = new Task($tasks, $method, $this->timestampStorage);
$task = new Task($tasks, $method, $this->timestampStorage);
if (array_key_exists($task->getName(), $this->tasks)) {
throw new DuplicateTaskNameException('Cannot use more tasks with the same name "' . $task->getName() . '".');
}
$this->tasks[$task->getName()] = $task;
}
}
$this->registeredTaskObjects[] = $tasksId;
Expand Down
10 changes: 10 additions & 0 deletions Cronner/exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class EmptyTaskNameException extends InvalidArgumentException



/**
* @author Martin Štekl <[email protected]>
*/
class DuplicateTaskNameException extends InvalidArgumentException
{

}



/**
* @author Martin Štekl <[email protected]>
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/CronnerTests/objects/AnotherSimpleTestObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace stekycz\Cronner\tests\objects;

use Nette\Object;


/**
* @author Martin Štekl <[email protected]>
*/
class AnotherSimpleTestObject extends Object
{

/**
* @cronner-task Test
*/
public function test01()
{
}

}
21 changes: 21 additions & 0 deletions tests/CronnerTests/objects/NextSimpleTestObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace stekycz\Cronner\tests\objects;

use Nette\Object;


/**
* @author Martin Štekl <[email protected]>
*/
class NextSimpleTestObject extends Object
{

/**
* @cronner-task Test
*/
public function test01()
{
}

}
31 changes: 31 additions & 0 deletions tests/CronnerTests/objects/SameTaskNameObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace stekycz\Cronner\tests\objects;

use Nette\Object;



/**
* @author Martin Štekl <[email protected]>
*/
class SameTaskNameObject extends Object
{

/**
* @cronner-task Test
*/
public function test01()
{
}



/**
* @cronner-task Test
*/
public function test02()
{
}

}

0 comments on commit ff2ef03

Please sign in to comment.