Completed
Pull Request — master (#8)
by Loïc
07:36
created

AddressContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A thereIsAddressLocatedAtCity() 0 4 1
A thereAreAddressesLocatedAtCity() 0 4 1
A createAddresses() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of Jedisjeux.
5
 *
6
 * (c) Loïc Frémont
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AppBundle\Behat\Context\Setup;
13
14
use AppBundle\Behat\DefaultContext;
15
16
class AddressContext extends DefaultContext
17
{
18
    /**
19
     * @Given there is an address located at :city
20
     */
21
    public function thereIsAddressLocatedAtCity(string $city)
22
    {
23
        $this->createAddresses(1, ['city' => $city]);
24
    }
25
26
    /**
27
     * @Given there are :count addresses located at :city
28
     */
29
    public function thereAreAddressesLocatedAtCity(int $count, string $city)
30
    {
31
        $this->createAddresses((int) $count, ['city' => $city]);
32
    }
33
34
    /**
35
     * @param int $count
36
     *
37
     * @param array $options
38
     */
39
    private function createAddresses(int $count, array $options = []): void
40
    {
41
        $manager = $this->getEntityManager();
42
        $factory = $this->getExampleFactory('address');
43
44
        for ($i=0 ; $i<$count ; $i++) {
45
            $address = $factory->create($options);
46
            $manager->persist($address);
47
        }
48
49
        $manager->flush();
50
    }
51
}
52