Passed
Push — main ( f8c128...609b6a )
by Siad
05:26
created

PharPackageTaskTest::testPharPackage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Test\Task\System;
22
23
use Phar;
24
use Phing\Test\Support\BuildFileTest;
25
26
/**
27
 * Tests for PharPackageTask.
28
 *
29
 * @author François Poirotte <[email protected]>
30
 */
31
class PharPackageTaskTest extends BuildFileTest
32
{
33
    public function setUp(): void
34
    {
35
        if ('1' == ini_get('phar.readonly')) {
36
            $this->markTestSkipped('This test require phar.readonly php.ini setting to be disabled');
37
        }
38
39
        $this->configureProject(PHING_TEST_BASE . '/etc/tasks/system/pharpackage/build.xml');
40
    }
41
42
    public function tearDown(): void
43
    {
44
        @unlink(PHING_TEST_BASE . '/etc/tasks/system/pharpackage/priv.key');
45
        @unlink(PHING_TEST_BASE . '/etc/tasks/system/pharpackage/pharpackage.phar.pubkey');
46
        @unlink(PHING_TEST_BASE . '/etc/tasks/system/pharpackage/pass.txt');
47
        @unlink(PHING_TEST_BASE . '/etc/tasks/system/pharpackage/pharpackage.phar');
48
        @unlink(PHING_TEST_BASE . '/etc/tasks/system/pharpackage/package.phar');
49
    }
50
51
    public function testPharPackage(): void
52
    {
53
        $this->executeTarget(__FUNCTION__);
54
55
        $dest = PHING_TEST_BASE . '/etc/tasks/system/pharpackage/package.phar';
56
        $this->assertFileExists($dest);
57
        $this->assertLogLineContaining('Building package');
58
    }
59
60
    public function testOpenSSLSignature(): void
61
    {
62
        // Generate a private key on the fly.
63
        $passphrase = uniqid('', true);
64
        $passfile = PHING_TEST_BASE . '/etc/tasks/system/pharpackage/pass.txt';
65
        file_put_contents($passfile, $passphrase);
66
        $pkey = openssl_pkey_new();
67
        openssl_pkey_export_to_file(
68
            $pkey,
69
            PHING_TEST_BASE . '/etc/tasks/system/pharpackage/priv.key',
70
            $passphrase
71
        );
72
        $this->executeTarget(__FUNCTION__);
73
74
        // Make sure we are dealing with an OpenSSL signature.
75
        // (Phar silently falls back to an SHA1 signature
76
        // whenever it fails to add an OpenSSL signature)
77
        $dest = PHING_TEST_BASE . '/etc/tasks/system/pharpackage/pharpackage.phar';
78
        $this->assertFileExists($dest);
79
        $phar = new Phar($dest);
80
        $signature = $phar->getSignature();
81
        $this->assertEquals('OpenSSL', $signature['hash_type']);
82
    }
83
}
84