Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
54.17% covered (warning)
54.17%
13 / 24
33.33% covered (danger)
33.33%
3 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
UploadFileWebdavCall
54.17% covered (warning)
54.17%
13 / 24
33.33% covered (danger)
33.33%
3 / 9
22.65
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTestName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getExpectedStatusCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 bootstrap
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 isFakeDatalayer
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 shouldDoRequestValidation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 shouldDoResponseValidation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRequest
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 verifyValidResponse
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Apie\IntegrationTests\Requests;
4
5use Apie\Common\IntegrationTestLogger;
6use Apie\Core\BoundedContext\BoundedContextId;
7use Apie\Core\Entities\EntityInterface;
8use Apie\Core\Identifiers\SnakeCaseSlug;
9use Apie\Faker\Datalayers\FakerDatalayer;
10use Apie\IntegrationTests\Interfaces\TestApplicationInterface;
11use Nyholm\Psr7\ServerRequest;
12use PHPUnit\Framework\TestCase;
13use Psr\Http\Message\ResponseInterface;
14use Psr\Http\Message\ServerRequestInterface;
15
16class UploadFileWebdavCall implements WebdavTestRequestInterface, BootstrapRequestInterface
17{
18    private bool $faked = false;
19
20    /**
21     * @param array<int, EntityInterface> $entities
22     */
23    public function __construct(
24        private readonly BoundedContextId $boundedContextId,
25        private readonly array $entities = [],
26    ) {
27    }
28
29    public function getTestName(): SnakeCaseSlug
30    {
31        return new SnakeCaseSlug('upload_file_in_' . $this->boundedContextId);
32    }
33
34    public function getExpectedStatusCode(): int
35    {
36        return 403;
37    }
38
39    public function bootstrap(TestApplicationInterface $testApplication): void
40    {
41        $apieFacade = $testApplication->getServiceContainer()->get('apie');
42        foreach ($this->entities as $entity) {
43            $apieFacade->persistNew($entity, $this->boundedContextId);
44        }
45        $this->faked = $testApplication->getApplicationConfig()->getDatalayerImplementation()->name === FakerDatalayer::class;
46    }
47
48    public function isFakeDatalayer(): bool
49    {
50        return $this->faked;
51    }
52
53    public function shouldDoRequestValidation(): bool
54    {
55        return false;
56    }
57
58    public function shouldDoResponseValidation(): bool
59    {
60        return false;
61    }
62
63    public function getRequest(): ServerRequestInterface
64    {
65        return new ServerRequest(
66            'PUT',
67            'http://localhost/webdav/' . $this->boundedContextId . '/test.txt',
68            [
69                'Content-Type'  => 'application/octet-stream',
70            ],
71            'This is the content of the uploaded file.'
72        );
73    }
74
75    public function verifyValidResponse(ResponseInterface $response): void
76    {
77        $body = (string) $response->getBody();
78        $statusCode = $response->getStatusCode();
79        if ($statusCode === 500) {
80            IntegrationTestLogger::failTestShowError();
81        }
82        TestCase::assertEquals(200, $statusCode, 'Expect status code 200, got: ' . $body);
83        TestCase::assertEquals('application/json', $response->getHeaderLine('content-type'));
84    }
85}