Completed
Push — develop ( dce9ea...970920 )
by Mathias
30s queued 20s
created

InstallContext::afterScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 1
f 0
cc 1
eloc 2
nc 1
nop 0
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';
0 ignored issues
show
Bug introduced by
Since $configFile is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $configFile to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
35
        static::$yawikGlobalConfig = getcwd() . '/config/autoload/yawik.config.global.php';
0 ignored issues
show
Bug introduced by
Since $yawikGlobalConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $yawikGlobalConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
36
        static::$yawikBackupConfig = str_replace('yawik.config.global.php', 'yawik.backup', static::$yawikGlobalConfig);
0 ignored issues
show
Bug introduced by
Since $yawikBackupConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $yawikBackupConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug introduced by
Since $yawikGlobalConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $yawikGlobalConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
37
    }
38
39
    /**
40
     * @Given I have install module activated
41
     */
42
    public function iHaveInstallModuleActivated()
43
    {
44
        $target = static::$configFile;
0 ignored issues
show
Bug introduced by
Since $configFile is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $configFile to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
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;
0 ignored issues
show
Bug introduced by
Since $yawikBackupConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $yawikBackupConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
53
        $yawikGlobalConfig = static::$yawikGlobalConfig;
0 ignored issues
show
Bug introduced by
Since $yawikGlobalConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $yawikGlobalConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
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()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
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()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
89
    {
90
        static::restoreConfig();
91
    }
92
93
    static public function restoreConfig()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
94
    {
95
        if(is_file($file = static::$configFile)){
0 ignored issues
show
Bug introduced by
Since $configFile is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $configFile to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
96
            unlink($file);
97
        }
98
99
        // restore backup
100
        $yawikBackupConfig = static::$yawikBackupConfig;
0 ignored issues
show
Bug introduced by
Since $yawikBackupConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $yawikBackupConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
101
        $yawikGlobalConfig = static::$yawikGlobalConfig;
0 ignored issues
show
Bug introduced by
Since $yawikGlobalConfig is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $yawikGlobalConfig to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

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:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
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