Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magento/magento2#27500 Replace deprecated constructs from Cron PHPUnit. #27577

Merged
merged 4 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -23,7 +26,7 @@ class CronCommandTest extends \PHPUnit\Framework\TestCase
*/
private $deploymentConfigMock;

protected function setUp()
protected function setUp(): void
{
$this->objectManagerFactory = $this->createMock(ObjectManagerFactory::class);
$this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
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 All @@ -33,7 +35,7 @@ class CronInstallCommandTest extends \PHPUnit\Framework\TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
$this->crontabManagerMock = $this->getMockBuilder(CrontabManagerInterface::class)
->getMockForAbstractClass();
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 All @@ -27,7 +29,7 @@ class CronRemoveCommandTest extends \PHPUnit\Framework\TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
$this->crontabManagerMock = $this->getMockBuilder(CrontabManagerInterface::class)
->getMockForAbstractClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DbTest extends \PHPUnit\Framework\TestCase
/**
* Prepare parameters
*/
protected function setUp()
protected function setUp(): void
{
$this->_converter = new \Magento\Cron\Model\Config\Converter\Db();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class XmlTest extends \PHPUnit\Framework\TestCase
/**
* Initialize parameters
*/
protected function setUp()
protected function setUp(): void
{
$this->_converter = new \Magento\Cron\Model\Config\Converter\Xml();
}
Expand Down Expand Up @@ -76,11 +76,10 @@ public function testConvert()

/**
* Testing converting not valid cron configuration, expect to get exception
*
* @expectedException \InvalidArgumentException
*/
public function testConvertWrongConfiguration()
{
$this->expectException(\InvalidArgumentException::class);
$xmlFile = __DIR__ . '/../_files/crontab_invalid.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
Expand Down
33 changes: 17 additions & 16 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()
protected function setUp(): void
{
$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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class XmlTest extends \PHPUnit\Framework\TestCase
/**
* Prepare parameters
*/
protected function setUp()
protected function setUp(): void
{
$fileResolver = $this->getMockBuilder(
\Magento\Framework\App\Config\FileResolver::class
Expand Down
43 changes: 19 additions & 24 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()
protected function setUp(): void
{
$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());
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Cron/Test/Unit/Model/Config/XsdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class XsdTest extends \PHPUnit\Framework\TestCase
*/
protected $_xsdFile;

protected function setUp()
protected function setUp(): void
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
Expand Down
40 changes: 19 additions & 21 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()
protected function setUp(): void
{
$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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class XmlTest extends \PHPUnit\Framework\TestCase
*/
protected $object;

protected function setUp()
protected function setUp(): void
{
$this->object = new \Magento\Cron\Model\Groups\Config\Converter\Xml();
}
Expand Down
Loading