From 12d3eef3d129fc53f1e09e9b326f7318a4c4e8c9 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Sat, 2 Apr 2011 15:40:18 +0200 Subject: [PATCH 1/2] monotone actually requires interface_version 13.0 or higher because of the extended manifest usage --- src/IDF/Scm/Monotone.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IDF/Scm/Monotone.php b/src/IDF/Scm/Monotone.php index 7a3c210..f5944d6 100644 --- a/src/IDF/Scm/Monotone.php +++ b/src/IDF/Scm/Monotone.php @@ -29,7 +29,7 @@ class IDF_Scm_Monotone extends IDF_Scm { /** the minimum supported interface version */ - public static $MIN_INTERFACE_VERSION = 12.0; + public static $MIN_INTERFACE_VERSION = 13.0; private $stdio; From fb62061e5abea007af01c13656f4b01404d48f33 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Wed, 6 Apr 2011 02:59:26 +0200 Subject: [PATCH 2/2] Started with a unit test for the monotone interface. Main test infrastructure is there, still lots of functionality left for testing. Fixed a possible bug in the SCM interface already: Pluf_HTTP_Response_NotFound needs a request instance as ctor argument, which we don't have at this point, therefor we just throw an exception. --- src/IDF/Scm/Monotone.php | 4 +- test/IDF/Scm/MonotoneTest.php | 249 ++++++++++++++++++++++++++++++++++ 2 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 test/IDF/Scm/MonotoneTest.php diff --git a/src/IDF/Scm/Monotone.php b/src/IDF/Scm/Monotone.php index f5944d6..ecec8c7 100644 --- a/src/IDF/Scm/Monotone.php +++ b/src/IDF/Scm/Monotone.php @@ -135,13 +135,13 @@ class IDF_Scm_Monotone extends IDF_Scm /** * @see IDF_Scm::getArchiveStream */ - public function getArchiveStream($commit, $prefix='repository/') + public function getArchiveStream($commit, $prefix = null) { $revs = $this->_resolveSelector($commit); // sanity: this should actually not happen, because the // revision is validated before already if (count($revs) == 0) { - return new Pluf_HTTP_Response_NotFound(); + throw new IDF_Scm_Exception("$commit is not a valid revision"); } return new IDF_Scm_Monotone_ZipRender($this->stdio, $revs[0]); } diff --git a/test/IDF/Scm/MonotoneTest.php b/test/IDF/Scm/MonotoneTest.php new file mode 100644 index 0000000..a54502d --- /dev/null +++ b/test/IDF/Scm/MonotoneTest.php @@ -0,0 +1,249 @@ +outputMap[serialize($args)][serialize($options)] = $output; + } + + public function exec(array $args, array $options = array()) + { + $optoutputs = @$this->outputMap[serialize($args)]; + if ($optoutputs === null) { + return false; + } + + return @$optoutputs[serialize($options)]; + } + + // unused + public function getLastOutOfBandOutput() {} +} + +class IDF_Scm_Monotone_Test extends PHPUnit_Framework_TestCase +{ + private $proj = null; + + public function setUp() + { + $this->proj = new IDF_Project(); + $this->proj->id = 1; + $this->proj->name = $this->proj->shortname = 'Test'; + $this->proj->create(); + + $this->proj->getConf()->setVal('mtn_master_branch', 'master.branch'); + } + + public function tearDown() + { + $this->proj->delete(); + } + + public function createMock(array $args = array(), array $options = array(), $output = null) + { + $instance = new IDF_Scm_Monotone($this->proj, new MonotoneStdioMock($this->proj)); + if (count($args) > 0) { + $instance->getStdio()->setExpectedOutput($args, $options, $output); + } + return $instance; + } + + public function testGetStdio() + { + $instance = $this->createMock(); + $this->assertNotNull($instance->getStdio()); + } + + public function testGetRepositorySize() + { + $this->markTestSkipped('Cannot mock real repository file'); + } + + public function testIsAvailable() + { + $instance = $this->createMock(array('interface_version'), array(), '13.0'); + $this->assertTrue($instance->isAvailable()); + + $instance->getStdio()->setExpectedOutput(array('interface_version'), array(), '12.7'); + $this->assertFalse($instance->isAvailable()); + + $instance->getStdio()->setExpectedOutput(array('interface_version'), array(), 'foo'); + $this->assertFalse($instance->isAvailable()); + } + + public function testGetBranches() + { + $instance = $this->createMock(array('branches'), array(), "foo\nbar.baz"); + $this->assertEquals(array( + 'h:foo' => 'foo', + 'h:bar.baz' => 'bar.baz', + ), $instance->getBranches()); + } + + public function testGetMainBranch() + { + $instance = $this->createMock(); + $this->assertEquals('master.branch', $instance->getMainBranch()); + $instance->project->getConf()->setVal('mtn_master_branch', ''); + $this->assertEquals('*', $instance->getMainBranch()); + } + + public function testGetArchiveStream() + { + $instance = $this->createMock(array('select', 'abc123'), array(), "1234567890123456789012345678901234567890\n"); + $ziprender = $instance->getArchiveStream('abc123'); + $this->assertTrue($ziprender instanceof IDF_Scm_Monotone_ZipRender); + + $thrown = false; + try { + $ziprender = $instance->getArchiveStream('foo'); + } + catch (IDF_Scm_Exception $e) { + $thrown = true; + } + $this->assertTrue($thrown); + } + + public function testInBranches() + { + // returns the branches the given commit is in + } + + public function testGetTags() + { + $stdio =<<createMock(array('tags'), array(), $stdio); + $this->assertEquals(array( + 't:foo-1.0' => 'foo-1.0', + 't:foo-1.1' => 'foo-1.1', + 't:bar-1.0' => 'bar-1.0', + ), $instance->getTags()); + } + + public function testInTags() + { + // returns the tags that are attached to the given commit + } + + public function testGetTree() + { + // test root and sub tree fetching + } + + public function testFindAuthor() + { + $this->markTestSkipped('This functionality here should reside in IDF_Scm'); + } + + public function testGetAnonymousAccessUrl() + { + // test the generation of the anonymous remote URL + } + + public function testGetAuthAccessUrl() + { + // test the generation of the authenticated remote URL (only really visible for SSH) + } + + public function testFactory() + { + $this->markTestSkipped('Cannot mock real repository'); + } + + public function testValidateRevision() + { + // test valid, invalid and ambigious + } + + public function testDisambiguateRevision() + { + // test for array of commit objects + } + + public function testGetPathInfo() + { + // return the info (creation date, last commit, et cetera) for a single file and commit + } + + public function testGetFile() + { + // test cmd_only and full file fetching + } + + public function testGetChanges() + { + // test retrieving the changes of a specific revision + } + + public function testGetCommit() + { + // test get commit information with and without a diff text + // test multiple branches, dates, authors, aso + } + + public function testGetExtraProperties() + { + // test array('parents' => array(rev1, rev2, ...)) or array() if root revision + } + + public function testIsCommitLarge() + { + // test for true / false with commits with more than 100 changes + } + + public function testGetChangeLog() + { + // test with no commit, empty $n + // test logging stops at unknown branches + // test logging stops at $n + } +} +