Skip to content

Commit

Permalink
Fixed FileUtils::contentEquals (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 authored and mrook committed Jan 29, 2018
1 parent 9e0498e commit 384d94f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
4 changes: 2 additions & 2 deletions classes/phing/util/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,11 @@ public function createTempFile($prefix, $suffix, PhingFile $parentDir, $deleteOn
*/
public function contentEquals(PhingFile $file1, PhingFile $file2)
{
if (!($file1->exists() || $file2->exists())) {
if (!($file1->exists() && $file2->exists())) {
return false;
}

if (!($file1->canRead() || $file2->canRead())) {
if (!($file1->canRead() && $file2->canRead())) {
return false;
}

Expand Down
57 changes: 57 additions & 0 deletions test/classes/phing/util/FileUtilsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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>.
*
* @package phing.util
*/

/**
* Testcases for phing.util.FileUtils
*
* @author Siad Ardroumli |siad.ardroumli@gmail.com>
* @package phing.util
*/
class FileUtilsTest extends BuildFileTest
{
/** @var FileUtils $fu */
private $fu;

public function setUp()
{
$this->fu = new FileUtils();
$this->configureProject(PHING_TEST_BASE . "/etc/util/fileutils.xml");
$this->executeTarget('dummy');
}

public function tearDown()
{
$this->fu = null;
}

/**
* @test
*/
public function contentEquals()
{
$this->assertFalse($this->fu->contentEquals(new PhingFile(__FILE__), new PhingFile('does_not_exists')));
$this->assertFalse($this->fu->contentEquals(new PhingFile('does_not_exists'), new PhingFile(__FILE__)));
$this->assertFalse($this->fu->contentEquals(new PhingFile(__DIR__), new PhingFile(__DIR__)));
$this->assertFalse($this->fu->contentEquals(new PhingFile(__FILE__), new PhingFile(__DIR__)));
$this->assertFalse($this->fu->contentEquals(new PhingFile(__DIR__), new PhingFile(__FILE__)));
$this->assertTrue($this->fu->contentEquals(new PhingFile(__FILE__), new PhingFile(__FILE__)));
}
}
7 changes: 7 additions & 0 deletions test/etc/util/fileutils.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<project name="fileutils-test" default="none">

<property name="tmp.dir" value="tmp"/>

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

0 comments on commit 384d94f

Please sign in to comment.