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->generateUrl('/'); |
66
|
|
|
$url = str_replace('/en','',$url); |
67
|
|
|
$this->visit($url); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @AfterSuite |
72
|
|
|
*/ |
73
|
|
|
static public function tearDown() |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
static::restoreConfig(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @AfterScenario |
80
|
|
|
*/ |
81
|
|
|
public function afterScenario() |
82
|
|
|
{ |
83
|
|
|
static::restoreConfig(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @BeforeSuite |
88
|
|
|
*/ |
89
|
|
|
static public function setUp() |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
static::restoreConfig(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
static public function restoreConfig() |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
if(is_file($file = static::$configFile)){ |
|
|
|
|
97
|
|
|
unlink($file); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// restore backup |
101
|
|
|
$yawikBackupConfig = static::$yawikBackupConfig; |
|
|
|
|
102
|
|
|
$yawikGlobalConfig = static::$yawikGlobalConfig; |
|
|
|
|
103
|
|
|
|
104
|
|
|
if(is_file($yawikBackupConfig)){ |
105
|
|
|
rename($yawikBackupConfig,$yawikGlobalConfig); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @Given I fill database connection with an active connection |
111
|
|
|
*/ |
112
|
|
|
public function iFillActiveConnectionString() |
113
|
|
|
{ |
114
|
|
|
$config = $this->getService('config'); |
115
|
|
|
$connection = $config['doctrine']['connection']['odm_default']['connectionString']; |
116
|
|
|
$this->minkContext->fillField('db_conn',$connection); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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
SomeClass
to useself
instead: