Skip to content

Commit 88c8ca1

Browse files
committed
test
1 parent 4902f48 commit 88c8ca1

File tree

10 files changed

+280
-121
lines changed

10 files changed

+280
-121
lines changed

api/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
},
4848
"require-dev": {
4949
"friendsofphp/php-cs-fixer": "^3.17",
50-
"phpunit/phpunit": "^12.1.4"
50+
"phpunit/phpunit": "^12.1.4",
51+
"symfony/browser-kit": "^6.3",
52+
"symfony/http-client": "^6.3"
5153
},
5254
"config": {
5355
"optimize-autoloader": true,

api/composer.lock

Lines changed: 175 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/config/packages/doctrine.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ doctrine:
1414
dir: '%kernel.project_dir%/src/Entity'
1515
prefix: 'App\Entity'
1616
alias: App
17+
18+
when@test:
19+
doctrine:
20+
dbal:
21+
driver: 'sqlite'
22+
url: '%env(resolve:DATABASE_URL)%'

api/config/packages/messenger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ when@test:
3535
framework:
3636
messenger:
3737
transports:
38-
async: 'test://'
38+
async: 'in-memory://'

api/src/Api/Processor/ArchiveInputProcessor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Bundle\SecurityBundle\Security;
1515
use ApiPlatform\Validator\ValidatorInterface;
1616
use ApiPlatform\Serializer\AbstractItemNormalizer;
17-
use Alchemy\Zippy\Archive\Archive as ArchiveArchive;
1817
use Symfony\Component\Messenger\MessageBusInterface;
1918
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
2019

api/tests/AbstractZippyTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected function getTestDataSetDir(): string
1616

1717
protected function getArchiveDir(): string
1818
{
19-
return self::$container->getParameter('app.archive_dir');
19+
return self::getContainer()->getParameter('app.archive_dir');
2020
}
2121

2222
protected function removeArchive(string $id): void
@@ -45,7 +45,7 @@ protected function expectedFiles(array $files, Archive $archive): void
4545
'uri' => $f->getUri(),
4646
'path' => $f->getPath(),
4747
];
48-
}, $archive->getFiles()->getValues()));
48+
}, $archive->getFiles()->toArray()));
4949
}
5050

5151
protected function createArchive(array $options = []): Archive

api/tests/ApiTestCase.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace App\Tests;
66

77
use Doctrine\ORM\EntityManagerInterface;
8-
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9-
use Symfony\Component\BrowserKit\AbstractBrowser;
10-
use Symfony\Component\HttpFoundation\Response;
8+
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase as TestCase;
9+
use ApiPlatform\Symfony\Bundle\Test\Client;
10+
use Symfony\Contracts\HttpClient\ResponseInterface;
1111

12-
abstract class ApiTestCase extends WebTestCase
12+
abstract class ApiTestCase extends TestCase
1313
{
14-
protected ?AbstractBrowser $client = null;
14+
15+
protected ?Client $client;
1516

1617
protected function request(
1718
string $method,
@@ -20,29 +21,28 @@ protected function request(
2021
array $files = [],
2122
array $server = [],
2223
?string $content = null
23-
): Response {
24-
$server['CONTENT_TYPE'] = $server['CONTENT_TYPE'] ?? 'application/json';
25-
$server['HTTP_ACCEPT'] = $server['HTTP_ACCEPT'] ?? 'application/json';
26-
$server['HTTP_AUTHORIZATION'] = 'client:secret';
27-
24+
): ResponseInterface {
25+
2826
if (empty($content) && !empty($params) && in_array($method, ['POST', 'PUT', 'DELETE', 'PATCH'], true)) {
2927
$content = json_encode($params);
3028
}
3129

32-
$this->client->request($method, $uri, $params, $files, $server, $content);
30+
$headers['Authorization'] = 'client:secret';
31+
$headers['Content-Type'] = $server['CONTENT_TYPE'] ?? 'application/json';
3332

34-
/** @var Response $response */
35-
$response = $this->client->getResponse();
36-
37-
return $response;
33+
return $this->client->request($method, $uri, [
34+
'headers' => $headers,
35+
'json' => $params
36+
]);
3837
}
3938

4039
protected function setUp(): void
4140
{
42-
if (!static::$booted) {
43-
$this->client = static::createClient();
44-
$this->client->disableReboot();
45-
}
41+
parent::setUp();
42+
43+
$this->client = static::createClient();
44+
// $this->client->disableReboot();
45+
4646
}
4747

4848
protected function tearDown(): void

0 commit comments

Comments
 (0)