Skip to content

Commit 0798c4e

Browse files
Merge pull request #141 from AlejandroPerez92/MINT-3699
Allow empty queries in GET requests
2 parents d44959d + e6b8b48 commit 0798c4e

6 files changed

Lines changed: 107 additions & 9 deletions

File tree

Components/WebService/Rest/RestConfigurableProducer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function request(ClientInterface $client, array $stepActionParams, arr
174174
}
175175
$restOptions['body'] = $requestBody;
176176

177-
if ('GET' == $httpMethod) {
177+
if ('GET' == $httpMethod && key_exists(self::REQUEST_QUERY_PARAMETERS, $params)) {
178178
$queryParameters = $this->confHelper->resolve($params[self::REQUEST_QUERY_PARAMETERS], $context);
179179
if (!$queryParameters) {
180180
throw new InvalidConfigurationException("'parameters' entry in 'request' configuration is mandatory for GET HTTP method");

Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
CURRENT_USER = $(shell id -u):$(shell id -g)
2+
USER_NAME = $(shell whoami)
3+
4+
DOCKER_COMPOSE = CURRENT_USER=$(CURRENT_USER) docker compose
5+
6+
EXEC_PHP = $(DOCKER_COMPOSE) exec php
7+
EXEC_SUDO_PHP = $(DOCKER_COMPOSE) exec -u root php
8+
9+
##
10+
## Project
11+
## -------
12+
##
13+
14+
build:
15+
$(DOCKER_COMPOSE) build --pull
16+
17+
kill:
18+
$(DOCKER_COMPOSE) kill
19+
$(DOCKER_COMPOSE) down --volumes --remove-orphans
20+
21+
install: ## Install and start the project
22+
install: build start useradd vendor
23+
24+
reset: ## Stop and start a fresh install of the project
25+
reset: kill install
26+
27+
docker-sync-start: #start docker sync
28+
docker-sync start
29+
30+
start: ## Start the project
31+
$(DOCKER_COMPOSE) up -d --remove-orphans --no-recreate
32+
33+
useradd: ## Add your host user to the container
34+
$(EXEC_SUDO_PHP) groupadd -f -g $(shell id -g) $(USER_NAME)
35+
$(EXEC_SUDO_PHP) useradd -u $(shell id -u) -g $(shell id -g) -m $(USER_NAME)
36+
37+
stop: ## Stop the project
38+
$(DOCKER_COMPOSE) stop
39+
40+
enter: ## Login into php docker
41+
$(EXEC_PHP) bash
42+
43+
clear-cache:
44+
$(EXEC_SUDO_PHP) bash -c 'rm -rf var/cache/*'
45+
46+
vendor:
47+
$(EXEC_PHP) composer install --prefer-dist
48+
49+
test:
50+
$(EXEC_PHP) php ./bin/phpunit

Tests/Functional/Producers/RestConfigurableProducerTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,49 @@ public function testCanOverrideBaseUrI($baseUri, $requestUri, $overrideBaseUri,
131131
$this->assertEquals($expectedHost, $request->getUri()->getHost());
132132
$this->assertEquals($expectedPath, $request->getUri()->getPath());
133133
}
134+
135+
public function testShouldAllowGetWithoutQuery()
136+
{
137+
$requestUri = 'v0/put/cats';
138+
$baseUri = 'http://someservice.com/api/';
139+
140+
$mockHandler = new MockHandler([
141+
new Response(200, ['X-Foo' => 'Bar']),
142+
]);
143+
144+
$container = [];
145+
$history = Middleware::history($container);
146+
$stack = HandlerStack::create($mockHandler);
147+
$stack->push($history);
148+
149+
$client = new Client(['handler' => $stack]);
150+
151+
$producer = $this->producer;
152+
$producer->setHttpClient($client);
153+
154+
$actionParams = [
155+
RestConfigurableProducer::REQUEST_NAME => 'someRequest',
156+
RestConfigurableProducer::REQUEST_HTTP_VERB => 'GET',
157+
RestConfigurableProducer::REQUEST_BODY => [],
158+
RestConfigurableProducer::REQUEST_URI => $requestUri,
159+
RestConfigurableProducer::DISPLAY_RESPONSE_ERROR => false,
160+
];
161+
162+
$options = [
163+
RestConfigurableProtocol::OPTION_BASE_URI => $baseUri,
164+
RestConfigurableProtocol::OPTION_ENCODING => RestConfigurableProtocol::ENCODING_JSON,
165+
ConfigurableWebserviceProtocol::OPTION_CONNECT_TIMEOUT => 10,
166+
ConfigurableWebserviceProtocol::OPTION_TIMEOUT => 10,
167+
RestConfigurableProtocol::OPTION_HEADERS => [],
168+
RestConfigurableProtocol::OPTION_AUTH => false,
169+
];
170+
$context = [
171+
'vars' => [],
172+
'msg' => new Message(new SerializableThing(), [], new Context()),
173+
'exchange' => new Exchange(),
174+
];
175+
176+
$response = $producer->executeStep(RestConfigurableProducer::STEP_REQUEST, $actionParams, $options, $context);
177+
$this->assertTrue($response, 'The producer should return true to say it has completed the Request Step');
178+
}
134179
}

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"stomp-php/stomp-php": "4.*",
3030
"symfony/monolog-bundle": "^2.4",
3131
"symfony/phpunit-bridge": "*",
32-
"symfony/stopwatch": "^2.8 || ^3.4"
32+
"symfony/stopwatch": "^2.8 || ^3.4",
33+
"phpunit/phpunit": "^7.5",
34+
"symfony/translation": "^4.3.8"
3335
},
3436
"config": {
3537
"bin-dir": "bin"

docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
version: '3'
2-
31
services:
42
php:
53
build: ./docker/php
64
working_dir: /app
5+
user: "${CURRENT_USER}"
76
volumes:
87
- .:/app
98
depends_on:
109
- rabbit
10+
environment:
11+
CURRENT_USER: '11:11'
1112

1213
rabbit:
1314
build: ./docker/rabbit
1415
environment:
1516
- RABBITMQ_DEFAULT_USER=guest
1617
- RABBITMQ_DEFAULT_PASS=guest
1718
ports:
18-
- "8081:15672"
19+
- "8082:15672"

docker/php/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM composer:1 AS composer
1+
FROM composer:lts AS composer
22

3-
FROM php:7.0-fpm
3+
FROM php:7.4-fpm
44

55
COPY --from=composer /usr/bin/composer /usr/bin/composer
66

@@ -15,9 +15,9 @@ RUN docker-php-ext-install \
1515
pcntl \
1616
sockets
1717

18-
RUN pecl install apcu-5.1.8 \
18+
RUN pecl install apcu-5.1.23 \
1919
mongodb \
20-
xdebug-2.7.2 #Latest version that supports PHP 7.0
20+
xdebug-3.1.6 #Latest version that supports PHP 7.4
2121

2222
RUN docker-php-ext-enable \
2323
apcu \

0 commit comments

Comments
 (0)