Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
61.54% covered (warning)
61.54%
16 / 26
44.44% covered (danger)
44.44%
4 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
ListFilesWebdavCall
61.54% covered (warning)
61.54%
16 / 26
44.44% covered (danger)
44.44%
4 / 9
20.19
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%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 bootstrap
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 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%
7 / 7
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
 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 ListFilesWebdavCall 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 int $depth = 1,
26        private readonly string $pathSuffix = '',
27        private readonly array $entities = [],
28    ) {
29    }
30
31    public function getTestName(): SnakeCaseSlug
32    {
33        return new SnakeCaseSlug(
34            'list_files_in_' . $this->boundedContextId . '_with_depth_' . $this->depth . '_' . count($this->entities) . ($this->pathSuffix ? ('_' . md5($this->pathSuffix)) : '')
35        );
36    }
37
38    public function bootstrap(TestApplicationInterface $testApplication): void
39    {
40        $apieFacade = $testApplication->getServiceContainer()->get('apie');
41        foreach ($this->entities as $entity) {
42            $apieFacade->persistNew($entity, $this->boundedContextId);
43            usleep(1); // Ensure different timestamps
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            'PROPFIND',
67            'http://localhost/webdav/' . $this->boundedContextId . $this->pathSuffix,
68            [
69                'depth' => $this->depth,
70            ]
71        );
72    }
73
74    public function getExpectedStatusCode(): int
75    {
76        return 207;
77    }
78
79    public function verifyValidResponse(ResponseInterface $response): void
80    {
81        $body = (string) $response->getBody();
82        $statusCode = $response->getStatusCode();
83        if ($statusCode === 500) {
84            IntegrationTestLogger::failTestShowError();
85        }
86        TestCase::assertEquals(200, $statusCode, 'Expect status code 200, got: ' . $body);
87        TestCase::assertEquals('application/json', $response->getHeaderLine('content-type'));
88    }
89}