Skip to content

Commit

Permalink
Merge 996f631 into 13c50c7
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed May 17, 2020
2 parents 13c50c7 + 996f631 commit f3b9bef
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 34 deletions.
10 changes: 2 additions & 8 deletions .travis.yml
@@ -1,6 +1,8 @@
sudo: required
dist: trusty
group: edge
services:
- elasticsearch
addons:
apt:
packages:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .travis/before_script.sh
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion Test/Integration/CleanRunningJobsTest.php
Expand Up @@ -19,22 +19,25 @@
class CleanRunningJobsTest extends TestCase
{
const NOW = '2019-02-09 18:33:00';

/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var Event\ManagerInterface
*/
private $eventManager;

/**
* @var FakeClock
*/
private $clock;

const DEAD_PID = 99999999;

protected function setUp()
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->objectManager->configure(['preferences' => [Clock::class => FakeClock::class]]);
Expand Down
6 changes: 5 additions & 1 deletion Test/Integration/Controller/Adminhtml/Manage/CreateTest.php
Expand Up @@ -15,6 +15,10 @@ public function testEditAction()
$this->dispatch($this->uri);
$result = $this->getResponse()->getBody();

$this->assertContains('<title>Create Cron Job / Tools / System / Magento Admin</title>', $result);
if (\method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString('<title>Create Cron Job / Tools / System / Magento Admin</title>', $result);
} else {
$this->assertContains('<title>Create Cron Job / Tools / System / Magento Admin</title>', $result);
}
}
}
6 changes: 5 additions & 1 deletion Test/Integration/Controller/Adminhtml/Manage/EditTest.php
Expand Up @@ -15,6 +15,10 @@ public function testEditAction()
$this->dispatch($this->uri);
$result = $this->getResponse()->getBody();

$this->assertContains('<title>Edit Cron Job / Tools / System / Magento Admin</title>', $result);
if (\method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString('<title>Edit Cron Job / Tools / System / Magento Admin</title>', $result);
} else {
$this->assertContains('<title>Edit Cron Job / Tools / System / Magento Admin</title>', $result);
}
}
}
6 changes: 5 additions & 1 deletion Test/Integration/Controller/Adminhtml/Manage/IndexTest.php
Expand Up @@ -18,7 +18,11 @@ public function testIndexAction()
$this->dispatch($this->uri);
$result = $this->getResponse()->getBody();

$this->assertContains('<title>Cron Job Dashboard / Tools / System / Magento Admin</title>', $result);
if (\method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString('<title>Cron Job Dashboard / Tools / System / Magento Admin</title>', $result);
} else {
$this->assertContains('<title>Cron Job Dashboard / Tools / System / Magento Admin</title>', $result);
}
}

public static function loadDataFixtureCron()
Expand Down
10 changes: 8 additions & 2 deletions Test/Integration/ErrorNotificationEmailTest.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
}
}
}
10 changes: 8 additions & 2 deletions Test/Integration/ErrorNotificationTest.php
Expand Up @@ -28,6 +28,7 @@
class ErrorNotificationTest extends TestCase
{
const NOW = '2019-02-09 18:33:00';

/**
* @var ObjectManager
*/
Expand All @@ -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(
Expand Down Expand Up @@ -156,4 +162,4 @@ function (Schedule $schedule) use ($expectedMessage) {
)
);
}
}
}
15 changes: 7 additions & 8 deletions Test/Integration/Model/ManagerTest.php
Expand Up @@ -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
{
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion Test/Integration/Model/ScheduleManagementTest.php
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion Test/Integration/ProcessIdTest.php
Expand Up @@ -18,17 +18,19 @@ class ProcessIdTest extends TestCase
*/
private $objectManager;

protected function setUp()
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
}

public function testProcessIdSavedOnStart()
{
$this->givenPid($pid);
$this->givenPendingSchedule($schedule);
$this->whenTryLockJob($schedule);
$this->thenScheduleIsSavedWithPid($schedule, $pid);
}

public function testProcessIdMaintainedAfterSuccesfulRun()
{
$this->givenPid($pid);
Expand Down
11 changes: 8 additions & 3 deletions Test/Integration/ProcessKillRequestsTest.php
Expand Up @@ -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]]);
Expand All @@ -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
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Test/Integration/phpunit.xml.dist
Expand Up @@ -14,7 +14,7 @@
</testsuites>
<!-- Code coverage filters -->
<filter>
<whitelist addUncoveredFilesFromWhiteList="true">
<whitelist>
<directory suffix=".php">../../../vendor/ethanyehuda/magento2-cronjobmanager</directory>
<exclude>
<directory>../../../vendor/ethanyehuda/magento2-cronjobmanager/Test</directory>
Expand Down
3 changes: 1 addition & 2 deletions Test/Unit/Console/Command/KillJobTest.php
Expand Up @@ -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),
Expand Down Expand Up @@ -304,4 +304,3 @@ private function mockMultipleSchedules(int $numOfSchedules): array
return $mockSchedules;
}
}

0 comments on commit f3b9bef

Please sign in to comment.