Skip to content

Commit

Permalink
Merge 9f9b3b0 into 4821714
Browse files Browse the repository at this point in the history
  • Loading branch information
mhor committed Mar 23, 2014
2 parents 4821714 + 9f9b3b0 commit c6853c5
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 35 deletions.
4 changes: 2 additions & 2 deletions phpunit.xml.dist
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<phpunit bootstrap="./test/bootstrap.php" colors="true">
<testsuites>
<testsuite name="test suite">
<directory suffix="Test.php">./tests</directory>
<directory suffix="Test.php">./test</directory>
</testsuite>
</testsuites>
<filter>
Expand Down
42 changes: 18 additions & 24 deletions src/AlreadyExtract/Checker/AlreadyExtractChecker.php
Expand Up @@ -7,9 +7,14 @@
class AlreadyExtractChecker
{
/**
* @var int
* @var float
*/
protected $averageTolerance = 20;
protected $maxTolerance = 1.45;

/**
* @var float
*/
protected $minTolerance = 0.1;

/**
* @var Filesystem
Expand Down Expand Up @@ -43,21 +48,16 @@ public function isAlreadyExtracted()
return 2;
}

/*
* TODO Not Implemented -----------------------------------------------
*/
$archiveSize = $this->archiveFile;
$archiveSize = filesize($this->archiveFile);

$maxSize = "0";
$minSize = "1";
$maxSize = $archiveSize * $this->maxTolerance;
$minSize = $archiveSize - ($archiveSize * $this->minTolerance);

$extractDirSize = $this->getDirectorySize($guessedDirectory);
if ($extractDirSize < $minSize || $extractDirSize > $maxSize) {
return 1;
}

//---------------------------------------------------------------------

return 0;
}

Expand All @@ -81,14 +81,6 @@ protected function getDirectorySize($path)
return $totalBytes;
}

/**
* @return string
*/
public function getArchiveFile()
{
return $this->archiveFile;
}

/**
* @param string $archiveFile
* @return AlreadyExtractChecker
Expand All @@ -100,20 +92,22 @@ public function setArchiveFile($archiveFile)
}

/**
* @return int
* @param float $maxTolerance
* @return AlreadyExtractChecker
*/
protected function getAverageTolerance()
public function setMaxTolerance($maxTolerance)
{
return $this->averageTolerance;
$this->maxTolerance = $maxTolerance;
return $this;
}

/**
* @param int $averageTolerance
* @param float $minTolerance
* @return AlreadyExtractChecker
*/
public function setAverageTolerance($averageTolerance)
public function setMinTolerance($minTolerance)
{
$this->averageTolerance = $averageTolerance;
$this->minTolerance = $minTolerance;
return $this;
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/AlreadyExtract/Command/AlreadyExtractCommand.php
Expand Up @@ -13,6 +13,16 @@

class AlreadyExtractCommand extends Command
{
/**
* @var int
*/
protected $countError = 0;

/**
* @var int
*/
protected $countWarning = 0;

/**
* @var array
*/
Expand Down Expand Up @@ -56,6 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$checker->isAlreadyExtracted()
);
}
$output->writeln("Warnings: " . $this->countWarning . " Errors: " . $this->countError);
}

/**
Expand All @@ -68,9 +79,11 @@ protected function writeOutput($filePath, OutputInterface $output, $level=0)
switch ($level) {
case 1:
$output->writeln("<comment>Warning: file " . $filePath . " looks weird</comment>");
$this->countWarning++;
break;
case 2:
$output->writeln("<error>Error: file " . $filePath . " might be not extracted</error>");
$this->countError++;
break;
}
}
Expand Down
9 changes: 0 additions & 9 deletions test/AlreadyExist/Command/AlreadyExistCommandTest.php

This file was deleted.

61 changes: 61 additions & 0 deletions test/AlreadyExtract/Checker/AlreadyExtractCheckerTest.php
@@ -0,0 +1,61 @@
<?php

namespace AlreadyExtract\Checker;


class AlreadyExtractCheckerTest extends \PHPUnit_Framework_TestCase
{

protected $archivesDir;

protected $successArchive = 'a.zip';

protected $warningArchive = 'b.zip';

protected $errorArchive = 'c.zip';

protected $tooBigArchive = 'd.zip';

public function __construct()
{
$this->archivesDir = __DIR__ . '/../../testArchive/';
}

public function testSuccessIfArchiveIsAlreadyExtract()
{
$checker = new AlreadyExtractChecker();
$checker->setArchiveFile($this->archivesDir . $this->successArchive);
$this->assertEquals(0, $checker->isAlreadyExtracted());
}

public function testWarningIfExtractedDirectoryIsLowerThanArchive()
{
$checker = new AlreadyExtractChecker();
$checker->setArchiveFile($this->archivesDir . $this->warningArchive);
$this->assertEquals(1, $checker->isAlreadyExtracted());
}

public function testErrorIfArchiveINotExtract()
{
$checker = new AlreadyExtractChecker();
$checker->setArchiveFile($this->archivesDir . $this->errorArchive);
$this->assertEquals(2, $checker->isAlreadyExtracted());
}

public function testSuccessIfToleranceIsLow()
{
$checker = new AlreadyExtractChecker();
$checker->setMinTolerance(0.99);
$checker->setArchiveFile($this->archivesDir . $this->warningArchive);
$this->assertEquals(0, $checker->isAlreadyExtracted());
}

public function testSuccessIfMaxToleranceIsHigh()
{
$checker = new AlreadyExtractChecker();
$checker->setMaxTolerance(2);
$checker->setArchiveFile($this->archivesDir . $this->tooBigArchive);
$this->assertEquals(0, $checker->isAlreadyExtracted());
}
}

12 changes: 12 additions & 0 deletions test/AlreadyExtract/Command/AlreadyExtractCommandTest.php
@@ -0,0 +1,12 @@
<?php

namespace AlreadyExtract\Command;

class AlreadyExtractCommandTest extends \PHPUnit_Framework_TestCase
{
public function testFake()
{
$this->assertEquals(0, 0);
}
}

Binary file added test/testArchive/a.zip
Binary file not shown.
Binary file added test/testArchive/a/fake.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/testArchive/b.zip
Binary file not shown.
20 changes: 20 additions & 0 deletions test/testArchive/b/LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 Maxime Horcholle

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file added test/testArchive/c.zip
Binary file not shown.
Binary file added test/testArchive/d.zip
Binary file not shown.
Binary file added test/testArchive/d/copy of fake.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/testArchive/d/fake.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c6853c5

Please sign in to comment.