|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* YAWIK |
|
5
|
|
|
* |
|
6
|
|
|
* @filesource |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* @copyright 2013 - 2017 Cross Solution <http://cross-solution.de> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Yawik\Behat; |
|
12
|
|
|
|
|
13
|
|
|
use Behat\Behat\Context\Context; |
|
14
|
|
|
use Behat\Behat\Hook\Scope\AfterScenarioScope; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class InstallContext |
|
18
|
|
|
* |
|
19
|
|
|
* @package Yawik\Behat |
|
20
|
|
|
* @author Anthonius Munthi <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class InstallContext implements Context |
|
23
|
|
|
{ |
|
24
|
|
|
use CommonContextTrait; |
|
25
|
|
|
|
|
26
|
|
|
static private $configFile; |
|
27
|
|
|
|
|
28
|
|
|
static private $yawikGlobalConfig; |
|
29
|
|
|
|
|
30
|
|
|
static private $yawikBackupConfig; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
static::$configFile = getcwd() . '/config/autoload/install.module.php'; |
|
|
|
|
|
|
35
|
|
|
static::$yawikGlobalConfig = getcwd() . '/config/autoload/yawik.config.global.php'; |
|
|
|
|
|
|
36
|
|
|
static::$yawikBackupConfig = str_replace('yawik.config.global.php', 'yawik.backup', static::$yawikGlobalConfig); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @Given I have install module activated |
|
41
|
|
|
*/ |
|
42
|
|
|
public function iHaveInstallModuleActivated() |
|
43
|
|
|
{ |
|
44
|
|
|
$target = static::$configFile; |
|
|
|
|
|
|
45
|
|
|
if(!file_exists($target)){ |
|
46
|
|
|
$source = __DIR__.'/../resources/install.module.php'; |
|
47
|
|
|
copy($source,$target); |
|
48
|
|
|
chmod($target,0777); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// backup existing file |
|
52
|
|
|
$yawikBackupConfig = static::$yawikBackupConfig; |
|
|
|
|
|
|
53
|
|
|
$yawikGlobalConfig = static::$yawikGlobalConfig; |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
if(is_file($yawikGlobalConfig)){ |
|
56
|
|
|
rename($yawikGlobalConfig,$yawikBackupConfig); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @Given I go to the install page |
|
62
|
|
|
*/ |
|
63
|
|
|
public function iGoToInstallPage() |
|
64
|
|
|
{ |
|
65
|
|
|
$url = $this->minkContext->locatePath('/'); |
|
66
|
|
|
$this->visit($url); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @AfterSuite |
|
71
|
|
|
*/ |
|
72
|
|
|
static public function tearDown() |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
static::restoreConfig(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @AfterScenario |
|
79
|
|
|
*/ |
|
80
|
|
|
public function afterScenario() |
|
81
|
|
|
{ |
|
82
|
|
|
static::restoreConfig(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @BeforeSuite |
|
87
|
|
|
*/ |
|
88
|
|
|
static public function setUp() |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
static::restoreConfig(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
static public function restoreConfig() |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
if(is_file($file = static::$configFile)){ |
|
|
|
|
|
|
96
|
|
|
unlink($file); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
// restore backup |
|
100
|
|
|
$yawikBackupConfig = static::$yawikBackupConfig; |
|
|
|
|
|
|
101
|
|
|
$yawikGlobalConfig = static::$yawikGlobalConfig; |
|
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
if(is_file($yawikBackupConfig)){ |
|
104
|
|
|
rename($yawikBackupConfig,$yawikGlobalConfig); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @Given I fill database connection with an active connection |
|
110
|
|
|
*/ |
|
111
|
|
|
public function iFillActiveConnectionString() |
|
112
|
|
|
{ |
|
113
|
|
|
$config = $this->getService('config'); |
|
114
|
|
|
$connection = $config['doctrine']['connection']['odm_default']['connectionString']; |
|
115
|
|
|
$this->minkContext->fillField('db_conn',$connection); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: