Support for PHP infection testing
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@
|
|||||||
*.log
|
*.log
|
||||||
config.yml
|
config.yml
|
||||||
*.phar
|
*.phar
|
||||||
*.deb
|
*.deb
|
||||||
|
.phpunit.result.cache
|
27
README.md
27
README.md
@ -14,5 +14,30 @@ rm phpDocumentor.phar
|
|||||||
wget https://phpdoc.org/phpDocumentor.phar
|
wget https://phpdoc.org/phpDocumentor.phar
|
||||||
chmod +x phpDocumentor.phar
|
chmod +x phpDocumentor.phar
|
||||||
|
|
||||||
|
# PHP latest for debian
|
||||||
|
curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
|
||||||
|
sudo apt update
|
||||||
|
sudo apt upgrade
|
||||||
|
sudo apt install php8.2-cli php8.2-xml php8.2-curl php8.2-zip php8.2-xdebug php8.2-mbstring unzip wget graphviz plantuml
|
||||||
|
|
||||||
|
|
||||||
|
# Rclone install
|
||||||
|
rm rclone-current-linux-amd64.deb
|
||||||
|
wget https://downloads.rclone.org/rclone-current-linux-amd64.deb
|
||||||
|
sudo dpkg -i rclone-current-linux-amd64.deb
|
||||||
|
|
||||||
|
# Infection install
|
||||||
|
|
||||||
|
rm infection.phar
|
||||||
|
wget https://github.com/infection/infection/releases/download/0.27.0/infection.phar
|
||||||
|
chmod +x infection.phar
|
||||||
|
|
||||||
|
# PHP CopyPasteDetector install
|
||||||
|
rm phpcpd.phar
|
||||||
|
wget https://phar.phpunit.de/phpcpd.phar
|
||||||
|
chmod +x phpcpd.phar
|
||||||
|
|
||||||
# Test, analyze, metrics, document
|
# Test, analyze, metrics, document
|
||||||
./composer.phar test-coverage && ./composer.phar analyze && ./composer.phar metrics && ./composer.phar doc
|
./composer.phar test-full && ./composer.phar analyze && ./composer.phar metrics && ./composer.phar doc
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vendor/bin/phpunit tests --display-warnings",
|
"test": "vendor/bin/phpunit tests --display-warnings",
|
||||||
"test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --path-coverage --testdox-html output/test.html --log-junit output/test.xml ",
|
"test-full": "vendor/bin/phpunit -c phpunit.full.xml",
|
||||||
"metrics": "vendor/bin/phpmetrics --report-html=output/metrics --junit=output/test.xml src/",
|
"metrics": "vendor/bin/phpmetrics --report-html=output/metrics --junit=output/test.xml src/",
|
||||||
"docs": "./phpDocumentor.phar --setting=graphs.enabled=true",
|
"docs": "./phpDocumentor.phar --setting=graphs.enabled=true",
|
||||||
"analyze": [
|
"analyze": [
|
||||||
|
16
infection.json5
Normal file
16
infection.json5
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/infection/infection/0.27.0/resources/schema.json",
|
||||||
|
"source": {
|
||||||
|
"directories": [
|
||||||
|
"src"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"logs": {
|
||||||
|
"text": "output/mutation/infection.log",
|
||||||
|
"html": "output/mutation/infection.html",
|
||||||
|
"summary": "output/mutation/summary.log",
|
||||||
|
},
|
||||||
|
"mutators": {
|
||||||
|
"@default": true
|
||||||
|
}
|
||||||
|
}
|
14
install.sh
14
install.sh
@ -1,14 +0,0 @@
|
|||||||
curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
|
|
||||||
sudo apt update
|
|
||||||
sudo apt upgrade
|
|
||||||
sudo apt install php8.2-cli php8.2-xml php8.2-curl php8.2-zip php8.2-xdebug php8.2-mbstring unzip wget graphviz plantuml
|
|
||||||
|
|
||||||
./composer.phar self-update
|
|
||||||
|
|
||||||
rm rclone-current-linux-amd64.deb
|
|
||||||
wget https://downloads.rclone.org/rclone-current-linux-amd64.deb
|
|
||||||
sudo dpkg -i rclone-current-linux-amd64.deb
|
|
||||||
|
|
||||||
rm phpDocumentor.phar
|
|
||||||
wget https://phpdoc.org/phpDocumentor.phar
|
|
||||||
chmod +x phpDocumentor.phar
|
|
36
phpunit.full.xml
Normal file
36
phpunit.full.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<phpunit
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
|
||||||
|
executionOrder="random"
|
||||||
|
testdox="true"
|
||||||
|
displayDetailsOnIncompleteTests="true"
|
||||||
|
displayDetailsOnSkippedTests="true"
|
||||||
|
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||||
|
displayDetailsOnTestsThatTriggerErrors="true"
|
||||||
|
displayDetailsOnTestsThatTriggerNotices="true"
|
||||||
|
displayDetailsOnTestsThatTriggerWarnings="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="All">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<source>
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
<file>backup</file>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
<logging>
|
||||||
|
<junit outputFile="output/test.xml"/>
|
||||||
|
<testdoxHtml outputFile="output/test.html"/>
|
||||||
|
<testdoxText outputFile="output/test.txt"/>
|
||||||
|
</logging>
|
||||||
|
<coverage includeUncoveredFiles="true"
|
||||||
|
pathCoverage="true">
|
||||||
|
<report>
|
||||||
|
<html outputDirectory="output/coverage"/>
|
||||||
|
<text outputFile="output/coverage.txt" showUncoveredFiles="true" showOnlySummary="true"/>
|
||||||
|
</report>
|
||||||
|
</coverage>
|
||||||
|
</phpunit>
|
11
phpunit.xml
Normal file
11
phpunit.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<phpunit
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="All">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
</phpunit>
|
@ -14,8 +14,9 @@ use InvalidArgumentException;
|
|||||||
*/
|
*/
|
||||||
class Ntfy implements NotificationInterface
|
class Ntfy implements NotificationInterface
|
||||||
{
|
{
|
||||||
const TOPIC_MAX_LENGTH = 256;
|
public const TOPIC_MAX_LENGTH = 256;
|
||||||
const MESSAGE_MAX_LENGTH = 4096;
|
public const TITLE_MAX_LENGTH = 256;
|
||||||
|
public const MESSAGE_MAX_LENGTH = 4096;
|
||||||
private string $topic = 'default';
|
private string $topic = 'default';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,7 +69,7 @@ class Ntfy implements NotificationInterface
|
|||||||
*/
|
*/
|
||||||
public function send(string $title, string $message): void
|
public function send(string $title, string $message): void
|
||||||
{
|
{
|
||||||
if (!strlen($title) || strlen($title) > self::TOPIC_MAX_LENGTH) {
|
if (!strlen($title) || strlen($title) > self::TITLE_MAX_LENGTH) {
|
||||||
throw new InvalidArgumentException("Invalid title length");
|
throw new InvalidArgumentException("Invalid title length");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class Rclone
|
class Rclone
|
||||||
{
|
{
|
||||||
|
private const MAX_RUNTIME = 4 * 3600; //4 hours maximum
|
||||||
protected string $version = "";
|
protected string $version = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +108,7 @@ class Rclone
|
|||||||
*
|
*
|
||||||
* @return Process Instance.
|
* @return Process Instance.
|
||||||
*/
|
*/
|
||||||
protected function exec(string $command, array $options = array()): Process
|
private function exec(string $command, array $options = array()): Process
|
||||||
{
|
{
|
||||||
$process = new Process(
|
$process = new Process(
|
||||||
array_merge(
|
array_merge(
|
||||||
@ -119,7 +120,7 @@ class Rclone
|
|||||||
|
|
||||||
$this->logger->info("Execute command", [$process->getCommandLine()]);
|
$this->logger->info("Execute command", [$process->getCommandLine()]);
|
||||||
|
|
||||||
$process->setTimeout(4 * 3600);
|
$process->setTimeout(self::MAX_RUNTIME);
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
// executes after the command finishes
|
// executes after the command finishes
|
||||||
|
@ -15,14 +15,23 @@ final class CommandBackupTest extends \PHPUnit\Framework\TestCase
|
|||||||
{
|
{
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
mkdir('temp');
|
if (!is_dir('temp')) {
|
||||||
mkdir('temp/destination');
|
mkdir('temp');
|
||||||
exec('rclone test makefiles temp/source 2>&1');
|
}
|
||||||
|
if (!is_dir('temp/destination')) {
|
||||||
|
mkdir('temp/destination');
|
||||||
|
}
|
||||||
|
exec('rclone test makefiles --files 10 temp/source 2>&1');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
exec('rclone purge temp 2>&1');
|
exec('rclone purge temp 2>&1');
|
||||||
|
|
||||||
|
if (is_dir('temp/destination')) {
|
||||||
|
rmdir('temp/destination');
|
||||||
|
}
|
||||||
|
|
||||||
if (is_dir("temp")) {
|
if (is_dir("temp")) {
|
||||||
rmdir('temp');
|
rmdir('temp');
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ final class NtfyTest extends TestCase
|
|||||||
public function testSendLong(): void
|
public function testSendLong(): void
|
||||||
{
|
{
|
||||||
$this->client->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class));
|
$this->client->expects($this->once())->method('send')->with($this->isInstanceOf(Message::class));
|
||||||
$this->instance->send(str_repeat("t", Ntfy::TOPIC_MAX_LENGTH), str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH));
|
$this->instance->send(str_repeat("t", Ntfy::TITLE_MAX_LENGTH), str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<int, array<int, string>> */
|
/** @return array<int, array<int, string>> */
|
||||||
@ -52,8 +52,8 @@ final class NtfyTest extends TestCase
|
|||||||
['', ''],
|
['', ''],
|
||||||
['', 'text'],
|
['', 'text'],
|
||||||
['title', ''],
|
['title', ''],
|
||||||
[str_repeat("t", Ntfy::TOPIC_MAX_LENGTH+1),'text'],
|
[str_repeat("t", Ntfy::TITLE_MAX_LENGTH + 1), 'text'],
|
||||||
['title',str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH+1)],
|
['title',str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH + 1)],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +80,7 @@ final class NtfyTest extends TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[''],
|
[''],
|
||||||
[str_repeat("t", Ntfy::TOPIC_MAX_LENGTH+1)],
|
[str_repeat("t", Ntfy::TOPIC_MAX_LENGTH + 1)],
|
||||||
[str_repeat("t", Ntfy::MESSAGE_MAX_LENGTH+1)],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user