Problem in autoload under test with PHPUnit and Composer in Windows

0

I'm having a problem with Composer in Windows 7.

I developed a project with the following structure:

Simpla_HTML
|--/src
|    |--/Simpla
|          |--/Html
|               |--/Element.php
/---tests
|    |--/Simpla
|          |--/Html
|               |--/ElementTest.php
|----Vendor
      |---...

And in Composer.json I set the autoload as follows:

"autoload": {
    "psr-4": {
        "Simpla\": [
            "src/",
            "tests/"
        ]
    }
}

My test was defined like this:

<?php

require './vendor/autoload.php';

use PHPUnit_Framework_TestCase as PHPUnit;
use Simpla\Html\Element;

class ElementTest extends PHPUnit{

    public function testElementoPai() {

        $actual = Element::tag('html');

        return $this->assertEquals('<html></html>', $actual->render());
    }
}

However, when trying to test my application the following error occurs in the CMD with the vendor \ bin \ phpunit tests command:

Fatal error: Class 'Simpla\Html\Element' not found in C:\EasyPHP\data\localweb\estudo\Simpla\tests\Simpla\Html\ElementTest.php on line 12
PHP Fatal error:  Class 'Simpla\Html\Element' not found in C:\EasyPHP\data\localweb\estudo\Simpla\tests\Simpla\Html\ElementTest.php on line 12

But if I change require in my test file ElementTest.php by% with% test normally runs.

Am I doing something wrong in my autoload?

    
asked by anonymous 28.10.2015 / 15:50

1 answer

2

The implementation you are trying is PSR-0, not PSR-4.

Try changing:

"autoload": {
    "psr-4": {
        "Simpla\": [
            "src/",
            "tests/"
        ]
    }
}

by:

"autoload": {
    "psr-4": {
        "Simpla\": [
            "src/Simpla/",
            "tests/Simpla/"
        ]
    }
}

Source: link

    
28.10.2015 / 19:13