Skip to content

Migrate E2E tests to BDD with Behat #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
74cf91f
Install Behat
Art4 Feb 8, 2024
f741fbe
Add support for Behat in RedmineExtension
Art4 Feb 8, 2024
e091cbd
Create simple test to create a project
Art4 Feb 8, 2024
47db9ee
Add test for creating project with more data
Art4 Feb 9, 2024
87f9b56
Move redmine version from freature into config, allow testing of mult…
Art4 Feb 9, 2024
9d67fe8
Add test for properties of returned data
Art4 Feb 9, 2024
1ee77c3
Test returned data after creating project
Art4 Feb 9, 2024
fd74f2a
Add scenario to list projects
Art4 Feb 9, 2024
843983b
Add tests for listing empty projects list
Art4 Feb 13, 2024
dc8969c
Add methods to check property types of returned data
Art4 Feb 13, 2024
241f074
Allow checking properties based on redmine version
Art4 Feb 13, 2024
9bbabbf
Add scenatio updating a project
Art4 Feb 13, 2024
f311072
Add scenario to show a project
Art4 Feb 13, 2024
53d14cd
Add tests for properties showing a project
Art4 Feb 13, 2024
763ef6e
Add scenario to test closing and reopening a project
Art4 Feb 13, 2024
76f9a08
Add scenarios for archiving and unarchiving a project
Art4 Feb 13, 2024
712b140
Remove migrated e2e tests
Art4 Feb 13, 2024
a038aff
Add tests for returned data
Art4 Feb 13, 2024
1fea118
add scenario for creating a group
Art4 Feb 13, 2024
e29ec67
Set user for redmine services to 1000:1000
Art4 Feb 13, 2024
b0960c5
Refactor project tests
Art4 Feb 13, 2024
3443a03
Create tests for groups
Art4 Feb 13, 2024
ecec44a
Create tests for listing groups
Art4 Feb 13, 2024
2f5e733
Add tests for showing a group
Art4 Feb 13, 2024
8f844dd
Add tests to update a group
Art4 Feb 13, 2024
cd27c85
Fix phpstan and code style
Art4 Feb 13, 2024
90e1f25
remove e2e tests for groups
Art4 Feb 13, 2024
a1b7157
create tests for uploading files
Art4 Feb 13, 2024
c2232cd
Add tests showing attachment details
Art4 Feb 13, 2024
03a02fd
remove e2e tests for attachments
Art4 Feb 13, 2024
60abad0
Merge branch 'v2.x' into behat
Art4 Feb 14, 2024
f8b7c9d
sort packages in composer.json
Art4 Feb 14, 2024
f710eb2
Update CHANGELOG.md
Art4 Feb 14, 2024
23ef303
Remove internal mark from Response interface
Art4 Feb 14, 2024
f50d499
Add tests for wiki pages
Art4 Feb 14, 2024
e6cf9e4
Add scenario to show a wiki page
Art4 Feb 14, 2024
118902a
Add scenarios for uploading attachments to wiki pages
Art4 Feb 14, 2024
aa9da36
Add scenario to update wiki page
Art4 Feb 14, 2024
c8dff79
Add scenario for deleting a wiki page
Art4 Feb 14, 2024
dd34b7a
Remove e2e tests for wiki
Art4 Feb 14, 2024
b4c3e7a
Remove e2e tests
Art4 Feb 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

### Added

- New method `Redmine\Api\...::getLastResponse()` to get the last response made by the API class.

### Fixed

- Parameter types for IDs were fixed in API for attachments, groups, issues, project, users and versions.
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
"psr/http-factory": "^1.0"
},
"require-dev": {
"behat/behat": "^3.14",
"friendsofphp/php-cs-fixer": "^3.45",
"phpunit/phpunit": "^9 || ^10.5",
"guzzlehttp/psr7": "^2",
"php-mock/php-mock-phpunit": "^2.6",
"phpstan/phpstan": "^1.10"
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9 || ^10.5"
},
"autoload": {
"psr-4": {
Expand All @@ -45,10 +46,13 @@
"Redmine\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true
},
"scripts": {
"behat": "behat --config tests/Behat/behat.yml",
"codestyle": "php-cs-fixer fix",
"coverage": "phpunit --coverage-html=\".phpunit.cache/code-coverage\"",
"end2end": "phpunit --configuration=\"phpunit-end2end.xml\"",
"phpstan": "phpstan analyze --memory-limit 512M --configuration .phpstan.neon",
"phpunit": "phpunit",
"test": [
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:

redmine-dev:
image: redmine:5.1.1
user: "1000:1000"
ports:
- "3000:3000"
environment:
Expand All @@ -27,6 +28,7 @@ services:

redmine-50101:
image: redmine:5.1.1
user: "1000:1000"
ports:
- "5101:3000"
environment:
Expand All @@ -38,6 +40,7 @@ services:

redmine-50007:
image: redmine:5.0.7
user: "1000:1000"
ports:
- "5007:3000"
environment:
Expand Down
30 changes: 0 additions & 30 deletions phpunit-end2end.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/Redmine/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final protected function getHttpClient(): HttpClient
return $this->httpClient;
}

final protected function getLastResponse(): Response
final public function getLastResponse(): Response
{
return $this->lastResponse !== null ? $this->lastResponse : HttpFactory::makeResponse(0, '', '');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ protected function prepareParamsXml($params)
{
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.3.0, use `\Redmine\Serializer\XmlSerializer::createFromArray()` instead.', E_USER_DEPRECATED);

return new \SimpleXMLElement(
return new SimpleXMLElement(
XmlSerializer::createFromArray(['project' => $params])->getEncoded()
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Redmine/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*
* The method signatures are defined with the intention that an implementing class
* can implment this interface and also the PSR-7 `\Psr\Http\Message\ResponseInterface`
*
* @internal
*/
interface Response
{
Expand Down
48 changes: 48 additions & 0 deletions tests/Behat/Bootstrap/AttachmentContextTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Redmine\Tests\Behat\Bootstrap;

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\TableNode;
use Redmine\Api\Attachment;

trait AttachmentContextTrait
{
/**
* @When I upload the content of the file :filepath with the following data
*/
public function iUploadTheContentOfTheFileWithTheFollowingData(string $filepath, TableNode $table)
{
$data = [];

foreach ($table as $row) {
$data[$row['property']] = $row['value'];
}

$filepath = str_replace('%tests_dir%', dirname(__FILE__, 3), $filepath);

/** @var Attachment */
$api = $this->getNativeCurlClient()->getApi('attachment');

$this->registerClientResponse(
$api->upload(file_get_contents($filepath), $data),
$api->getLastResponse()
);
}

/**
* @When I show the attachment with the id :attachmentId
*/
public function iShowTheAttachmentWithTheId(int $attachmentId)
{
/** @var Attachment */
$api = $this->getNativeCurlClient()->getApi('attachment');

$this->registerClientResponse(
$api->show($attachmentId),
$api->getLastResponse()
);
}
}
Loading