Skip to content
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

remove some dependencies #275

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
"homepage": "https://github.com/mimmi20/ua-generic-request",
"require": {
"php": "^7.4.3 || ^8.0.0",
"ext-json": "*",
"ext-mbstring": "*",
"laminas/laminas-diactoros": "^2.8.0",
"psr/http-message": "^1.0.1"
},
"require-dev": {
"mimmi20/coding-standard": "^2.5.2",
"mimmi20/json-class": "^4.0.0",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^1.2.0",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpunit/phpunit": "^9.5.10",
"symfony/finder": "^5.4.0 || ^6.0.0"
"phpunit/phpunit": "^9.5.10"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
44 changes: 23 additions & 21 deletions tests/GenericRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@

namespace UaRequestTest;

use JsonClass\DecodeErrorException;
use JsonClass\Json;
use JsonException;
use Laminas\Diactoros\ServerRequestFactory;
use LogicException;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RegexIterator;
use RuntimeException;
use SebastianBergmann\RecursionContext\InvalidArgumentException;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use UaRequest\Constants;
use UaRequest\GenericRequest;
use UaRequest\GenericRequestFactory;
use UnexpectedValueException;

use function array_merge;
use function assert;
use function file_exists;
use function file_get_contents;
use function is_array;
use function is_string;
use function json_decode;

use const JSON_THROW_ON_ERROR;
use const PHP_EOL;

final class GenericRequestFactoryTest extends TestCase
Expand Down Expand Up @@ -174,7 +178,6 @@ public function testData(array $headers, string $expectedDeviceUa, string $expec
* @return array<array<array<string, string>|string>>
* @phpstan-return array<array{0: array<string, string>, 1: string, 2: string, 3: string, 4: string}>
*
* @throws LogicException
* @throws RuntimeException
*/
public function providerUa(): array
Expand All @@ -185,31 +188,30 @@ public function providerUa(): array
return [];
}

$finder = new Finder();
$finder->files();
$finder->name('*.json');
$finder->ignoreDotFiles(true);
$finder->ignoreVCS(true);
$finder->sortByName();
$finder->ignoreUnreadableDirs();
$finder->in($path);
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$files = new RegexIterator($iterator, '/^.+\.json$/i', RegexIterator::GET_MATCH);

$allData = [];

foreach ($finder as $file) {
/** @var SplFileInfo $file */
$content = $file->getContents();
foreach ($files as $file) {
assert(is_array($file));
$file = $file[0];

if ('' === $content || PHP_EOL === $content) {
assert(is_string($file));
$content = file_get_contents($file);

if (false === $content || '' === $content || PHP_EOL === $content) {
throw new UnexpectedValueException('empty content');
}

try {
$data = (new Json())->decode(
$data = json_decode(
$content,
true
true,
512,
JSON_THROW_ON_ERROR
);
} catch (DecodeErrorException $e) {
} catch (JsonException $e) {
throw new UnexpectedValueException('invalid content', 0, $e);
}

Expand Down