Skip to content

Commit

Permalink
Added coverage merge test (#1432)
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 authored Nov 14, 2020
1 parent 0c03f01 commit e5b487f
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/classes/phing/tasks/ext/CoverageMergeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/

/**
* @author Siad Ardroumli <siad.ardroumli@gmail.com>
* @package phing.tasks.ext
*/
class CoverageMergeTest extends BuildFileTest
{
public function setUp(): void
{
if (!file_exists(PHING_TEST_BASE . "/etc/tasks/ext/coverage/workspace")) {
mkdir(PHING_TEST_BASE . "/etc/tasks/ext/coverage/workspace");
}
$this->configureProject(PHING_TEST_BASE . "/etc/tasks/ext/coverage/build.xml");
}

public function tearDown(): void
{
$this->rmdir(PHING_TEST_BASE . "/etc/tasks/ext/coverage/workspace");
}

public function testCoverage(): void
{
$workspace = PHING_TEST_BASE . "/etc/tasks/ext/coverage/workspace";
$this->executeTarget('collect');
$this->assertFileExists($workspace . '/1/clover-coverage.xml');
$this->assertFileExists($workspace . '/2/clover-coverage.xml');
$this->assertFileExists($workspace . '/3/clover-coverage.xml');
$this->assertFileExists($workspace . '/output.xml');
$this->assertFileExists($workspace . '/test.db');
$this->assertFileExists($workspace . '/test-results1.xml');
$this->assertFileExists($workspace . '/test-results2.xml');
$this->assertFileExists($workspace . '/test-results3.xml');
$this->assertStringContainsString('Dummy1Test.php', file_get_contents($workspace . '/test.db'));
$this->assertStringContainsString('Dummy2Test.php', file_get_contents($workspace . '/test.db'));
$this->assertStringContainsString('Dummy3Test.php', file_get_contents($workspace . '/test.db'));
}
}
59 changes: 59 additions & 0 deletions test/etc/tasks/ext/coverage/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>

<!--
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
~ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
~ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
~ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
~ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
~ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
~ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
~ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
~ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
~ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~
~ This software consists of voluntary contributions made by many individuals
~ and is licensed under the LGPL. For more information please see
~ <http://phing.info>.
-->

<project name="Coverage Build Tests" default="main" basedir=".">
<resolvepath propertyName="workspace" path="${phing.dir}/workspace" />
<property name="test" value="${workspace}/test.db" />
<property name="output" value="${workspace}/output.xml" />

<target name="collect">
<coverage-setup database="${test}">
<fileset dir="${phing.dir}" includes="**/test/*"/>
</coverage-setup>
<phpunit codecoverage="true">
<formatter type="xml" todir="${workspace}" outfile="test-results1.xml"/>
<formatter type="clover" todir="${workspace}/1"/>
<formatter type="plain" usefile="false"/>
<batchtest>
<fileset dir="${phing.dir}" includes="test-1/test/*"/>
</batchtest>
</phpunit>
<phpunit codecoverage="true">
<formatter type="xml" todir="${workspace}" outfile="test-results2.xml"/>
<formatter type="clover" todir="${workspace}/2"/>
<formatter type="plain" usefile="false"/>
<batchtest>
<fileset dir="${phing.dir}" includes="test-2/test/*"/>
</batchtest>
</phpunit>
<phpunit codecoverage="true">
<formatter type="xml" todir="${workspace}" outfile="test-results3.xml"/>
<formatter type="clover" todir="${workspace}/3"/>
<formatter type="plain" usefile="false"/>
<batchtest>
<fileset dir="${phing.dir}" includes="test-3/test/*"/>
</batchtest>
</phpunit>
<coverage-report outfile="${output}"/>
</target>
<target name="main">
<echo msg="Use this test inside the phing test suite."/>
</target>
</project>
17 changes: 17 additions & 0 deletions test/etc/tasks/ext/coverage/test-1/src/Dummy1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Dummy1
{
/** @var mixed */
private $arg;

public function __construct($arg)
{
$this->arg = $arg;
}

public function result()
{
return $this->arg;
}
}
13 changes: 13 additions & 0 deletions test/etc/tasks/ext/coverage/test-1/test/Dummy1Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

include __DIR__ . '/../src/Dummy1.php';

use PHPUnit\Framework\TestCase;

class Dummy1Test extends TestCase
{
public function testDummy1()
{
$this->assertSame('foo', (new Dummy1('foo'))->result());
}
}
17 changes: 17 additions & 0 deletions test/etc/tasks/ext/coverage/test-2/src/Dummy2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Dummy2
{
/** @var mixed */
private $arg;

public function __construct($arg)
{
$this->arg = $arg;
}

public function result()
{
return $this->arg;
}
}
13 changes: 13 additions & 0 deletions test/etc/tasks/ext/coverage/test-2/test/Dummy2Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

include __DIR__ . '/../src/Dummy2.php';

use PHPUnit\Framework\TestCase;

class Dummy2Test extends TestCase
{
public function testDummy1()
{
$this->assertSame('foo', (new Dummy1('foo'))->result());
}
}
17 changes: 17 additions & 0 deletions test/etc/tasks/ext/coverage/test-3/src/Dummy3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Dummy3
{
/** @var mixed */
private $arg;

public function __construct($arg)
{
$this->arg = $arg;
}

public function result()
{
return $this->arg;
}
}
13 changes: 13 additions & 0 deletions test/etc/tasks/ext/coverage/test-3/test/Dummy3Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

include __DIR__ . '/../src/Dummy3.php';

use PHPUnit\Framework\TestCase;

class Dummy3Test extends TestCase
{
public function testDummy3()
{
$this->assertSame('foo', (new Dummy1('foo'))->result());
}
}

0 comments on commit e5b487f

Please sign in to comment.