|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\PHPUnit; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Framework\App\ResourceConnection; |
|
6
|
|
|
use Magento\Framework\DB\Adapter\AdapterInterface; |
|
7
|
|
|
use N98\Magento\Application; |
|
8
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class TestCase |
|
12
|
|
|
* |
|
13
|
|
|
* @codeCoverageIgnore |
|
14
|
|
|
* @package N98\Magento\Command\PHPUnit |
|
15
|
|
|
*/ |
|
16
|
|
|
class TestCase extends \PHPUnit_Framework_TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var Application |
|
20
|
|
|
*/ |
|
21
|
|
|
private $application = null; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string|null |
|
25
|
|
|
*/ |
|
26
|
|
|
private $root; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* getter for the magento root directory of the test-suite |
|
30
|
|
|
* |
|
31
|
|
|
* @see ApplicationTest::testExecute |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getTestMagentoRoot() |
|
36
|
|
|
{ |
|
37
|
|
|
if ($this->root) { |
|
|
|
|
|
|
38
|
|
|
return $this->root; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$root = getenv('N98_MAGERUN2_TEST_MAGENTO_ROOT'); |
|
42
|
|
|
if (empty($root)) { |
|
43
|
|
|
if ($buffer = rtrim(file_get_contents(getcwd() . '/.n98-magerun2'))) { |
|
44
|
|
|
$root = $buffer; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
if (empty($root)) { |
|
48
|
|
|
$this->markTestSkipped( |
|
49
|
|
|
'Please specify environment variable N98_MAGERUN2_TEST_MAGENTO_ROOT with path to your test ' . |
|
50
|
|
|
'magento installation!' |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$this->root = realpath($root); |
|
55
|
|
|
return $this->root; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return Application|PHPUnit_Framework_MockObject_MockObject |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getApplication() |
|
62
|
|
|
{ |
|
63
|
|
|
if ($this->application === null) { |
|
64
|
|
|
$root = $this->getTestMagentoRoot(); |
|
65
|
|
|
|
|
66
|
|
|
/** @var Application|PHPUnit_Framework_MockObject_MockObject $application */ |
|
67
|
|
|
$application = $this->getMock('N98\Magento\Application', array('getMagentoRootFolder')); |
|
68
|
|
|
$loader = require __DIR__ . '/../../../../../vendor/autoload.php'; |
|
69
|
|
|
$application->setAutoloader($loader); |
|
|
|
|
|
|
70
|
|
|
$application->expects($this->any())->method('getMagentoRootFolder')->will($this->returnValue($root)); |
|
|
|
|
|
|
71
|
|
|
$application->init(); |
|
|
|
|
|
|
72
|
|
|
$application->initMagento(); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$this->application = $application; |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $this->application; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return AdapterInterface |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getDatabaseConnection() |
|
84
|
|
|
{ |
|
85
|
|
|
$resource = $this->getApplication()->getObjectManager()->get(ResourceConnection::class); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
return $resource->getConnection('write'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: