vendredi 27 janvier 2017

PHPUnit autoloader classes with composer

My project's structure is:

--/
--src
--tests
--phpunit.xml
--composer.json

I want to use composer for autoloading my classes from src folder in tests. My composer.json:

{
"name": "codewars/pack",
"description": "Codewars project",
"type": "project",
"require": {
    "fxp/composer-asset-plugin": "^1.2.0",
    "phpunit/phpunit": "5.5.*",
    "phpunit/dbunit": "2.0.*"
},
"autoload": {
    "psr-4": {"Source\\": "src/"
    }
}

}

Autoloder files generated:

<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
'Source\\' => array($baseDir . '/src'),
);

My phpunit.xml:

<phpunit bootstrap="vendor/autoload.php">
<testsuites>
    <testsuite name="Tests">
        <directory>tests</directory>
    </testsuite>
</testsuites>
</phpunit>

And my test file example:

class Task2Test extends PHPUnit_Framework_TestCase
{
public function testTask2(){
    $list=[1,3,5,9,11];
    $this->assertEquals(7,\Source\findMissing($list));
    $list=[1,5,7];
    $this->assertEquals(3,\Source\findMissing($list));
 }

}

And when I run tests I get error such as Fatal error: Call to undefined function Source\findMissing()

Please, help me, how can I solve this problem?

Aucun commentaire:

Enregistrer un commentaire