Skip to content

Commit 81259f3

Browse files
authored
Merge pull request #378 from Art4/behat
Migrate E2E tests to BDD with Behat
2 parents 6a4e464 + b4c3e7a commit 81259f3

28 files changed

+1420
-662
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/kbsali/php-redmine-api/compare/v2.5.0...v2.x)
99

10+
### Added
11+
12+
- New method `Redmine\Api\...::getLastResponse()` to get the last response made by the API class.
13+
1014
### Fixed
1115

1216
- Parameter types for IDs were fixed in API for attachments, groups, issues, project, users and versions.

composer.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
"psr/http-factory": "^1.0"
3030
},
3131
"require-dev": {
32+
"behat/behat": "^3.14",
3233
"friendsofphp/php-cs-fixer": "^3.45",
33-
"phpunit/phpunit": "^9 || ^10.5",
3434
"guzzlehttp/psr7": "^2",
3535
"php-mock/php-mock-phpunit": "^2.6",
36-
"phpstan/phpstan": "^1.10"
36+
"phpstan/phpstan": "^1.10",
37+
"phpunit/phpunit": "^9 || ^10.5"
3738
},
3839
"autoload": {
3940
"psr-4": {
@@ -45,10 +46,13 @@
4546
"Redmine\\Tests\\": "tests/"
4647
}
4748
},
49+
"config": {
50+
"sort-packages": true
51+
},
4852
"scripts": {
53+
"behat": "behat --config tests/Behat/behat.yml",
4954
"codestyle": "php-cs-fixer fix",
5055
"coverage": "phpunit --coverage-html=\".phpunit.cache/code-coverage\"",
51-
"end2end": "phpunit --configuration=\"phpunit-end2end.xml\"",
5256
"phpstan": "phpstan analyze --memory-limit 512M --configuration .phpstan.neon",
5357
"phpunit": "phpunit",
5458
"test": [

docker-compose.yml

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414

1515
redmine-dev:
1616
image: redmine:5.1.1
17+
user: "1000:1000"
1718
ports:
1819
- "3000:3000"
1920
environment:
@@ -27,6 +28,7 @@ services:
2728

2829
redmine-50101:
2930
image: redmine:5.1.1
31+
user: "1000:1000"
3032
ports:
3133
- "5101:3000"
3234
environment:
@@ -38,6 +40,7 @@ services:
3840

3941
redmine-50007:
4042
image: redmine:5.0.7
43+
user: "1000:1000"
4144
ports:
4245
- "5007:3000"
4346
environment:

phpunit-end2end.xml

-30
This file was deleted.

src/Redmine/Api/AbstractApi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ final protected function getHttpClient(): HttpClient
7272
return $this->httpClient;
7373
}
7474

75-
final protected function getLastResponse(): Response
75+
final public function getLastResponse(): Response
7676
{
7777
return $this->lastResponse !== null ? $this->lastResponse : HttpFactory::makeResponse(0, '', '');
7878
}

src/Redmine/Api/Project.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ protected function prepareParamsXml($params)
347347
{
348348
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.3.0, use `\Redmine\Serializer\XmlSerializer::createFromArray()` instead.', E_USER_DEPRECATED);
349349

350-
return new \SimpleXMLElement(
350+
return new SimpleXMLElement(
351351
XmlSerializer::createFromArray(['project' => $params])->getEncoded()
352352
);
353353
}

src/Redmine/Http/Response.php

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*
1010
* The method signatures are defined with the intention that an implementing class
1111
* can implment this interface and also the PSR-7 `\Psr\Http\Message\ResponseInterface`
12-
*
13-
* @internal
1412
*/
1513
interface Response
1614
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Redmine\Tests\Behat\Bootstrap;
6+
7+
use Behat\Behat\Tester\Exception\PendingException;
8+
use Behat\Gherkin\Node\TableNode;
9+
use Redmine\Api\Attachment;
10+
11+
trait AttachmentContextTrait
12+
{
13+
/**
14+
* @When I upload the content of the file :filepath with the following data
15+
*/
16+
public function iUploadTheContentOfTheFileWithTheFollowingData(string $filepath, TableNode $table)
17+
{
18+
$data = [];
19+
20+
foreach ($table as $row) {
21+
$data[$row['property']] = $row['value'];
22+
}
23+
24+
$filepath = str_replace('%tests_dir%', dirname(__FILE__, 3), $filepath);
25+
26+
/** @var Attachment */
27+
$api = $this->getNativeCurlClient()->getApi('attachment');
28+
29+
$this->registerClientResponse(
30+
$api->upload(file_get_contents($filepath), $data),
31+
$api->getLastResponse()
32+
);
33+
}
34+
35+
/**
36+
* @When I show the attachment with the id :attachmentId
37+
*/
38+
public function iShowTheAttachmentWithTheId(int $attachmentId)
39+
{
40+
/** @var Attachment */
41+
$api = $this->getNativeCurlClient()->getApi('attachment');
42+
43+
$this->registerClientResponse(
44+
$api->show($attachmentId),
45+
$api->getLastResponse()
46+
);
47+
}
48+
}

0 commit comments

Comments
 (0)