Skip to content

Instantly share code, notes, and snippets.

@iamdylanngo
Last active December 8, 2020 07:54
Show Gist options
  • Save iamdylanngo/ca256c9b06cc515c5cc43646ae32e8d1 to your computer and use it in GitHub Desktop.
Save iamdylanngo/ca256c9b06cc515c5cc43646ae32e8d1 to your computer and use it in GitHub Desktop.
CleanTableCronJob
<?php
namespace Demo\Demo\Cron;
// Need move to CleanTableCronJobTest class
use Magento\Catalog\Model\ProductRepository;
use Magento\Store\Model\StoreManagerInterface;
class CleanTableCronJob
{
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var ProductRepository
*/
private $productRepository;
public function __construct(
StoreManagerInterface $storeManager,
ProductRepository $productRepository
) {
$this->storeManager = $storeManager;
$this->productRepository = $productRepository;
}
/**
* CronJob Description
*
* @return void
*/
public function execute(): void
{
// todo: implement cronjob logic here
}
}
<?php
declare(strict_types=1);
namespace Demo\Demo\Test\Unit\Cron;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;
use Mockery;
use Demo\Demo\Cron\CleanTableCronJob;
// Auto import
use Magento\Catalog\Model\ProductRepository;
use Magento\Store\Model\StoreManagerInterface;
class CleanTableCronJobTest extends TestCase
{
/**
* @var ObjectManager
*/
public $objectManager;
protected function setUp()
{
parent::setUp();
$this->objectManager = new ObjectManager($this);
$this->storeManager = Mockery::mock(StoreManagerInterface:class);
$this->productRepository = Mockery::mock(ProductRepository:class);
}
protected function tearDown()
{
parent::tearDown();
Mockery::close();
}
/**
* @return object|CleanTableCronJob
*/
public function getSubjectUnderTest()
{
return $this->objectManager->getObject(CleanTableCronJob::class, [
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment