Skip to content

Commit 625b293

Browse files
authored
Merge pull request #89 from ec-europa/EWPP-1908
EWPP-1908: Update to php8.
2 parents cef974c + 99dd10b commit 625b293

28 files changed

+216
-209
lines changed

.drone.yml

+28-10
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,58 @@ workspace:
44

55
services:
66
web:
7-
image: ${IMAGE_PHP=registry.fpfis.eu/fpfis/httpd-php:7.3-ci}
7+
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
88
environment:
9+
- COMPOSERVER=--2
910
- DOCUMENT_ROOT=/test/oe-poetry-client
1011

1112
pipeline:
1213
composer-install:
1314
group: prepare
14-
image: ${IMAGE_PHP=registry.fpfis.eu/fpfis/httpd-php:7.3-ci}
15+
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
1516
volumes:
1617
- /cache:/cache
1718
commands:
18-
- composer update ${COMPOSER_BOUNDARY}
19+
- composer self-update --2
20+
- composer install --ansi --no-progress
21+
when:
22+
matrix:
23+
COMPOSER_BOUNDARY: highest
24+
25+
composer-update-lowest:
26+
group: prepare
27+
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
28+
volumes:
29+
- /cache:/cache
30+
commands:
31+
- composer self-update --2
32+
- composer update --prefer-lowest --prefer-stable --ansi --no-progress
33+
when:
34+
matrix:
35+
COMPOSER_BOUNDARY: lowest
1936

2037
grumphp:
2138
group: test
22-
image: ${IMAGE_PHP=registry.fpfis.eu/fpfis/httpd-php:7.3-ci}
39+
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
2340
commands:
2441
- ./vendor/bin/grumphp run
2542

2643
phpunit:
2744
group: test
28-
image: ${IMAGE_PHP=registry.fpfis.eu/fpfis/httpd-php:7.3-ci}
45+
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
2946
commands:
3047
- ./vendor/bin/phpunit
3148

3249
phpspec:
3350
group: test
34-
image: ${IMAGE_PHP=registry.fpfis.eu/fpfis/httpd-php:7.3-ci}
51+
image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci
3552
commands:
3653
- ./vendor/bin/phpspec run
3754

3855
matrix:
39-
IMAGE_PHP:
40-
- registry.fpfis.eu/fpfis/httpd-php:7.3-ci
4156
COMPOSER_BOUNDARY:
42-
- '--prefer-lowest'
43-
- ''
57+
- lowest
58+
- highest
59+
PHP_VERSION:
60+
- 7.4
61+
- 8.0

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ phpunit.xml
44
composer.lock
55
.idea
66
log.txt
7-
docker-compose.yml
7+
.phpunit.result.cache

composer.json

