Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation needed: phpspec.yml does not support different PSRs in different suites #1468

Open
ash-m opened this issue Feb 15, 2024 · 1 comment

Comments

@ash-m
Copy link

ash-m commented Feb 15, 2024

So, I just started throwing some misc classes in my fake/ directory. They are just minimal interface implementations so I didn't care to reflect where they might go in the src/ directory if they were real classes. But adding "Fake\\": "fake/" to composer.json would mean that the specs for these classes would be in spec/, which I felt would be confusing. Solution? PSR-0. Now they get their own directory, spec/Fake. But if you have a psr4_prefix mapping in your phpspec.yml configuration, then phpspec won't be able to find the class, claiming it must be in "the base spec namespace spec\App\".

Here' s part of my composer.json:

  "autoload": {
    "psr-4": {
      "App\\": "src/"
    },
    "psr-0": {
      "Fake\\": "fake/"
    }
  }

Here's my phpspec.yml:

suites:
  fake: 
    namespace: Fake
    src_path: fake
  default:
    namespace: App
    psr4_prefix: App
    src_path: src

Here's what I ran:

0d209c8f2ff3:/app# php vendor/bin/phpspec desc Fake/Foo
Specification for Fake\Foo created in /app/spec/Fake/FooSpec.php.

0d209c8f2ff3:/app# php vendor/bin/phpspec run Fake/Foo
                                                                                 0
0 specs
0 examples
0ms

0d209c8f2ff3:/app# php vendor/bin/phpspec run spec/Fake/FooSpec.php

In PSR0Locator.php line 300:

  Spec class `spec\Fake\FooSpec` must be in the base spec namespace `spec\App\`.


run [-f|--format FORMAT] [--stop-on-failure] [--no-code-generation] [--no-rerun] [--fake] [-b|--bootstrap BOOTSTRAP] [--] [<spec>]

0d209c8f2ff3:/app#

Although this does sort of make it seem like the concept of a suite is not isolated, this isn't a huge problem. I don't really need to do this, but it would've been nice to have it documented.

@ash-m
Copy link
Author

ash-m commented Feb 15, 2024

Actually, it would seem if any suite has the psr4_prefix then it seems to only pick one for the root namespace. How this decision is made escapes me.

@ash-m ash-m changed the title Documentation needed: phpspec.yml does not different PSRs in different suites Documentation needed: phpspec.yml does not support different PSRs in different suites Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant