Skip to main content
4 of 4
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/

Think simple! The Cron class is a "normal" class. We can use a Playground to test our Cron: How can I bootstrap Magento 2 in a test.php script?. The Object Manager will create our Cron Object. And then, we can test our Cron by calling the url directly on Browser.

** Note if using Nginx you can put these files in the pub/ folder and adjust the require path for the Test.php file to require '../app/bootstrap.php';

Test.php

<?php
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);

TestApp.php

 public function launch()
 {
        /** @var \Vendor\Module\Cron\Test $cron */
        $cron = \Magento\Framework\App\ObjectManager::getInstance()
            ->create('Vendor\Module\Cron\Test');

        $cron->execute();

        return $this->_response;

 }

enter image description here

Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156