Skip to content

Commit

Permalink
Replace deprecated phpunit methods
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Oct 12, 2016
1 parent fcbed5c commit dc4d4dd
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Tests/Repository/Vcs/PerforceDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ protected function setUp()
$this->overrideDriverInternalPerforce($this->perforce);
}

protected function getMockIOInterface()
{
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
}

protected function getMockProcessExecutor()
{
return $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
}

public function testInitializeCapturesVariablesFromRepoConfig()
{
$driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
Expand Down Expand Up @@ -139,8 +149,6 @@ protected function getMockPerforce()
{
$methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec');

return $this->getMockBuilder('Fxp\Composer\AssetPlugin\Util\Perforce', $methods)
->disableOriginalConstructor()
->getMock();
return $this->createPartialMock('Fxp\Composer\AssetPlugin\Util\Perforce', $methods);
}
}
69 changes: 69 additions & 0 deletions Tests/Util/PerforceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Fxp\Composer\AssetPlugin\Tests\Util;

use Composer\IO\IOInterface;
use Composer\Test\Util\PerforceTest as BasePerforceTest;
use Composer\Util\Filesystem;
use Composer\Util\ProcessExecutor;
Expand Down Expand Up @@ -38,6 +39,14 @@ class PerforceTest extends BasePerforceTest
*/
protected $repoConfig;

protected function setUp()
{
$this->processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$this->repoConfig = $this->getTestRepoConfig();
$this->io = $this->getMockIOInterface();
$this->createNewPerforceWithWindowsFlag(true);
}

protected function tearDown()
{
parent::tearDown();
Expand All @@ -46,6 +55,14 @@ protected function tearDown()
$fs->remove($this::TEST_PATH);
}

/**
* @return IOInterface|\PHPUnit_Framework_MockObject_MockObject
*/
public function getMockIOInterface()
{
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
}

public function testQueryP4PasswordWithPasswordAlreadySet()
{
$repoConfig = array(
Expand Down Expand Up @@ -249,6 +266,58 @@ function ($command, &$output) {
$this->assertSame('', $result);
}

public function testCheckServerExists()
{
/* @var ProcessExecutor|\PHPUnit_Framework_MockObject_MockObject $processExecutor */
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();

$expectedCommand = 'p4 -p perforce.does.exist:port info -s';
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand), $this->equalTo(null))
->will($this->returnValue(0));

$result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor);
$this->assertTrue($result);
}

/**
* Test if "p4" command is missing.
*
* @covers \Composer\Util\Perforce::checkServerExists
*
* @return void
*/
public function testCheckServerClientError()
{
/* @var ProcessExecutor|\PHPUnit_Framework_MockObject_MockObject $processExecutor */
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();

$expectedCommand = 'p4 -p perforce.does.exist:port info -s';
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand), $this->equalTo(null))
->will($this->returnValue(127));

$result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor);
$this->assertFalse($result);
}

public function testCleanupClientSpecShouldDeleteClient()
{
/* @var Filesystem|\PHPUnit_Framework_MockObject_MockObject $fs */
$fs = $this->getMockBuilder('Composer\Util\Filesystem')->getMock();
$this->perforce->setFilesystem($fs);

$testClient = $this->perforce->getClient();
$expectedCommand = 'p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . $testClient;
$this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand));

$fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec());

$this->perforce->cleanupClientSpec();
}

protected function createNewPerforceWithWindowsFlag($flag)
{
$this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, $flag, $this->io);
Expand Down

0 comments on commit dc4d4dd

Please sign in to comment.