Skip to content

Commit

Permalink
magento#27500 Replace deprecated constructs from Cron PHPUnit.
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Apr 4, 2020
1 parent b307274 commit 9bdea07
Show file tree
Hide file tree
Showing 9 changed files with 332 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
namespace Magento\Cron\Test\Unit\Console\Command;

use Magento\Cron\Console\Command\CronCommand;
use Magento\Framework\App\Cron;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManagerFactory;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Magento\Framework\ObjectManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

class CronCommandTest extends \PHPUnit\Framework\TestCase
class CronCommandTest extends TestCase
{
/**
* @var ObjectManagerFactory|MockObject
Expand Down Expand Up @@ -57,8 +60,8 @@ public function testExecuteWithDisabledCrons()
*/
public function testExecute()
{
$objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
$cron = $this->createMock(\Magento\Framework\App\Cron::class);
$objectManager = $this->createMock(ObjectManagerInterface::class);
$cron = $this->createMock(Cron::class);
$objectManager->expects($this->once())
->method('create')
->willReturn($cron);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
*/
namespace Magento\Cron\Test\Unit\Console\Command;

use Symfony\Component\Console\Tester\CommandTester;
use Magento\Cron\Console\Command\CronInstallCommand;
use Magento\Framework\Console\Cli;
use Magento\Framework\Crontab\CrontabManagerInterface;
use Magento\Framework\Crontab\TasksProviderInterface;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

class CronInstallCommandTest extends \PHPUnit\Framework\TestCase
class CronInstallCommandTest extends TestCase
{
/**
* @var CrontabManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var CrontabManagerInterface|MockObject
*/
private $crontabManagerMock;

/**
* @var TasksProviderInterface|\PHPUnit_Framework_MockObject_MockObject
* @var TasksProviderInterface|MockObject
*/
private $tasksProviderMock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
*/
namespace Magento\Cron\Test\Unit\Console\Command;

use Symfony\Component\Console\Tester\CommandTester;
use Magento\Cron\Console\Command\CronRemoveCommand;
use Magento\Framework\Crontab\CrontabManagerInterface;
use Magento\Framework\Console\Cli;
use Magento\Framework\Crontab\CrontabManagerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

class CronRemoveCommandTest extends \PHPUnit\Framework\TestCase
class CronRemoveCommandTest extends TestCase
{
/**
* @var CrontabManagerInterface|\PHPUnit_Framework_MockObject_MockObject
* @var CrontabManagerInterface|MockObject
*/
private $crontabManagerMock;

Expand Down
31 changes: 16 additions & 15 deletions app/code/Magento/Cron/Test/Unit/Model/Config/Reader/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,42 @@
*/
namespace Magento\Cron\Test\Unit\Model\Config\Reader;

use Magento\Cron\Model\Config\Converter\Db as DbConfigConverter;
use Magento\Cron\Model\Config\Reader\Db as DbConfigReader;
use Magento\Framework\App\Config;
use Magento\GoogleAdwords\Block\Code;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test reading for cron parameters from data base storage
*
* @package Magento\Cron\Test\Unit\Model\Config\Reader
*/
class DbTest extends \PHPUnit\Framework\TestCase
class DbTest extends TestCase
{
/**
* @var Config | \PHPUnit_Framework_MockObject_MockObject
* @var Config|MockObject
*/
protected $config;
private $configMock;

/**
* @var \Magento\Cron\Model\Config\Converter\Db|\PHPUnit_Framework_MockObject_MockObject
* @var DbConfigConverter
*/
protected $_converter;
private $configConverter;

/**
* @var \Magento\Cron\Model\Config\Reader\Db
* @var DbConfigReader
*/
protected $_reader;
private $reader;

/**
* Initialize parameters
*/
protected function setUp()
{
$this->config = $this->getMockBuilder(Config::class)
$this->configMock = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$this->_converter = new \Magento\Cron\Model\Config\Converter\Db();
$this->_reader = new \Magento\Cron\Model\Config\Reader\Db($this->config, $this->_converter);
$this->configConverter = new DbConfigConverter();
$this->reader = new DbConfigReader($this->configMock, $this->configConverter);
}

/**
Expand All @@ -50,7 +51,7 @@ public function testGet()
$job1 = ['schedule' => ['cron_expr' => '* * * * *']];
$job2 = ['schedule' => ['cron_expr' => '1 1 1 1 1']];
$data = ['crontab' => ['default' => ['jobs' => ['job1' => $job1, 'job2' => $job2]]]];
$this->config->expects($this->once())
$this->configMock->expects($this->once())
->method('get')
->with('system', 'default')
->will($this->returnValue($data));
Expand All @@ -61,7 +62,7 @@ public function testGet()
],
];

$result = $this->_reader->get();
$result = $this->reader->get();
$this->assertEquals($expected['default']['job1']['schedule'], $result['default']['job1']['schedule']);
$this->assertEquals($expected['default']['job2']['schedule'], $result['default']['job2']['schedule']);
}
Expand Down
41 changes: 18 additions & 23 deletions app/code/Magento/Cron/Test/Unit/Model/Config/SchemaLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,39 @@
*/
namespace Magento\Cron\Test\Unit\Model\Config;

class SchemaLocatorTest extends \PHPUnit\Framework\TestCase
use Magento\Cron\Model\Config\SchemaLocator;
use Magento\Framework\Module\Dir\Reader as ModuleDirReader;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class SchemaLocatorTest extends TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject|ModuleDirReader
*/
protected $_moduleReaderMock;
private $moduleReaderMock;

/**
* @var \Magento\Cron\Model\Config\SchemaLocator
* @var SchemaLocator
*/
protected $_locator;
private $locator;

/**
* Initialize parameters
*/
protected function setUp()
{
$this->_moduleReaderMock = $this->getMockBuilder(
\Magento\Framework\Module\Dir\Reader::class
)->disableOriginalConstructor()->getMock();
$this->_moduleReaderMock->expects(
$this->once()
)->method(
'getModuleDir'
)->with(
'etc',
'Magento_Cron'
)->will(
$this->returnValue('schema_dir')
);
$this->_locator = new \Magento\Cron\Model\Config\SchemaLocator($this->_moduleReaderMock);
$this->moduleReaderMock = $this->getMockBuilder(ModuleDirReader::class)
->disableOriginalConstructor()->getMock();
$this->moduleReaderMock->expects($this->once())
->method('getModuleDir')
->with('etc', 'Magento_Cron')
->will($this->returnValue('schema_dir'));
$this->locator = new SchemaLocator($this->moduleReaderMock);
}

/**
* Testing that schema has file
*/
public function testGetSchema()
{
$this->assertEquals('schema_dir/crontab.xsd', $this->_locator->getSchema());
$this->assertEquals('schema_dir/crontab.xsd', $this->locator->getSchema());
}
}
38 changes: 18 additions & 20 deletions app/code/Magento/Cron/Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,40 @@
*/
namespace Magento\Cron\Test\Unit\Model;

/**
* Class \Magento\Cron\Model\Config
*/
class ConfigTest extends \PHPUnit\Framework\TestCase
use Magento\Cron\Model\Config;
use Magento\Cron\Model\Config\Data as ConfigDataModel;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
/**
* @var \Magento\Cron\Model\Config\Data|\PHPUnit_Framework_MockObject_MockObject
* @var ConfigDataModel|MockObject
*/
protected $_configData;
private $configDataMock;

/**
* @var \Magento\Cron\Model\Config
* @var Config
*/
protected $_config;
private $config;

/**
* Prepare data
*/
protected function setUp()
{
$this->_configData = $this->getMockBuilder(
\Magento\Cron\Model\Config\Data::class
$this->configDataMock = $this->getMockBuilder(
ConfigDataModel::class
)->disableOriginalConstructor()->getMock();
$this->_config = new \Magento\Cron\Model\Config($this->_configData);
$this->config = new Config($this->configDataMock);
}

/**
* Test method call
*/
public function testGetJobs()
public function testGetJobsReturnsOriginalConfigData()
{
$jobList = [
'jobname1' => ['instance' => 'TestInstance', 'method' => 'testMethod', 'schedule' => '* * * * *'],
];
$this->_configData->expects($this->once())->method('getJobs')->will($this->returnValue($jobList));
$result = $this->_config->getJobs();
$this->configDataMock->expects($this->once())
->method('getJobs')
->will($this->returnValue($jobList));
$result = $this->config->getJobs();
$this->assertEquals($jobList, $result);
}
}
Loading

0 comments on commit 9bdea07

Please sign in to comment.