Skip to content

Commit

Permalink
Bumped dependencies, removed nette/utils dep
Browse files Browse the repository at this point in the history
  • Loading branch information
peldax committed Nov 10, 2023
1 parent 4327c2a commit 4249b45
Show file tree
Hide file tree
Showing 7 changed files with 691 additions and 1,031 deletions.
17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "infinityloop-dev/graphpinator-upload",
"description": "Module to handle multipart formdata requests.",
"homepage": "https://www.infinityloop.dev/",
"homepage": "https://github.com/graphpql/",
"type": "library",
"license": ["MIT"],
"authors": [
Expand All @@ -12,16 +12,15 @@
}
],
"require": {
"php": ">=8.0.1",
"infinityloop-dev/graphpinator": "^1.1",
"infinityloop-dev/utils": "^2.1.2",
"nette/utils": "^3.2",
"psr/http-message": "^1.0.1"
"php": ">=8.1",
"infinityloop-dev/graphpinator": "^1.6",
"infinityloop-dev/utils": "^2.3",
"psr/http-message": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"infection/infection": "^0.26",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^10.4",
"infection/infection": "^0.27",
"phpstan/phpstan": "^1.10",
"infinityloop-dev/coding-standard": "^0.2"
},
"scripts": {
Expand Down
1,626 changes: 644 additions & 982 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<clover outputFile="./build/phpunit.clover.xml"/>
<html outputDirectory="./build/html" lowUpperBound="70" highLowerBound="100"/>
Expand All @@ -18,4 +15,9 @@
<logging>
<junit outputFile="./build/logfile.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/FileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface FileProvider
{
public function getMap() : ?\Infinityloop\Utils\Json\MapJson;
public function getMap() : ?\Infinityloop\Utils\Json;

public function getFile(string $key) : \Psr\Http\Message\UploadedFileInterface;
}
9 changes: 4 additions & 5 deletions src/UploadModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

final class UploadModule implements \Graphpinator\Module\Module
{
use \Nette\SmartObject;

public function __construct(
private FileProvider $fileProvider,
)
Expand All @@ -17,10 +15,11 @@ public function __construct(
public function processRequest(\Graphpinator\Request\Request $request) : \Graphpinator\Request\Request
{
$variables = $request->getVariables();
$map = $this->fileProvider->getMap()
?? \Infinityloop\Utils\Json::fromNative([]);

foreach ($this->fileProvider->getMap()
?? [] as $fileKey => $locations) {
$fileValue = $this->fileProvider->getFile($fileKey);
foreach ($map as $fileKey => $locations) {
$fileValue = $this->fileProvider->getFile((string) $fileKey);

foreach ($locations as $location) {
/**
Expand Down
2 changes: 0 additions & 2 deletions tests/TestSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

final class TestSchema
{
use \Nette\StaticClass;

private static array $types = [];
private static ?\Graphpinator\Typesystem\Container $container = null;

Expand Down
54 changes: 27 additions & 27 deletions tests/UploadModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class UploadModuleTest extends \PHPUnit\Framework\TestCase
{
public function simpleDataProvider() : array
public static function simpleDataProvider() : array
{
return [
[
Expand Down Expand Up @@ -117,31 +117,7 @@ public function simpleDataProvider() : array
];
}

/**
* @dataProvider simpleDataProvider
* @param string $map
* @param \Infinityloop\Utils\Json $request
* @param \Infinityloop\Utils\Json $expected
*/
public function testSimple(string $map, Json $request, Json $expected) : void
{
$stream = $this->createStub(\Psr\Http\Message\StreamInterface::class);
$stream->method('getContents')->willReturn('test file');
$file = $this->createStub(\Psr\Http\Message\UploadedFileInterface::class);
$file->method('getClientFilename')->willReturn('a.txt');
$file->method('getStream')->willReturn($stream);
$fileProvider = $this->createStub(\Graphpinator\Upload\FileProvider::class);
$fileProvider->method('getMap')->willReturn(Json\MapJson::fromString($map));
$fileProvider->method('getFile')->willReturn($file);
$graphpinator = new \Graphpinator\Graphpinator(TestSchema::getSchema(), false, new \Graphpinator\Module\ModuleSet([
new \Graphpinator\Upload\UploadModule($fileProvider),
]));
$result = $graphpinator->run(new \Graphpinator\Request\JsonRequestFactory($request));

self::assertSame($expected->toString(), $result->toString());
}

public function invalidDataProvider() : array
public static function invalidDataProvider() : array
{
return [
[
Expand Down Expand Up @@ -235,6 +211,30 @@ public function invalidDataProvider() : array
];
}

/**
* @dataProvider simpleDataProvider
* @param string $map
* @param \Infinityloop\Utils\Json $request
* @param \Infinityloop\Utils\Json $expected
*/
public function testSimple(string $map, Json $request, Json $expected) : void
{
$stream = $this->createStub(\Psr\Http\Message\StreamInterface::class);
$stream->method('getContents')->willReturn('test file');
$file = $this->createStub(\Psr\Http\Message\UploadedFileInterface::class);
$file->method('getClientFilename')->willReturn('a.txt');
$file->method('getStream')->willReturn($stream);
$fileProvider = $this->createStub(\Graphpinator\Upload\FileProvider::class);
$fileProvider->method('getMap')->willReturn(Json::fromString($map));
$fileProvider->method('getFile')->willReturn($file);
$graphpinator = new \Graphpinator\Graphpinator(TestSchema::getSchema(), false, new \Graphpinator\Module\ModuleSet([
new \Graphpinator\Upload\UploadModule($fileProvider),
]));
$result = $graphpinator->run(new \Graphpinator\Request\JsonRequestFactory($request));

self::assertSame($expected->toString(), $result->toString());
}

/**
* @dataProvider invalidDataProvider
* @param string $map
Expand All @@ -253,7 +253,7 @@ public function testInvalid(string $map, Json $request, string $exception, ?stri
$file->method('getClientFilename')->willReturn('a.txt');
$file->method('getStream')->willReturn($stream);
$fileProvider = $this->createStub(\Graphpinator\Upload\FileProvider::class);
$fileProvider->method('getMap')->willReturn(Json\MapJson::fromString($map));
$fileProvider->method('getMap')->willReturn(Json::fromString($map));
$fileProvider->method('getFile')->willReturn($file);
$graphpinator = new \Graphpinator\Graphpinator(TestSchema::getSchema(), false, new \Graphpinator\Module\ModuleSet([
new \Graphpinator\Upload\UploadModule($fileProvider),
Expand Down

0 comments on commit 4249b45

Please sign in to comment.