Skip to content

Commit 0533c16

Browse files
Make everything work with Symfony 5
Not sure yet if it also works with older versions.
1 parent c56e1c6 commit 0533c16

File tree

6 files changed

+138
-93
lines changed

6 files changed

+138
-93
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ before_install:
1616
composer require --dev --no-update symfony/validator "$SYMFONY_VERSION" &&
1717
composer require --dev --no-update symfony/form "$SYMFONY_VERSION" &&
1818
composer require --dev --no-update symfony/yaml "$SYMFONY_VERSION" &&
19-
composer require --dev --no-update symfony/finder "$SYMFONY_VERSION"
19+
composer require --dev --no-update symfony/finder "$SYMFONY_VERSION" &&
20+
composer require --dev --no-update symfony/translation "$SYMFONY_VERSION"
2021
2122
install:
2223
- composer update --prefer-dist

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
}
2424
},
2525
"require": {
26-
"php": ">=7.0",
26+
"php": ">=7.1",
2727
"symfony/form": "~3.4|~4.0|~5.0",
2828
"symfony/console": "~3.4|~4.0|~5.0",
2929
"symfony/translation": "~3.4|~4.0|~5.0"
3030
},
3131
"require-dev": {
3232
"beberlei/assert": "~2.1",
33-
"behat/behat": "~3.0",
33+
"behat/behat": "^3.6",
3434
"friendsofphp/php-cs-fixer": "^1.10|^2.2",
3535
"symfony/finder": "~3.4|~4.0|~5.0",
3636
"symfony/framework-bundle": "~3.4|~4.0|~5.0",
3737
"symfony/validator": "~3.4|~4.0|~5.0",
3838
"symfony/yaml": "~3.4|~4.0|~5.0",
39-
"symfony/security": "~3.4|~4.0|~5.0"
39+
"symfony/security": "~3.4|~4.0|~5.0",
40+
"phpunit/phpunit": "^7"
4041
}
4142
}

features/bootstrap/FeatureContext.php

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

3-
use Assert\Assertion;
43
use Behat\Behat\Context\Context;
54
use Behat\Behat\Context\SnippetAcceptingContext;
65
use Behat\Gherkin\Node\PyStringNode;
6+
use Behat\Gherkin\Node\TableNode;
77
use Matthias\SymfonyConsoleForm\Tests\AppKernel;
8-
use Matthias\SymfonyConsoleForm\Tests\Helper\ApplicationTester;
98
use Matthias\SymfonyConsoleForm\Tests\Helper\StringUtil;
9+
use PHPUnit\Framework\Assert;
1010
use Symfony\Bundle\FrameworkBundle\Console\Application;
11+
use Symfony\Component\Console\Tester\ApplicationTester;
1112

1213
/**
1314
* Defines application features from the specific context.
@@ -37,15 +38,17 @@ public function __construct()
3738

3839
$kernel = new AppKernel('test', true);
3940
$this->application = new Application($kernel);
41+
$this->application->setAutoExit(false);
4042
$this->tester = new ApplicationTester($this->application);
4143
}
4244

4345
/**
4446
* @Given /^I run the command "([^"]*)" and I provide as input$/
4547
*/
46-
public function iRunTheCommandAndIProvideAsInput($name, PyStringNode $input)
48+
public function iRunTheCommandAndIProvideAsInput($name, TableNode $input)
4749
{
48-
$this->runCommandWithInteractiveInput($name, $input);
50+
$inputs = array_column($input->getHash(), 'Input');
51+
$this->runCommandWithInteractiveInput($name, $inputs);
4952
}
5053

5154
/**
@@ -61,33 +64,38 @@ public function iRunTheCommandAndIProvideAsInputOneLine($name, $input)
6164
*/
6265
public function theOutputShouldBe(PyStringNode $expectedOutput)
6366
{
64-
Assertion::same(
65-
StringUtil::trimLines($this->getOutput()),
66-
StringUtil::trimLines((string) $expectedOutput)
67+
Assert::assertEquals(
68+
StringUtil::trimLines((string) $expectedOutput),
69+
StringUtil::trimLines($this->getOutput())
6770
);
6871
}
6972

70-
private function runCommandWithInteractiveInput($name, $input)
73+
private function runCommandWithInteractiveInput($name, array $inputs)
7174
{
72-
$input = str_replace('[enter]', "\n", $input);
73-
$this->tester->putToInputStream($input);
74-
$this->tester->run($name, array('interactive' => true, 'decorated' => false));
75+
$this->tester->setInputs($inputs);
76+
$this->tester->run(['command' => $name], array('interactive' => true, 'decorated' => false));
7577
}
7678

7779
/**
7880
* @Then /^the output should contain$/
7981
*/
8082
public function theOutputShouldContain(PyStringNode $expectedOutput)
8183
{
82-
Assertion::contains(StringUtil::trimLines($this->getOutput()), StringUtil::trimLines((string) $expectedOutput));
84+
Assert::assertStringContainsString(
85+
StringUtil::trimLines((string) $expectedOutput),
86+
StringUtil::trimLines($this->getOutput())
87+
);
8388
}
8489

8590
/**
8691
* @Then /^the output should not contain$/
8792
*/
8893
public function theOutputShouldNotContain(PyStringNode $expectedOutput)
8994
{
90-
Assertion::false(strpos(StringUtil::trimLines($this->getOutput()), StringUtil::trimLines((string) $expectedOutput)));
95+
Assert::assertStringNotContainsString(
96+
StringUtil::trimLines($this->getOutput()),
97+
StringUtil::trimLines((string) $expectedOutput)
98+
);
9199
}
92100

93101
private function getOutput()
@@ -100,27 +108,34 @@ private function getOutput()
100108
*/
101109
public function theCommandHasFinishedSuccessfully()
102110
{
103-
Assertion::same($this->tester->getStatusCode(), 0);
111+
Assert::assertEquals(0, $this->tester->getStatusCode());
104112
}
105113

106114
/**
107115
* @Then /^the command was not successful$/
108116
*/
109117
public function theCommandWasNotSuccessful()
110118
{
111-
Assertion::notSame($this->tester->getStatusCode(), 0);
119+
Assert::assertNotEquals(0, $this->tester->getStatusCode());
112120
}
113121

114122
/**
115-
* @When /^I run the command "([^"]*)" non\-interactively$/
123+
* @When /^I run a command non-interactively with parameters$/
116124
*/
117-
public function iRunTheCommandNonInteractively($command)
125+
public function iRunTheCommandNonInteractively(TableNode $parameters)
118126
{
119-
$this->runCommandWithNonInteractiveInput($command);
127+
$parameters = $parameters->getHash();
128+
129+
$input = array_combine(
130+
array_column($parameters, 'Parameter'),
131+
array_column($parameters, 'Value')
132+
);
133+
134+
$this->runCommandWithNonInteractiveInput($input);
120135
}
121136

122-
private function runCommandWithNonInteractiveInput($name)
137+
private function runCommandWithNonInteractiveInput(array $input)
123138
{
124-
$this->tester->run($name, array('interactive' => false, 'decorated' => false));
139+
$this->tester->run($input, array('interactive' => false, 'decorated' => false));
125140
}
126141
}

0 commit comments

Comments
 (0)