+22-10
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@
22
"name": "ec-europa/oe-poetry-client",
33
"description": "Client library for the European Commission Poetry Service",
44
"type": "library",
5-
"minimum-stability": "stable",
5+
"minimum-stability": "dev",
66
"prefer-stable": true,
77
"license": "EUPL-1.2",
88
"require": {
99
"ext-soap": "*",
1010
"jeremeamia/superclosure": "~2.2",
1111
"league/plates": "^3.3.0",
12-
"php": ">=7.3",
12+
"php": ">=7.4",
1313
"pimple/pimple": "~3.2.3",
1414
"psr/log": "~1",
15-
"symfony/dom-crawler": "^3.4 || ^4.4",
15+
"symfony/dom-crawler": "^3.4 || ^4.4.12",
1616
"symfony/event-dispatcher": "^3.4 || ^4.4",
1717
"symfony/expression-language": "^3.4 || ^4.4",
1818
"symfony/validator": "^3.4 || ^4.4",
1919
"symfony/yaml": "^3.4 || ^4.4"
2020
},
2121
"require-dev": {
22-
"guzzle/guzzle": "~2.7 || ~3.0",
23-
"internations/http-mock": "~0.8",
24-
"mockery/mockery": "^0.9.9",
25-
"openeuropa/code-review": "~1.7",
26-
"peridot-php/leo": "~1.6",
27-
"phpspec/phpspec": "~4.0@alpha",
28-
"phpunit/phpunit": "~6.0"
22+
"internations/http-mock": "dev-php74#cd52a62136c98b1b66eca6edbd564a3a91f7e79c",
23+
"lstrojny/hmmmath": "^0.8",
24+
"mockery/mockery": "^1.5",
25+
"openeuropa/code-review": "^2.0",
26+
"phpspec/phpspec": "^7.0",
27+
"phpunit/phpunit": "^8.0"
2928
},
29+
"_readme": [
30+
"We need to lock internations/http-mock on dev branch with a stable commit since the component doesn't support php7.4 yet.",
31+
"We need to set symfony/dom-crawler as minimum 4.4.12 due to potential errors on higher php versions.",
32+
"We need to add dependency of lstrojny/hmmmath to guarantee correct compatiblity with lower versions."
33+
],
3034
"suggest": {
3135
"monolog/monolog": "Log Poetry requests and responses via Monolog",
3236
"ec-europa/oe-poetry-behat": "Test Poetry service integration with Behat"
@@ -41,5 +45,13 @@
4145
"EC\\Poetry\\Tests\\": "./tests/src/",
4246
"spec\\EC\\Poetry\\": "./spec/"
4347
}
48+
},
49+
"config": {
50+
"sort-packages": true,
51+
"allow-plugins": {
52+
"cweagans/composer-patches": true,
53+
"dealerdirect/phpcodesniffer-composer-installer": true,
54+
"phpro/grumphp": true
55+
}
4456
}
4557
}

docker-compose.yml.dist docker-compose.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
version: '2'
22
services:
33
web:
4-
image: fpfis/httpd-php-dev:7.1
4+
image: fpfis/httpd-php-dev:8.0
55
working_dir: /var/www/html
66
ports:
77
- 8080:8080
88
volumes:
99
- .:/var/www/html # Non Mac users.
1010
# - nfsmount:/var/www/html # Mac Users with the nfsmount volume.
1111
environment:
12-
XDEBUG_CONFIG: "remote_enable=1 remote_host=10.254.254.254 remote_port=9000 idekey=PHPSTORM remote_autostart=1"
12+
COMPOSERVER: "--2"
13+
XDEBUG_CONFIG: "client_host=172.17.0.1" # Non-Mac users.
14+
# XDEBUG_CONFIG: "client_host=host.docker.internal" # Mac users.
15+
XDEBUG_MODE: "develop, debug"
1316
PHP_IDE_CONFIG: "serverName=Docker"
14-
# For Xdebug setup, run this command in the terminal:
15-
# For Mac users: sudo ifconfig en0 alias 10.254.254.254 255.255.255.0
16-
# For Linux users: sudo ip addr add 10.254.254.254/32 dev lo label lo:1
17+
# Enable step debugging for all PHP request. See ./README.md#step-debugging for more information.
18+
# XDEBUG_SESSION: 1
1719

1820
#### Mac users: uncomment the "volumes" key to enable the NFS file sharing. You can find more information about Docker for Mac here: https://github.com/openeuropa/openeuropa/blob/master/docs/starting/tooling.md#using-docker-on-macos
1921

grumphp.yml.dist

+3
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ parameters:
88
tasks.phpmd.exclude:
99
- vendor/
1010
- src/Messages/Components/
11+
grumphp:
12+
git_hook_variables:
13+
EXEC_GRUMPHP_COMMAND: 'docker-compose exec -T web'

phpunit.xml.dist

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
convertWarningsToExceptions = "true"
99
processIsolation = "false"
1010
stopOnFailure = "false"
11-
syntaxCheck = "false"
1211
beStrictAboutTestsThatDoNotTestAnything = "false"
1312
bootstrap = "vendor/autoload.php">
1413
<testsuites>
15-
<testsuite>
14+
<testsuite name="unit">
1615
<directory>src/</directory>
1716
<directory>tests/</directory>
1817
</testsuite>

