Giter Club home page Giter Club logo

http-mock's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http-mock's Issues

Allow using symfony/process 5

Currently, the requirements are symfony/process ~3|~4. This needs to be symfony/process ~3|~4|~5 so this library can be used together with Symfony 5.

New version

How about a v0.8.1 to contain the newest updates?

version 0.7.8. http-mock issues warnings because timezone and breaks phpunit tests

when trying to run tests with http-mock, there is this warning

PHPUnit 4.8.29 by Sebastian Bergmann and contributors.

.F.................................

Time: 203 ms, Memory: 10.00MB

There was 1 failure:

1) Doofinder\Api\Test\Management\ClientTest::testDummy
HTTP mock server standard error output should be empty
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
+[Thu Dec  1 10:37:39 2016] PHP Warning:  DateTime::createFromFormat(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/jzarate/havet/php-doofinder/vendor/symfony/http-foundation/Response.php on line 333
+[Thu Dec  1 10:37:39 2016] PHP Warning:  DateTime::createFromFormat(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/jzarate/havet/php-doofinder/vendor/symfony/http-foundation/Response.php on line 333

/home/jzarate/havet/php-doofinder/vendor/internations/http-mock/src/InterNations/Component/HttpMock/PHPUnit/HttpMockTrait.php:56
/home/jzarate/havet/php-doofinder/src/Test/Management/ClientTest.php:42

it's related to not having timezone defined.

Since http-mock starts its own process, nothing I do on phpunit tests (like disabling warnings, setting timezone, etc..) will fix this (http-mock runs in its own process)

I haven't found a way to pass php init options or the like to http-mock's process, phpunit is unusable

Http mock fails with new symfony/http-foundation - 4x

It fails with new http foundation. In my case it is 4.0.8
From yesterday my API tests started to failing after updating dependencies from silex 2.2.4 to 2.3.0
which installed new symfony components in 4.x version
Update info:

Package operations: 0 installs, 5 updates, 1 removal

  • Removing symfony/polyfill-php70 (v1.7.0)
  • Updating symfony/routing (v3.4.8 => v4.0.8): Loading from cache
  • Updating symfony/http-foundation (v3.4.8 => v4.0.8): Loading from cache
  • Updating symfony/event-dispatcher (v3.4.8 => v4.0.8): Loading from cache
  • Updating symfony/http-kernel (v3.4.8 => v4.0.8): Loading from cache
  • Updating silex/silex (v2.2.4 => v2.3.0): Loading from cache

In tests I get error:

Client error: GET http://localhost:8082/v1/countries/de.json resulted in a 404 Not Found
with content which I set in body: { name: Proxy-Germany, code: de }

Test code:


$I->getHttpMock()->mock
	->when()
		->methodIs('GET')
		->pathIs('/v1/countries/de.json')
	->then()
		->header('content-type', 'application/json')
		->body('{ "name": "Proxy-Germany", "code": "de" }')
	->end();
$I->getHttpMock()->setUp();

$countryCode = "de";

$I->sendGET('/v1/countries/'. $countryCode . '-proxy.json');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['code' => $countryCode, 'name' => 'Proxy-Germany']);  

After many hours of investigation I noticed that I can fix it by replacing body method with callback:

$I->getHttpMock()->mock
	->when()
		->methodIs('GET')
		->pathIs('/v1/countries/de.json')
	->then()
		->header('content-type', 'application/json')
		->callback(
			function (Response $response) {
				$response->setContent('{ "name": "Proxy-Germany", "code": "de" }')
					->setStatusCode(200);
			}
		)
	->end();
$I->getHttpMock()->setUp();

$countryCode = "de";

$I->sendGET('/v1/countries/'. $countryCode . '-proxy.json');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['code' => $countryCode, 'name' => 'Proxy-Germany']);

I guessing that http mock library uses some old code that isn't present in 4.x versions.

Please fix issue.
Regards,
Pawel

PHPUnit failing

I've done

git clone [email protected]:InterNations/http-mock.git
cd http-mock
composer install
phpunit

