Compress scenario

This commit is contained in:
Kamil Kokot
2018-12-31 17:19:50 +01:00
parent 032ecb64d2
commit 9c41bdbcba
3 changed files with 93 additions and 51 deletions

View File

@@ -22,7 +22,8 @@
"behat/mink-extension": "^2.2", "behat/mink-extension": "^2.2",
"phpstan/phpstan-shim": "^0.10", "phpstan/phpstan-shim": "^0.10",
"sylius-labs/coding-standard": "^3.0", "sylius-labs/coding-standard": "^3.0",
"symfony/framework-bundle": "^3.4|^4.1" "symfony/framework-bundle": "^3.4|^4.1",
"symfony/yaml": "^3.4|^4.1"
}, },
"suggest": { "suggest": {
"behat/mink-browserkit-driver": "^1.3" "behat/mink-browserkit-driver": "^1.3"

View File

@@ -1,51 +1,9 @@
Feature: Running bare Behat scenarios Feature: Running bare Behat scenarios
Scenario: Running Behat with SymfonyExtension Scenario: Running Behat with SymfonyExtension
Given a Behat configuration containing: Given a Behat configuration with the minimal working configuration for SymfonyExtension
""" And a Behat configuration with the minimal working configuration for MinkExtension
default: And an application kernel with the minimal working configuration for SymfonyExtension
extensions:
FriendsOfBehat\SymfonyExtension:
kernel:
path: app/AppKernel.php
class: AppKernel
Behat\MinkExtension:
base_url: "http://localhost:8080/"
default_session: symfony
sessions:
symfony:
symfony: ~
"""
And a file "app/AppKernel.php" containing:
"""
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle(),
];
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container): void {
$container->loadFromExtension('framework', [
'test' => $this->getEnvironment() === 'test',
'secret' => 'Pigeon',
]);
});
}
}
"""
And a feature file with passing scenario And a feature file with passing scenario
When I run Behat When I run Behat
Then it should pass Then it should pass

View File

@@ -8,6 +8,7 @@ use Behat\Behat\Context\Context;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
use Symfony\Component\Yaml\Yaml;
final class TestContext implements Context final class TestContext implements Context
{ {
@@ -63,7 +64,53 @@ final class TestContext implements Context
*/ */
public function thereIsConfiguration($content): void public function thereIsConfiguration($content): void
{ {
$this->thereIsFile('behat.yml', $content); $mainConfigFile = sprintf('%s/behat.yml', self::$workingDir);
$newConfigFile = sprintf('%s/behat-%s.yml', self::$workingDir, md5($content));
self::$filesystem->dumpFile($newConfigFile, (string) $content);
if (!file_exists($mainConfigFile)) {
self::$filesystem->dumpFile($mainConfigFile, Yaml::dump(['imports' => []]));
}
$mainBehatConfiguration = Yaml::parseFile($mainConfigFile);
$mainBehatConfiguration['imports'][] = $newConfigFile;
self::$filesystem->dumpFile($mainConfigFile, Yaml::dump($mainBehatConfiguration));
}
/**
* @Given /^a Behat configuration with the minimal working configuration for SymfonyExtension$/
*/
public function thereIsConfigurationWithMinimalWorkingConfigurationForSymfonyExtension(): void
{
$this->thereIsConfiguration(<<<'CON'
default:
extensions:
FriendsOfBehat\SymfonyExtension:
kernel:
path: app/AppKernel.php
class: AppKernel
CON
);
}
/**
* @Given /^a Behat configuration with the minimal working configuration for MinkExtension$/
*/
public function thereIsConfigurationWithMinimalWorkingConfigurationForMinkExtension(): void
{
$this->thereIsConfiguration(<<<'CON'
default:
extensions:
Behat\MinkExtension:
base_url: "http://localhost:8080/"
default_session: symfony
sessions:
symfony:
symfony: ~
CON
);
} }
/** /**
@@ -74,6 +121,42 @@ final class TestContext implements Context
self::$filesystem->dumpFile(self::$workingDir . '/' . $file, (string) $content); self::$filesystem->dumpFile(self::$workingDir . '/' . $file, (string) $content);
} }
/**
* @Given /^an application kernel with the minimal working configuration for SymfonyExtension$/
*/
public function thereIsKernelWithMinimalWorkingConfiguration(): void
{
$this->thereIsFile('app/AppKernel.php', <<<'CON'
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle(),
];
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container): void {
$container->loadFromExtension('framework', [
'test' => $this->getEnvironment() === 'test',
'secret' => 'Pigeon',
]);
});
}
}
CON
);
}
/** /**
* @Given /^a feature file containing(?: "([^"]+)"|:)$/ * @Given /^a feature file containing(?: "([^"]+)"|:)$/
*/ */
@@ -87,7 +170,7 @@ final class TestContext implements Context
*/ */
public function thereIsFeatureFileWithPassingScenario(): void public function thereIsFeatureFileWithPassingScenario(): void
{ {
$this->thereIsFile('features/bootstrap/FeatureContext.php', <<<CON $this->thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON'
<?php <?php
declare(strict_types=1); declare(strict_types=1);
@@ -114,7 +197,7 @@ FEA
*/ */
public function thereIsFeatureFileWithFailingScenario(): void public function thereIsFeatureFileWithFailingScenario(): void
{ {
$this->thereIsFile('features/bootstrap/FeatureContext.php', <<<CON $this->thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON'
<?php <?php
declare(strict_types=1); declare(strict_types=1);
@@ -141,7 +224,7 @@ FEA
*/ */
public function thereIsFeatureFileWithScenarioWithMissingStep(): void public function thereIsFeatureFileWithScenarioWithMissingStep(): void
{ {
$this->thereIsFile('features/bootstrap/FeatureContext.php', <<<CON $this->thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON'
<?php <?php
declare(strict_types=1); declare(strict_types=1);
@@ -164,7 +247,7 @@ FEA
*/ */
public function thereIsFeatureFileWithScenarioWithPendingStep(): void public function thereIsFeatureFileWithScenarioWithPendingStep(): void
{ {
$this->thereIsFile('features/bootstrap/FeatureContext.php', <<<CON $this->thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON'
<?php <?php
declare(strict_types=1); declare(strict_types=1);