Skip to content

Commit

Permalink
Merge pull request #14 from oleksandr-gribiennikov-paysera/EC-966
Browse files Browse the repository at this point in the history
EC-966: set default value for the $message
  • Loading branch information
alexanderzaiets-paysera authored Nov 15, 2023
2 parents 7e9d0f1 + 4445858 commit 2466525
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .dist.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BASE_CONTAINER='<paysera internal container name>'
APACHE_RUN_USER=
APACHE_RUN_GROUP=
1 change: 1 addition & 0 deletions .docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
supervisor.conf
27 changes: 27 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG BASE_CONTAINER
FROM ${BASE_CONTAINER}

ARG BASE_CONTAINER
ENV BASE_CONTAINER ${BASE_CONTAINER}

ARG APACHE_RUN_USER
ENV APACHE_RUN_USER ${APACHE_RUN_USER}

ARG APACHE_RUN_GROUP
ENV APACHE_RUN_GROUP ${APACHE_RUN_GROUP}

RUN apt update \
&& apt install -y mc

RUN composer self-update --2

RUN php=$(echo "${BASE_CONTAINER}" | sed -nE 's/.*php-([0-9]+\.[0-9]+).*/\1/p') \
&& echo "xdebug.mode=develop,debug,coverage" >> /etc/php/${php}/mods-available/xdebug.ini

RUN sed -iE "s/^export APACHE_RUN_USER=.*$/export APACHE_RUN_USER=${APACHE_RUN_USER}/g" /etc/apache2/envvars \
&& sed -iE "s/^export APACHE_RUN_GROUP=.*$/export APACHE_RUN_GROUP=${APACHE_RUN_GROUP}/g" /etc/apache2/envvars

RUN phpenmod xdebug

RUN usermod -a -G 1000 www-data
RUN usermod -a -G 1000 mysql
26 changes: 26 additions & 0 deletions .docker/supervisor.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[supervisord]
nodaemon=true
[program:apache2]
command = /usr/sbin/apache2ctl -DFOREGROUND
user = root
autostart = false
stdout_events_enabled = true
stderr_events_enabled = true
[program:php-fpm]
command = /usr/sbin/php-fpm7.4 --nodaemonize
user = root
autostart = true
stdout_events_enabled = true
stderr_events_enabled = true
[program:redis]
command = /usr/bin/redis-server
user = root
autostart = false
stdout_events_enabled = true
stderr_events_enabled = true
[program:mysql]
command = /bin/bash -c "service mysql start && sleep 100"
user = root
autostart = false
stdout_events_enabled = true
stderr_events_enabled = true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ composer.lock
vendor/
bin/
.arcconfig
.phpunit.result.cache
dump.rdb

coverage/

.env
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 2.7.0
### Changed
- Minimal version of PHP is increased to `7.4`.

### Fixed
- Deprecation error in the RequestException class (occurs in PHP 8+ only) was fixed

### Development tools
- PHPUnit version is narrowed to `^9.0`.
- Docker wrapper added

## 2.6.2
### Fixed
- Fixed some deprecation warning temporarily for PHP 8.1.
Expand Down
27 changes: 27 additions & 0 deletions LOCAL_DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Local deployment for development and/or running tests

1. Run:
- cp .docker/supervisor.conf.dist .docker/supervisor.conf
- cp .dist.env .env

Set environment values inside the `.env`.\
Also configure `supervisor`'s options if you need. By default no services autostart but that's enough to run tests.
\
Then:
- docker-compose build
- docker-compose up -d --remove-orphans

2. Check:
- docker ps | grep lib-rest-client-common\
You should see an output similar to this:\
`
1a7b71f2d8f9 lib-rest-client-common-lib "/usr/bin/supervisord" 21 minutes ago Up 21 minutes rest-client-common
`
3. Enter the container:\
`docker exec -it lib-rest-client-common bash`\
and run inside:\
`composer i`

5. Run tests:\
`bin/phpunit`
6. Enjoy your work!
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "paysera/lib-rest-client-common",
"version": "2.7.0",
"description": "Base classes/helpers used in REST Clients",
"autoload": {
"psr-4": {
Expand All @@ -12,17 +13,25 @@
}
},
"require": {
"php": ">=5.5",
"php": ">=7.4",
"psr/http-message": "^1.0",
"guzzlehttp/guzzle": "^6.0 | ^7.0",
"fig/http-message-util": "^1.0",
"guzzlehttp/psr7": "^1.4|^2.0"
"guzzlehttp/psr7": "^1.4|^2.0",
"ext-json": "*"
},
"minimum-stability": "stable",
"require-dev": {
"phpunit/phpunit": "^4.8|^9.0|^10.0"
"phpunit/phpunit": "^9.0"
},
"config": {
"bin-dir": "bin"
},
"archive": {
"exclude": [
".docker",
"docker-compose.yml",
"LOCAL_DEPLOYMENT.md"
]
}
}
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'

