Conditions | 4 |
Paths | 1 |
Total Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
12 | public function modify(Container $di) |
||
13 | { |
||
14 | $adr = $di->get('radar/adr:adr'); |
||
15 | |||
16 | // For demonstration purposes, seed database using test fixtures |
||
17 | $adr->get('seed', "/seed", function () use ($di) { |
||
18 | $payload = new Payload(); |
||
19 | |||
20 | $di->get('db.schema')->drop(); |
||
21 | $di->get('db.schema')->create(); |
||
22 | |||
23 | $yaml = new Parser(); |
||
24 | $yamlFile = __DIR__ . "/../../../../tests/Infrastructure/DBAL/fixtures.yml"; |
||
25 | $fixtures = $yaml->parse(file_get_contents($yamlFile)); |
||
26 | |||
27 | if (! is_array($fixtures)) { |
||
28 | throw new RuntimeException("Could not parse fixtures file"); |
||
29 | } |
||
30 | |||
31 | foreach ($fixtures as $table => $rows) { |
||
32 | foreach ($rows as $row) { |
||
33 | $di->get('db.connection')->insert($table, $row); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | $payload->setStatus($payload::SUCCESS); |
||
38 | $payload->setOutput(["message" => "Database seeded"]); |
||
39 | |||
40 | return $payload; |
||
41 | }); |
||
42 | } |
||
43 | } |
||
44 |