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

[ReflexiveTask] Fixed behavior, if file attribute points to a directory. #1537

Merged
merged 2 commits into from
Feb 14, 2021
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
7 changes: 6 additions & 1 deletion src/Phing/Task/System/ReflexiveTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ReflexiveTask extends Task

/**
* Single file to process.
* @var File
*/
private $file;

Expand All @@ -82,6 +83,10 @@ public function main()
throw new BuildException("You must specify a file or fileset(s) for the <reflexive> task.");
}

if ($this->file->isDirectory()) {
throw new BuildException('File cannot be a directory.');
}

// compile a list of all files to modify, both file attrib and fileset elements
// can be used.

Expand Down Expand Up @@ -133,7 +138,7 @@ public function main()
if ($in) {
$in->close();
}
$this->log("Erorr reading file: " . $e->getMessage(), Project::MSG_WARN);
$this->log("Error reading file: " . $e->getMessage(), Project::MSG_WARN);
}

try {
Expand Down
55 changes: 55 additions & 0 deletions tests/Phing/Task/System/ReflexiveTaskTest.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>.
*/

namespace Phing\Task\System;

use Phing\Project;
use Phing\Support\BuildFileTest;

/**
* Tests the Copy Task
*
* @author Siad Ardroumli <siad.ardroumli@gmail.com>
*/
class ReflexiveTaskTest extends BuildFileTest
{
public function setUp(): void
{
$this->configureProject(
PHING_TEST_BASE
. "/etc/tasks/system/ReflexiveTaskTest.xml"
);
$this->executeTarget("setup");
}

public function tearDown(): void
{
$this->executeTarget("clean");
}

public function test1()
{
$this->expectBuildException(__FUNCTION__, 'You must specify a file or fileset(s) for the <reflexive> task.');
}

public function test2()
{
$this->expectBuildException(__FUNCTION__, 'File cannot be a directory.');
}
}
22 changes: 22 additions & 0 deletions tests/etc/tasks/system/ReflexiveTaskTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="CopyTaskTest" default="main">
<property name="tmp.dir" value="tmp"/>

<target name="setup">
<mkdir dir="${tmp.dir}"/>
</target>

<target name="clean">
<delete dir="${tmp.dir}"/>
</target>

<target name="test1">
<reflexive/>
</target>

<target name="test2">
<reflexive file=""/>
</target>

<target name="main"/>
</project>