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

Pact-PHP 9.x.x - Is there any support multiple providers #237

Closed
ALTELMA opened this issue Mar 21, 2022 · 7 comments
Closed

Pact-PHP 9.x.x - Is there any support multiple providers #237

ALTELMA opened this issue Mar 21, 2022 · 7 comments

Comments

@ALTELMA
Copy link

ALTELMA commented Mar 21, 2022

Thanks for hardwork to create this package.

As we trying and look for more in pact-php. I did not see any example to switch or setup provider while run testing.

In my case, my app is frontend. It call to 2 or 3 services just need to generate the contracts for all.

Is it possible?

@tienvx
Copy link
Contributor

tienvx commented Mar 22, 2022

@ALTELMA
Copy link
Author

ALTELMA commented Mar 22, 2022

@tienvx to answer you. Yes, I want this, but not sure How it works? Need to review more.
And do you still using MockServerEnvConfig?

However, let's see your PR will be approved.
I was wondering why your PR name is related to Rust?

@tienvx
Copy link
Contributor

tienvx commented Mar 22, 2022

And do you still using MockServerEnvConfig?

Yes, I am trying to make the PR small and easy to migrate to new version as possible. But I removed almost half of environment variables and only keep the one that make sense.

I was wondering why your PR name is related to Rust?

Pact moved from Ruby implementation to Rust implementation. You can find the reasons here. But it's still not perfect. There are some features are missing, so you can see in my PR there are still something related to Ruby.

@cfmack
Copy link
Collaborator

cfmack commented Mar 23, 2022

By the way, thanks for the PR @tienvx . It's such a large shift that I have no had the time to do a deep dive into the Rust implementation. It's needs to happen, just a huge shift

@ALTELMA
Copy link
Author

ALTELMA commented Mar 24, 2022

@cfmack Do you have any plan for this?
I have been sawing a new request from @bethesque to add something like this.

However, while I waiting for any support for this feature. I try to go with customizing PhpPactListener by myself.
To get a new configuration per test suite like the example below.

phpunit.xml

<testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="PhpPact User Tests">
            <file>./tests/Consumer/Api/UserApi.php</file>
        </testsuite>
        <testsuite name="PhpPact Order Tests">
            <file>./tests/Consumer/Api/OrderApi.php</file>
        </testsuite>
    </testsuites>
    <listeners>
        <listener class="App\Pact\PactTestListener">
            <arguments>
                <array>
                    <element key="0">
                        <string>PhpPact User Tests</string>
                    </element>
                </array>
                <array>
                    <element key="provider_name">
                        <string>RabbitMemberUserService</string>
                    </element>
                </array>
            </arguments>
        </listener>
        <listener class="App\Pact\PactTestListener">
            <arguments>
                <array>
                    <element key="0">
                        <string>PhpPact Order Tests</string>
                    </element>
                </array>
                <array>
                    <element key="provider_name">
                        <string>AuthService</string>
                    </element>
                </array>
            </arguments>
        </listener>
    </listeners>
public function __construct(array $testSuiteNames, array $config)
{
    $this->testSuiteNames   = $testSuiteNames;
    $this->mockServerConfig = new MockServerConfig();
    $this->mockServerConfig->setHost(env('PACT_MOCK_SERVER_HOST'));
    $this->mockServerConfig->setPort(env('PACT_MOCK_SERVER_PORT'));
    $this->mockServerConfig->setProvider($config['provider_name']);
    $this->mockServerConfig->setConsumer(env('PACT_CONSUMER_NAME'));
    $this->mockServerConfig->setHealthCheckRetrySec(1);
    $this->mockServerConfig->setHealthCheckTimeout(1);
}

This is a temporary solution for me. @cfmack What do you think about this?
I was discussing with @mefellows to know what it should be doing about this.
If you agree to go with this way. I will try to implement it like this and create PR.

@YOU54F
Copy link
Member

YOU54F commented May 12, 2023

That is a neat solution!

@YOU54F
Copy link
Member

YOU54F commented May 16, 2024

If someone still wants to implement this in the now release/9.x branch you can

https://github.com/pact-foundation/pact-php/tree/release/9.x

Please consider there is a request to update to phpunit 10 in that branch as well #338 which will impact the Listener functionality and therefore the proposed solution here

otherwise support for multiple providers in available in v10.x beta, and in the mainline master branch

Going to close this request down for now but anyone feel free to give us a shout if they want to backport to 9.x, or if they have issues trying this out with multiple providers in v10.x

@YOU54F YOU54F closed this as completed May 16, 2024
@YOU54F YOU54F changed the title Is there any support multiple providers Pact-PHP 9.x.x - Is there any support multiple providers May 16, 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

4 participants