Skip to content

Commit 1cd43f8

Browse files
committed
Unittests for log bugfixes
check log directory existence fix styleci issues fix style ci issues remove .Log from gitignore fix style ci issues
1 parent a80b5d7 commit 1cd43f8

File tree

7 files changed

+97
-32
lines changed

7 files changed

+97
-32
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.Build
22
/.idea
33
composer.lock
4+
.phpunit.result.cache

src/PhpunitMerger/Command/LogCommand.php

+18-30
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LogCommand extends Command
2222
*/
2323
private $domElements = [];
2424

25-
private $keysToCalculate = ["assertions", "time", "tests", "errors", "failures", "skipped"];
25+
private $keysToCalculate = ['assertions', 'time', 'tests', 'errors', 'failures', 'skipped'];
2626

2727
protected function configure()
2828
{
@@ -44,36 +44,35 @@ protected function execute(InputInterface $input, OutputInterface $output)
4444
{
4545
$finder = new Finder();
4646
$finder->files()
47-
->in(realpath($input->getArgument('directory')));
47+
->in(realpath($input->getArgument('directory')))->sortByName(true);
4848

4949
$this->document = new \DOMDocument('1.0', 'UTF-8');
5050
$this->document->formatOutput = true;
5151

5252
$root = $this->document->createElement('testsuites');
5353
$baseSuite = $this->document->createElement('testsuite');
54-
$baseSuite->setAttribute('name', "All Suites");
55-
$baseSuite->setAttribute('tests', "0");
56-
$baseSuite->setAttribute('assertions', "0");
57-
$baseSuite->setAttribute('errors', "0");
58-
$baseSuite->setAttribute('failures', "0");
59-
$baseSuite->setAttribute('skipped', "0");
60-
$baseSuite->setAttribute('time', "0");
54+
$baseSuite->setAttribute('name', 'All Suites');
55+
$baseSuite->setAttribute('tests', '0');
56+
$baseSuite->setAttribute('assertions', '0');
57+
$baseSuite->setAttribute('errors', '0');
58+
$baseSuite->setAttribute('failures', '0');
59+
$baseSuite->setAttribute('skipped', '0');
60+
$baseSuite->setAttribute('time', '0');
6161

62-
$this->domElements["All Suites"] = $baseSuite;
62+
$this->domElements['All Suites'] = $baseSuite;
6363

6464
$root->appendChild($baseSuite);
6565
$this->document->appendChild($root);
6666

6767
foreach ($finder as $file) {
6868
try {
6969
$xml = new \SimpleXMLElement(file_get_contents($file->getRealPath()));
70-
$code = json_encode($xml);
7170
$xmlArray = json_decode(json_encode($xml), true);
7271
if (!empty($xmlArray)) {
7372
$this->addTestSuites($baseSuite, $xmlArray);
7473
}
7574
} catch (\Exception $exception) {
76-
$output->writeln(sprintf("<error>Error in file %s: %s</error>", $file->getRealPath(), $exception->getMessage()));
75+
$output->writeln(sprintf('<error>Error in file %s: %s</error>', $file->getRealPath(), $exception->getMessage()));
7776
}
7877
}
7978

@@ -151,41 +150,30 @@ private function addTestCases(\DOMElement $parent, array $testCases)
151150
$this->domElements[$name] = $element;
152151
}
153152
}
153+
154154
private function addChildElements(array $tree, \DOMElement $element)
155155
{
156156
foreach ($tree as $key => $value) {
157-
if ($key == "@attributes") {
157+
if ($key == '@attributes') {
158158
continue;
159159
}
160160
$child = $this->document->createElement($key);
161161
$child->nodeValue = $value;
162162
$element->appendChild($child);
163163
}
164164
}
165-
private function addAttributeValueToTestSuite(\DOMElement $element, $key, $value)
166-
{
167-
if (in_array($key, $this->keysToCalculate)) {
168-
$currentValue = $element->hasAttribute($key) ? $element->getAttribute($key) : 0;
169-
$element->setAttribute($key, (string)($currentValue + $value));
170-
171-
if ($element->hasAttribute('parent')) {
172-
$parent = $element->getAttribute('parent');
173-
if (isset($this->domElements[$parent])) {
174-
$this->addAttributeValueToTestSuite($this->domElements[$parent], $key, $value);
175-
}
176-
}
177-
}
178-
}
179165

180166
private function calculateTopLevelStats()
181167
{
182168
/** @var \DOMElement $topNode */
183-
$suites = $this->document->getElementsByTagName("testsuites")->item(0);
169+
$suites = $this->document->getElementsByTagName('testsuites')->item(0);
184170
$topNode = $suites->firstChild;
185171
if ($topNode->hasChildNodes()) {
186172
$stats = array_flip($this->keysToCalculate);
187-
$stats = array_map(function ($_value) { return 0; }, $stats);
188-
foreach($topNode->childNodes as $child) {
173+
$stats = array_map(function ($_value) {
174+
return 0;
175+
}, $stats);
176+
foreach ($topNode->childNodes as $child) {
189177
$attributes = $child->attributes;
190178
foreach ($attributes as $key => $value) {
191179
if (in_array($key, $this->keysToCalculate)) {

tests/PhpunitMerger/Command/AbstractCommandTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ abstract class AbstractCommandTest extends TestCase
2222
public function assertOutputFileNotExists()
2323
{
2424
$filesystem = new Filesystem();
25+
self::assertDirectoryExists($this->logDirectory, $this->logDirectory . ' does not exists');
2526
$filesystem->remove($this->logDirectory . $this->outputFile);
2627

2728
$this->assertFileNotExists($this->logDirectory . $this->outputFile);
2829
}
2930

3031
public function assertOutputDirectoryNotExists()
3132
{
33+
self::assertDirectoryExists($this->logDirectory, $this->logDirectory . ' does not exists');
3234
$filesystem = new Filesystem();
3335
$filesystem->remove($this->logDirectory . dirname($this->outputFile));
3436

tests/PhpunitMerger/Command/Log/LogCommandTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class LogCommandTest extends AbstractCommandTest
1616
*/
1717
protected $outputFile = 'log.xml';
1818

19-
public function testRunMergesCoverage()
19+
public function testRunMergesLogs()
2020
{
2121
$this->assertOutputFileNotExists();
2222

2323
$input = new ArgvInput(
2424
[
2525
'log',
26-
$this->logDirectory . 'log/',
26+
__DIR__ . '/datasets/',
2727
$this->logDirectory . $this->outputFile,
2828
]
2929
);
@@ -33,5 +33,6 @@ public function testRunMergesCoverage()
3333
$command->run($input, $output->reveal());
3434

3535
$this->assertFileExists($this->logDirectory . $this->outputFile);
36+
self::assertXmlFileEqualsXmlFile(__DIR__ . '/expected_merge.xml', $this->logDirectory . $this->outputFile);
3637
}
3738
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="" tests="2" assertions="3" errors="0" failures="0" skipped="0" time="8.728057">
4+
<testsuite name="Integration Tests" tests="2" assertions="3" errors="0" failures="0" skipped="0" time="8.728057">
5+
<testsuite name="ForestsoftMerchant\tests\functional\Components\FTPFiles\FTPFilesOrderImportNotificationTest" file="/var/www/html/custom/project/ForestsoftMerchant/tests/functional/Components/FTPFiles/FTPFilesOrderImportNotificationTest.php" tests="2" assertions="3" errors="0" failures="0" skipped="0" time="0.032107">
6+
<testcase name="test__toString" class="ForestsoftMerchant\tests\functional\Components\FTPFiles\FTPFilesOrderImportNotificationTest" classname="ForestsoftMerchant.tests.functional.Components.FTPFiles.FTPFilesOrderImportNotificationTest" file="/var/www/html/custom/project/ForestsoftMerchant/tests/functional/Components/FTPFiles/FTPFilesOrderImportNotificationTest.php" line="13" assertions="1" time="0.006198"/>
7+
<testcase name="test__toString_with_ordermessages" class="ForestsoftMerchant\tests\functional\Components\FTPFiles\FTPFilesOrderImportNotificationTest" classname="ForestsoftMerchant.tests.functional.Components.FTPFiles.FTPFilesOrderImportNotificationTest" file="/var/www/html/custom/project/ForestsoftMerchant/tests/functional/Components/FTPFiles/FTPFilesOrderImportNotificationTest.php" line="22" assertions="2" time="0.025909"/>
8+
</testsuite>
9+
</testsuite>
10+
</testsuite>
11+
</testsuites>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="" tests="6" assertions="6" errors="0" failures="1" skipped="5" time="10.119620">
4+
<testsuite name="Unit Tests" tests="6" assertions="6" errors="0" failures="1" skipped="5" time="10.119620">
5+
<testsuite name="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" tests="4" assertions="5" errors="0" failures="0" skipped="0" time="0.077074">
6+
<testcase name="should_skip_install_mail_model_if_it_exist" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="105" assertions="2" time="0.066342"/>
7+
<testcase name="should_install_mail_model" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="90" assertions="1" time="0.004449"/>
8+
<testcase name="test_should_return_schema_tool" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="118" assertions="1" time="0.001749"/>
9+
<testcase name="test_install_should_create_tables" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="61" assertions="1" time="0.004534"/>
10+
</testsuite>
11+
<testsuite name="CasProductLabels\Tests\Unit\Components\PDFLabelTest" file="/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php" tests="2" assertions="1" errors="0" failures="1" skipped="0" time="0.104663">
12+
<testcase name="testCanCreatedByDI" class="CasProductLabels\Tests\Unit\Components\PDFLabelTest" classname="CasProductLabels.Tests.Unit.Components.PDFLabelTest" file="/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php" line="49" assertions="1" time="0.003620"/>
13+
<testcase name="testGenerate" class="CasProductLabels\Tests\Unit\Components\PDFLabelTest" classname="CasProductLabels.Tests.Unit.Components.PDFLabelTest" file="/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php" line="33" assertions="0" time="0.101043">
14+
<failure type="PHPUnit\Framework\ExpectationFailedException">
15+
CasProductLabels\Tests\Unit\Components\PDFLabelTest::testGenerate
16+
Expectation failed for method name is equal to 'createRenderer' when invoked 1 time(s)
17+
Parameter 1 for invocation CasProductLabels\Components\RendererFactory::createRenderer(Shopware\Models\Document\Document Object (...), '&lt;!DOCTYPE html PUBLIC "-//W3C...tml&gt;\n', false): CasProductLabels\Components\PDFRenderer does not match expected value.
18+
Failed asserting that a traversable contains '&lt;html&gt;'.
19+
20+
/var/www/html/custom/project/CasProductLabels/Components/PDFLabel.php:152
21+
/var/www/html/custom/project/CasProductLabels/Components/PDFLabel.php:95
22+
/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php:45
23+
</failure>
24+
</testcase>
25+
</testsuite>
26+
</testsuite>
27+
</testsuite>
28+
</testsuites>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="All Suites" tests="8" assertions="9" errors="0" failures="1" skipped="5" time="18.847677">
4+
<testsuite name="Integration Tests" tests="2" assertions="3" errors="0" failures="0" skipped="0" time="8.728057">
5+
<testsuite name="ForestsoftMerchant\tests\functional\Components\FTPFiles\FTPFilesOrderImportNotificationTest" file="/var/www/html/custom/project/ForestsoftMerchant/tests/functional/Components/FTPFiles/FTPFilesOrderImportNotificationTest.php" tests="2" assertions="3" errors="0" failures="0" skipped="0" time="0.032107">
6+
<testcase name="test__toString" class="ForestsoftMerchant\tests\functional\Components\FTPFiles\FTPFilesOrderImportNotificationTest" classname="ForestsoftMerchant.tests.functional.Components.FTPFiles.FTPFilesOrderImportNotificationTest" file="/var/www/html/custom/project/ForestsoftMerchant/tests/functional/Components/FTPFiles/FTPFilesOrderImportNotificationTest.php" line="13" assertions="1" time="0.006198"/>
7+
<testcase name="test__toString_with_ordermessages" class="ForestsoftMerchant\tests\functional\Components\FTPFiles\FTPFilesOrderImportNotificationTest" classname="ForestsoftMerchant.tests.functional.Components.FTPFiles.FTPFilesOrderImportNotificationTest" file="/var/www/html/custom/project/ForestsoftMerchant/tests/functional/Components/FTPFiles/FTPFilesOrderImportNotificationTest.php" line="22" assertions="2" time="0.025909"/>
8+
</testsuite>
9+
</testsuite>
10+
<testsuite name="Unit Tests" tests="6" assertions="6" errors="0" failures="1" skipped="5" time="10.119620">
11+
<testsuite name="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" tests="4" assertions="5" errors="0" failures="0" skipped="0" time="0.077074">
12+
<testcase name="should_skip_install_mail_model_if_it_exist" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="105" assertions="2" time="0.066342"/>
13+
<testcase name="should_install_mail_model" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="90" assertions="1" time="0.004449"/>
14+
<testcase name="test_should_return_schema_tool" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="118" assertions="1" time="0.001749"/>
15+
<testcase name="test_install_should_create_tables" class="ForestsoftOrderBenchmark\Tests\Unit\InstallerTest" classname="ForestsoftOrderBenchmark.Tests.Unit.InstallerTest" file="/var/www/html/custom/project/ForestsoftOrderBenchmark/Tests/Unit/InstallerTest.php" line="61" assertions="1" time="0.004534"/>
16+
</testsuite>
17+
<testsuite name="CasProductLabels\Tests\Unit\Components\PDFLabelTest" file="/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php" tests="2" assertions="1" errors="0" failures="1" skipped="0" time="0.104663">
18+
<testcase name="testCanCreatedByDI" class="CasProductLabels\Tests\Unit\Components\PDFLabelTest" classname="CasProductLabels.Tests.Unit.Components.PDFLabelTest" file="/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php" line="49" assertions="1" time="0.003620"/>
19+
<testcase name="testGenerate" class="CasProductLabels\Tests\Unit\Components\PDFLabelTest" classname="CasProductLabels.Tests.Unit.Components.PDFLabelTest" file="/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php" line="33" assertions="0" time="0.101043">
20+
<failure>
21+
CasProductLabels\Tests\Unit\Components\PDFLabelTest::testGenerate
22+
Expectation failed for method name is equal to 'createRenderer' when invoked 1 time(s)
23+
Parameter 1 for invocation CasProductLabels\Components\RendererFactory::createRenderer(Shopware\Models\Document\Document Object (...), '&lt;!DOCTYPE html PUBLIC "-//W3C...tml&gt;\n', false): CasProductLabels\Components\PDFRenderer does not match expected value.
24+
Failed asserting that a traversable contains '&lt;html&gt;'.
25+
26+
/var/www/html/custom/project/CasProductLabels/Components/PDFLabel.php:152
27+
/var/www/html/custom/project/CasProductLabels/Components/PDFLabel.php:95
28+
/var/www/html/custom/project/CasProductLabels/Tests/Unit/Components/PDFLabelTest.php:45
29+
</failure>
30+
</testcase>
31+
</testsuite>
32+
</testsuite>
33+
</testsuite>
34+
</testsuites>

0 commit comments

Comments
 (0)