diff --git a/composer.json b/composer.json index bbc84b1..1c79ef5 100755 --- a/composer.json +++ b/composer.json @@ -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 } } diff --git a/src/AutoUpdate.php b/src/AutoUpdate.php index e2b0c3f..4349031 100755 --- a/src/AutoUpdate.php +++ b/src/AutoUpdate.php @@ -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); diff --git a/tests/AutoUpdateTest.php b/tests/AutoUpdateTest.php index 4accfa5..45643cb 100755 --- a/tests/AutoUpdateTest.php +++ b/tests/AutoUpdateTest.php @@ -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)); + } }