Skip to content

Commit 7acdbd1

Browse files
authored
Merge pull request #6 from run-as-root/feature/#5-phpunit-bootstrap
Adds bootstrap file for the unit tests
2 parents fef5ca0 + c7a6a09 commit 7acdbd1

File tree

7 files changed

+149
-33
lines changed

7 files changed

+149
-33
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"magento/module-backend": ">=102.0.5",
1717
"magento/module-config": ">=101.2.5",
1818
"magento/module-ui": ">=101.2.5",
19-
"php-amqplib/php-amqplib": "^v3.2.0"
19+
"php-amqplib/php-amqplib": "^v3.2.0",
20+
"magento/framework-amqp": ">=100.4.3"
2021
},
2122
"require-dev": {
2223
"phpunit/phpunit": "~9.5.20",

composer.lock

+59-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/unit/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/phpunit.xml
2+
/var/allure-results/

dev/tests/unit/framework/autoload.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Magento\Framework\App\Filesystem\DirectoryList;
6+
use Magento\Framework\Code\Generator\Io;
7+
use Magento\Framework\Filesystem\Driver\File;
8+
use Magento\Framework\TestFramework\Unit\Autoloader\ExtensionAttributesGenerator;
9+
use Magento\Framework\TestFramework\Unit\Autoloader\ExtensionAttributesInterfaceGenerator;
10+
use Magento\Framework\TestFramework\Unit\Autoloader\FactoryGenerator;
11+
use Magento\Framework\TestFramework\Unit\Autoloader\GeneratedClassesAutoloader;
12+
13+
$generatorIo = new Io(
14+
new File(),
15+
TESTS_TEMP_DIR . '/' . DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_CODE][DirectoryList::PATH]
16+
);
17+
$generatedCodeAutoloader = new GeneratedClassesAutoloader(
18+
[
19+
new ExtensionAttributesGenerator(),
20+
new ExtensionAttributesInterfaceGenerator(),
21+
new FactoryGenerator(),
22+
],
23+
$generatorIo
24+
);
25+
spl_autoload_register([$generatedCodeAutoloader, 'load']);
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Magento\Framework\Phrase;
6+
use Magento\Framework\Phrase\Renderer\Placeholder;
7+
use PHPUnit\Framework\Exception;
8+
9+
if (!defined('TESTS_TEMP_DIR')) {
10+
define('TESTS_TEMP_DIR', dirname(__DIR__) . '/tmp');
11+
}
12+
13+
require_once __DIR__ . '/autoload.php';
14+
15+
setCustomErrorHandler();
16+
17+
Phrase::setRenderer(new Placeholder());
18+
19+
error_reporting(E_ALL);
20+
ini_set('display_errors', 1);
21+
22+
/* For data consistency between displaying (printing) and serialization a float number */
23+
ini_set('precision', 14);
24+
ini_set('serialize_precision', 14);
25+
26+
function setCustomErrorHandler(): void
27+
{
28+
set_error_handler(
29+
callback: function ($errNo, $errStr, $errFile, $errLine) {
30+
$errLevel = error_reporting();
31+
if (($errLevel & $errNo) !== 0) {
32+
$errorNames = [
33+
E_ERROR => 'Error',
34+
E_WARNING => 'Warning',
35+
E_PARSE => 'Parse',
36+
E_NOTICE => 'Notice',
37+
E_CORE_ERROR => 'Core Error',
38+
E_CORE_WARNING => 'Core Warning',
39+
E_COMPILE_ERROR => 'Compile Error',
40+
E_COMPILE_WARNING => 'Compile Warning',
41+
E_USER_ERROR => 'User Error',
42+
E_USER_WARNING => 'User Warning',
43+
E_USER_NOTICE => 'User Notice',
44+
E_STRICT => 'Strict',
45+
E_RECOVERABLE_ERROR => 'Recoverable Error',
46+
E_DEPRECATED => 'Deprecated',
47+
E_USER_DEPRECATED => 'User Deprecated',
48+
];
49+
50+
$errName = $errorNames[$errNo] ?? "";
51+
52+
$message = "$errName: $errStr in $errFile:$errLine.";
53+
throw new Exception($message, $errNo);
54+
}
55+
}
56+
);
57+
}

dev/tests/unit/tmp/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*
2+
!/.gitignore

phpunit.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.5/phpunit.xsd"
44
colors="true"
55
columns="max"
6-
beStrictAboutTestsThatDoNotTestAnything="false">
6+
beStrictAboutTestsThatDoNotTestAnything="false"
7+
bootstrap="./dev/tests/unit/framework/bootstrap.php">
78
<testsuite name="Unit Test Suite">
89
<directory suffix="Test.php">./src/Test/Unit</directory>
910
</testsuite>

0 commit comments

Comments
 (0)