Skip to content

Commit

Permalink
Merge 02a67bc into 1a8c968
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed May 17, 2020
2 parents 1a8c968 + 02a67bc commit c2e2e4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Api/ScheduleManagementInterface.php
Expand Up @@ -4,6 +4,7 @@

use Magento\Cron\Model\Schedule;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;

interface ScheduleManagementInterface
Expand All @@ -26,7 +27,8 @@ public function listJobs(): array;
/**
* @param string $jobCode
* @param string[]|null $groups
* @return string|null
* @return string
* @throws LocalizedException
*/
public function getGroupId(string $jobCode, $groups = null);

Expand Down
6 changes: 5 additions & 1 deletion Model/ScheduleManagement.php
Expand Up @@ -9,6 +9,7 @@
use EthanYehuda\CronjobManager\Api\JobManagementInterface;
use Magento\Cron\Model\ScheduleFactory;
use Magento\Cron\Model\Schedule;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Stdlib\DateTime\DateTime;

class ScheduleManagement implements ScheduleManagementInterface
Expand Down Expand Up @@ -109,7 +110,10 @@ public function getGroupId(string $jobCode, $groups = null): string
}
}

return null;
throw new LocalizedException(__(
'No such job: %jobCode',
['jobCode' => $jobCode]
));
}

public function flush(): bool
Expand Down
14 changes: 14 additions & 0 deletions Test/Integration/Model/ScheduleManagementTest.php
Expand Up @@ -5,6 +5,7 @@

use EthanYehuda\CronjobManager\Api\ScheduleManagementInterface;
use Magento\Cron\Model\Schedule;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -32,6 +33,19 @@ protected function setUp(): void
$this->scheduleManagement = $this->objectManager->get(ScheduleManagementInterface::class);
}

public function testGetGroupIdWithValidJobCode()
{
$groupId = $this->scheduleManagement->getGroupId('backend_clean_cache');
$this->assertSame('default', $groupId);
}

public function testGetGroupIdWithInvalidJobCode()
{
$this->expectException(LocalizedException::class);
$this->expectExceptionMessage('No such job: not_valid');
$this->scheduleManagement->getGroupId('not_valid');
}

public function testKillRequestForRunningJobSucceeds()
{
$this->givenRunningSchedule($schedule);
Expand Down

0 comments on commit c2e2e4f

Please sign in to comment.