diff --git a/.travis.yml b/.travis.yml index ce76cfa7..7ce97545 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ sudo: required dist: trusty group: edge +services: + - elasticsearch addons: apt: packages: @@ -33,14 +35,6 @@ matrix: env: - MAGENTO_VERSION=2.3 - TEST_SUITE=unit - - php: 7.2 - env: - - MAGENTO_VERSION=2.4-develop - - TEST_SUITE=integration - - php: 7.2 - env: - - MAGENTO_VERSION=2.4-develop - - TEST_SUITE=unit - php: 7.2 env: - MAGENTO_VERSION=2.3 diff --git a/.travis/before_script.sh b/.travis/before_script.sh index b2b37a20..44ab8577 100755 --- a/.travis/before_script.sh +++ b/.travis/before_script.sh @@ -16,6 +16,9 @@ phpenv rehash; composer selfupdate +# Allow elasticsearch service to start. See https://docs.travis-ci.com/user/database-setup/#elasticsearch +sleep 10 + # clone main magento github repository git clone --branch $MAGENTO_VERSION --depth=1 https://github.com/magento/magento2 diff --git a/Test/Integration/CleanRunningJobsTest.php b/Test/Integration/CleanRunningJobsTest.php index d1b34114..7979998a 100644 --- a/Test/Integration/CleanRunningJobsTest.php +++ b/Test/Integration/CleanRunningJobsTest.php @@ -19,14 +19,17 @@ class CleanRunningJobsTest extends TestCase { const NOW = '2019-02-09 18:33:00'; + /** * @var ObjectManager */ private $objectManager; + /** * @var Event\ManagerInterface */ private $eventManager; + /** * @var FakeClock */ @@ -34,7 +37,7 @@ class CleanRunningJobsTest extends TestCase const DEAD_PID = 99999999; - protected function setUp() + protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->objectManager->configure(['preferences' => [Clock::class => FakeClock::class]]); diff --git a/Test/Integration/Controller/Adminhtml/Manage/CreateTest.php b/Test/Integration/Controller/Adminhtml/Manage/CreateTest.php index 83ecabbb..1af3281e 100644 --- a/Test/Integration/Controller/Adminhtml/Manage/CreateTest.php +++ b/Test/Integration/Controller/Adminhtml/Manage/CreateTest.php @@ -15,6 +15,10 @@ public function testEditAction() $this->dispatch($this->uri); $result = $this->getResponse()->getBody(); - $this->assertContains('Create Cron Job / Tools / System / Magento Admin', $result); + if (\method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString('Create Cron Job / Tools / System / Magento Admin', $result); + } else { + $this->assertContains('Create Cron Job / Tools / System / Magento Admin', $result); + } } } diff --git a/Test/Integration/Controller/Adminhtml/Manage/EditTest.php b/Test/Integration/Controller/Adminhtml/Manage/EditTest.php index 7f91213a..1f0457eb 100644 --- a/Test/Integration/Controller/Adminhtml/Manage/EditTest.php +++ b/Test/Integration/Controller/Adminhtml/Manage/EditTest.php @@ -15,6 +15,10 @@ public function testEditAction() $this->dispatch($this->uri); $result = $this->getResponse()->getBody(); - $this->assertContains('Edit Cron Job / Tools / System / Magento Admin', $result); + if (\method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString('Edit Cron Job / Tools / System / Magento Admin', $result); + } else { + $this->assertContains('Edit Cron Job / Tools / System / Magento Admin', $result); + } } } diff --git a/Test/Integration/Controller/Adminhtml/Manage/IndexTest.php b/Test/Integration/Controller/Adminhtml/Manage/IndexTest.php index d87783fb..b040910f 100644 --- a/Test/Integration/Controller/Adminhtml/Manage/IndexTest.php +++ b/Test/Integration/Controller/Adminhtml/Manage/IndexTest.php @@ -18,7 +18,11 @@ public function testIndexAction() $this->dispatch($this->uri); $result = $this->getResponse()->getBody(); - $this->assertContains('Cron Job Dashboard / Tools / System / Magento Admin', $result); + if (\method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString('Cron Job Dashboard / Tools / System / Magento Admin', $result); + } else { + $this->assertContains('Cron Job Dashboard / Tools / System / Magento Admin', $result); + } } public static function loadDataFixtureCron() diff --git a/Test/Integration/ErrorNotificationEmailTest.php b/Test/Integration/ErrorNotificationEmailTest.php index 1057a3fb..4b0716f2 100644 --- a/Test/Integration/ErrorNotificationEmailTest.php +++ b/Test/Integration/ErrorNotificationEmailTest.php @@ -22,16 +22,18 @@ class ErrorNotificationEmailTest extends TestCase * @var ObjectManager */ private $objectManager; + /** * @var ErrorNotificationEmail */ private $errorNotificationEmail; + /** * @var \Magento\TestFramework\Mail\Template\TransportBuilderMock */ private $transportBuilder; - protected function setUp() + protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->transportBuilder = $this->objectManager->get(TransportBuilderMock::class); @@ -131,7 +133,11 @@ private function andEmailShouldHaveContents(Message $sentMessage, array $expecte $content = $sentMessage->getBody()->getParts()[0]->getContent(); $content = \Zend_Mime_Decode::decodeQuotedPrintable($content); foreach ($expectedContents as $expectedKey => $expectedContent) { - $this->assertContains($expectedContent, $content, "Content should contain $expectedKey"); + if (\method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString($expectedContent, $content, "Content should contain $expectedKey"); + } else { + $this->assertContains($expectedContent, $content, "Content should contain $expectedKey"); + } } } } diff --git a/Test/Integration/ErrorNotificationTest.php b/Test/Integration/ErrorNotificationTest.php index c28133ff..4f35e9ca 100644 --- a/Test/Integration/ErrorNotificationTest.php +++ b/Test/Integration/ErrorNotificationTest.php @@ -28,6 +28,7 @@ class ErrorNotificationTest extends TestCase { const NOW = '2019-02-09 18:33:00'; + /** * @var ObjectManager */ @@ -37,28 +38,33 @@ class ErrorNotificationTest extends TestCase * @var ScheduleManagementInterface */ private $scheduleManagement; + /** * @var ScheduleRepositoryInterface */ private $scheduleRepository; + /** * @var FakeClock */ private $clock; + /** * @var \Magento\Framework\App\CacheInterface */ private $cache; + /** * @var ErrorNotification|\PHPUnit_Framework_MockObject_MockObject */ private $errorNotification; + /** * @var ProcessCronQueueObserver */ private $processCronQueueObserver; - protected function setUp() + protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->objectManager->configure( @@ -156,4 +162,4 @@ function (Schedule $schedule) use ($expectedMessage) { ) ); } -} \ No newline at end of file +} diff --git a/Test/Integration/Model/ManagerTest.php b/Test/Integration/Model/ManagerTest.php index 7167588e..fe37b1af 100644 --- a/Test/Integration/Model/ManagerTest.php +++ b/Test/Integration/Model/ManagerTest.php @@ -7,6 +7,7 @@ use Magento\TestFramework\Helper\Bootstrap; use EthanYehuda\CronjobManager\Model\Manager; use Magento\Cron\Model\ScheduleFactory; +use Magento\Framework\Exception\NoSuchEntityException; class ManagerTest extends TestCase { @@ -21,10 +22,10 @@ class ManagerTest extends TestCase */ private $scheduleFactory; - protected function setUp() + protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); - + $this->manager = $objectManager->create(Manager::class); $this->scheduleFactory = $objectManager->create(ScheduleFactory::class); } @@ -50,11 +51,10 @@ public function testSaveCronJob() $this->assertEquals(Schedule::STATUS_SUCCESS, $cron->getStatus()); } - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - */ public function testSaveCronInvalidId() { + $this->expectException(NoSuchEntityException::class); + $this->expectExceptionMessage('The Schedule with the "99999" ID doesn\'t exist'); $this->manager->saveCronJob(99999); } @@ -69,11 +69,10 @@ public function testDeleteCronJob() $this->assertNull($cron->getScheduleId()); } - /** - * @expectedException \Magento\Framework\Exception\NoSuchEntityException - */ public function testDeleteInvalidId() { + $this->expectException(NoSuchEntityException::class); + $this->expectExceptionMessage('The Schedule with the "99999" ID doesn\'t exist'); $this->manager->deleteCronJob(99999); } diff --git a/Test/Integration/Model/ScheduleManagementTest.php b/Test/Integration/Model/ScheduleManagementTest.php index 7582c3e5..b3da5cff 100644 --- a/Test/Integration/Model/ScheduleManagementTest.php +++ b/Test/Integration/Model/ScheduleManagementTest.php @@ -26,11 +26,12 @@ class ScheduleManagementTest extends TestCase const NOW = '2019-02-09 18:33:00'; - protected function setUp() + protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->scheduleManagement = $this->objectManager->get(ScheduleManagementInterface::class); } + public function testKillRequestForRunningJobSucceeds() { $this->givenRunningSchedule($schedule); diff --git a/Test/Integration/ProcessIdTest.php b/Test/Integration/ProcessIdTest.php index c3e64893..7ea9f587 100644 --- a/Test/Integration/ProcessIdTest.php +++ b/Test/Integration/ProcessIdTest.php @@ -18,10 +18,11 @@ class ProcessIdTest extends TestCase */ private $objectManager; - protected function setUp() + protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); } + public function testProcessIdSavedOnStart() { $this->givenPid($pid); @@ -29,6 +30,7 @@ public function testProcessIdSavedOnStart() $this->whenTryLockJob($schedule); $this->thenScheduleIsSavedWithPid($schedule, $pid); } + public function testProcessIdMaintainedAfterSuccesfulRun() { $this->givenPid($pid); diff --git a/Test/Integration/ProcessKillRequestsTest.php b/Test/Integration/ProcessKillRequestsTest.php index 873b5b75..37061dfb 100644 --- a/Test/Integration/ProcessKillRequestsTest.php +++ b/Test/Integration/ProcessKillRequestsTest.php @@ -21,32 +21,38 @@ class ProcessKillRequestsTest extends TestCase { const NOW = '2019-02-09 18:33:00'; + /** * @var int */ private $childPid = 0; + /** * @var ObjectManager */ private $objectManager; + /** * @var Event\ManagerInterface */ private $eventManager; + /** * @var ScheduleManagementInterface */ private $scheduleManagement; + /** * @var ProcessManagement */ private $processManagement; + /** * @var FakeClock */ private $clock; - protected function setUp() + protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->objectManager->configure(['preferences' => [Clock::class => FakeClock::class]]); @@ -57,7 +63,7 @@ protected function setUp() $this->processManagement = $this->objectManager->get(ProcessManagement::class); } - protected function tearDown() + protected function tearDown(): void { /* * Take care of children that we failed to kill @@ -78,7 +84,6 @@ public function testDeadRunningJobsAreCleaned() private function givenRunningScheduleWithKillRequest(&$schedule, int $timestamp) { - /** @var Schedule $schedule */ $schedule = $this->objectManager->create(Schedule::class); $schedule->setStatus(Schedule::STATUS_RUNNING); diff --git a/Test/Integration/phpunit.xml.dist b/Test/Integration/phpunit.xml.dist index 396a1988..871d4dd1 100644 --- a/Test/Integration/phpunit.xml.dist +++ b/Test/Integration/phpunit.xml.dist @@ -14,7 +14,7 @@ - + ../../../vendor/ethanyehuda/magento2-cronjobmanager ../../../vendor/ethanyehuda/magento2-cronjobmanager/Test diff --git a/Test/Unit/Console/Command/KillJobTest.php b/Test/Unit/Console/Command/KillJobTest.php index a40f6a42..e71c44fa 100644 --- a/Test/Unit/Console/Command/KillJobTest.php +++ b/Test/Unit/Console/Command/KillJobTest.php @@ -35,7 +35,7 @@ class KillJobTest extends TestCase private $mockFilterBuilder; private $mockFilterGroupBuilder; - protected function setUp() + protected function setUp(): void { $this->mockState = $this->getMockBuilder(State::class)->setConstructorArgs([ $this->createMock(ScopeInterface::class), @@ -304,4 +304,3 @@ private function mockMultipleSchedules(int $numOfSchedules): array return $mockSchedules; } } - diff --git a/Test/Unit/Console/Command/RunjobTest.php b/Test/Unit/Console/Command/RunjobTest.php new file mode 100644 index 00000000..ea159d06 --- /dev/null +++ b/Test/Unit/Console/Command/RunjobTest.php @@ -0,0 +1,62 @@ +runner = $this->createMock(Runner::class); + + $objectManager = $this->createMock(ObjectManagerInterface::class); + $objectManager->expects($this->any()) + ->method('create') + ->willReturn($this->runner); + + $objectManagerFactory = $this->createMock(ObjectManagerFactory::class); + $objectManagerFactory->expects($this->any()) + ->method('create') + ->willReturn($objectManager); + + $command = new Runjob($objectManagerFactory); + $this->commandTester = new CommandTester($command); + } + + public function testExecuteThrowsWithoutRequiredArgument() + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Not enough arguments (missing: "job_code").'); + + $this->commandTester->execute([]); + } + + public function testExecute() + { + $jobCode = 'good_job'; + $resultCode = Cli::RETURN_SUCCESS; + $resultMessage = "$jobCode successfully ran"; + + $this->runner->expects($this->once()) + ->method('runCron') + ->with($jobCode) + ->willReturn([$resultCode, $resultMessage]); + + $commandResult = $this->commandTester->execute([ + 'job_code' => $jobCode, + ]); + $this->assertSame($resultCode, $commandResult); + $this->assertSame($resultMessage . PHP_EOL, $this->commandTester->getDisplay()); + } +} diff --git a/Test/Unit/phpunit.xml.dist b/Test/Unit/phpunit.xml.dist index 735370d3..5c9bc6f3 100644 --- a/Test/Unit/phpunit.xml.dist +++ b/Test/Unit/phpunit.xml.dist @@ -14,7 +14,7 @@ - + ../../../vendor/ethanyehuda/magento2-cronjobmanager ../../../vendor/ethanyehuda/magento2-cronjobmanager/Test diff --git a/composer.json b/composer.json index 06097b1e..31652963 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,8 @@ "name": "ethanyehuda/magento2-cronjobmanager", "description": "A module for managing scheduled cron jobs from magento's admin panel", "require": { - "php": "~7.1.0||~7.2.0||~7.3.0", + "php": "~7.1.0||~7.2.0||~7.3.0||~7.4.0", + "ext-posix": "*", "magento/framework": "~100.3.0-dev|~101.0.0|~102.0.0" }, "require-dev": {