tests/src/AbstractHttpMockTest.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace EC\Poetry\Tests;
44

5-
use EC\Poetry\Poetry;
6-
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
7-
use Symfony\Component\HttpFoundation\Response;
5+
use InterNations\Component\HttpMock\PHPUnit\HttpMock;
86

97
/**
108
* Class AbstractHttpMockTest
@@ -13,40 +11,32 @@
1311
*/
1412
abstract class AbstractHttpMockTest extends AbstractTest
1513
{
16-
use HttpMockTrait;
14+
use HttpMock;
1715

1816
/**
1917
* {@inheritdoc}
2018
*/
21-
public static function setUpBeforeClass()
19+
public static function setUpBeforeClass(): void
2220
{
2321
static::setUpHttpMockBeforeClass('8082', 'localhost');
2422
}
2523

2624
/**
2725
* {@inheritdoc}
2826
*/
29-
public static function tearDownAfterClass()
27+
public static function tearDownAfterClass(): void
3028
{
3129
static::tearDownHttpMockAfterClass();
3230
}
3331

3432
/**
3533
* {@inheritdoc}
3634
*/
37-
public function setUp()
35+
public function setUp(): void
3836
{
3937
$this->setUpHttpMock();
4038
}
4139

42-
/**
43-
* {@inheritdoc}
44-
*/
45-
public function tearDown()
46-
{
47-
$this->tearDownHttpMock();
48-
}
49-
5040
/**
5141
* Setup notification endpoint.
5242
*/
@@ -82,6 +72,6 @@ protected function notifyServer($endpoint, $username, $password, $message)
8272
$wsdl = 'data://text/plain;base64,'.base64_encode($rendered);
8373
$client = new \SoapClient($wsdl, ['cache_wsdl' => WSDL_CACHE_NONE]);
8474

85-
return $client->__soapCall('handle', [$username, $password, $message]);
75+
return $client->handle($username, $password, $message);
8676
}
8777
}

tests/src/AbstractTest.php

+26-27
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Monolog\Formatter\JsonFormatter;
88
use Monolog\Handler\StreamHandler;
99
use Monolog\Logger;
10-
use Peridot\Leo\Leo;
1110
use PHPUnit\Framework\TestCase;
1211
use Symfony\Component\Validator\ConstraintViolationListInterface;
1312

@@ -23,31 +22,6 @@ abstract class AbstractTest extends TestCase
2322
*/
2423
protected $logFile = __DIR__.'/log.txt';
2524

26-
/**
27-
* {@inheritdoc}
28-
*/
29-
protected function setUp()
30-
{
31-
$assertion = Leo::assertion();
32-
$unit = $this;
33-
$assertion->addMethod('xml', function ($fixture) use ($unit) {
34-
$actual = $this->getActual();
35-
$expected = $unit->getFixture($fixture);
36-
37-
$doc1 = new \DOMDocument();
38-
$doc1->loadXML($actual);
39-
40-
$doc2 = new \DOMDocument();
41-
$doc2->loadXML($expected);
42-
43-
$element1 = $doc1->getElementsByTagName('POETRY')->item(0);
44-
$element2 = $doc2->getElementsByTagName('POETRY')->item(0);
45-
46-
$unit->assertXmlStringEqualsXmlString($expected, $actual);
47-
$unit->assertEqualXMLStructure($element1, $element2);
48-
});
49-
}
50-
5125
/**
5226
* @return \EC\Poetry\Poetry
5327
*/
@@ -153,8 +127,33 @@ protected function assertProperties($component, $properties)
153127
$this->assertProperties($component->$getProperty()[$i], $property);
154128
}
155129
} else {
156-
expect($component->$getProperty())->to->equal($value);
130+
$this->assertEquals($value, $component->$getProperty());
157131
}
158132
}
159133
}
134+
135+
/**
136+
* Assert given XML equals the one contained in given fixture file.
137+
*
138+
* @param $fixture
139+
* @param $actual
140+
*
141+
* @return void
142+
*/
143+
protected function assertXmlFromFixture($fixture, $actual)
144+
{
145+
$expected = $this->getFixture($fixture);
146+
147+
$doc1 = new \DOMDocument();
148+
$doc1->loadXML($actual);
149+
150+
$doc2 = new \DOMDocument();
151+
$doc2->loadXML($expected);
152+
153+
$element1 = $doc1->getElementsByTagName('POETRY')->item(0);
154+
$element2 = $doc2->getElementsByTagName('POETRY')->item(0);
155+
156+
$this->assertXmlStringEqualsXmlString($expected, $actual);
157+
$this->assertEqualXMLStructure($element1, $element2);
158+
}
160159
}

tests/src/ClientTest.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
namespace EC\Poetry\Tests;
44

5-
use EC\Poetry\Events\ParseNotificationEvent;
65
use EC\Poetry\Messages\Requests\CreateTranslationRequest;
7-
use EC\Poetry\Messages\Responses\Status;
86
use EC\Poetry\Poetry;
97
use EC\Poetry\Services\Settings;
10-
use EC\Poetry\Tests\Logger\TestLogger;
118
use Psr\Log\LogLevel;
129

1310
/**
@@ -43,7 +40,7 @@ public function testSend()
4340

4441
$response = $poetry->getClient()->send($request);
4542
$rendererResponse = $this->getContainer()->get('renderer')->render($response);
46-
expect($rendererResponse)->has->same->xml('messages/responses/response-status.xml');
43+
$this->assertXmlFromFixture('messages/responses/response-status.xml', $rendererResponse);
4744
}
4845

4946
/**
@@ -53,17 +50,17 @@ public function testWsdl()
5350
{
5451
$poetry = new Poetry();
5552
$actual = $poetry->getWsdl()->getXml();
56-
expect($actual)->to->contain('<soap:address location="" />');
53+
$this->assertStringContainsString('<soap:address location="" />', $actual);
5754

5855
$poetry = new Poetry([
5956
'notification.endpoint' => 'http://example.com/notification/endpoint',
6057
]);
6158
$actual = $poetry->getWsdl()->getXml();
62-
expect($actual)->to->contain('<soap:address location="http://example.com/notification/endpoint" />');
59+
$this->assertStringContainsString('<soap:address location="http://example.com/notification/endpoint" />', $actual);
6360

6461
$actual = $poetry->getWsdl()->getHeaders();
65-
expect($actual)->to->equal([
62+
$this->assertEquals([
6663
'content-type' => 'application/xml; utf-8',
67-
]);
64+
], $actual);
6865
}
6966
}

tests/src/Messages/Components/ContactTest.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ public function testValidation()
2424
$contact->setAction('action');
2525
$contact->setEmail('email');
2626

27-
2827
$violations = $validator->validate($contact);
29-
expect($violations->count())->to->be->above(0);
28+
$this->assertGreaterThan(0, $violations->count());
3029
$expected = [
3130
'type' => "The value you selected is not a valid choice.",
3231
'action' => "The value you selected is not a valid choice.",
3332
'nickname' => "This value should not be blank.",
3433
'email' => "This value is not a valid email address.",
3534
];
3635
foreach ($this->getViolations($violations) as $name => $violation) {
37-
expect($violation)->to->be->equal($expected[$name]);
36+
$this->assertEquals($expected[$name], $violation);
3837
}
3938
}
4039

@@ -53,9 +52,9 @@ public function testParsing($xml, $type, $nickname, $email)
5352
/** @var \EC\Poetry\Messages\Components\Contact $component */
5453
$component = $this->getContainer()->get('component.contact')->fromXml($xml);
5554

56-
expect($component->getType())->to->equal($type);
57-
expect($component->getNickname())->to->equal($nickname);
58-
expect($component->getEmail())->to->equal($email);
55+
$this->assertEquals($type, $component->getType());
56+
$this->assertEquals($nickname, $component->getNickname());
57+
$this->assertEquals($email, $component->getEmail());
5958
}
6059

6160
/**

0 commit comments

Comments
 (0)