UploadTypeTest::testCanParseUploadedFileInstance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLTests\Upload;
6
7
use GraphQL\Error\Error;
8
use GraphQL\Error\InvariantViolation;
9
use GraphQL\Language\AST\StringValueNode;
10
use GraphQL\Upload\UploadType;
11
use GraphQLTests\Upload\Psr7\PsrUploadedFileStub;
12
use PHPUnit\Framework\TestCase;
13
use UnexpectedValueException;
14
15
final class UploadTypeTest extends TestCase
16
{
17
    public function testCanParseUploadedFileInstance(): void
18
    {
19
        $type = new UploadType();
20
        $file = new PsrUploadedFileStub('image.jpg', 'image/jpeg');
21
        $actual = $type->parseValue($file);
22
        self::assertSame($file, $actual);
23
    }
24
25
    public function testCannotParseNonUploadedFileInstance(): void
26
    {
27
        $type = new UploadType();
28
        $this->expectException(UnexpectedValueException::class);
29
        $this->expectExceptionMessage('Could not get uploaded file, be sure to conform to GraphQL multipart request specification. Instead got: "foo"');
30
31
        $type->parseValue('foo');
32
    }
33
34
    public function testCanNeverBeSerialized(): void
35
    {
36
        $type = new UploadType();
37
        $this->expectException(InvariantViolation::class);
38
        $this->expectExceptionMessage('`Upload` cannot be serialized');
39
40
        $type->serialize('foo');
41
    }
42
43
    public function testCanNeverParseLiteral(): void
44
    {
45
        $type = new UploadType();
46
        $node = new StringValueNode(['value' => 'foo']);
47
48
        $this->expectException(Error::class);
49
        $this->expectExceptionMessage('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification. Instead got: StringValue');
50
        $type->parseLiteral($node);
51
    }
52
}
53