Passed
Push — main ( 2c83d5...fb3f8a )
by Siad
05:21
created

PearPkg2CompatibilityTest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
namespace Phing\Test\Regression;
21
22
use Exception;
23
use Phing\Test\Support\BuildFileTest;
24
25
/**
26
 * Regression test for tickets
27
 * http://www.phing.info/trac/ticket/524
28
 *
29
 * TODO: skip when user doesn't have pear installed (you cannot check for the class name, because
30
 *       it is included via composer)
31
 */
32
class PearPkg2CompatibilityTest extends BuildFileTest
33
{
34
    private $savedErrorLevel;
35
36
    public function setUp(): void
37
    {
38
        $this->savedErrorLevel = error_reporting();
39
        error_reporting(E_ERROR);
40
        $buildFile = PHING_TEST_BASE . "/etc/regression/524/build.xml";
41
        $this->configureProject($buildFile);
42
43
        if (!class_exists('PEAR_PackageFileManager', false)) {
44
            $this->markTestSkipped("This test requires PEAR_PackageFileManager to be installed");
45
        }
46
47
        $this->executeTarget("setup");
48
    }
49
50
    public function tearDown(): void
51
    {
52
        error_reporting($this->savedErrorLevel);
53
        $this->executeTarget("teardown");
54
    }
55
56
    protected function assertPreConditions(): void
57
    {
58
        try {
59
            $this->executeTarget("inactive");
60
        } catch (Exception $e) {
61
            if (strpos($e->getMessage(), 'Unknown channel') !== false) {
62
                $this->markTestSkipped($e->getMessage());
63
            }
64
        }
65
    }
66
67
    public function testInactiveMaintainers()
68
    {
69
        $this->executeTarget("inactive");
70
        $content = file_get_contents(PHING_TEST_BASE . '/etc/regression/524/out/package2.xml');
71
        $this->assertStringContainsString('<active>no</active>', $content);
72
    }
73
74
    public function testActiveMaintainers()
75
    {
76
        $this->executeTarget("active");
77
        $content = file_get_contents(PHING_TEST_BASE . '/etc/regression/524/out/package2.xml');
78
        $this->assertStringContainsString('<active>yes</active>', $content);
79
    }
80
81
    public function testNotSetMaintainers()
82
    {
83
        $this->executeTarget("notset");
84
        $content = file_get_contents(PHING_TEST_BASE . '/etc/regression/524/out/package2.xml');
85
        $this->assertStringContainsString('<active>yes</active>', $content);
86
    }
87
}
88