Skip to content

Commit

Permalink
Updated packages and correctly check if file got written, closes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
thelfensdrfer committed Apr 24, 2017
1 parent 4cb49e2 commit 11f0b3f
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 149 deletions.
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
],
"minimum-stability": "stable",
"require": {
"php": ">= 5.5.9",
"vierbergenlars/php-semver": "3.0.*",
"desarrolla2/cache": "2.1.*",
"monolog/monolog": "~1.21"
"monolog/monolog": "1.21.*",
"php": ">= 5.6.4",
"vierbergenlars/php-semver": "3.0.*"
},
"require-dev": {
"phpunit/phpunit": "4.8.*"
"phpunit/phpunit": "6.1.*"
},
"autoload": {
"psr-4": {
"VisualAppeal\\": "src/"
}
},
"config": {
"sort-packages": true
}
}
2 changes: 1 addition & 1 deletion src/AutoUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ protected function _install($updateFile, $simulateInstall, $version)
}
} else {
// touch will fail if PHP is not the owner of the file, and file_put_contents is faster than touch.
if (!file_put_contents($absoluteFilename)) {
if (file_put_contents($absoluteFilename, '') === false) {
$this->_log->addError(sprintf('[SIMULATE] The file "%s" could not be created!', $absoluteFilename));
zip_close($zip);

Expand Down
292 changes: 148 additions & 144 deletions tests/AutoUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,150 +2,154 @@

require(__DIR__ . '/../vendor/autoload.php');

use \VisualAppeal\AutoUpdate;
use PHPUnit\Framework\TestCase;
use VisualAppeal\AutoUpdate;

class AutoUpdateTest extends PHPUnit_Framework_TestCase
class AutoUpdateTest extends TestCase
{
/**
* AutoUpdate instance.
*
* @var \VisualAppeal\AutoUpdate
*/
private $_update = null;

/**
* Setup the auto update
*/
protected function setUp()
{
$this->_update = new AutoUpdate(__DIR__ . DIRECTORY_SEPARATOR . 'temp', __DIR__ . DIRECTORY_SEPARATOR . 'install');
$this->_update->setCurrentVersion('0.1.0');
$this->_update->setUpdateUrl(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures');
$this->_update->addLogHandler(new Monolog\Handler\StreamHandler(__DIR__ . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'update.log'));
}

protected function tearDown()
{
unset($this->_update);
$this->_update = null;
}

/**
* Test creation of class instance.
*/
public function testInit()
{
$this->assertInstanceOf('\VisualAppeal\AutoUpdate', $this->_update);
}

/**
* Test if errors get catched if no update file was found.
*/
public function testErrorUpdateCheck()
{
$this->_update->setUpdateFile('404.json');
$response = $this->_update->checkUpdate();

$this->assertEquals(false, $response);
$this->assertFalse($this->_update->newVersionAvailable());
$this->assertEquals(0, count($this->_update->getVersionsToUpdate()));
}

/**
* Test if new update is available with a json file.
*/
public function testJsonNewVersion()
{
$this->_update->setUpdateFile('updateAvailable.json');
$response = $this->_update->checkUpdate();

$this->assertTrue($response);
$this->assertTrue($this->_update->newVersionAvailable());
$this->assertEquals('0.2.1', $this->_update->getLatestVersion());

$newVersions = $this->_update->getVersionsToUpdate();
$this->assertEquals(2, count($newVersions));
$this->assertEquals('0.2.0', $newVersions[0]);
$this->assertEquals('0.2.1', $newVersions[1]);
}

/**
* Test if NO new update is available with a json file.
*/
public function testJsonNoNewVersion()
{
$this->_update->setUpdateFile('noUpdateAvailable.json');
$response = $this->_update->checkUpdate();

$this->assertEquals(AutoUpdate::NO_UPDATE_AVAILABLE, $response);
$this->assertFalse($this->_update->newVersionAvailable());
$this->assertEquals(0, count($this->_update->getVersionsToUpdate()));
}

/**
* Test if new update is available with a ini file.
*/
public function testIniNewVersion()
{
$this->_update->setUpdateFile('updateAvailable.ini');
$response = $this->_update->checkUpdate();

$this->assertTrue($response);
$this->assertTrue($this->_update->newVersionAvailable());
$this->assertEquals('0.2.1', $this->_update->getLatestVersion());

$newVersions = $this->_update->getVersionsToUpdate();
$this->assertEquals(2, count($newVersions));
$this->assertEquals('0.2.0', $newVersions[0]);
$this->assertEquals('0.2.1', $newVersions[1]);
}

/**
* Test if NO new update is available with a ini file.
*/
public function testIniNoNewVersion()
{
$this->_update->setUpdateFile('noUpdateAvailable.ini');
$response = $this->_update->checkUpdate();

$this->assertEquals(AutoUpdate::NO_UPDATE_AVAILABLE, $response);
$this->assertFalse($this->_update->newVersionAvailable());
$this->assertEquals(0, count($this->_update->getVersionsToUpdate()));
}

/**
* Ensure that a new dev version is available.
*/
public function testBranchDev()
{
$this->_update->setUpdateFile('updateAvailable.json');
$this->_update->setBranch('dev');
$response = $this->_update->checkUpdate();

$this->assertTrue($response);
}

/**
* Ensure that no new master version is available
*/
public function testBranchMaster()
{
$this->_update->setUpdateFile('noUpdateAvailable.json');
$this->_update->setBranch('master');
$response = $this->_update->checkUpdate();

$this->assertEquals(AutoUpdate::NO_UPDATE_AVAILABLE, $response);
}

/**
* Test the trailing slash method.
*/
public function testTrailingSlashes()
{
$dir = DIRECTORY_SEPARATOR . 'test';
$this->assertEquals(DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR, $this->_update->addTrailingSlash($dir));

$dir = DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR;
$this->assertEquals(DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR, $this->_update->addTrailingSlash($dir));
}
/**
* AutoUpdate instance.
*
* @var \VisualAppeal\AutoUpdate
*/
private $_update = null;

/**
* Setup the auto update.
*/
protected function setUp()
{
$this->_update = new AutoUpdate(__DIR__ . DIRECTORY_SEPARATOR . 'temp', __DIR__ . DIRECTORY_SEPARATOR . 'install');
$this->_update->setCurrentVersion('0.1.0');
$this->_update->setUpdateUrl(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures');
$this->_update->addLogHandler(new Monolog\Handler\StreamHandler(__DIR__ . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'update.log'));
}

/**
* Unset the auto update.
*/
protected function tearDown()
{
unset($this->_update);
$this->_update = null;
}

/**
* Test creation of class instance.
*/
public function testInit()
{
$this->assertInstanceOf('\VisualAppeal\AutoUpdate', $this->_update);
}

/**
* Test if errors get catched if no update file was found.
*/
public function testErrorUpdateCheck()
{
$this->_update->setUpdateFile('404.json');
$response = $this->_update->checkUpdate();

$this->assertEquals(false, $response);
$this->assertFalse($this->_update->newVersionAvailable());
$this->assertEquals(0, count($this->_update->getVersionsToUpdate()));
}

/**
* Test if new update is available with a json file.
*/
public function testJsonNewVersion()
{
$this->_update->setUpdateFile('updateAvailable.json');
$response = $this->_update->checkUpdate();

$this->assertTrue($response);
$this->assertTrue($this->_update->newVersionAvailable());
$this->assertEquals('0.2.1', $this->_update->getLatestVersion());

$newVersions = $this->_update->getVersionsToUpdate();
$this->assertEquals(2, count($newVersions));
$this->assertEquals('0.2.0', $newVersions[0]);
$this->assertEquals('0.2.1', $newVersions[1]);
}

/**
* Test if NO new update is available with a json file.
*/
public function testJsonNoNewVersion()
{
$this->_update->setUpdateFile('noUpdateAvailable.json');
$response = $this->_update->checkUpdate();

$this->assertEquals(AutoUpdate::NO_UPDATE_AVAILABLE, $response);
$this->assertFalse($this->_update->newVersionAvailable());
$this->assertEquals(0, count($this->_update->getVersionsToUpdate()));
}

/**
* Test if new update is available with a ini file.
*/
public function testIniNewVersion()
{
$this->_update->setUpdateFile('updateAvailable.ini');
$response = $this->_update->checkUpdate();

$this->assertTrue($response);
$this->assertTrue($this->_update->newVersionAvailable());
$this->assertEquals('0.2.1', $this->_update->getLatestVersion());

$newVersions = $this->_update->getVersionsToUpdate();
$this->assertEquals(2, count($newVersions));
$this->assertEquals('0.2.0', $newVersions[0]);
$this->assertEquals('0.2.1', $newVersions[1]);
}

/**
* Test if NO new update is available with a ini file.
*/
public function testIniNoNewVersion()
{
$this->_update->setUpdateFile('noUpdateAvailable.ini');
$response = $this->_update->checkUpdate();

$this->assertEquals(AutoUpdate::NO_UPDATE_AVAILABLE, $response);
$this->assertFalse($this->_update->newVersionAvailable());
$this->assertEquals(0, count($this->_update->getVersionsToUpdate()));
}

/**
* Ensure that a new dev version is available.
*/
public function testBranchDev()
{
$this->_update->setUpdateFile('updateAvailable.json');
$this->_update->setBranch('dev');
$response = $this->_update->checkUpdate();

$this->assertTrue($response);
}

/**
* Ensure that no new master version is available
*/
public function testBranchMaster()
{
$this->_update->setUpdateFile('noUpdateAvailable.json');
$this->_update->setBranch('master');
$response = $this->_update->checkUpdate();

$this->assertEquals(AutoUpdate::NO_UPDATE_AVAILABLE, $response);
}

/**
* Test the trailing slash method.
*/
public function testTrailingSlashes()
{
$dir = DIRECTORY_SEPARATOR . 'test';
$this->assertEquals(DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR, $this->_update->addTrailingSlash($dir));

$dir = DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR;
$this->assertEquals(DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR, $this->_update->addTrailingSlash($dir));
}
}

0 comments on commit 11f0b3f

Please sign in to comment.