1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the feedback project. |
5
|
|
|
* |
6
|
|
|
* (c) Florian Moser <[email protected]> |
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 App\DataFixtures\Base; |
13
|
|
|
|
14
|
|
|
use App\Entity\Traits\AddressTrait; |
|
|
|
|
15
|
|
|
use App\Entity\Traits\PersonTrait; |
|
|
|
|
16
|
|
|
use App\Entity\Traits\ThingTrait; |
|
|
|
|
17
|
|
|
use App\Entity\Traits\UserTrait; |
|
|
|
|
18
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
19
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
20
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
21
|
|
|
use Faker\Factory; |
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
24
|
|
|
|
25
|
|
|
abstract class BaseFixture extends Fixture implements OrderedFixtureInterface, ContainerAwareInterface |
26
|
|
|
{ |
27
|
|
|
/* @var ContainerInterface $container */ |
28
|
|
|
private $container; |
29
|
|
|
|
30
|
|
|
public function setContainer(ContainerInterface $container = null) |
31
|
|
|
{ |
32
|
|
|
$this->container = $container; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function getTranslator() |
36
|
|
|
{ |
37
|
|
|
return $this->container->get('translator'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return \Faker\Generator |
42
|
|
|
*/ |
43
|
|
|
protected function getFaker() |
44
|
|
|
{ |
45
|
|
|
return Factory::create('de_CH'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param UserTrait $obj |
50
|
|
|
*/ |
51
|
|
|
protected function fillUser($obj) |
52
|
|
|
{ |
53
|
|
|
$faker = $this->getFaker(); |
54
|
|
|
$obj->setEmail($faker->email); |
55
|
|
|
$obj->setPlainPassword($faker->password); |
56
|
|
|
$obj->setPassword(); |
57
|
|
|
$obj->setRegistrationDate(new \DateTime()); |
58
|
|
|
$obj->setLastLogin(new \DateTime()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param AddressTrait $obj |
63
|
|
|
*/ |
64
|
|
|
protected function fillAddress($obj) |
65
|
|
|
{ |
66
|
|
|
$faker = $this->getFaker(); |
67
|
|
|
$obj->setStreet($faker->streetAddress); |
68
|
|
|
$obj->setStreetNr($faker->numberBetween(0, 300)); |
69
|
|
|
if ($faker->numberBetween(0, 10) > 8) { |
70
|
|
|
$obj->setAddressLine($faker->streetAddress); |
71
|
|
|
} |
72
|
|
|
$obj->setPostalCode($faker->numberBetween(0, 9999)); |
73
|
|
|
$obj->setCity($faker->city); |
74
|
|
|
$obj->setCountry($faker->countryCode); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param ThingTrait $obj |
79
|
|
|
*/ |
80
|
|
|
protected function fillThing($obj) |
81
|
|
|
{ |
82
|
|
|
$faker = $this->getFaker(); |
83
|
|
|
$obj->setName($faker->text(50)); |
84
|
|
|
if ($faker->numberBetween(0, 10) > 5) { |
85
|
|
|
$obj->setDescription($faker->text(200)); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param PersonTrait $obj |
91
|
|
|
*/ |
92
|
|
|
protected function fillPerson($obj) |
93
|
|
|
{ |
94
|
|
|
$faker = $this->getFaker(); |
95
|
|
|
$obj->setGivenName($faker->firstName); |
96
|
|
|
$obj->setFamilyName($faker->lastName); |
97
|
|
|
if ($faker->numberBetween(0, 10) > 5) { |
98
|
|
|
$obj->setJobTitle($faker->jobTitle); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* create random instances. |
104
|
|
|
* |
105
|
|
|
* @param $count |
106
|
|
|
* |
107
|
|
|
* @throws \Exception |
108
|
|
|
*/ |
109
|
|
|
protected function loadSomeRandoms(ObjectManager $manager, $count = 5) |
110
|
|
|
{ |
111
|
|
|
for ($i = 0; $i < $count; ++$i) { |
112
|
|
|
$instance = $this->getRandomInstance(); |
|
|
|
|
113
|
|
|
if ($instance === null) { |
114
|
|
|
throw new \Exception('you need to override getRandomInstance to return an instance before you can use this function'); |
115
|
|
|
} |
116
|
|
|
$manager->persist($instance); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* create an instance with all random values. |
122
|
|
|
* |
123
|
|
|
* @return mixed |
124
|
|
|
*/ |
125
|
|
|
protected function getRandomInstance() |
126
|
|
|
{ |
127
|
|
|
return null; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths