Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added coverage-* related test setup #1432

Merged
merged 1 commit into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}