Skip to content

Commit

Permalink
Enforce "en" lang in tests.
Browse files Browse the repository at this point in the history
Some tests compare the result to english strings.

Do not test UnixCommandExecutor on Windows.

PharTest: explain why PHAR writing test are skipped.

InstallCommandTest: mock checkRequirements to allow the tests to run.

Run php_parallel_lint before all other tests.

Close #846
  • Loading branch information
Adirelle authored and tvbeek committed Apr 22, 2015
1 parent 9590336 commit 452a5ba
Show file tree
Hide file tree
Showing 37 changed files with 492 additions and 272 deletions.
2 changes: 1 addition & 1 deletion PHPCI/Helper/Lang.php
Expand Up @@ -156,7 +156,7 @@ protected static function loadLanguage()
return null;
}

require_once($langFile);
require($langFile);

if (is_null($strings) || !is_array($strings) || !count($strings)) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion PHPCI/Plugin/Util/Factory.php
Expand Up @@ -185,7 +185,7 @@ private function getParamType(\ReflectionParameter $param)
return $class->getName();
} elseif ($param->isArray()) {
return self::TYPE_ARRAY;
} elseif ($param->isCallable()) {
} elseif (is_callable($param)) {
return self::TYPE_CALLABLE;
} else {
return null;
Expand Down
17 changes: 9 additions & 8 deletions Tests/PHPCI/Command/CreateAdminCommandTest.php
@@ -1,13 +1,14 @@
<?php

/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace PHPCI\Plugin\Tests\Command;
namespace Tests\PHPCI\Plugin\Command;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -34,17 +35,17 @@ public function setup()
parent::setup();

$this->command = $this->getMockBuilder('PHPCI\\Command\\CreateAdminCommand')
->setConstructorArgs([$this->getMock('PHPCI\\Store\\UserStore')])
->setMethods(['reloadConfig'])
->setConstructorArgs(array($this->getMock('PHPCI\\Store\\UserStore')))
->setMethods(array('reloadConfig'))
->getMock()
;

$this->dialog = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\DialogHelper')
->setMethods([
->setMethods(array(
'ask',
'askAndValidate',
'askHiddenResponse',
])
))
->getMock()
;

Expand All @@ -71,7 +72,7 @@ public function testExecute()
$this->dialog->expects($this->at(2))->method('askHiddenResponse')->will($this->returnValue('foobar123'));

$commandTester = $this->getCommandTester();
$commandTester->execute([]);
$commandTester->execute(array());

$this->assertEquals('User account created!' . PHP_EOL, $commandTester->getDisplay());
}
Expand Down
29 changes: 20 additions & 9 deletions Tests/PHPCI/Command/InstallCommandTest.php
@@ -1,16 +1,23 @@
<?php

namespace PHPCI\Plugin\Tests\Command;
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace Tests\PHPCI\Plugin\Command;

use Symfony\Component\Console\Application;
use Prophecy\PhpUnit\ProphecyTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Helper\HelperSet;

class InstallCommandTest extends ProphecyTestCase
class InstallCommandTest extends \PHPUnit_Framework_TestCase
{
protected $config;
protected $admin;
public $config;
public $admin;
protected $application;

public function setup()
Expand Down Expand Up @@ -55,22 +62,26 @@ protected function getInstallCommandMock()
'setupDatabase',
'createAdminUser',
'writeConfigFile',
'checkRequirements',
))
->getMock();

$self = $this;

