Refactored project structure.
This commit is contained in:
parent
cfe93434ad
commit
c015d8c58b
308 changed files with 39 additions and 47 deletions
18
tests/src/Helper/AnsiConverterTest.php
Normal file
18
tests/src/Helper/AnsiConverterTest.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\PHPCensor\Helper;
|
||||
|
||||
use PHPCensor\Helper\AnsiConverter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AnsiConverterTest extends TestCase
|
||||
{
|
||||
public function testConvert_convertToHtml()
|
||||
{
|
||||
$input = "\e[31mThis is red !\e[0m";
|
||||
$expectedOutput = '<span class="ansi_color_bg_black ansi_color_fg_red">This is red !</span>';
|
||||
$actualOutput = AnsiConverter::convert($input);
|
||||
|
||||
self::assertEquals($expectedOutput, $actualOutput);
|
||||
}
|
||||
}
|
||||
48
tests/src/Helper/BuildInterpolatorTest.php
Normal file
48
tests/src/Helper/BuildInterpolatorTest.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\PHPCensor\Helper;
|
||||
|
||||
use PHPCensor\Helper\BuildInterpolator;
|
||||
|
||||
class BuildInterpolatorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var BuildInterpolator
|
||||
*/
|
||||
protected $testedInterpolator;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setup();
|
||||
$this->testedInterpolator = new BuildInterpolator();
|
||||
}
|
||||
|
||||
public function testInterpolate_LeavesStringsUnchangedByDefault()
|
||||
{
|
||||
$string = "Hello World";
|
||||
$expectedOutput = "Hello World";
|
||||
|
||||
$actualOutput = $this->testedInterpolator->interpolate($string);
|
||||
|
||||
self::assertEquals($expectedOutput, $actualOutput);
|
||||
}
|
||||
|
||||
public function testInterpolate_LeavesStringsUnchangedWhenBuildIsSet()
|
||||
{
|
||||
$build = $this->prophesize('PHPCensor\\Model\\Build')->reveal();
|
||||
|
||||
$string = "Hello World";
|
||||
$expectedOutput = "Hello World";
|
||||
|
||||
$this->testedInterpolator->setupInterpolationVars(
|
||||
$build,
|
||||
"/buildpath/",
|
||||
"php-censor.local"
|
||||
);
|
||||
|
||||
$actualOutput = $this->testedInterpolator->interpolate($string);
|
||||
|
||||
self::assertEquals($expectedOutput, $actualOutput);
|
||||
}
|
||||
}
|
||||
|
||||
109
tests/src/Helper/CommandExecutorTest.php
Normal file
109
tests/src/Helper/CommandExecutorTest.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\PHPCensor\Helper;
|
||||
|
||||
use PHPCensor\Helper\CommandExecutor;
|
||||
|
||||
class CommandExecutorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var CommandExecutor
|
||||
*/
|
||||
protected $testedExecutor;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$mockBuildLogger = $this->prophesize('PHPCensor\Logging\BuildLogger');
|
||||
|
||||
$class = 'PHPCensor\Helper\CommandExecutor';
|
||||
$this->testedExecutor = new $class($mockBuildLogger->reveal(), __DIR__);
|
||||
}
|
||||
|
||||
public function testGetLastOutput_ReturnsOutputOfCommand()
|
||||
{
|
||||
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
|
||||
$output = $this->testedExecutor->getLastOutput();
|
||||
self::assertEquals("Hello World", $output);
|
||||
}
|
||||
|
||||
public function testGetLastOutput_ForgetsPreviousCommandOutput()
|
||||
{
|
||||
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
|
||||
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello Tester']);
|
||||
$output = $this->testedExecutor->getLastOutput();
|
||||
self::assertEquals("Hello Tester", $output);
|
||||
}
|
||||
|
||||
public function testExecuteCommand_ReturnsTrueForValidCommands()
|
||||
{
|
||||
$returnValue = $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
|
||||
self::assertTrue($returnValue);
|
||||
}
|
||||
|
||||
public function testExecuteCommand_ReturnsFalseForInvalidCommands()
|
||||
{
|
||||
$returnValue = $this->testedExecutor->executeCommand(['eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World']);
|
||||
self::assertFalse($returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a script that generates an output that fills the standard error
|
||||
* buffer first, followed by the standard output buffer. The function
|
||||
* should be able to read from both streams, thereby preventing the child
|
||||
* process from blocking because one of its buffers is full.
|
||||
*/
|
||||
public function testExecuteCommand_AlternatesBothBuffers()
|
||||
{
|
||||
$length = 80000;
|
||||
$script = <<<EOD
|
||||
/bin/sh -c 'data="$(printf %%${length}s | tr " " "-")"; >&2 echo "\$data"; >&1 echo "\$data"'
|
||||
EOD;
|
||||
$data = str_repeat("-", $length);
|
||||
$returnValue = $this->testedExecutor->executeCommand([$script]);
|
||||
self::assertTrue($returnValue);
|
||||
self::assertEquals($data, trim($this->testedExecutor->getLastOutput()));
|
||||
self::assertEquals($data, trim($this->testedExecutor->getLastError()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedMessageRegex WorldWidePeace
|
||||
*/
|
||||
public function testFindBinary_ThrowsWhenNotFound()
|
||||
{
|
||||
$thisFileName = "WorldWidePeace";
|
||||
$this->testedExecutor->findBinary($thisFileName);
|
||||
}
|
||||
|
||||
public function testFindBinary_ReturnsNullWihQuietArgument()
|
||||
{
|
||||
$thisFileName = "WorldWidePeace";
|
||||
self::assertFalse($this->testedExecutor->findBinary($thisFileName, true));
|
||||
}
|
||||
|
||||
public function testReplaceIllegalCharacters()
|
||||
{
|
||||
self::assertEquals(
|
||||
"start <20> end",
|
||||
$this->testedExecutor->replaceIllegalCharacters(
|
||||
"start \xf0\x9c\x83\x96 end"
|
||||
)
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
"start <20> end",
|
||||
$this->testedExecutor->replaceIllegalCharacters(
|
||||
"start \xF0\x9C\x83\x96 end"
|
||||
)
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
"start 123_X08<30>_X00<30>_Xa4<61>_5432 end",
|
||||
$this->testedExecutor->replaceIllegalCharacters(
|
||||
"start 123_X08\x08_X00\x00_Xa4\xa4_5432 end"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
58
tests/src/Helper/MailerFactoryTest.php
Normal file
58
tests/src/Helper/MailerFactoryTest.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\PHPCensor\Helper;
|
||||
|
||||
use PHPCensor\Helper\MailerFactory;
|
||||
|
||||
/**
|
||||
* Unit tests for the ProjectService class.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class MailerFactoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function testExecute_TestGetMailConfig()
|
||||
{
|
||||
$config = [
|
||||
'smtp_address' => 'mail.example.com',
|
||||
'smtp_port' => 225,
|
||||
'smtp_encryption' => 'tls',
|
||||
'smtp_username' => 'php-censor-user',
|
||||
'smtp_password' => 'php-censor-password',
|
||||
'default_mailto_address' => 'admin@php-censor.local',
|
||||
];
|
||||
|
||||
$factory = new MailerFactory(['email_settings' => $config]);
|
||||
|
||||
self::assertEquals($config['smtp_address'], $factory->getMailConfig('smtp_address'));
|
||||
self::assertEquals($config['smtp_port'], $factory->getMailConfig('smtp_port'));
|
||||
self::assertEquals($config['smtp_encryption'], $factory->getMailConfig('smtp_encryption'));
|
||||
self::assertEquals($config['smtp_username'], $factory->getMailConfig('smtp_username'));
|
||||
self::assertEquals($config['smtp_password'], $factory->getMailConfig('smtp_password'));
|
||||
self::assertEquals($config['default_mailto_address'], $factory->getMailConfig('default_mailto_address'));
|
||||
}
|
||||
|
||||
public function testExecute_TestMailer()
|
||||
{
|
||||
$config = [
|
||||
'smtp_address' => 'mail.example.com',
|
||||
'smtp_port' => 225,
|
||||
'smtp_encryption' => 'tls',
|
||||
'smtp_username' => 'php-censor-user',
|
||||
'smtp_password' => 'php-censor-password',
|
||||
'default_mailto_address' => 'admin@php-censor.local',
|
||||
];
|
||||
|
||||
$factory = new MailerFactory(['email_settings' => $config]);
|
||||
$mailer = $factory->getSwiftMailerFromConfig();
|
||||
|
||||
self::assertEquals($config['smtp_address'], $mailer->getTransport()->getHost());
|
||||
self::assertEquals($config['smtp_port'], $mailer->getTransport()->getPort());
|
||||
self::assertEquals('tls', $mailer->getTransport()->getEncryption());
|
||||
self::assertEquals($config['smtp_username'], $mailer->getTransport()->getUsername());
|
||||
self::assertEquals($config['smtp_password'], $mailer->getTransport()->getPassword());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue