Skip to content

Commit

Permalink
feat: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit382 committed May 1, 2024
1 parent 387d052 commit 1cc05fe
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"require-dev": {
"symfony/cache": "^6.1.3",
"phpunit/phpunit": "^9.5.21",
"phpunit/phpunit": "^10.5",
"phpstan/phpstan": "^1.8.2",
"phpstan/phpstan-phpunit": "^1.1.1",
"friendsofphp/php-cs-fixer": "^3.9.5"
Expand Down
2 changes: 2 additions & 0 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ private function getDefaultOptions(): array
if ($this->auth) {
$data['auth'] = array_values($this->auth);
}

return $data;
}

Expand All @@ -574,6 +575,7 @@ private function getDefaultOptions(): array
*/
private function getDefaultHeaders(): array
{
//Force the use of user agent on each http client no matter they come
return [
'User-Agent' => 'SDK PHP - ' . $this->userAgent,
];
Expand Down
3 changes: 1 addition & 2 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class Document
/**
* Initialization the document and specify from which API it was extract
* @param array $data the whole data
* @param string|null $api the api name
*/
public function __construct(array $data, string $api = null)
public function __construct(array $data)
{
$this->recursiveSortArray($data);
$this->data = $data;
Expand Down
2 changes: 1 addition & 1 deletion tests/FilesystemTrait.php → src/FilesystemTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

trait FilesystemTrait
{
public static function recursiveDeleteDirectory(string $dir): void
public function recursiveDeleteDirectory(string $dir): void
{
if (is_dir($dir)) {
$objects = scandir($dir) ?: [];
Expand Down
11 changes: 3 additions & 8 deletions tests/ApiFoodCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace OpenFoodFactsTests;

use GuzzleHttp;
use OpenFoodFacts\FilesystemTrait;
use OpenFoodFacts\Api;
use OpenFoodFacts\FilesystemTrait;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;

Expand All @@ -29,15 +29,10 @@ protected function setUp(): void
// "http_errors" => false, // MUST not use as it crashes error handling
'Connection' => 'close',
CURLOPT_FORBID_REUSE => true,
CURLOPT_FRESH_CONNECT => true,
'defaults' => [
'headers' => [
CURLOPT_USERAGENT => 'OFF - PHP - SDK - Unit Test',
],
],
CURLOPT_FRESH_CONNECT => true
]);

$api = new Api('SDK Unit test', 'food', 'fr-en', $this->log, $httpClient, $cache);
$api = new Api('Integration test', 'food', 'fr-en', $this->log, $httpClient, $cache);
$this->assertInstanceOf(Api::class, $api);
$this->api = $api;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ApiFoodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace OpenFoodFactsTests;

use OpenFoodFacts\FilesystemTrait;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use OpenFoodFacts\Api;
use OpenFoodFacts\Collection;
use OpenFoodFacts\Document\FoodDocument;
use OpenFoodFacts\Document;
use OpenFoodFacts\Exception\ProductNotFoundException;
use OpenFoodFacts\Document\FoodDocument;
use OpenFoodFacts\Exception\BadRequestException;
use OpenFoodFacts\Exception\ProductNotFoundException;
use OpenFoodFacts\FilesystemTrait;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

class ApiFoodTest extends TestCase
Expand All @@ -28,7 +28,7 @@ protected function setUp(): void
{
$this->log = $this->createMock(NullLogger::class);

$this->api = new Api('SDK Unit test', 'food', 'fr-en', $this->log);
$this->api = new Api('Integration test', 'food', 'fr-en', $this->log);
$testFolder = 'tests/tmp';
if (file_exists($testFolder)) {
rmdir($testFolder);
Expand Down
8 changes: 4 additions & 4 deletions tests/ApiPetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace OpenFoodFactsTests;

use OpenFoodFacts\FilesystemTrait;
use PHPUnit\Framework\TestCase;
use OpenFoodFacts\Api;
use OpenFoodFacts\Collection;
use OpenFoodFacts\Document\PetDocument;
use OpenFoodFacts\Document;
use OpenFoodFacts\Document\PetDocument;
use OpenFoodFacts\Exception\BadRequestException;
use OpenFoodFacts\FilesystemTrait;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

class ApiPetTest extends TestCase
Expand All @@ -19,7 +19,7 @@ class ApiPetTest extends TestCase

protected function setUp(): void
{
$this->api = new Api('SDK Unit test', 'pet', 'fr', $this->createMock(NullLogger::class));
$this->api = new Api('Integration test', 'pet', 'fr', $this->createMock(NullLogger::class));

foreach (glob('tests/images/*') ?: [] as $file) {
unlink($file);
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testUploadImageMustThrowAnExceptionForInvalidApi(): void
{
$this->expectException(BadRequestException::class);
$this->expectExceptionMessage('not Available yet');
$api = new Api('SDK Unit test', 'product');
$api = new Api('Integration test', 'product');
$api->uploadImage('unknown', 'foo', 'bar');
}
}

0 comments on commit 1cc05fe

Please sign in to comment.