|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of file-fixture-plugin. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Noritaka Horio <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace holyshared\peridot; |
|
13
|
|
|
|
|
14
|
|
|
use holyshared\fixture\FileFixture; |
|
15
|
|
|
use holyshared\fixture\factory\FixtureContainerFactory; |
|
16
|
|
|
use holyshared\fixture\container\LoaderContainer; |
|
17
|
|
|
use holyshared\fixture\loader\TextLoader; |
|
18
|
|
|
use holyshared\fixture\loader\CacheLoader; |
|
19
|
|
|
use holyshared\fixture\loader\MustacheLoader; |
|
20
|
|
|
use holyshared\fixture\loader\ArtLoader; |
|
21
|
|
|
use Evenement\EventEmitterInterface; |
|
22
|
|
|
use Peridot\Core\Suite; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
class FileFixturePlugin implements Registrar |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var \holyshared\peridot\FileFixtureScope |
|
30
|
|
|
*/ |
|
31
|
|
|
private $scope; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $configFile; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Create a new plugin |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $configFile |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct($configFile) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->configFile = $configFile; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function registerTo(EventEmitterInterface $emitter) |
|
50
|
|
|
{ |
|
51
|
|
|
$emitter->on(self::START_EVENT, [ $this, 'onStart' ]); |
|
52
|
|
|
$emitter->on(self::SUITE_START_EVENT, [ $this, 'onSuiteStart' ]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function onStart() |
|
56
|
|
|
{ |
|
57
|
|
|
$textLoader = new CacheLoader(new TextLoader()); |
|
58
|
|
|
$mustacheLoader = new MustacheLoader($textLoader); |
|
59
|
|
|
$artLoader = new ArtLoader($mustacheLoader); |
|
60
|
|
|
|
|
61
|
|
|
$loaders = new LoaderContainer([ |
|
62
|
|
|
$textLoader, |
|
63
|
|
|
$mustacheLoader, |
|
64
|
|
|
$artLoader |
|
65
|
|
|
]); |
|
66
|
|
|
|
|
67
|
|
|
$factory = new FixtureContainerFactory(); |
|
68
|
|
|
$fixtures = $factory->createFromFile($this->configFile); |
|
69
|
|
|
|
|
70
|
|
|
$fixture = new FileFixture($fixtures, $loaders); |
|
71
|
|
|
$this->scope = new FileFixtureScope($fixture); |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param \Peridot\Core\Suite $suite |
|
78
|
|
|
*/ |
|
79
|
|
|
public function onSuiteStart(Suite $suite) |
|
80
|
|
|
{ |
|
81
|
|
|
$parentScope = $suite->getScope(); |
|
82
|
|
|
$parentScope->peridotAddChildScope($this->scope); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|