I scrapped the earlier form of my question because it was too convoluted. Here's the new version.
I want to use phpspec with my psr-4 formatted projects.
Here's the way I tried to set up a test project:
Created a new folder for the project:
cd ~/Desktop/ mkdir TestPhpSpec cd TestPhpSpec
create a new
composer.json
file and require phpspec:composer require phpspec/phpspec
Which creates my composer.json
file:
{
"require": {
"phpspec/phpspec": "^2.3"
}
}
I add my psr-4 namespace to the autoload property of my
composer.json
file:{ "require": { "phpspec/phpspec": "^2.3" }, "autoload": { "psr-4": { "Acme\\": "src/Acme" } } }
Then I dump my autoload to make sure my namespace is loaded:
composer dumpautoload
After that, I create my
phpspec.yml
to describe the namespace to phpspec:suites: acme_suite: namespace: Acme psr4_prefix: Acme
Then I describe the class I want to start building:
phpspec describe Acme/Markdown
This is where I run into the first problem. Even though I specify the Acme namespace in my describe
command, the spec does not get placed in a folder matching the namespace:
Though the class it creates is namespaced correctly:
<?php
namespace spec\Acme; // correct namespace
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MarkdownSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Acme\Markdown');
}
}
Then if I try to run the test to start TDD-ing.
phpspec run
It offers to create the class for me and I let it. From there I get the second problem; I get the error message:
[PhpSpec\Process\Prerequisites\PrerequisiteFailedException] The type Acme\Markdown was generated but could not be loaded. Do you need to configure an autoloader?
And the class it creates is not in it's namespaced folder:
The class it creates is also namespaced correctly:
<?php
namespace Acme; // correct namespace
class Markdown
{
}
I've looked over the docs and can't figure out what I'm doing wrong. Any suggestions?