InjectionException doesn't reflect real Error (PHP 7) #3869

Open
timtkachenko opened this Issue Dec 23, 2016 · 2 comments

Projects

None yet

3 participants

@timtkachenko

What are you trying to achieve?

I'd like to see correct error/exceptions that will be clear.

PHPUnit_Framework_Exception: Declaration of Step\Functional\Bar::make($name) should be compatible with Step\Functional\Base::make($name = NULL)
/srv/test/tests/_support/Step/Functional/Bar.php:4

What do you get instead?

currently I get

[InjectionException] Failed to inject dependencies in instance of 'FooCest'. Class Step\Functional\Bar does not exist

doesn't reflect real Error

Provide console output if related. Use -vvv mode for more details.

./codecept run functional --debug -vvv

# paste output here

Codeception PHP Testing Framework v2.2.7
Powered by PHPUnit 5.7.4 by Sebastian Bergmann and contributors.

Functional Tests (1) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: \Helper\Functional
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FooCest: Try to test
Signature: FooCest:tryToTest
Test: tests/functional/FooCest.php:tryToTest
Scenario --
 ERROR 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 72 ms, Memory: 8.00MB

There was 1 error:

---------
1) FooCest: Try to test
 Test  tests/functional/FooCest.php:tryToTest
                                                                                                                         
  [InjectionException] Failed to inject dependencies in instance of 'FooCest'. Class Step\Functional\Bar does not exist  
                                                                                                                         

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

Provide test source code if related
generate ./codecept generate:stepobject functional Base

namespace Step\Functional;

class Base extends \FunctionalTester
{

	public function make($name = null)
	{
		$I = $this;
	}

}

extend with incorect signature

// paste test
namespace Step\Functional;

class Bar extends Base
{

    public function make($name)
    {
        $I = $this;
    }

}

Details

  • Codeception version:
    Codeception PHP Testing Framework v2.2.7
  • PHP Version: 7.*
  • Operating System: ubuntu 16
  • Installation type:Composer
  • List of installed packages (composer show) irrelevant
  • Suite configuration:
# paste suite config here
default

potential fix

codeception/codeception/src/Codeception/Lib/Di.php

public function injectDependencies
...
        try {
            $args = $this->prepareArgs($reflectedMethod, $defaults);
        } catch (\Exception $e) {
                // lines [115 ... 121]
		$msg = $e->getMessage();
		if($e->getPrevious()){
			$msg .= '; '. $e->getPrevious();
		}
            throw new InjectionException(
                "Failed to inject dependencies in instance of '{$reflectedObject->name}'. " . $msg
            );
        }
...
@DavertMik DavertMik added the BUG label Dec 23, 2016
@DavertMik
Member

Thanks for the detailed report

@Naktibalda
Contributor

@timtkachenko Please make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment