1

I use PHPSPEC 3.4.0.When I run phpsec with

vendor/bin/phpspec run

I get this error:

class Eastsea\Service\FileStorage\DuplicateFileStorage does not exist.

Here is my composer.json file about autoload section:

"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "psr-0": {
        "EastSea\\": "src/"
    }
}

And here is my folder tree:

    ./src
`-- EastSea
    `-- Service
        `-- FileStorage
            |-- DuplicateFile.php
            |-- DuplicateFileStorage.php
            `-- Result.php

Classes:

<?php

namespace EastSea\Service\FileStorage;

class DuplicateFileStorage
{
    public function validate()
    {
        // TODO: write logic here
    }

    public function storage()
    {
        // TODO: write logic here
    }

    public function handle(DuplicateFile $file)
    {
        $file->hash();
    }
}

Spec:

<?php

namespace spec\Eastsea\Service\FileStorage;

use \EastSea\Service\FileStorage\DuplicateFileStorage;
use \EastSea\Service\FileStorage\Result;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class DuplicateFileStorageSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->shouldHaveType(DuplicateFileStorage::class);
    }

}
macc
  • 105
  • 9

1 Answers1

1

Try with this:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "": "src/"
    }
}

And obviously run composer dump-autoload after your composer.json's update.

sensorario
  • 20,262
  • 30
  • 97
  • 159
  • It works.Thanks a lot.But why dose my configuration not work?I have wrote a test.php to create that object.Both of 'EastSea\\' and '""' worked. – macc Jun 02 '17 at 10:51