Added functional test

* The packager will throws exceptions when the output folder exists
This commit is contained in:
Walter Dal Mut 2015-05-26 10:15:42 +02:00
parent 248c14d301
commit 9ccde2227a
4 changed files with 140 additions and 31 deletions

View file

@ -19,7 +19,8 @@
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4"
"phpunit/phpunit": "~4",
"mikey179/vfsStream": "1.4.*"
},
"autoload": {
"psr-0": {

92
composer.lock generated
View file

@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "42aa3f85b9b2e12726c3a920256505a0",
"hash": "452e33232d90b29107daa9bb4740b3ea",
"packages": [],
"packages-dev": [
{
@ -61,6 +61,44 @@
],
"time": "2014-10-13 12:58:55"
},
{
"name": "mikey179/vfsStream",
"version": "v1.4.0",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "61b12172292cf539685507aa65b076c1530e83c1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mikey179/vfsStream/zipball/61b12172292cf539685507aa65b076c1530e83c1",
"reference": "61b12172292cf539685507aa65b076c1530e83c1",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"homepage": "http://vfs.bovigo.org/",
"time": "2014-09-14 10:18:53"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "2.0.4",
@ -112,16 +150,16 @@
},
{
"name": "phpspec/prophecy",
"version": "1.4.0",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5"
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5",
"reference": "8724cd239f8ef4c046f55a3b18b4d91cc7f3e4c5",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"shasum": ""
},
"require": {
@ -168,20 +206,20 @@
"spy",
"stub"
],
"time": "2015-03-27 19:31:25"
"time": "2015-04-27 22:15:08"
},
{
"name": "phpunit/php-code-coverage",
"version": "2.0.16",
"version": "2.0.17",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c"
"reference": "c4e8e7725e351184a76544634855b8a9c405a6e3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/934fd03eb6840508231a7f73eb8940cf32c3b66c",
"reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c4e8e7725e351184a76544634855b8a9c405a6e3",
"reference": "c4e8e7725e351184a76544634855b8a9c405a6e3",
"shasum": ""
},
"require": {
@ -230,7 +268,7 @@
"testing",
"xunit"
],
"time": "2015-04-11 04:35:00"
"time": "2015-05-25 05:11:59"
},
{
"name": "phpunit/php-file-iterator",
@ -418,16 +456,16 @@
},
{
"name": "phpunit/phpunit",
"version": "4.6.4",
"version": "4.6.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "163232991e652e6efed2f8470326fffa61e848e2"
"reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/163232991e652e6efed2f8470326fffa61e848e2",
"reference": "163232991e652e6efed2f8470326fffa61e848e2",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/57bf06dd4eebe2a5ced79a8de71509e7d5c18b25",
"reference": "57bf06dd4eebe2a5ced79a8de71509e7d5c18b25",
"shasum": ""
},
"require": {
@ -486,7 +524,7 @@
"testing",
"xunit"
],
"time": "2015-04-11 05:23:21"
"time": "2015-05-25 05:18:18"
},
{
"name": "phpunit/phpunit-mock-objects",
@ -916,17 +954,17 @@
},
{
"name": "symfony/yaml",
"version": "v2.6.6",
"version": "v2.6.7",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "174f009ed36379a801109955fc5a71a49fe62dd4"
"reference": "f157ab074e453ecd4c0fa775f721f6e67a99d9e2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/174f009ed36379a801109955fc5a71a49fe62dd4",
"reference": "174f009ed36379a801109955fc5a71a49fe62dd4",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/f157ab074e453ecd4c0fa775f721f6e67a99d9e2",
"reference": "f157ab074e453ecd4c0fa775f721f6e67a99d9e2",
"shasum": ""
},
"require": {
@ -951,18 +989,18 @@
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
"time": "2015-03-30 15:54:10"
"homepage": "https://symfony.com",
"time": "2015-05-02 15:18:45"
}
],
"aliases": [],

View file

@ -1,6 +1,7 @@
<?php
namespace wdm\debian;
use RuntimeException;
use wdm\debian\control\StandardFile;
class Packager
@ -109,13 +110,14 @@ class Packager
$iterator = new \DirectoryIterator($this->getOutputPath());
foreach ($iterator as $path) {
if ($path != '.' && $path != '..') {
echo "OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!" . PHP_EOL;
exit();
throw new RuntimeException("OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!");
}
}
}
mkdir($this->getOutputPath(), 0777);
if (!file_exists($this->getOutputPath())) {
mkdir($this->getOutputPath(), 0777);
}
foreach ($this->_mountPoints as $path => $dest) {
$this->_pathToPath($path, $this->getOutputPath() . DIRECTORY_SEPARATOR . $dest);

View file

@ -1,6 +1,8 @@
<?php
namespace wdm\debian;
use org\bovigo\vfs\vfsStream;
class PackagerTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
@ -22,4 +24,70 @@ class PackagerTest extends \PHPUnit_Framework_TestCase
$this->assertSame($control, $this->object->getControl());
}
/**
* @expectedException RuntimeException
* @expectedExceptionMessage OUTPUT DIRECTORY MUST BE EMPTY! Something exists, exit immediately!
*/
public function testOutputFolderIsNotEmpty()
{
$root = vfsStream::setup('root');
mkdir(vfsStream::url('root/tmp'));
file_put_contents(vfsStream::url('root/tmp/ciao.txt'), "ciao");
$this->object->setOutputPath(vfsStream::url('root/tmp'));
$control = new control\StandardFile();
$this->object->setControl($control);
$this->object->run();
}
public function testOutputFolderExistsButIsEmpty()
{
$root = vfsStream::setup('root');
mkdir(vfsStream::url('root/tmp'));
$this->object->setOutputPath(vfsStream::url('root/tmp'));
$control = new control\StandardFile();
$this->object->setControl($control);
$this->object->run();
$command = $this->object->build();
$this->assertEquals("dpkg -b vfs://root/tmp tmp.deb", $command);
}
public function testCreateDebWhenOutputFolderIsMissing()
{
$root = vfsStream::setup('root');
$this->object->setOutputPath(vfsStream::url('root/tmp'));
$control = new control\StandardFile();
$this->object->setControl($control);
$this->object->run();
$command = $this->object->build();
$this->assertEquals("dpkg -b vfs://root/tmp tmp.deb", $command);
}
public function testCreateDebPackageWithAnotherName()
{
$root = vfsStream::setup('root');
$this->object->setOutputPath(vfsStream::url('root/tmp'));
$control = new control\StandardFile();
$this->object->setControl($control);
$this->object->run();
$command = $this->object->build("myname.deb");
$this->assertEquals("dpkg -b vfs://root/tmp myname.deb", $command);
}
}