services:
lib:
container_name: rest-client-common
build:
context: .
dockerfile: .docker/Dockerfile
args:
- BASE_CONTAINER=${BASE_CONTAINER}
- APACHE_RUN_USER=${APACHE_RUN_USER}
- APACHE_RUN_GROUP=${APACHE_RUN_GROUP}
volumes:
- ./:/home/app/src
- ./.docker/supervisor.conf:/etc/supervisor/conf.d/supervisor.conf
extra_hosts:
- host.docker.internal:host-gateway
26 changes: 15 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "vendor/autoload.php">

backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
convertDeprecationsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
bootstrap = "vendor/autoload.php">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Library test suite">
<directory>tests</directory>
Expand Down
1 change: 1 addition & 0 deletions src/Exception/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
ResponseInterface $response,
Exception $previous = null
) {
$message = ($message === null ? '' : $message);
parent::__construct($message, 0, $previous);

$this->request = $request;
Expand Down
18 changes: 14 additions & 4 deletions tests/AuthenticationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Fig\Http\Message\StatusCodeInterface;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
use Paysera\Component\RestClientCommon\Exception\ClientException;
use Paysera\Component\RestClientCommon\Middleware\Authentication\BasicAuthentication;
use Paysera\Component\RestClientCommon\Middleware\Authentication\OAuthAuthentication;
use Paysera\Component\RestClientCommon\Tests\Client\TestClientFactory;
Expand Down Expand Up @@ -112,9 +113,6 @@ public function testBasicAuthenticationAdded()
$this->assertSame('Basic ' . base64_encode(sprintf('%s:%s', $username, $password)), $auth);
}

/**
* @expectedException \Paysera\Component\RestClientCommon\Exception\ClientException
*/
public function testUnauthorizedResponse()
{
TestClientFactory::setHandler(
Expand All @@ -125,6 +123,18 @@ public function testUnauthorizedResponse()

$factory = new TestClientFactory([]);
$client = $factory->getTestClient();
$client->getSomething();

try {
$client->getSomething();
} catch (ClientException $exception) {
$this->assertNull($exception->getError());

$this->assertEquals(
"",
$exception->getResponse()->getBody()->getContents()
);

$this->assertEquals(401, $exception->getResponse()->getStatusCode());
}
}
}
2 changes: 2 additions & 0 deletions tests/Client/TestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Fig\Http\Message\RequestMethodInterface;
use Paysera\Component\RestClientCommon\Client\ApiClient;
use Paysera\Component\RestClientCommon\Exception\ClientException;

class TestClient
{
Expand All @@ -20,6 +21,7 @@ public function withOptions(array $options)
}

/**
* @throws ClientException
* @return null
*/
public function getSomething()
Expand Down
4 changes: 2 additions & 2 deletions tests/ClientExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ClientExceptionTest extends TestCase
{
private $config;

public function setUp()
public function setUp(): void
{
$this->config = [
OAuthAuthentication::TYPE => [
Expand Down Expand Up @@ -103,7 +103,7 @@ public function testExceptionResponseWhenStreaming()
$factory = new TestClientFactory($this->config);
$client = $factory->getTestClient();

$this->setExpectedException(ClientException::class);
$this->expectException(ClientException::class);

$client->getSomething();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ClientWithOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testExceptionThrownWhenMissingUrlPlaceholders()
])
);

$this->setExpectedException(ConfigurationException::class);
$this->expectException(ConfigurationException::class);
new TestClientFactoryWithBaseUrlParams([]);
}

Expand Down
37 changes: 37 additions & 0 deletions tests/Exception/RequestExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Paysera\Component\RestClientCommon\Tests\Exception;

use GuzzleHttp\Psr7\Response;
use Paysera\Component\RestClientCommon\Exception\RequestException;
use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;

class RequestExceptionTest extends TestCase
{

public function test__construct()
{
$requestMock = $this->createMock(RequestInterface::class);
$responseMock = new Response(200, [], 'some body');

$errorReporting = error_reporting();

error_reporting(-1);

try {
RequestException::create($requestMock, $responseMock);

$this->assertTrue(true);
} catch (Deprecated $exception) {
$this->assertEquals(
'Exception::__construct(): Passing null to parameter #1 ($message) of type string is deprecated',
$exception->getMessage()
);
$this->fail($exception->getMessage());
} finally {
error_reporting($errorReporting);
}
}
}

0 comments on commit 2466525

Please sign in to comment.