Skip to content

Commit a367183

Browse files
authored
Merge pull request #1439 from meyerbaptiste/fix_behat_2.0
Clean Behat tests
2 parents afd7ae7 + a11598b commit a367183

File tree

13 files changed

+205
-333
lines changed

13 files changed

+205
-333
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ before_install:
2222
- if [[ $coverage = 1 ]]; then mkdir -p build/logs build/cov; fi
2323
- if [[ $coverage = 1 ]]; then wget https://phar.phpunit.de/phpcov.phar; fi
2424
- if [[ $coverage = 1 ]]; then wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi
25-
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.3.1/php-cs-fixer.phar; fi
25+
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.6.0/php-cs-fixer.phar; fi
2626
- if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi
2727
- export PATH="$PATH:$HOME/.composer/vendor/bin"
2828

features/bootstrap/CoverageContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author Kévin Dunglas <[email protected]>
2525
* @copyright Adapted from https://gist.github.com/eliecharra/9c8b3ba57998b50e14a6
2626
*/
27-
class CoverageContext implements Context
27+
final class CoverageContext implements Context
2828
{
2929
/**
3030
* @var CodeCoverage

features/bootstrap/FeatureContext.php

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,21 @@
2828
use Behat\Behat\Context\SnippetAcceptingContext;
2929
use Behatch\HttpCall\Request;
3030
use Doctrine\Common\Persistence\ManagerRegistry;
31+
use Doctrine\ORM\EntityManagerInterface;
3132
use Doctrine\ORM\Tools\SchemaTool;
3233

3334
/**
3435
* Defines application features from the specific context.
3536
*/
36-
class FeatureContext implements Context, SnippetAcceptingContext
37+
final class FeatureContext implements Context, SnippetAcceptingContext
3738
{
38-
private $doctrine;
39-
4039
/**
41-
* @var \Doctrine\Common\Persistence\ObjectManager
40+
* @var EntityManagerInterface
4241
*/
4342
private $manager;
44-
45-
/**
46-
* @var SchemaTool
47-
*/
43+
private $doctrine;
4844
private $schemaTool;
49-
50-
/**
51-
* @var array
52-
*/
5345
private $classes;
54-
55-
/**
56-
* @var Request
57-
*/
5846
private $request;
5947

6048
/**
@@ -103,7 +91,7 @@ public function dropDatabase()
10391
/**
10492
* @Given there is :nb dummy objects
10593
*/
106-
public function thereIsDummyObjects($nb)
94+
public function thereIsDummyObjects(int $nb)
10795
{
10896
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
10997

@@ -123,7 +111,7 @@ public function thereIsDummyObjects($nb)
123111
/**
124112
* @Given there is :nb dummy objects with relatedDummy
125113
*/
126-
public function thereIsDummyObjectsWithRelatedDummy($nb)
114+
public function thereIsDummyObjectsWithRelatedDummy(int $nb)
127115
{
128116
for ($i = 1; $i <= $nb; ++$i) {
129117
$relatedDummy = new RelatedDummy();
@@ -144,7 +132,7 @@ public function thereIsDummyObjectsWithRelatedDummy($nb)
144132
/**
145133
* @Given there is :nb dummy objects having each :nbrelated relatedDummies
146134
*/
147-
public function thereIsDummyObjectsWithRelatedDummies($nb, $nbrelated)
135+
public function thereIsDummyObjectsWithRelatedDummies(int $nb, int $nbrelated)
148136
{
149137
for ($i = 1; $i <= $nb; ++$i) {
150138
$dummy = new Dummy();
@@ -154,11 +142,12 @@ public function thereIsDummyObjectsWithRelatedDummies($nb, $nbrelated)
154142
for ($j = 1; $j <= $nbrelated; ++$j) {
155143
$relatedDummy = new RelatedDummy();
156144
$relatedDummy->setName('RelatedDummy'.$j.$i);
145+
157146
$this->manager->persist($relatedDummy);
147+
158148
$dummy->addRelatedDummy($relatedDummy);
159149
}
160150

161-
$this->manager->persist($relatedDummy);
162151
$this->manager->persist($dummy);
163152
}
164153

@@ -168,7 +157,7 @@ public function thereIsDummyObjectsWithRelatedDummies($nb, $nbrelated)
168157
/**
169158
* @Given there is :nb dummy objects with dummyDate
170159
*/
171-
public function thereIsDummyObjectsWithDummyDate($nb)
160+
public function thereIsDummyObjectsWithDummyDate(int $nb)
172161
{
173162
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
174163

@@ -194,7 +183,7 @@ public function thereIsDummyObjectsWithDummyDate($nb)
194183
/**
195184
* @Given there is :nb dummy objects with dummyDate and dummyBoolean :bool
196185
*/
197-
public function thereIsDummyObjectsWithDummyDateAndDummyBoolean($nb, $bool)
186+
public function thereIsDummyObjectsWithDummyDateAndDummyBoolean(int $nb, string $bool)
198187
{
199188
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
200189

@@ -230,7 +219,7 @@ public function thereIsDummyObjectsWithDummyDateAndDummyBoolean($nb, $bool)
230219
/**
231220
* @Given there is :nb dummy objects with dummyDate and relatedDummy
232221
*/
233-
public function thereIsDummyObjectsWithDummyDateAndRelatedDummy($nb)
222+
public function thereIsDummyObjectsWithDummyDateAndRelatedDummy(int $nb)
234223
{
235224
for ($i = 1; $i <= $nb; ++$i) {
236225
$date = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));
@@ -258,7 +247,7 @@ public function thereIsDummyObjectsWithDummyDateAndRelatedDummy($nb)
258247
/**
259248
* @Given there is :nb dummy objects with dummyPrice
260249
*/
261-
public function thereIsDummyObjectsWithDummyPrice($nb)
250+
public function thereIsDummyObjectsWithDummyPrice(int $nb)
262251
{
263252
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
264253
$prices = ['9.99', '12.99', '15.99', '19.99'];
@@ -279,7 +268,7 @@ public function thereIsDummyObjectsWithDummyPrice($nb)
279268
/**
280269
* @Given there is :nb dummy objects with dummyBoolean :bool
281270
*/
282-
public function thereIsDummyObjectsWithDummyBoolean($nb, $bool)
271+
public function thereIsDummyObjectsWithDummyBoolean(int $nb, string $bool)
283272
{
284273
if (in_array($bool, ['true', '1', 1], true)) {
285274
$bool = true;
@@ -394,7 +383,7 @@ public function thereIsAFooEntityWithRelatedBars()
394383
/**
395384
* @Given there is a RelatedDummy with :nb friends
396385
*/
397-
public function thereIsARelatedDummyWithFriends($nb)
386+
public function thereIsARelatedDummyWithFriends(int $nb)
398387
{
399388
$relatedDummy = new RelatedDummy();
400389
$relatedDummy->setName('RelatedDummy with friends');
@@ -426,10 +415,9 @@ public function thereIsARelatedDummyWithFriends($nb)
426415
/**
427416
* @Then the password :password for user :user should be hashed
428417
*/
429-
public function thePasswordForUserShouldBeHashed($password, $user)
418+
public function thePasswordForUserShouldBeHashed(string $password, string $user)
430419
{
431-
$repository = $this->doctrine->getRepository(User::class);
432-
$user = $repository->find($user);
420+
$user = $this->doctrine->getRepository(User::class)->find($user);
433421

434422
if (!password_verify($password, $user->getPassword())) {
435423
throw new \Exception('User password mismatch');

0 commit comments

Comments
 (0)