Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Write ManifestStrategy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Dec 16, 2015
1 parent a241016 commit a35b4c1
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/Humbug/Test/SelfUpdate/UpdaterManifestStrategyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Humbug\Test\SelfUpdate;

use Humbug\SelfUpdate\Updater;
use Humbug\SelfUpdate\Strategy\ManifestStrategy;

class UpdaterManifestStrategyTest extends \PHPUnit_Framework_TestCase
{

private $files;

/** @var Updater */
private $updater;

private $manifestFile;

private $tmp;

public function setup()
{
$this->tmp = sys_get_temp_dir();
$this->files = __DIR__ . '/_files';
$this->updater = new Updater($this->files . '/test.phar', false);
$this->manifestFile = $this->files . '/manifest.json';
}

public function testGetLocalVersion()
{
$strategy = new ManifestStrategy('1.0.0', $this->manifestFile);
$this->assertEquals('1.0.0', $strategy->getCurrentLocalVersion($this->updater));
}

public function testSuggestMostRecentStable()
{
$strategy = new ManifestStrategy('1.0.0', $this->manifestFile);
$this->assertEquals('1.2.0', $strategy->getCurrentRemoteVersion($this->updater));
}

public function testSuggestNewestUnstable()
{
$strategy = new ManifestStrategy('1.0.0', $this->manifestFile, false, true);
$this->assertEquals('1.3.0-beta', $strategy->getCurrentRemoteVersion($this->updater));
}

public function testSuggestNewestStableFromUnstable()
{
$strategy = new ManifestStrategy('1.0.0-beta', $this->manifestFile);
$this->assertEquals('1.2.0', $strategy->getCurrentRemoteVersion($this->updater));
}

public function testSuggestNewestUnstableFromUnstable()
{
$strategy = new ManifestStrategy('1.2.9-beta', $this->manifestFile);
$this->assertEquals('1.3.0-beta', $strategy->getCurrentRemoteVersion($this->updater));
}

public function testUpdate()
{
copy($this->files . '/test.phar', $this->tmp . '/test.phar');
$updater = new Updater($this->tmp . '/test.phar', false);
$strategy = new ManifestStrategy('1.0.0', $this->manifestFile);
$updater->setStrategyObject($strategy);
$updater->setBackupPath($this->tmp . '/backup.phar');
$cwd = getcwd();
chdir(__DIR__);
$updater->update();
chdir($cwd);
}

public function teardown()
{
@unlink($this->tmp . '/test.phar');
@unlink($this->tmp . '/backup.phar');
}
}
42 changes: 42 additions & 0 deletions tests/Humbug/Test/SelfUpdate/_files/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"sha1": "",
"url": "",
"version": "2.0.0"
},
{
"sha1": "",
"url": "",
"version": "2.0.0-beta"
},
{
"sha1": "",
"url": "",
"version": "1.3.0-beta"
},
{
"sha1": "0bc24f886bc0c7563187167b334e56cfb8e1151a",
"url": "_files/build/nosig.phar",
"version": "1.2.0"
},
{
"sha1": "",
"url": "",
"version": "1.1.0"
},
{
"sha1": "",
"url": "",
"version": "1.0.0"
},
{
"sha1": "",
"url": "",
"version": "1.0.0-beta"
},
{
"sha1": "",
"url": "",
"version": "0.9.0"
}
]

0 comments on commit a35b4c1

Please sign in to comment.