PHPUnit class not found

Folder structure

/app/lib/Helper.php

/tests/HelperTest.php

/vendor/autoload.php

composer.json

{
    "require-dev": {
        "phpunit/phpunit": "*"
    },

    "autoload": {
        "psr-4": {
            "Datapark\\LPS\\": "app/"
        }
     },

     "autoload-dev": {
         "psr-4": {
             "Datapark\\LPS\\Tests\\": "tests/"
          }
     },
}

helper.php

<?php

namespace lib;

class Helper
{   
    public function array_get($array, $key, $default = null)
    {
        // code
    } 
}

HelperTest.php

<?php

use lib\Helper;

class HelperTest extends \PHPUnit_Framework_TestCase
{
    public function test_array_get()
    {
        $helper = new Helper();

    }
}

Command executed on server [Debian 8 / PHP7]

phpunit-bootstrap vendor / autoload.php tests

The error I get

1) HelperTest :: test_array_get

Error: class 'lib \ Helper' not found

lib \ Helper loads through the namespace, and my IDE (PhpStorm) also recognizes it. Fighting around for several hours and not getting him to work.

+4
source share
2 answers

The startup configuration indicates:

        "Datapark\\LPS\\": "app/"

This means something like:

classes in the directory apphave a space prefix Datapark\LPS\.

app/lib/Helper.php Datapark\LPS\lib. Helper:

namespace Datapark\LPS\lib;

.

+5

, :

$ vendor/bin/phpunit tests

+2

All Articles