From 44634a689d7342c4814885af888955e4f507bcab Mon Sep 17 00:00:00 2001 From: Rafael Kassner Date: Mon, 3 Oct 2016 13:17:07 +0200 Subject: [PATCH 1/2] HgDriver does not identify bitbucket mercurial repos correctly --- src/Composer/Repository/Vcs/HgDriver.php | 2 +- .../Test/Repository/Vcs/HgDriverTest.php | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Repository/Vcs/HgDriverTest.php diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index c82c8c4aa..4dc103d38 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -195,7 +195,7 @@ class HgDriver extends VcsDriver */ public static function supports(IOInterface $io, Config $config, $url, $deep = false) { - if (preg_match('#(^(?:https?|ssh)://(?:[^@]@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) { + if (preg_match('#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i', $url)) { return true; } diff --git a/tests/Composer/Test/Repository/Vcs/HgDriverTest.php b/tests/Composer/Test/Repository/Vcs/HgDriverTest.php new file mode 100644 index 000000000..3b62ac317 --- /dev/null +++ b/tests/Composer/Test/Repository/Vcs/HgDriverTest.php @@ -0,0 +1,63 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test\Repository\Vcs; + +use Composer\Repository\Vcs\HgDriver; +use Composer\TestCase; +use Composer\Util\Filesystem; +use Composer\Config; + +class HgDriverTest extends TestCase +{ + + /** @type \Composer\IO\IOInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $io; + /** @type \Composer\Config */ + private $config; + /** @type string */ + private $home; + + public function setUp() + { + $this->io = $this->getMock('Composer\IO\IOInterface'); + $this->home = $this->getUniqueTmpDirectory(); + $this->config = new Config(); + $this->config->merge(array( + 'config' => array( + 'home' => $this->home, + ), + )); + } + + public function tearDown() + { + $fs = new Filesystem; + $fs->removeDirectory($this->home); + } + + public function testSupports() + { + $this->assertTrue( + HgDriver::supports($this->io, $this->config, 'ssh://bitbucket.org/user/repo') + ); + + $this->assertTrue( + HgDriver::supports($this->io, $this->config, 'ssh://hg@bitbucket.org/user/repo') + ); + + $this->assertTrue( + HgDriver::supports($this->io, $this->config, 'ssh://user@bitbucket.org/user/repo') + ); + } + +} From 34ec5fba58487770e2118653d0153d9f3e17fe98 Mon Sep 17 00:00:00 2001 From: Rafael Kassner Date: Mon, 3 Oct 2016 13:35:48 +0200 Subject: [PATCH 2/2] Code review fixes --- .../Test/Repository/Vcs/HgDriverTest.php | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/Composer/Test/Repository/Vcs/HgDriverTest.php b/tests/Composer/Test/Repository/Vcs/HgDriverTest.php index 3b62ac317..da326aaf5 100644 --- a/tests/Composer/Test/Repository/Vcs/HgDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/HgDriverTest.php @@ -22,7 +22,7 @@ class HgDriverTest extends TestCase /** @type \Composer\IO\IOInterface|\PHPUnit_Framework_MockObject_MockObject */ private $io; - /** @type \Composer\Config */ + /** @type Config */ private $config; /** @type string */ private $home; @@ -45,18 +45,24 @@ class HgDriverTest extends TestCase $fs->removeDirectory($this->home); } - public function testSupports() + /** + * @dataProvider supportsDataProvider + */ + public function testSupports($repositoryUrl) { $this->assertTrue( - HgDriver::supports($this->io, $this->config, 'ssh://bitbucket.org/user/repo') - ); - - $this->assertTrue( - HgDriver::supports($this->io, $this->config, 'ssh://hg@bitbucket.org/user/repo') + HgDriver::supports($this->io, $this->config, $repositoryUrl) ); + } - $this->assertTrue( - HgDriver::supports($this->io, $this->config, 'ssh://user@bitbucket.org/user/repo') + public function supportsDataProvider() + { + return array( + array('ssh://bitbucket.org/user/repo'), + array('ssh://hg@bitbucket.org/user/repo'), + array('ssh://user@bitbucket.org/user/repo'), + array('https://bitbucket.org/user/repo'), + array('https://user@bitbucket.org/user/repo'), ); }