Skip to content

Commit e3c6d8c

Browse files
committed
API-599: correct tests
1 parent c650a6d commit e3c6d8c

18 files changed

+128
-121
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ before_install:
1818
- composer self-update --no-interaction
1919

2020
install:
21+
- composer require php-http/guzzle6-adapter
2122
- composer install --prefer-dist --no-interaction
2223

2324
script:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ rm -rf composer.lock vendor/
139139
docker-compose run client_56 composer install
140140
docker-compose run client_56 bin/phpunit -c phpunit.xml.dist
141141
docker-compose run client_56 bin/phpspec run
142+
docker-compose run client_56 bin/php-cs-fixer fix --diff --dry-run --config=.php_cs.php
142143
```
143144

144145
## Support

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@
2727
"php-http/discovery": "^1.0",
2828
"php-http/message-factory": "^v1.0",
2929
"php-http/multipart-stream-builder": "^1.0",
30-
"php-http/client-implementation": "^1.0",
31-
"php-http/guzzle6-adapter": "^1.1"
30+
"php-http/client-implementation": "^1.0"
3231
},
3332
"require-dev": {
3433
"friendsofphp/php-cs-fixer": "^v2.3",
3534
"phpunit/phpunit": "5.7.*",
3635
"phpspec/phpspec": "3.2.*",
3736
"symfony/yaml": "^3.3",
38-
"donatj/mock-webserver": "^2.0",
39-
"php-http/guzzle6-adapter": "^1.1"
37+
"donatj/mock-webserver": "^2.0"
4038
},
4139
"config": {
4240
"bin-dir": "bin"

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
convertErrorsToExceptions="true"
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
10-
processIsolation="false"
10+
processIsolation="true"
1111
stopOnFailure="false"
1212
syntaxCheck="false">
1313

spec/Api/ProductMediaFileApiSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function it_creates_a_media_file($resourceClient, ResponseInterface $response)
133133
->willReturn($response);
134134

135135
$this->create($fileResource, $product)
136-
->shouldReturn($response);
136+
->shouldReturn('1/e/e/d/1eed10f108bde68b279d6f903f17b4b053e9d89d_akeneo.png');
137137
}
138138

139139
function it_throws_an_exception_if_the_file_is_unreadable_when_creating_a_media_file()

spec/Search/SearchBuilderSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ function it_builds_a_search_with_a_single_filter_without_options()
3131

3232
function it_builds_a_search_with_a_single_filter_without_value_nor_option()
3333
{
34-
$this->addFilter('family' , Operator::IS_EMPTY)->shouldReturn($this);
34+
$this->addFilter('family' , Operator::EMPTY)->shouldReturn($this);
3535

3636
$this->getFilters()->shouldReturn(
3737
[
3838
'family'=> [
3939
[
40-
'operator' => Operator::IS_EMPTY,
40+
'operator' => Operator::EMPTY,
4141
]
4242
]
4343
]

src/Api/MediaFileApiInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
88
use Akeneo\Pim\ApiClient\Exception\HttpException;
99
use Akeneo\Pim\ApiClient\Exception\RuntimeException;
10-
use GuzzleHttp\Psr7\Response;
1110

1211
/**
1312
* API to manage the media files.
@@ -30,7 +29,7 @@ interface MediaFileApiInterface extends
3029
* @throws HttpException If the request failed.
3130
* @throws RuntimeException If the file could not be opened.
3231
*
33-
* @return Response returns the code of created media file
32+
* @return string returns the code of created media file
3433
*/
3534
public function create($mediaFile, array $data);
3635
}

src/Api/ProductMediaFileApi.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,8 @@ public function create($mediaFile, array $productData)
9999
];
100100

101101
$response = $this->resourceClient->createMultipartResource(static::MEDIA_FILES_URI, [], $requestParts);
102-
$headers = $response->getHeaders();
103-
104-
if (!isset($headers['Location'][0])) {
105-
throw new RuntimeException('The response does not contain the URI of the created media-file.');
106-
}
107102

108-
$matches = [];
109-
if (1 !== preg_match(ProductMediaFileApi::MEDIA_FILE_URI_CODE_REGEX, $headers['Location'][0], $matches)) {
110-
throw new RuntimeException('Unable to find the code in the URI of the created media-file.');
111-
}
112-
113-
return $response;
103+
return $this->extractCodeFromCreationResponse($response);
114104
}
115105

116106
/**

src/Search/Operator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class Operator
2727
const GREATER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'GREATER OR EQUALS THAN ON ALL LOCALES';
2828
const LOWER_THAN_ON_ALL_LOCALES = 'LOWER THAN ON ALL LOCALES';
2929
const LOWER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'LOWER OR EQUALS THAN ON ALL LOCALES';
30-
const IS_EMPTY = 'EMPTY';
30+
const EMPTY = 'EMPTY';
3131
const NOT_EMPTY = 'NOT EMPTY';
3232
const BETWEEN = 'BETWEEN';
3333
const NOT_BETWEEN = 'NOT BETWEEN';

tests/Api/ApiTestCase.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use Akeneo\Pim\ApiClient\AkeneoPimClientBuilder;
66
use Akeneo\Pim\ApiClient\AkeneoPimClientInterface;
77
use Akeneo\Pim\ApiClient\Api\AuthenticationApi;
8-
use Akeneo\Pim\ApiClient\Api\ProductMediaFileApi;
9-
use Akeneo\Pim\ApiClient\Exception\RuntimeException;
108
use donatj\MockWebServer\MockWebServer;
119
use donatj\MockWebServer\Response;
1210
use donatj\MockWebServer\ResponseStack;
@@ -69,43 +67,4 @@ private function getAuthenticatedJson()
6967
}
7068
JSON;
7169
}
72-
73-
/**
74-
* Extracts the code of a media-file from a creation response.
75-
*
76-
* @param $response
77-
*
78-
* @throws RuntimeException if unable to extract the code
79-
*
80-
* @return mixed
81-
*/
82-
protected function extractCodeFromCreationResponse($response)
83-
{
84-
$headers = $response->getHeaders();
85-
86-
if (!isset($headers['Location'][0])) {
87-
throw new RuntimeException('The response does not contain the URI of the created media-file.');
88-
}
89-
90-
$matches = [];
91-
if (1 !== preg_match(ProductMediaFileApi::MEDIA_FILE_URI_CODE_REGEX, $headers['Location'][0], $matches)) {
92-
throw new RuntimeException('Unable to find the code in the URI of the created media-file.');
93-
}
94-
95-
return $matches['code'];
96-
}
97-
98-
/**
99-
* @param CursorInterface $result
100-
* @param array $expected
101-
*/
102-
protected function assertSameResults()
103-
{
104-
$products = [];
105-
foreach ($result as $product) {
106-
$products[] = $product->getIdentifier();
107-
}
108-
109-
$this->assertSame($products, $expected);
110-
}
11170
}

0 commit comments

Comments
 (0)