Completed
Pull Request — master (#335)
by Simon
07:27 queued 03:11
created

AbstractConnectUnitTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace ShopwarePlugins\Connect\Tests;
9
10
/**
11
 * Every unit test should depend on this abstract class. It is only used to prevent a call to the Shopware() singleton.
12
 */
13
abstract class AbstractConnectUnitTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var \Shopware|null
17
     */
18
    private static $appState = null;
19
20
    protected function setUp()
21
    {
22
        @trigger_error('Please use @before annotation');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
23
    }
24
25
    protected function tearDown()
26
    {
27
        @trigger_error('Please use @after annotation');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
28
    }
29
30
    /**
31
     * @before
32
     */
33
    public function killShopwareFunctionBefore()
34
    {
35
        self::$appState = Shopware();
36
        Shopware(new EmptyShopwareApplication());
37
    }
38
39
    /**
40
     * @after
41
     */
42
    public function restoreShopwareFunctionAfter()
43
    {
44
        Shopware(self::$appState);
45
    }
46
}
47
48
class EmptyShopwareApplication
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
49
{
50
    public function __call($name, $arguments)
51
    {
52
        throw new RestrictedCallException('Restricted to call ' . $name . ' because you should not have a test kernel in this test case.');
53
    }
54
}
55
56
class RestrictedCallException extends \RuntimeException
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
57
{
58
}