File: MergerTest.php

package info (click to toggle)
phpunit 12.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 50,696 kB
  • sloc: php: 102,219; xml: 2,115; makefile: 124; sh: 99
file content (137 lines) | stat: -rw-r--r-- 6,039 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PHPUnit\TextUI\XmlConfiguration;

use function uniqid;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Medium;
use PHPUnit\Framework\Attributes\Ticket;
use PHPUnit\Framework\TestCase;
use PHPUnit\TextUI\CliArguments\Builder;
use PHPUnit\TextUI\Configuration\Merger;

#[CoversClass(Merger::class)]
#[Medium]
final class MergerTest extends TestCase
{
    public function testNoLoggingShouldOnlyAffectXmlConfiguration(): void
    {
        $junitLog = uniqid('junit_log_');
        $fromFile = (new Loader)->load(TEST_FILES_PATH . 'configuration_logging.xml');

        $this->assertTrue($fromFile->logging()->hasTeamCity());
        $this->assertTrue($fromFile->logging()->hasTestDoxHtml());
        $this->assertTrue($fromFile->logging()->hasTestDoxText());

        $this->assertTrue($fromFile->logging()->hasJunit());
        $this->assertNotSame($junitLog, $fromFile->logging()->junit()->target()->path());

        $fromCli = (new Builder)->fromParameters([
            '--no-logging',
            '--log-junit',
            $junitLog,
        ]);

        $mergedConfig = (new Merger)->merge($fromCli, $fromFile);

        $this->assertFalse($mergedConfig->hasLogfileTeamcity());
        $this->assertFalse($mergedConfig->hasLogfileTestdoxHtml());
        $this->assertFalse($mergedConfig->hasLogfileTestdoxText());

        $this->assertTrue($mergedConfig->hasLogfileJunit());
        $this->assertSame($junitLog, $mergedConfig->logfileJunit());
    }

    public function testNoCoverageShouldOnlyAffectXmlConfiguration(): void
    {
        $phpCoverage = uniqid('php_coverage_');
        $fromFile    = (new Loader)->load(TEST_FILES_PATH . 'configuration_codecoverage.xml');

        $this->assertTrue($fromFile->codeCoverage()->hasClover());
        $this->assertTrue($fromFile->codeCoverage()->hasCobertura());
        $this->assertTrue($fromFile->codeCoverage()->hasCrap4j());
        $this->assertTrue($fromFile->codeCoverage()->hasHtml());
        $this->assertTrue($fromFile->codeCoverage()->hasOpenClover());
        $this->assertTrue($fromFile->codeCoverage()->hasText());
        $this->assertTrue($fromFile->codeCoverage()->hasXml());

        $this->assertTrue($fromFile->codeCoverage()->hasPhp());
        $this->assertNotSame($phpCoverage, $fromFile->codeCoverage()->php()->target()->path());

        $fromCli = (new Builder)->fromParameters([
            '--no-coverage',
            '--coverage-php',
            $phpCoverage,
        ]);

        $mergedConfig = (new Merger)->merge($fromCli, $fromFile);

        $this->assertFalse($mergedConfig->hasCoverageClover());
        $this->assertFalse($mergedConfig->hasCoverageCobertura());
        $this->assertFalse($mergedConfig->hasCoverageCrap4j());
        $this->assertFalse($mergedConfig->hasCoverageHtml());
        $this->assertFalse($mergedConfig->hasCoverageOpenClover());
        $this->assertFalse($mergedConfig->hasCoverageText());
        $this->assertFalse($mergedConfig->hasCoverageXml());

        $this->assertTrue($mergedConfig->hasCoveragePhp());
        $this->assertSame($phpCoverage, $mergedConfig->coveragePhp());
    }

    #[Ticket('https://github.com/sebastianbergmann/phpunit/issues/6340')]
    public function testIssue6340(): void
    {
        $fromFile = (new Loader)->load(TEST_FILES_PATH . 'configuration-issue-6340.xml');

        $this->assertTrue($fromFile->phpunit()->failOnPhpunitDeprecation());
        $this->assertTrue($fromFile->phpunit()->failOnPhpunitNotice());
        $this->assertTrue($fromFile->phpunit()->failOnDeprecation());
        $this->assertTrue($fromFile->phpunit()->failOnNotice());
        $this->assertTrue($fromFile->phpunit()->failOnWarning());
        $this->assertTrue($fromFile->phpunit()->failOnIncomplete());
        $this->assertTrue($fromFile->phpunit()->failOnSkipped());

        $fromCli = (new Builder)->fromParameters([
            '--do-not-fail-on-phpunit-deprecation',
            '--do-not-fail-on-phpunit-notice',
            '--do-not-fail-on-deprecation',
            '--do-not-fail-on-notice',
            '--do-not-fail-on-warning',
            '--do-not-fail-on-incomplete',
            '--do-not-fail-on-skipped',
        ]);

        $this->assertTrue($fromCli->doNotFailOnPhpunitDeprecation());
        $this->assertTrue($fromCli->doNotFailOnPhpunitNotice());
        $this->assertTrue($fromCli->doNotFailOnDeprecation());
        $this->assertTrue($fromCli->doNotFailOnNotice());
        $this->assertTrue($fromCli->doNotFailOnWarning());
        $this->assertTrue($fromCli->doNotFailOnIncomplete());
        $this->assertTrue($fromCli->doNotFailOnSkipped());

        $mergedConfig = (new Merger)->merge($fromCli, $fromFile);

        $this->assertTrue($mergedConfig->doNotFailOnPhpunitDeprecation());
        $this->assertTrue($mergedConfig->doNotFailOnPhpunitNotice());
        $this->assertTrue($mergedConfig->doNotFailOnDeprecation());
        $this->assertTrue($mergedConfig->doNotFailOnNotice());
        $this->assertTrue($mergedConfig->doNotFailOnWarning());
        $this->assertTrue($mergedConfig->doNotFailOnIncomplete());
        $this->assertTrue($mergedConfig->doNotFailOnSkipped());

        $this->assertFalse($mergedConfig->displayDetailsOnPhpunitDeprecations());
        $this->assertFalse($mergedConfig->displayDetailsOnPhpunitNotices());
        $this->assertFalse($mergedConfig->displayDetailsOnTestsThatTriggerDeprecations());
        $this->assertFalse($mergedConfig->displayDetailsOnTestsThatTriggerNotices());
        $this->assertFalse($mergedConfig->displayDetailsOnTestsThatTriggerWarnings());
        $this->assertFalse($mergedConfig->displayDetailsOnIncompleteTests());
        $this->assertFalse($mergedConfig->displayDetailsOnSkippedTests());
    }
}