Skip to content

Commit

Permalink
Merge branch 'master' into fix/avoid-php-warnings-for-mkdir
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Jun 17, 2019
2 parents 485c41a + 53af2a9 commit 394b923
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 25 deletions.
25 changes: 5 additions & 20 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,6 @@ public function setTokenUrl($tokenUrl)
$this->tokenUrl = $tokenUrl;
}

/**
* @return \Http\Adapter\Guzzle6\Client
*/
public function getHttpClient()
{
if (!$this->httpClient) {
$this->httpClient = new \Http\Adapter\Guzzle6\Client();
}
return $this->httpClient;
}

/**
* @param \Http\Adapter\Guzzle6\Client $httpClient
*/
public function setHttpClient($httpClient)
{
$this->httpClient = $httpClient;
}

/**
* @param ProjectData|null $project
*/
Expand Down Expand Up @@ -1052,7 +1033,11 @@ public function getOutput()
/** @var Message $msg */
$msg = $message['message'];
$msg->setContext($message['context']);
$msgs[] = $message['message'];
if (isset($message['context']['command'])) {
$msg = new Message($msg->getMessage(), Message::COMMAND);
$msg->setContext($message['context']);
}
$msgs[] = $msg;
}
return $msgs;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Providers/PublicGithubWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public function createFork($user, $repo, $fork_user)

public function createPullRequest($user_name, $user_repo, $params)
{
$http_client = $this->getHttpClient();
$request = $this->createPullRequestRequest($user_name, $user_repo, $params);
$jar = new CookieJar();
$jar->addCookie(new Cookie('XDEBUG_SESSION', 'XDEBUG_ECLIPSE', null, 'violinist.localhost'));
Expand All @@ -114,7 +113,6 @@ public function createPullRequest($user_name, $user_repo, $params)

public function updatePullRequest($user_name, $user_repo, $id, $params)
{
$http_client = $this->getHttpClient();
$jar = new CookieJar();
$jar->addCookie(new Cookie('XDEBUG_SESSION', 'XDEBUG_ECLIPSE', null, 'violinist.localhost'));
$plugin = new CookiePlugin($jar);
Expand Down
1 change: 1 addition & 0 deletions test/GetCosyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function getMockCosy($dir = null)
}
$mock_checker = $this->createMock(SecurityChecker::class);
$c->getCheckerFactory()->setChecker($mock_checker);
$c->setUserToken('user-token');
return $c;
}
}
2 changes: 1 addition & 1 deletion test/integration/FailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testGitFail()
->will($this->returnCallback(
function ($cmd, $log = true, $timeout = 120) {

if (strpos($cmd, 'git clone --depth=1 https://:@github.com/a/b') === 0) {
if (strpos($cmd, 'git clone --depth=1 https://user-token:@github.com/a/b') === 0) {
return 42;
}
return 0;
Expand Down
35 changes: 35 additions & 0 deletions test/integration/OutputFromUpdateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

use eiriksm\ArrayOutput\ArrayOutput;
use eiriksm\CosyComposer\CommandExecuter;
use eiriksm\CosyComposer\Exceptions\ChdirException;

class OutputFromUpdateTest extends Base
{
/**
* Test that when we invoke the updater, the message log gets populated with the commands that are run.
*/
public function testUpdateOutput()
{
$c = $this->getMockCosy();
$dir = '/tmp/' . uniqid();
$this->setupDirectory($c, $dir);
$definition = $this->getMockDefinition();
$mock_app = $this->getMockApp($definition);
$c->setApp($mock_app);
$mock_output = $this->getMockOutputWithUpdate('eirik/private-pack', '1.0.0', '1.0.2');
$c->setOutput($mock_output);
$this->placeComposerContentsFromFixture('composer-json-private.json', $dir);
$mock_executer = $this->createMock(CommandExecuter::class);
$mock_executer->method('executeCommand')
->willReturn(0);
$c->setExecuter($mock_executer);
$this->registerProviderFactory($c);
$this->placeComposerLockContentsFromFixture('composer-lock-private.lock', $dir);
$c->run();
$this->assertOutputContainsMessage('Creating command composer update -n --no-ansi eirik/private-pack --with-dependencies', $c);
$this->assertEquals(true, true);
}
}
2 changes: 0 additions & 2 deletions test/integration/issues/Issue98Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Issue98Test extends Base
public function testIssue98()
{
$c = $this->getMockCosy();
$user_token = 'user-token';
$c->setUserToken($user_token);
$dir = '/tmp/' . uniqid();
$this->setupDirectory($c, $dir);
$definition = $this->getMockDefinition();
Expand Down
50 changes: 50 additions & 0 deletions test/unit/CosyComposerUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Http\Adapter\Guzzle6\Client;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Violinist\Slug\Slug;

class CosyComposerUnitTest extends TestCase
{
Expand Down Expand Up @@ -45,6 +46,55 @@ public function testLastStdOut()
$this->assertEquals('output', $c->getLastStdOut());
}

/**
* @dataProvider setUrlValues
*/
public function testSetUrl($url, $user, $repo, $host, $port)
{
// Use reflection to invoke the protected method we want to test.
$class = new \ReflectionClass(CosyComposer::class);
$property = $class->getProperty('slug');
$url_property = $class->getProperty('urlArray');
$property->setAccessible(true);
$url_property->setAccessible(true);
$mock_cosy = $this->getMockCosy();
$mock_cosy->setUrl($url);
/** @var Slug $value */
$value = $property->getValue($mock_cosy);
$this->assertEquals($user, $value->getUserName());
$this->assertEquals($repo, $value->getUserRepo());
$url_value = $url_property->getValue($mock_cosy);
$this->assertEquals($url_value['host'], $host);
$this->assertEquals($url_value['port'], $port);
}

public function setUrlValues()
{
return [
[
'url' => 'https://github.com/user/repo',
'user' => 'user',
'repo' => 'repo',
'host' => 'github.com',
'port' => 443,
],
[
'url' => 'http://example.com/user/repo',
'user' => 'user',
'repo' => 'repo',
'host' => 'example.com',
'port' => 80,
],
[
'url' => 'https://internal.gitlab.instance:2278/user/repo',
'user' => 'user',
'repo' => 'repo',
'host' => 'internal.gitlab.instance',
'port' => 2278,
],
];
}

/**
* @dataProvider getComposerJsonVariations
*/
Expand Down

0 comments on commit 394b923

Please sign in to comment.