Skip to content

Commit

Permalink
Init ApiTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jan 16, 2025
1 parent 0bbb117 commit 095e9f1
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 43 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"symfony/css-selector": "^6.4 || ^7.1",
"symfony/dependency-injection": "^6.4 || ^7.1",
"symfony/dotenv": "^6.4 || ^7.1",
"symfony/http-client": "^6.4 || ^7.1",
"symfony/http-kernel": "^6.4 || ^7.1",
"symfony/messenger": "^6.4 || ^7.1",
"symfony/security-bundle": "^6.4 || ^7.1",
Expand Down Expand Up @@ -130,7 +131,8 @@
"Sylius\\Component\\Resource\\spec\\": "src/Component/legacy/spec/",
"Sylius\\Component\\Resource\\Tests\\": "src/Component/legacy/tests/",
"Sylius\\Resource\\Tests\\": "src/Component/tests/",
"App\\": "tests/Application/src/"
"App\\": "tests/Application/src/",
"Tests\\": "tests/"
}
},
"scripts": {
Expand Down
49 changes: 49 additions & 0 deletions tests/ApiTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests;

use Coduo\PHPMatcher\Backtrace\VoidBacktrace;
use Coduo\PHPMatcher\Factory\MatcherFactory;
use Coduo\PHPMatcher\Matcher;
use Coduo\PHPMatcher\PHPUnit\PHPMatcherAssertions;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

abstract class ApiTestCase extends WebTestCase
{
use PHPMatcherAssertions;

protected KernelBrowser $client;

protected Matcher $matcher;

protected function setUp(): void
{
$this->client = self::createClient();
$this->matcher = self::createMatcher();
}

protected static function createMatcher(): Matcher
{
return (new MatcherFactory())->createMatcher(new VoidBacktrace());
}

protected function assertResponseMatchesPattern(string $pattern): void
{
$response = $this->client->getResponse();
$content = $response->getContent();

self::assertMatchesPattern($pattern, $content);
}
}
Loading

0 comments on commit 095e9f1

Please sign in to comment.