vendredi 29 janvier 2016

Laravel container doesn't resolve Test methods dependencies

I have a test suit for a CLI program created in App\Commands namespace. The problem I have is that it seems laravel container doesn't resolve test method dependencies nor laravel helpers, ... . I'm on Windows 10.

PHP code :

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

use ACME\SomeClass;

class CLICommandTest extends TestCase
{
    use DatabaseTransactions;

    protected $key = '';
    protected $someClass = null;

    public function __construct(SomeClass $someClass)
    {
        parent::__construct();

        $this->someClass = $someClass;
        $this->key = config('someconfig')['key'];
    }

    /*
     * test handle method
     */
    public function testHandle()
    {
        //assertions
    }

}

I've created & included the service provider for this :

<?php

use ACME\someClass;

$this->app->bind('ACME\SomeClass', function($app){
    return new SomeClass($value);
});

when I run phpunit from either PATH or vendor/bin this error comes up :

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to CLICommandTest::__construct() must be an instance of ACME\someClass, none given, called in phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php on line 475 and defined in C:\path\tests\CLICommandTest.php:16
Stack trace:
#0 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(475): CLICommandTest->__construct()
#1 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(880): PHPUnit_Framework_TestSuite::createTest(Object(ReflectionClass), 'testHandle')
#2 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(195): PHPUnit_Framework_TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#3 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(297): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass))
#4 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php(381): PHPUnit_Framework_TestSuite->addTestSuite(Object(ReflectionClass))
#5 phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuit in C:\path\tests\CLICommandTest.php on line 16

Fatal error: Uncaught TypeError: Argument 1 passed to CLICommandTest::__construct() must be an instance of ACME\someClass, none given, called in phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php on line 475 and defined in C:\path\tests\CLICommandTest.php on line 16

TypeError: Argument 1 passed to CLICommandTest::__construct() must be an instance of ACME\someClass, none given, called in phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php on line 475 in C:\path\tests\CLICommandTest.php on line 16

Call Stack:
    0.0036     492584   1. {main}() C:\PHPUnit\phpunit:0
    0.1375    8875000   2. PHPUnit_TextUI_Command::main() C:\PHPUnit\phpunit:515
    0.1375    8878160   3. PHPUnit_TextUI_Command->run() phar://C:/PHPUnit/phpunit/phpunit/TextUI/Command.php:106
    0.1375    8878160   4. PHPUnit_TextUI_Command->handleArguments() phar://C:/PHPUnit/phpunit/phpunit/TextUI/Command.php:117
    0.1624   10379328   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() phar://C:/PHPUnit/phpunit/phpunit/TextUI/Command.php:663
    0.1624   10379912   6. PHPUnit_Util_Configuration->getTestSuite() phar://C:/PHPUnit/phpunit/phpunit/Util/Configuration.php:796
    0.1651   10381496   7. PHPUnit_Framework_TestSuite->addTestFiles() phar://C:/PHPUnit/phpunit/phpunit/Util/Configuration.php:885
    0.1651   10381496   8. PHPUnit_Framework_TestSuite->addTestFile() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:409
    0.1732   10916648   9. PHPUnit_Framework_TestSuite->addTestSuite() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:381
    0.1732   10917104  10. PHPUnit_Framework_TestSuite->__construct() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:297
    0.1733   10982344  11. PHPUnit_Framework_TestSuite->addTestMethod() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:195
    0.1733   10982760  12. PHPUnit_Framework_TestSuite::createTest() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:880
    0.1735   10986272  13. CLICommandTest->__construct() phar://C:/PHPUnit/phpunit/phpunit/Framework/TestSuite.php:475

Whats the problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire