gorghoa / ScenarioStateBehatExtension

Provide a way to share scenario state through steps
MIT License
33 stars 7 forks source link

Unable to autoload ScenarioStateArgument #19

Closed walterdolce closed 7 years ago

walterdolce commented 7 years ago

The ScenarioStateArgument doesn't seem to be working by default.

It gives a:

 [Doctrine\Common\Annotations\AnnotationException]
  [Semantical Error] The annotation "@Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument" in method ForumContext::iVisitTheForumPage() does not exist, or could not be auto-loaded.

I would expect to have it autoloaded automatically instead of adding code specifically for autoloading it.

Here's my context:

<?php

use Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareContext;
use Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareTrait;
use Page\ForumPage;
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument;
use SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext;

/**
 * Class ForumContext
 */
class ForumContext extends PageObjectContext implements ScenarioStateAwareContext
{
    use ScenarioStateAwareTrait;

    /**
     * @When I visit the :forumName forum page
     *
     * @ScenarioStateArgument(name="forumName", argument="storedForumName")
     *
     * @param string $forumName
     * @param string $storedForumName
     */
    public function iVisitTheForumPage($forumName, $storedForumName)
    {
        $this->getPage(ForumPage::class)->open(['forum' => $storedForumName]);
    }
}
vincentchalamon commented 7 years ago

Hi @walterdolce, I think your issue is in your project autoloader, not in this current projet. The example you gave is just for functional testing this project, it's not a documentation neither a recommendation about how to implement it.

walterdolce commented 7 years ago

@vincentchalamon thank you for coming back to me so quickly. I raised #20 for this.

walterdolce commented 7 years ago

I think your issue is in your project autoloader

Hmmm. There's nothing special in my autoloader:

{
  "require-dev": {
    # Dependencies...
    "gorghoa/scenariostate-behat-extension": "v1.0.0-rc.2"
  },
  "autoload": {
    "psr-0": {
      "": [
        "webapp/php/lib",
        "webapp/php/sharedlib",
        "../pear",
        "../php"
      ]
    }
  },
  "config": {
    "bin-dir": "bin"
  }
}

My behat files are placed differently than normal. Not sure whether it should matter at all. I will include just to give more info:

# behat.yml
default:
  autoload:
    '': %paths.base%/features/behat/bootstrap
# ...

I see you are specifically requesting the annotation registry to have the ScenarioStateArgument autoloaded. So I suspect everyone else will have to do it... #20 should fix this by registering the annotation at extension initialisation time.