Completed
Branch master (f63bf1)
by Adrien
01:47
created

UploadTypeTest::testCanNeverParseLiteral()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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