And am getting tons of failures, all along the lines of:

  1. InterNations\Component\HttpMock\Tests\PHPUnit\HttpMockPHPUnitIntegrationTest::testLimitDurationOfAResponse
    Guzzle\Http\Exception\CurlException: [curl] 52: Empty reply from server [url] http://localhost:28080/_all

~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php:420
~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php:354
~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php:286
~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php:247
~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php:140
~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMultiProxy.php:106
~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php:385
~/dev/http-mock/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php:258
~/dev/http-mock/src/InterNations/Component/HttpMock/Server.php:97
~/dev/http-> mock/src/InterNations/Component/HttpMock/PHPUnit/HttpMockFacade.php:76
~/dev/http-mock/src/InterNations/Component/HttpMock/PHPUnit/HttpMockTrait.php:26
~/dev/http-mock/tests/InterNations/Component/HttpMock/Tests/PHPUnit/HttpMockPHPUnitIntegrationTest.php:24

I'm running PHP 5.4.11 and have curl extension installed. Do you have any idea what the issue might be?

Thanks!

Save and return post data.

Hi

It would be useful for me if data posted to the mocked server was saved and returned when using in tests. You could then check the post data was as expected, eg

$this->assertSame( 'expected', $this->http->requests->latest()->getPostField( 'my_field' ) );

I have implemented this quickly in my fork, https://github.com/cosmorogers/http-mock, shall I make a pull request for this?

"Uncaught Error: Function name must be a string" when matching on a callback

Hi,

I'm trying to follow the 2nd snippet of the doc here https://github.com/InterNations/http-mock/blob/main/doc/stubbing.md but I get an error. I'm not sure if I'm doing something wrong or if there is an issue and I would be thrilled if you can give me pointer to fix it.
Here is my code:

<?php
declare(strict_types=1);

use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;

final class CalDAVUTest extends TestCase {
    use HttpMockTrait;
    public static function setUpBeforeClass() : void {
        static::setUpHttpMockBeforeClass('8082', 'localhost');
    }
    public static function tearDownAfterClass() : void {
        static::tearDownHttpMockAfterClass();
    }
    public function setUp() : void {
        $this->setUpHttpMock();
    }
    public function tearDown() : void {
        $this->tearDownHttpMock();
    }

    public function test_doc(){
        $this->http->mock
            ->when()
                ->callback(
                    static function (Request $request) {
                        return $request->getMethod() === 'GET' && $request->getPathInfo() === '/resource';
                    }
                )
            ->then()
                ->callback(
                    static function (Response $response) {
                        $response->setBody('response');
                    }
                )
            ->end();
        $this->http->setUp();


        $curl = curl_init("http://localhost:8082/resource");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_exec($curl);
    }
}

and here is the error I have:

1) CalDAVUTest::test_doc
HTTP mock server standard error output should be empty
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'[Tue Dec 21 22:59:15 2021] PHP Fatal error:  Uncaught Error: Function name must be a string in /documents/zwp/slack-agenda-app/vendor/jeremeamia/superclosure/src/SerializableClosure.php(210) : eval()'d code:2
+Stack trace:
+#0 [internal function]: InterNations\Component\HttpMock\Matcher\AbstractMatcher::{closure}()
+#1 /documents/zwp/slack-agenda-app/vendor/jeremeamia/superclosure/src/SerializableClosure.php(75): call_user_func_array()
+#2 /documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/app.php(130): SuperClosure\SerializableClosure->__invoke()
+#3 [internal function]: InterNations\Component\HttpMock\{closure}()
+#4 /documents/zwp/slack-agenda-app/vendor/silex/silex/src/Silex/ExceptionListenerWrapper.php(53): call_user_func()
+#5 /documents/zwp/slack-agenda-app/vendor/symfony/event-dispatcher/EventDispatcher.php(264): Silex\ExceptionListenerWrapper->__invoke()
+#6 /documents/zwp/slack-agenda-app/vendor/symfony/event-dispatcher/EventDispatcher.php(239): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch()
+#7 /documents/zwp/slack-agen in /documents/zwp/slack-agenda-app/vendor/jeremeamia/superclosure/src/SerializableClosure.php(210) : eval()'d code on line 2'

/documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/PHPUnit/HttpMockTrait.php:73
/documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/PHPUnit/HttpMockFacade.php:85
/documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/PHPUnit/HttpMockTrait.php:75
/documents/zwp/slack-agenda-app/tests/CalDAVUTest.php:20

Here is the relevant part of my composer.json:

    "require-dev": {
        "phpunit/phpunit": "^9.5",
        "internations/http-mock": "^0.14.0"
    }

(and in my composer.lock I see that I'm using jeremeamia/superclosure version 2.4.0)

Does this error rings a bell?

Make new release with latest code updates

Jeremeamia\SuperClosure namespace compatibility was fixes here 203f6ef, but the latest release doesn't contain that changes, thus master branch has to be used which is not super cool. It would be really great to have some latest stable version released. Thanks!

Real mocks instead of stubs

I think that now HTTP mocks are more simple stubs, they aren't mocks in classical meaning (because they don't set any assertions based on prepared HTTP queries).

For example, if I write a test with a classic mock object in PHPUnit:

    public function testMock()
    {
        $mock = $this->getMock(\ArrayObject::class);
        $mock->expects($this->once())->method('count')->willReturn(5);

        assertTrue(true);
    }

I will get it failed:

There was 1 failure:

1) ExampleTest::testMock
Expectation failed for method name is equal to <string:count> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.

But with HTTP mocks behaviour isn't the same. expects() works only to restrict HTTP calls inside a web server, but not for tests.

What do you think about automatic addition of assertions for HTTP mocks, like it's done for class/interface mocks?

register different successive responses for the same endpoint

Hi,

first of all, thanks for this software.

