chore: Add Behat and PHP Unit dependencies
This commit is contained in:
parent
3aaad5274f
commit
8a3068419e
8
.env
8
.env
@ -20,11 +20,5 @@ APP_SECRET=ff44e0bb0862dabdb2d0a1ba40f489d9
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> doctrine/doctrine-bundle ###
|
||||
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
|
||||
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
|
||||
#
|
||||
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||
DATABASE_URL="mysql://iteo:iteo@mariadb:3306/iteo?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
6
.env.test
Normal file
6
.env.test
Normal file
@ -0,0 +1,6 @@
|
||||
# define your env variables for the test env here
|
||||
KERNEL_CLASS='App\Kernel'
|
||||
APP_SECRET='$ecretf0rt3st'
|
||||
SYMFONY_DEPRECATIONS_HELPER=999999
|
||||
PANTHER_APP_ENV=panther
|
||||
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
|
14
.gitignore
vendored
14
.gitignore
vendored
@ -8,3 +8,17 @@
|
||||
/var/
|
||||
/vendor/
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> friends-of-behat/symfony-extension ###
|
||||
/behat.yml
|
||||
###< friends-of-behat/symfony-extension ###
|
||||
|
||||
###> symfony/phpunit-bridge ###
|
||||
.phpunit.result.cache
|
||||
/phpunit.xml
|
||||
###< symfony/phpunit-bridge ###
|
||||
|
||||
###> phpunit/phpunit ###
|
||||
/phpunit.xml
|
||||
.phpunit.result.cache
|
||||
###< phpunit/phpunit ###
|
||||
|
12
behat.yml.dist
Normal file
12
behat.yml.dist
Normal file
@ -0,0 +1,12 @@
|
||||
default:
|
||||
suites:
|
||||
default:
|
||||
contexts:
|
||||
- App\Tests\Behat\ApiCallContext
|
||||
|
||||
extensions:
|
||||
FriendsOfBehat\SymfonyExtension:
|
||||
bootstrap: tests/bootstrap.php
|
||||
kernel:
|
||||
class: App\Kernel
|
||||
environment: test
|
23
bin/phpunit
Executable file
23
bin/phpunit
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
ini_set('date.timezone', 'UTC');
|
||||
}
|
||||
|
||||
if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
|
||||
} else {
|
||||
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
|
||||
require PHPUNIT_COMPOSER_INSTALL;
|
||||
PHPUnit\TextUI\Command::main();
|
||||
}
|
||||
} else {
|
||||
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
|
||||
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
|
||||
}
|
@ -75,6 +75,11 @@
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/maker-bundle": "^1.58"
|
||||
"friends-of-behat/symfony-extension": "^2.0",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"symfony/browser-kit": "7.0.*",
|
||||
"symfony/css-selector": "7.0.*",
|
||||
"symfony/maker-bundle": "^1.58",
|
||||
"symfony/phpunit-bridge": "^7.0"
|
||||
}
|
||||
}
|
||||
|
2401
composer.lock
generated
2401
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -6,4 +6,5 @@ return [
|
||||
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
|
||||
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
|
||||
Rekalogika\Mapper\RekalogikaMapperBundle::class => ['all' => true],
|
||||
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true],
|
||||
];
|
||||
|
@ -25,12 +25,6 @@ doctrine:
|
||||
controller_resolver:
|
||||
auto_mapping: true
|
||||
|
||||
when@test:
|
||||
doctrine:
|
||||
dbal:
|
||||
# "TEST_TOKEN" is typically set by ParaTest
|
||||
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
|
||||
|
||||
when@prod:
|
||||
doctrine:
|
||||
orm:
|
||||
|
7
config/packages/translation.yaml
Normal file
7
config/packages/translation.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
framework:
|
||||
default_locale: en
|
||||
translator:
|
||||
default_path: '%kernel.project_dir%/translations'
|
||||
fallbacks:
|
||||
- en
|
||||
providers:
|
@ -22,3 +22,7 @@ services:
|
||||
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
||||
Symfony\Component\Uid\Command\GenerateUlidCommand: ~
|
||||
Symfony\Component\Uid\Command\GenerateUuidCommand: ~
|
||||
Symfony\Component\Uid\Command\InspectUlidCommand: ~
|
||||
Symfony\Component\Uid\Command\InspectUuidCommand: ~
|
||||
|
7
config/services_test.yaml
Normal file
7
config/services_test.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
App\Tests\Behat\:
|
||||
resource: '../tests/Behat/*'
|
38
phpunit.xml.dist
Normal file
38
phpunit.xml.dist
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
convertDeprecationsToExceptions="false"
|
||||
>
|
||||
<php>
|
||||
<ini name="display_errors" value="1" />
|
||||
<ini name="error_reporting" value="-1" />
|
||||
<server name="APP_ENV" value="test" force="true" />
|
||||
<server name="SHELL_VERBOSITY" value="-1" />
|
||||
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
|
||||
<server name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Project Test Suite">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">src</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
|
||||
<listeners>
|
||||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
|
||||
</listeners>
|
||||
|
||||
<extensions>
|
||||
</extensions>
|
||||
</phpunit>
|
57
symfony.lock
57
symfony.lock
@ -26,6 +26,35 @@
|
||||
"migrations/.gitignore"
|
||||
]
|
||||
},
|
||||
"friends-of-behat/symfony-extension": {
|
||||
"version": "2.5",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes-contrib",
|
||||
"branch": "main",
|
||||
"version": "2.0",
|
||||
"ref": "1e012e04f573524ca83795cd19df9ea690adb604"
|
||||
},
|
||||
"files": [
|
||||
"behat.yml.dist",
|
||||
"config/services_test.yaml",
|
||||
"features/demo.feature",
|
||||
"tests/Behat/DemoContext.php"
|
||||
]
|
||||
},
|
||||
"phpunit/phpunit": {
|
||||
"version": "9.6",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "9.6",
|
||||
"ref": "7364a21d87e658eb363c5020c072ecfdc12e2326"
|
||||
},
|
||||
"files": [
|
||||
".env.test",
|
||||
"phpunit.xml.dist",
|
||||
"tests/bootstrap.php"
|
||||
]
|
||||
},
|
||||
"rekalogika/mapper": {
|
||||
"version": "v1.1.1"
|
||||
},
|
||||
@ -81,6 +110,21 @@
|
||||
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
|
||||
}
|
||||
},
|
||||
"symfony/phpunit-bridge": {
|
||||
"version": "7.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.3",
|
||||
"ref": "a411a0480041243d97382cac7984f7dce7813c08"
|
||||
},
|
||||
"files": [
|
||||
".env.test",
|
||||
"bin/phpunit",
|
||||
"phpunit.xml.dist",
|
||||
"tests/bootstrap.php"
|
||||
]
|
||||
},
|
||||
"symfony/routing": {
|
||||
"version": "7.0",
|
||||
"recipe": {
|
||||
@ -94,6 +138,19 @@
|
||||
"config/routes.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/translation": {
|
||||
"version": "7.0",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.3",
|
||||
"ref": "e28e27f53663cc34f0be2837aba18e3a1bef8e7b"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/translation.yaml",
|
||||
"translations/.gitignore"
|
||||
]
|
||||
},
|
||||
"symfony/uid": {
|
||||
"version": "7.0",
|
||||
"recipe": {
|
||||
|
102
tests/Behat/ApiCallContext.php
Normal file
102
tests/Behat/ApiCallContext.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Behat;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Gherkin\Node\PyStringNode;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
final class ApiCallContext implements Context
|
||||
{
|
||||
private Response $response;
|
||||
private array $query = [];
|
||||
private ?string $body = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly KernelInterface $kernel
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I send a request to ":path"
|
||||
*/
|
||||
public function iSendARequestToPath(string $path): void
|
||||
{
|
||||
$this->iSendARequestToWithFollowingBody('GET', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the response should be received
|
||||
*/
|
||||
public function theResponseShouldBeReceived(): void
|
||||
{
|
||||
if ($this->response === null) {
|
||||
throw new \RuntimeException('No response received');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the response status should be :code
|
||||
*/
|
||||
public function theResponseStatusShouldBe(int $code): void
|
||||
{
|
||||
$this->theResponseShouldBeReceived();
|
||||
|
||||
if ($this->response->getStatusCode() !== $code) {
|
||||
throw new \RuntimeException(
|
||||
strtr(
|
||||
'The response code was %received% not %expected%', [
|
||||
'%received%' => $this->response->getStatusCode(),
|
||||
'%expected%' => $code
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^the request has the following body:$/
|
||||
*/
|
||||
public function theRequestHasTheFollowingBody(PyStringNode $string)
|
||||
{
|
||||
$this->body = $string->getRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^the request has the following query:$/
|
||||
*/
|
||||
public function theRequestHasTheFollowingQuery(TableNode $tableNode)
|
||||
{
|
||||
foreach ($tableNode as $row) {
|
||||
$this->query[$row['arg']] = $row['value'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I send a (\w+) request to "([^"]*)"$/
|
||||
*/
|
||||
public function iSendARequestToWithFollowingBody($method, $path)
|
||||
{
|
||||
$request = Request::create(
|
||||
$path.'?'.http_build_query($this->query),
|
||||
method: $method,
|
||||
content: $this->body
|
||||
);
|
||||
|
||||
if ($this->body) {
|
||||
$request->headers->set('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
$this->doRequest($request);
|
||||
}
|
||||
|
||||
private function doRequest(Request $request): void
|
||||
{
|
||||
$this->response = $this->kernel->handle($request);
|
||||
}
|
||||
}
|
13
tests/bootstrap.php
Normal file
13
tests/bootstrap.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
|
||||
if (method_exists(Dotenv::class, 'bootEnv')) {
|
||||
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
|
||||
}
|
||||
|
||||
if ($_SERVER['APP_DEBUG']) {
|
||||
umask(0000);
|
||||
}
|
0
translations/.gitignore
vendored
Normal file
0
translations/.gitignore
vendored
Normal file
Loading…
Reference in New Issue
Block a user