svn: /pear2/Pyrus/trunk/ src/Pyrus/ScriptFrontend/Commands.php tests/ScriptFrontend/Commands/channelDiscover3.phpt

[email protected] (Brett Bieber)
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
saltybeagle                              Fri, 16 Jul 2010 21:46:24 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=301339

Log:
Bug #17596 	Pyrus: Commands -> channelDiscover. Add patch from Warnar Boekkooi [boekkooi], and a cli test. Discovering a channel twice should fail.

Bug: http://pear.php.net/bugs/17596 (unknown) 
      
Changed paths:
    U   pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php
    A   pear2/Pyrus/trunk/tests/ScriptFrontend/Commands/channelDiscover3.phpt

Modified: pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php
===================================================================
--- pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php	2010-07-16 21:25:40 UTC (rev 301338)
+++ pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php	2010-07-16 21:46:24 UTC (rev 301339)
@@ -664,10 +664,6 @@
             if ($response->code != 200) {
                 throw new \PEAR2\Pyrus\Exception('Download of channel.xml failed');
             }
-addchan_success:
-            $chan = new \PEAR2\Pyrus\Channel(new \PEAR2\Pyrus\ChannelFile($response->body, true));
-            \PEAR2\Pyrus\Config::current()->channelregistry->add($chan);
-            echo "Discovery of channel ", $chan->name, " successful\n";
         } catch (\Exception $e) {
             try {
                 $chan = 'http://' . $args['channel'] . '/channel.xml';
@@ -675,12 +671,16 @@
                 if ($response->code != 200) {
                     throw new \PEAR2\Pyrus\Exception('Download of channel.xml failed');
                 }
-                goto addchan_success;
             } catch (\Exception $e) {
                 // failed, re-throw original error
-                echo "Discovery of channel ", $args['channel'], " failed: ", $e->getMessage();
+                echo "Discovery of channel ", $args['channel'], " failed: ", $e->getMessage(), "\n";
+                return;
             }
         }
+
+        $chan = new \PEAR2\Pyrus\Channel(new \PEAR2\Pyrus\ChannelFile($response->body, true));
+        \PEAR2\Pyrus\Config::current()->channelregistry->add($chan);
+        echo "Discovery of channel ", $chan->name, " successful\n";
     }

     /**

Added: pear2/Pyrus/trunk/tests/ScriptFrontend/Commands/channelDiscover3.phpt
===================================================================
--- pear2/Pyrus/trunk/tests/ScriptFrontend/Commands/channelDiscover3.phpt	                        (rev 0)
+++ pear2/Pyrus/trunk/tests/ScriptFrontend/Commands/channelDiscover3.phpt	2010-07-16 21:46:24 UTC (rev 301339)
@@ -0,0 +1,61 @@
+--TEST--
+\PEAR2\Pyrus\ScriptFrontend\Commands::channelDiscover() Discover channel twice
+--FILE--
+<?php
+require __DIR__ . '/setup.php.inc';
+if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'testit')) {
+    $dir = __DIR__ . '/testit';
+    include __DIR__ . '/../../clean.php.inc';
+}
+mkdir(__DIR__ . DIRECTORY_SEPARATOR . 'testit');
+set_include_path(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testit');
+$c = \PEAR2\Pyrus\Config::singleton(__DIR__.'/testit', __DIR__ . '/testit/plugins/pearconfig.xml');
+$c->bin_dir = __DIR__ . '/testit/bin';
+restore_include_path();
+$c->saveConfig();
+
+require __DIR__ . '/../../Mocks/Internet.php';
+
+Internet::addDirectory(__DIR__ . '/testit',
+                       'http://pear.unl.edu/');
+\PEAR2\Pyrus\Main::$downloadClass = 'Internet';
+file_put_contents(__DIR__ . '/testit/channel.xml', '<?xml version="1.0" encoding="UTF-8"?>
+<channel version="1.0" xmlns="http://pear.php.net/channel-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://pear.php.net/dtd/channel-1.0 http://pear.php.net/dtd/channel-1.0.xsd">
+ <name>pear.unl.edu</name>
+ <suggestedalias>salty</suggestedalias>
+ <summary>Simple PEAR Channel</summary>
+ <servers>
+  <primary>
+   <rest>
+    <baseurl type="REST1.0">http://foo/rest/</baseurl>
+    <baseurl type="REST1.1">http://foo/rest/</baseurl>
+    <baseurl type="REST1.3">http://foo/rest/</baseurl>
+   </rest>
+  </primary>
+ </servers>
+</channel>');
+
+ob_start();
+$cli = new \PEAR2\Pyrus\ScriptFrontend\Commands(true);
+$cli->run($args = array (__DIR__ . '/testit', 'channel-discover', 'pear.unl.edu'));
+$test->assertEquals(true, isset(\PEAR2\Pyrus\Config::current()->channelregistry['pear.unl.edu']),
+                    'after discover of pear.unl.edu');
+
+try {
+    $cli->run($args = array (__DIR__ . '/testit', 'channel-discover', 'pear.unl.edu'));
+    throw new \Exception('Should have thrown a channel registry exception.');
+} catch(\Exception $e) {
+    $test->assertEquals('Error: channel pear.unl.edu has already been discovered', $e->getMessage(), 'exception thrown on existing channel');
+}
+$contents = ob_get_contents();
+ob_end_clean();
+
+?>
+===DONE===
+--CLEAN--
+<?php
+$dir = __DIR__ . '/testit';
+include __DIR__ . '/../../clean.php.inc';
+?>
+--EXPECT--
+===DONE===
\ No newline at end of file
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.