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

[generate:controller] Error: Does not have a method 'getTestPath' #3998

reganking opened this issue Feb 7, 2019 · 1 comment


None yet
2 participants
Copy link

commented Feb 7, 2019


  • generate:controller results in error and creation of controller file at /.

  • Drupal version: 8.6.7.

  • Console version: 1.8.0.

How to reproduce

From docroot:

../vendor/drupal/console/bin/drupal generate:controller  \
--module="unify_event"  \
--class="MyController"  \
--routes='"title":"ControllerMethod", "name":"unify_event.view_events", "method":"view_event", "path":"/events/{name}"'  \
 [ERROR] <em class="placeholder">Warning</em>: call_user_func_array() expects parameter 1 to be a valid callback,       
         class 'SplFileInfo' does not have a method 'getTestPath' in Drupal\Core\Extension\Extension->__call() (line 155 of core/lib/Drupal/Core/Extension/Extension.php). Drupal\Core\Extension\Extension->__call('getTestPath', Array) (Line: 57)        
         Drupal\Console\Generator\ControllerGenerator->generate(Array) (Line: 156)                                   
         Drupal\Console\Command\Generate\ControllerCommand->execute(Object, Object) (Line: 255)                      
         Symfony\Component\Console\Command\Command->run(Object, Object) (Line: 971)                                  
         Symfony\Component\Console\Application->doRunCommand(Object, Object, Object) (Line: 248)                     
         Symfony\Component\Console\Application->doRun(Object, Object) (Line: 185)                                    
         Drupal\Console\Core\Application->doRun(Object, Object) (Line: 64)                                           
         Drupal\Console\Application->doRun(Object, Object) (Line: 148)                                               
         Symfony\Component\Console\Application->run() (Line: 89)                                                     
         require('[...]/vendor/drupal/console/bin/drupal.php') (Line: 4) 


  • Error occurs regardless whether module is enabled or disabled.
  • File MyControllerTest.php is created at / due to missing path expected from getTestPath().
  • drupal/console/src/extension/Manager->getTestPath() is never called. drupal/console/src/extension/Manager->getModule() <- createExtension() is called.

In ControllerGenerator.php (erroneously calls \Drupal\Console\Extension\Extension->getTestPath()):

        if ($test) {
                **$moduleInstance->getTestPath('Controller')** . '/' . $class . 'Test.php',

The `Manager->getTestPath()' takes the `testType` argument: 
public function getTestPath($testType, $fullPath = false)
    return $this->getPath($fullPath) . '/Tests/' . $testType;
Aside: Function `$this->getPath()` is not in the `Manager` class, but the class is in the `Extension` namespace.

A `\Drupal\Console\Extension\Extension->getTest**s**Path()` function exists, but doesn't have a `testType` argument.

### Temporary Solution
`sudo mv /MyControllerTest.php docroot/modules/unify_event/tests/Controller/`

### Solution
Move the `Manager->getTestPath()` `testType' argument over to `Extension->getTestsPath()` and correct `getTestPath` to `getTestsPath` in `ControllerGenerator`.

Note: This needs testing.

reganking added a commit to reganking/drupal-console that referenced this issue Feb 7, 2019

@reganking reganking referenced this issue Feb 7, 2019


Fix for #3998 #3999

@LOBsTerr LOBsTerr added this to the 1.9.0 milestone Feb 12, 2019

LOBsTerr added a commit that referenced this issue Feb 12, 2019


This comment has been minimized.

Copy link

commented Feb 12, 2019

@reganking Thank you for your contribution. It has been merged

@LOBsTerr LOBsTerr closed this Feb 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.