Skip to main content
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/
Source Link

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?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

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

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

added full code and fixed the launch with the return $this->_response; added note about Nginx
Source Link

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

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.

TestApp.php

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

        $cron->execute();

 }

enter image description here

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

added 87 characters in body
Source Link
Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156

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.

TestApp.php

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

        $cron->execute();

 }

enter image description here

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.

TestApp.php

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

        $cron->execute();

 }

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.

TestApp.php

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

        $cron->execute();

 }

enter image description here

Source Link
Khoa TruongDinh
  • 32.3k
  • 11
  • 90
  • 156
Loading