Giter VIP home page Giter VIP logo

urimocker's Introduction

Tairocruiz URIMocker

Tairocruiz URIMocker is a PHP package that allows you to mock URLs in your Laravel applications. It leverages the php-vcr library to record and replay HTTP interactions, making it easy to test your code that interacts with external APIs.

Installation

You can install the Tairocruiz URIMocker package via Composer. Run the following command in your Laravel project's root directory:

composer require tairocruiz/urimocker

Usage

1. Initialize URIMocker

First, you need to initialize URIMocker in your Laravel application. You can do this in your service provider or any other appropriate location. Here's an example of how to initialize URIMocker:

use Tairocruiz\URIMocker\URIMocker;

URIMocker::configure()->enableLibraryHooks(['curl']);
URIMocker::configure()->setCassettePath(__DIR__ . '/fixtures');
URIMocker::turnOn();

2. Mock URLs

Once URIMocker is initialized, you can mock URLs in your tests or application code. Use the mockUrl method to specify the URL you want to mock and the response it should return:

URIMocker::mockUrl('http://example.com/api', 'Mocked response for the API');

3. Make HTTP Requests

Now you can make HTTP requests to the mocked URLs in your application code. URIMocker will intercept these requests and return the mocked responses:

$response = file_get_contents('http://example.com/api');

4. Eject Cassettes

After each test or test suite, it's a good practice to eject the cassette to stop URIMocker from recording further interactions:

URIMocker::eject();

Contributing

Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on GitHub.

License

The Tairocruiz URIMocker package is open-source software licensed under the MIT license.

urimocker's People

Contributors

algoetech avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.