$command->expects($this->once())->method('verifyNotInstalled')->willReturn(true);
$command->expects($this->once())->method('verifyDatabaseDetails')->willReturn(true);
$command->expects($this->once())->method('setupDatabase')->willReturn(true);
$command->expects($this->once())->method('createAdminUser')->will(
$this->returnCallback(function ($adm) {// use (&$admin) {
$this->admin = $adm;
$this->returnCallback(function ($adm) use ($self) {
$self->admin = $adm;
})
);
$command->expects($this->once())->method('writeConfigFile')->will(
$this->returnCallback(function ($cfg) { //use (&$config) {
$this->config = $cfg;
$this->returnCallback(function ($cfg) use ($self) {
$self->config = $cfg;
})
);
$command->expects($this->once())->method('checkRequirements');

return $command;
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/PHPCI/Controller/WebhookControllerTest.php
@@ -1,18 +1,18 @@
<?php

/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace PHPCI\Tests\Controller;
namespace Tests\PHPCI\Controller;

use PHPCI\Controller\WebhookController;
use Prophecy\PhpUnit\ProphecyTestCase;

class WebhookControllerTest extends ProphecyTestCase
class WebhookControllerTest extends \PHPUnit_Framework_TestCase
{
public function test_wrong_action_name_return_json_with_error()
{
Expand Down
17 changes: 16 additions & 1 deletion Tests/PHPCI/Helper/AnsiConverterTest.php
@@ -1,12 +1,27 @@
<?php

namespace PHPCI\Helper\Tests;
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace Tests\PHPCI\Helper;

use PHPCI\Helper\AnsiConverter;
use PHPUnit_Framework_TestCase;

class AnsiConverterTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
$this->markTestSkipped('External library do not support PHP 5.3');
}
}

public function testConvert_convertToHtml()
{
$input = "\e[31mThis is red !\e[0m";
Expand Down
15 changes: 11 additions & 4 deletions Tests/PHPCI/Helper/BuildInterpolatorTest.php
@@ -1,11 +1,18 @@
<?php

namespace PHPCI\Plugin\Tests\Helper;
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace Tests\PHPCI\Plugin\Helper;

use PHPCI\Helper\BuildInterpolator;
use Prophecy\PhpUnit\ProphecyTestCase;

class BuildInterpolatorTest extends ProphecyTestCase
class BuildInterpolatorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var BuildInterpolator
Expand Down Expand Up @@ -46,4 +53,4 @@ public function testInterpolate_LeavesStringsUnchangedWhenBuildIsSet()
$this->assertEquals($expectedOutput, $actualOutput);
}
}

19 changes: 15 additions & 4 deletions Tests/PHPCI/Helper/CommandExecutorTest.php
@@ -1,11 +1,18 @@
<?php

namespace PHPCI\Plugin\Tests\Helper;
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace Tests\PHPCI\Plugin\Helper;

use PHPCI\Helper\UnixCommandExecutor;
use \Prophecy\PhpUnit\ProphecyTestCase;

class CommandExecutorTest extends ProphecyTestCase
class CommandExecutorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var UnixCommandExecutor
Expand All @@ -14,6 +21,10 @@ class CommandExecutorTest extends ProphecyTestCase

protected function setUp()
{
if (IS_WIN) {
$this->markTestSkipped("Cannot test UnixCommandExecutor on ".PHP_OS);
return;
}
parent::setUp();
$mockBuildLogger = $this->prophesize('PHPCI\Logging\BuildLogger');
$this->testedExecutor = new UnixCommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/");
Expand Down Expand Up @@ -52,4 +63,4 @@ public function testFindBinary_ReturnsPathInSpecifiedRoot()
$returnValue = $this->testedExecutor->findBinary($thisFileName);
$this->assertEquals(__DIR__ . "/" . $thisFileName, $returnValue);
}
}
}
13 changes: 10 additions & 3 deletions Tests/PHPCI/Helper/LangTest.php
@@ -1,12 +1,19 @@
<?php

namespace PHPCI\Tests\Helper;
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace Tests\PHPCI\Helper;

use DateTime;
use PHPCI\Helper\Lang;
use Prophecy\PhpUnit\ProphecyTestCase;

class LangTest extends ProphecyTestCase
class LangTest extends \PHPUnit_Framework_TestCase
{
public function testLang_UsePassedParameters()
{
Expand Down
7 changes: 4 additions & 3 deletions Tests/PHPCI/Helper/MailerFactoryTest.php
@@ -1,13 +1,14 @@
<?php

/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace PHPCI\Service\Tests;
namespace tests\PHPCI\Service;

use PHPCI\Helper\MailerFactory;

Expand Down
15 changes: 11 additions & 4 deletions Tests/PHPCI/Logging/BuildLoggerTest.php
@@ -1,13 +1,20 @@
<?php

namespace PHPCI\Plugin\Tests\Helper;
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace Tests\PHPCI\Plugin\Helper;

use PHPCI\Logging\BuildLogger;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTestCase;
use Psr\Log\LogLevel;

class BuildLoggerTest extends ProphecyTestCase
class BuildLoggerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var BuildLogger
Expand Down Expand Up @@ -104,4 +111,4 @@ public function testLogFailure_AddsExceptionContext()
$this->testedBuildLogger->logFailure($message, $exception);
}
}

12 changes: 10 additions & 2 deletions Tests/PHPCI/Logging/LoggerConfigTest.php
@@ -1,6 +1,14 @@
<?php

namespace PHPCI\Plugin\Tests\Helper;
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace Tests\PHPCI\Plugin\Helper;

use \PHPCI\Logging\LoggerConfig;

Expand Down Expand Up @@ -74,4 +82,4 @@ public function testGetFor_IgnoresAlternativeHandlers()
$this->assertNotSame($alternativeHandler, $actualHandler);
}
}

8 changes: 5 additions & 3 deletions Tests/PHPCI/Model/BuildTest.php
@@ -1,13 +1,15 @@
<?php

/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace PHPCI\Model\Tests;

namespace Tests\PHPCI\Model;

use PHPCI\Model\Build;
use PHPCI\Model;
Expand Down
8 changes: 5 additions & 3 deletions Tests/PHPCI/Model/ProjectTest.php
@@ -1,13 +1,15 @@
<?php

/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/

namespace PHPCI\Model\Tests;

namespace Tests\PHPCI\Model;

use PHPCI\Model\Project;
use PHPCI\Model;
Expand Down

0 comments on commit 452a5ba

Please sign in to comment.