jeudi 11 février 2021

What is wrong with my phpspec configuration for autoloading?

I need to use PHPspec but my folder structure is a bit more complex than the typical 'src' or 'app/scr' and I am having a very difficult time getting things to work properly.

My folder structure

  • Root
    • bundle
      • services
        • app
          • data (classes live here)
          • tests
            • spec (specs live here)

My composer autoload file

    "autoload": {
    "psr-4": {
        "bundle\\": "./bundle"
        "data\\": "./bundle/services/app/data" (I don't think this one is necessary?)
    },

My phpspec.yml file Examples and The errors with each attempt

I have tried several different iterations of this and can't get everything to line up properly and work across the board.

Given the following phpspec.yml:

        suites:
         data_suite: (I still have no idea if suites is arbitrary or follows some naming rules)
           namespace: data
           psr4_prefix: data
           src_path: '../data'
           spec_path: '%paths.config%'

When I run the following phpspec command

bin/phpspec describe SomeClass

I get:

 Can not find appropriate suite scope for class `someClass`. 

Now, if I simply take away the suite and namespace configuration from the phpspec.yml I can generate classes, but then they can't be autoloaded.

Given the following phpspec.yml (just giving up on the suite idea)

           src_path: '../data'
           spec_path: '%paths.config%'

The Spec gets properly created and put in test/spec

Then when I run:

bin/phpspec run

It asks me if I would like to create the class to which I say yes. It then creates the class and puts it in the '../data' folder where I want it, but then shows this error:

    In SuitePrerequisites.php line 45:
The type someClass was generated but could not be loaded. Do you need to configure an autoloader?

I feel I have tried every iteration/combination of different namespaces in the phpspec.yml file to sort this out but I either can't create the spec because of it not being able to find the appropriate suite scope, or I can create the classes, but they can't be autoloaded.

Do I have something wrong in my composer autoload? Or do I simply not have the yml file setup properly?

Aucun commentaire:

Enregistrer un commentaire