Download the PHP package lequipefr/mockserver-behat-context without Composer

On this page you can find all versions of the php package lequipefr/mockserver-behat-context. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mockserver-behat-context

MockServer Behat context

Php client and behat context for MockServer.

Install

Then add a context in your behat.yml, with the url to your local MockServer instance:

Now, in your behat tests, you should be able to mock the webservices your project depends to, with:

Usage

Behat context

See all available behat phrases you can use.

PHP client

You can also use this library as a simple PHP client, and send your expectations as raw arrays, as defined in mockserver swagger api:

Builder

Instead of raw arrays, you can use the expectation builder and let your IDE autocomplete:

Configuration example

You may want to configure your project so that in test environment, external API are replaced by MockServer.

For example, you may have this kind of configuration:

.env: points to real api

.env.test: points to MockServer instance

Multiple services

If you have multiple apis or microservices and want to make sure a request is sent to the expected service, you can use one of these following trick:

Custom path prefix

.env:

.env.test:

This way, when running behat tests, your application will hit mockserver in any case, but with a different path prefix.

Then, your tests will looks like:

Custom domain name

One drawback of the solution above is that it can be difficult to concatenate a base host with a relative path if you didn't handled this case since the beginning, and always assumed that you hit your api at the root.

So in this case you can use different hosts name:

.env:

.env.test:

If you do the necessary in your hosts name resolution to make any *.mockserver requests will hit your localhost, your mockserver instance will receive all requests with a different hostname that you can match with the httpRequest.headers[name = 'Host'] parameter in expectation.

FAQ

I am still getting 404's when my application under test is trying to query mocked external service

For all trouble you get between your application and mockserver, you should use MockServer UI.

It is already installed and accessible here: http://127.0.0.1:1080/mockserver/dashboard.

If not, check MockServer UI documentation.

The UI displays useful information:

If you get 404's, you may check all this points:

In "Active Expectations" you must see the mock you defined in your behat test. If not, check if the mockserver url in behat.yml valid and used:

In "Received Requests", you must see the request sent by your tested application. If not, check where is sent the request then. You should configure your application to use mockserver as base host instead the external service, something like:

If "Active Expectations" and "Received Requests" contains your mock and a received request, did the request matched the mock ?

Mockserver can contains multiple mocks and will response with the mock only if path, headers... matches.

To check that, in "Log Messages" section, you should see MATCHED_EXPECTATION. If not, check the log line about the received request, it will tell you with the request didn't matched the mock.

Sometimes it didn't match just because slash in path is like api/... instead of /api/....

Contributing

See CONTRIBUTING.md.

License

This library is under MIT license.


All versions of mockserver-behat-context with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.2
behat/behat Version ^3.0
behat/gherkin Version ^4.0
psr/http-client Version ^1.0
psr/http-message Version ^1.0|^2.0
php-http/discovery Version ^1.14
guzzlehttp/psr7 Version ^2.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lequipefr/mockserver-behat-context contains the following files

Loading the files please wait ....