Then, here is a feature request:
I'm trying to test a "retry" feature in my http client. So I would like to be able to set up http-mock so that the 1st query it receives returns a response with status code 500, and so that the 2nd query it receives returns a response with status code 200.
I've looked at the doc, made some experiments but couldn't find a way to do i (in particular I tried to redefine the behavior of the mock in a ->then()->callback(...) but that didn't seem to work).

To put it in a nutshell:

  • Is it already possible to do this kind of setup? If yes, would it be possible to add some doc about it?
  • If it's not possible, does it seem like a feature you might want to consider?

Address already in use

Failed to listen on 127.0.0.1:33371 (reason: Address already in use) appear second Test unit class which in the same life cycle.
it seems that it have no release socket In teardown() really or Http-mock is not a singleInstance.

http-mock fails for the path '/' with the newest symfony routers (3.4.8 || 4.0.8)

This new change in symfony router (symfony/symfony#26792), now adds an extra check to make sure there are allowed methods configured in case the matching path is '/'.

I am not 100% sure if this is a side effect of a bit hacky approach to rely on app errors (without registering any proper routes) or a possible BC break by the symfony router.

Example test case:

<?php

namespace Tests;

use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
    use HttpMockTrait;

    public static function setUpBeforeClass()
    {
        static::setUpHttpMockBeforeClass('8082', 'localhost');
    }

    public static function tearDownAfterClass()
    {
        static::tearDownHttpMockAfterClass();
    }

    public function setUp()
    {
        $this->setUpHttpMock();
    }

    public function tearDown()
    {
        $this->tearDownHttpMock();
    }

    public function testSimpleRequest()
    {
        $this->http->mock
            ->when()
            ->methodIs('GET')
            ->pathIs('/')
            ->then()
            ->body('mocked body')
            ->end();
        $this->http->setUp();

        $this->assertSame('mocked body', file_get_contents('http://localhost:8082/'));
    }
}

This test will fail because now router will throw a NoConfigurationException

Weird behavior with PHP 7.4, symfony/process and stderr output

Hello!

After I updated my project to use PHP 7.4, now when I try to run my integration tests I always get a very weird output from the stderr pipe when running HttpMockTrait::tearDownHttpMock();:

HTTP mock server standard error output should be empty
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'[Fri Feb 21 18:48:56 2020] 127.0.0.1:59798 Accepted
+[Fri Feb 21 18:48:56 2020] 127.0.0.1:59798 Closing
+[Fri Feb 21 18:48:56 2020] 127.0.0.1:59800 Accepted
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59800 Closing
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59802 Accepted
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59802 Closing
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59804 Accepted
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59804 Closing
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59806 Accepted
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59806 Closing
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59808 Accepted
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59808 Closing
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59810 Accepted
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59810 Closing
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59812 Accepted
+[Fri Feb 21 18:48:57 2020] 127.0.0.1:59812 Closing
+'

All my tests are failing because of the same error. If I stop calling the $this->tearDownHttpMock();, then the tests starts passing.

Someone else is experiencing this too? It's happening only after I updated the PHP version. This is some kind of new behavior of Php?
Shouldn't this output be directed to the stdout pipe instead of the stderr? I mean, these are not errors, they're just logs in fact.

I'm not even sure if the issue is with internations/http-mock or symfony/process, so, I'm sorry if this issue isn't in the correct place.

PHPUnit WebTestCase failing when 2 tests are using the same port.

Using PHP 5.6.18 with PHPUnit 5.7.5, the following error is produced:
UnexpectedValueException: Expected status code 200 from "/_request/2", got 404

The call is from the first test with a loop which is calling $this->http->requests->at($i);.

The codes in the first class is:

/**
     * @beforeClass
     * @SuppressWarnings(PHPMD.StaticAccess)
     */
    public static function init()
    {
        static::setUpHttpMockBeforeClass('8880', 'localhost');
    }

    /**
     * @afterClass
     */
    public static function shutdown()
    {
        static::tearDownHttpMockAfterClass();
    }

    public function testMethod()
    {
        // do stuffs
           $this->http->requests->at($i);
        //do other stuffs
    }

And the second class is

    public static function setUpBeforeClass()
    {
        static::setUpHttpMockBeforeClass('8880', 'localhost');
    }

    public static function tearDownAfterClass()
    {
        static::tearDownHttpMockAfterClass();
    }

    // other stuff

Both class extends from WebTestCase and use the HttpMockTrait

When the port is different in the second class or the second test is skipped, the test runs successfully.

Failure running built in server on PHP 7.1.12

Encountered this on our travis builds today. It seems there was a change to the web server logic on PHP 7.1.12.. may be a bug on their part.

+[Tue Nov 28 21:58:09 2017] PHP Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
+[Tue Nov 28 21:58:09 2017] PHP Fatal error: Unknown: Failed opening required '/home/travis/build/---/vendor/internations/http-mock/public/public/index.php' (include_path='.:/home/travis/.phpenv/versions/7.1.12/share/pear') in Unknown on line 0

As far as I can tell changing the command in the constructor for InterNations\Component\HttpMock\Server to:
'exec php -dalways_populate_raw_post_data=-1 -derror_log= -S %s -t public/ index.php', seems to fix it for my environment.

PHP 5.6 as minimum required version

symfony/process already requires PHP 5.5.9, the whole library will not work with PHP < 5.5.9.

So the current requirement (5.4.0) is a lie :)

Dev dependencies

I'm wondering why do you need the following dependencies to dev versions instead stable

        "silex/silex": "1.0.*@dev",
        "guzzle/guzzle": "dev-master#89c6d12090642e09d5efdabf0cae7fcb7547a9d0",
        "symfony/process": "2.*@dev",
        "jeremeamia/superclosure": "dev-master",
        "nikic/php-parser": "dev-master",
        "lstrojny/hmmmath": "dev-master"

I'm working on a project in which the minimum-stability is set to stable so composer can't resolver this dependencies.
Thanks!

Fatal error when using closure in callback matcher

Hi,
I'm trying to create a mock with headers validation. I'm using callback for that.

I'm getting this error:

Fatal error: Function name must be a string in /vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(210) : eval()'d code on line 2

My code looks like this:

$method = 'POST';
$path = '/path';
$requestHeaders = [
   'Content-Type' => 'application/json'
];

