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

Separate suits for every component in one directory #1125

Open
meridius opened this issue Jul 25, 2017 · 0 comments
Open

Separate suits for every component in one directory #1125

meridius opened this issue Jul 25, 2017 · 0 comments
Labels

Comments

@meridius
Copy link

Situation

I have multiple "components" in src directory and would like to create separate suites for each of them. Below is expected behavior and two variants I thought I'd get there (none of them fully works).

The question is - what configuration should I use to achieve that?

Expected behavior

phpspec.yml

????? something

generate the spec file

~/projects/store$ bin/phpspec des ACME/Dory/Checkout/Foo
Specification for ACME\Dory\Checkout\Foo created in /var/www/store/tests/spec/Checkout/FooSpec.php.

generated tests/spec/Checkout/FooSpec.php

<?php declare(strict_types = 1);

namespace spec\ACME\Dory\Checkout;

use PhpSpec\ObjectBehavior;

class FooSpec extends ObjectBehavior
{
    public function it_is_initializable()
    {
        $this->shouldHaveType(\ACME\Dory\Checkout\Foo::class);
    }
}

generated src/Checkout/Foo.php

<?php

namespace ACME\Dory\Checkout;

class Foo
{
}

Variant 1 - No spec_prefix

  • the generated spec file
    • location OK
    • namespace is missing spec at the beginning (obviously)
  • the generated src file
    • location OK
    • namespace OK

phpspec.yml

suites:
    checkout:
        namespace: ACME\Dory\Checkout
        psr4_prefix: ACME\Dory\Checkout
        spec_prefix:
        src_path: %paths.config%/src/Checkout
        spec_path: %paths.config%/tests/spec/Checkout
    store:
        namespace: ACME\Dory\Store
        psr4_prefix: ACME\Dory\Store
        spec_prefix:
        src_path: %paths.config%/src/Store
        spec_path: %paths.config%/tests/spec/Store

generate the spec file

~/projects/store$ bin/phpspec des ACME/Dory/Checkout/Foo
Specification for ACME\Dory\Checkout\Foo created in /var/www/store/tests/spec/Checkout/FooSpec.php.

generated tests/spec/Checkout/FooSpec.php

<?php declare(strict_types = 1);

namespace ACME\Dory\Checkout;

use PhpSpec\ObjectBehavior;

class FooSpec extends ObjectBehavior
{
    public function it_is_initializable()
    {
        $this->shouldHaveType(\ACME\Dory\Checkout\Foo::class);
    }
}

generated src/Checkout/Foo.php

<?php

namespace ACME\Dory\Checkout;

class Foo
{
}

Variant 2 - Default spec_prefix

  • the generated spec file
    • location has extra spec at the end
    • namespace OK
  • the generated src file
    • location OK
    • namespace OK

phpspec.yml

suites:
    checkout:
        namespace: ACME\Dory\Checkout
        psr4_prefix: ACME\Dory\Checkout
        spec_prefix: spec
        src_path: %paths.config%/src/Checkout
        spec_path: %paths.config%/tests/spec/Checkout
    store:
        namespace: ACME\Dory\Store
        psr4_prefix: ACME\Dory\Store
        spec_prefix: spec
        src_path: %paths.config%/src/Store
        spec_path: %paths.config%/tests/spec/Store

generate the spec file

~/projects/store$ bin/phpspec des ACME/Dory/Checkout/Foo
Specification for ACME\Dory\Checkout\Foo created in /var/www/store/tests/spec/Checkout/spec/FooSpec.php.

generated tests/spec/Checkout/spec/FooSpec.php

<?php declare(strict_types = 1);

namespace spec\ACME\Dory\Checkout;

use PhpSpec\ObjectBehavior;

class FooSpec extends ObjectBehavior
{
    public function it_is_initializable()
    {
        $this->shouldHaveType(\ACME\Dory\Checkout\Foo::class);
    }
}

generated src/Checkout/Foo.php

<?php

namespace ACME\Dory\Checkout;

class Foo
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants