2

The method outlined here to create a dirty playground doesn't work in magento 2.1.6: https://magento.stackexchange.com/a/40848/55108

It generates the error:

Uncaught TypeError: Argument 2 passed to Magento\Framework\App\Http::__construct() must be an instance of Magento\Framework\Event\Manager, none given

The TestApp class in the example extends \Magento\Framework\App\Http. This is the Http classes constructor:

public function __construct(
    \Magento\Framework\ObjectManagerInterface $objectManager,
    Event\Manager $eventManager,
    AreaList $areaList,
    RequestHttp $request,
    ResponseHttp $response,
    ConfigLoaderInterface $configLoader,
    State $state,
    Filesystem $filesystem,
    \Magento\Framework\Registry $registry
) {
    $this->_objectManager = $objectManager;
    $this->_eventManager = $eventManager;
    $this->_areaList = $areaList;
    $this->_request = $request;
    $this->_response = $response;
    $this->_configLoader = $configLoader;
    $this->_state = $state;
    $this->_filesystem = $filesystem;
    $this->registry = $registry;
}

So I guess it is failing because $eventManager doesn't exist within the playgrounds context?

How does the code need to be updated to work with 2.1.6?

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Guerrilla
  • 187
  • 2
  • 13
  • Seems to work straight away for me i'm testing on 2.1.7 however, what mode are you in i've seen this issue was fixed elsewhere when setting mode to developer? https://github.com/magento/magento2/issues/7151 – harri Aug 13 '17 at 13:37

4 Answers4

0

I don't know if it satisfies your needs but when I need to poke with Magento 2 runtime I use a shell script like this:

<?php
// set error verbosity
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// require boostrap file
try {
    require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL;
    exit(1);
}

// bootstrap framework
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */

// get the Object Manager
$objectManager = $bootstrap->getObjectManager();

// set application area
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

// YOUR CODE HERE

// e.g.: get the Event Manager
$eventManager = $objectManager->get('Magento\Framework\EntityManager\EventManager');

Hope it helps.

Enjoy,

-Alessandro

Alessandro Ronchi
  • 3,746
  • 1
  • 23
  • 28
0

Just tested this in 2.1.6 and 2.1.8 and it works in both places.

I got the answer from the post you originally linked to: https://magento.stackexchange.com/a/96875/36487

File magento2_root/test.php

<?php

use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$objectManager = $bootstrap->getObjectManager();

// This is just an example showing that it gets through the bootstrap
// and works
echo get_class($objectManager->create('\Magento\Catalog\Model\Category'));

Console output

| => php test.php
Magento\Catalog\Model\Category\Interceptor
nick.graziano
  • 269
  • 1
  • 9
0

Please set your Magento in Developer Mode using below command

php bin/magento deploy:mode:set developer

Then after delete var/generation folder. After refresh page Magento will create new generation folder in var/generation.

I face this type of error many times. When add or remove parameters in class __construct.

May be this will help you.

Nimesh Patel
  • 451
  • 4
  • 15
0

Do you have a correct path for Magento\Framework\EntityManager\EventManager with the namespace ?

You can try to recompile de code.

Franck Garnier
  • 2,946
  • 1
  • 17
  • 35