$this->http->mock
            ->when()
            ->methodIs($method)
            ->pathIs($path)
            ->callback(static function(Request $request) use($requestHeaders) {
                foreach ($requestHeaders as $header => $value) {
                    if (!$request->hasHeader($header) || $request->getHeader($header) != $value) {
                        return false;
                    }
                }
                return true;
            })
            ->then()
            ->statusCode(200)
           ->body('ok')
           ->end();

Because of that bug, I cannot validate expected request headers. Could you please provide some alternative method to validate request headers until this issue is fixed?

Thanks

Add option to set a base path during setup

Allowing a base path allows for more customised APIs. For example, I have an API backend that I want to mock that has the following configuration option (I use symfony so it's a parameter option): http://localhost:8080/custom-api/
All end points append to that, but this can change per developer and per server.
Allowing for a base path would for example have the following:

    protected static function setUpHttpMockBeforeClass($port = 28080, $host = 'localhost', $basePath = '')
    {
        static::$staticHttp = new HttpMockFacade($port, $host);
        ServerManager::getInstance()->add(static::$staticHttp->server);
    }

    public static function setUpBeforeClass()
    {
        static::setUpHttpMockBeforeClass('8082', 'localhost', 'custom-api');
    }

Which would allow us to do the following:

    public function testSimpleRequest()
    {
        $this->http->mock
            ->when()
                ->methodIs('GET')
                ->pathIs('/foo') // this would automatically be prepended with '/custom-api'
            ->then()
                ->body('mocked body')
            ->end();
        $this->http->setUp();

        $this->assertSame('mocked body', file_get_contents('http://localhost:8082/custom-api/foo'));
    }

While obviously this isn't that helpful in this test scenaria, but if for example you're doing an integration test where the actual code that's being tested runs a curl request to the custom api with the path, we can automatically select the correct path and everything.

tearDownHttpMock fails when test runs in isolation

I have got a simple test for a gateway. Everything goes fine while the test is not ran in a separateProcess

    public function testSingle() {
        $this->http->mock
            ->when()
            ->then()
            ->callback(
                function (\Symfony\Component\HttpFoundation\Response $response) {
                    $response->setContent(file_get_contents(__DIR__ . '/../../xml/single.xml'))->setStatusCode(
                        200
                    );
                }
            )
            ->end();

        $this->http->setUp();
        //initialize gateway
        $response = $gateway->byName('my-name')->query();
        $rows = $response->getRows();
        self::assertCount(1, $rows);
    }

But If I add the runInSeparateProcess annotation, then tearDownHttpMock fails

   /**     
    *
    * @runInSeparateProcess
    * @preserveGlobalState disabled
    */
    public function testSingle() {
        //my code
    }

$server->getIncrementalErrorOutput() returns [Wed Apr 3 16:52:26 2019] Failed to listen on 127.0.0.1:33371 (reason: Address already in use)

As workaround I override the method into my test class

    protected function tearDownHttpMock()
    {
        if (!$this->http) {
            return;
        }

        //just skipping to make test work
        if($this->isInIsolation()){
            return;
        }

        $http = $this->http;
        $this->http = null;
        $http->each(
            function (HttpMockFacade $facade) {
                $this->assertSame(
                    '',
                    (string) $facade->server->getIncrementalErrorOutput(),
                    'HTTP mock server standard error output should be empty'
                );
            }
        );
    }

But I guess if there is another (better/proper) way to do this

php8 compatibility

According to dc87f31 http-mock is compatible with PHP8. It would be really cool to release a package which updates this constraint in order to be able to use http-mock on a CI running on this version of PHP8.
Is it something you could consider doing?

Breaks when doing composer update due to Silex 2.3

Hello,

I did a composer update recently which caused the version of Silex to update to 2.3. This resulted in my tests failing due to always returning 404 even though they always returned the correct body and X-Status-Code: 200.

Some debugging output from strace for a found match:

sendto(4, "HTTP/1.1 404 Not Found\r\nHost: localhost:8181\r\nDate: Wed, 02 May 2018 23:33:55 +0000\r\nConnection: close\r\nX-Powered-By: PHP/7.2.4\r\nSet-Cookie: XDEBUG_SESSION=10818; expires=Thu, 03-May-2018 00:33:55 GMT; Max-Age=3600; path=/\r\nCache-Control: no-cache, private\r\nDate: Wed, 02 May 2018 23:28:09 GMT\r\nX-Status-Code: 200\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n", 357, 0, NULL, 0) = 357

My temporary fix was to lock silex in composer to 2.2.2: "silex/silex": "2.2.2",

No post data in request

Library doesn't parse POST data in request body

I send request throw php curl and it accepts fine in nginx, nodejs but

$this->http->requests->latest()->getPostFields()

is empty.

Checking request query string?

Is there a way to check the query string of a request (particularly for GET requests)? I want to make sure a transformation in my request wrapper actually occurs when I make the request.

If this isn't yet possible, here's the API I would expect:

$this->http->mock
    ->when()
        ->methodIs("GET")
        ->pathIs("/my/test/path")
        ->queryIs("param1=test1&param2=test2")
    ->then()->body("{}")->statusCode(200)
    ->end();

or

$this->http->mock
    ->when()
        ->methodIs("GET")
        ->pathIs("/my/test/path")
        ->queryIs(array("param1" => "test1", "param2" => "test2"))
    ->then()->body("{}")->statusCode(200)
    ->end();

PS: Thank you for making this library. It's nice to be able to mock HTTP requests in my test suite.

Update http-mock to work with jeremeamia/SuperClosure v2

dependent lib jeremeamia/SuperClosure was updated to v2, and your code stopped to work(

PHP Fatal error: Class 'Jeremeamia\SuperClosure\SerializableClosure' not found in /work/www/tsw/vendor/internations/http-mock/src/InterNations/Component/HttpMock/Matcher/AbstractMatcher.php on line 32

Deprecation with Symfony/Process 4.2

DEPRECATION: Passing a command as string when creating a "Symfony\Component\Process\Process" instance is deprecated since Symfony 4.2, pass it as an array of its arguments instead, or use the "Process::fromShellCommandline()" constructor if you need features provided by the shell.

This is happening in src/Server.php line 25

        parent::__construct(
            sprintf(
                'exec php -dalways_populate_raw_post_data=-1 -derror_log= -S %s -t public/ %s',
                $this->getConnectionString(),
                $packagePath
            ),
            $packageRoot
        );

It should use the new array format, or Process::fromShellCommandline(

Problems running built-in server under PHP 7.1.21 on Fedora 27

I'm setting up a mock under the above PHP version, using PHPUnit 6.5.21, and have run into problems simply trying to get an empty test to run. I haven't hooked up any specific framework, beyond the bits that http-mock itself pulls in.

Here's the guts of my base test class:

<?php
namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;

abstract class TestCase extends BaseTestCase

    use HttpMockTrait;	
    public static function setUpBeforeClass()
    {
        static::setUpHttpMockBeforeClass(null, 'localhost');
    }

    public static function tearDownAfterClass()
    {
        static::tearDownHttpMockAfterClass();
    }
    public function setUp()
    {
        $this->setUpHttpMock();
        parent::setUp();
        $this->http->mock
            ->when()
                ->methodIs('POST')
            ->then()
                ->body('')
            ->end();
        $this->http->setUp();
    }
    public function tearDown()
    {
        $this->tearDownHttpMock();
        parent::tearDown();
    }
}

And the test in question

class baseTest extends TestCase {
    public function testSimpleRequest()
    {
        $request = $this->http->requests->latest();
    }
}

Test result:

1) ...\Tests\baseTest::testSimpleRequest
UnexpectedValueException: Expected status code 200 from "/_request/last", got 404

.../vendor/internations/http-mock/src/RequestCollectionFacade.php:158
.../vendor/internations/http-mock/src/RequestCollectionFacade.php:141
.../vendor/internations/http-mock/src/RequestCollectionFacade.php:27
.../tests/baseTest.php:18

I'm not sure what else I can trim out. Have I managed to do something dumb like leave out a "start the mock server" step? From a quick read through the getting started guide, it doesn't seem like that.

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.