Skip to content

Commit fb204ce

Browse files
committed
updates adding tests in and updating readme/composer file
1 parent 25d1810 commit fb204ce

File tree

9 files changed

+880
-21
lines changed

9 files changed

+880
-21
lines changed

.github/workflows/tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php-version: ['8.0', '8.1', '8.2', '8.3']
15+
16+
name: PHP ${{ matrix.php-version }}
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php-version }}
26+
extensions: curl, xml
27+
coverage: xdebug
28+
29+
- name: Install dependencies
30+
run: composer install --prefer-dist --no-progress
31+
32+
- name: Run tests
33+
run: vendor/bin/phpunit --colors=always
34+
35+
- name: Run tests with coverage
36+
if: matrix.php-version == '8.2'
37+
run: vendor/bin/phpunit --coverage-text --colors=always

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ vendor/
33
.bettercodehub.yml
44
.idea/workspace.xml
55
.idea/libraries
6+
.phpunit.result.cache

README.md

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,82 @@
1-
# Cloudlinux Licensing Class
1+
# MyAdmin CloudLinux Licensing Plugin
22

3-
Cloudlinux Licensing Class
3+
[![Tests](https://github.com/detain/myadmin-cloudlinux-licensing/actions/workflows/tests.yml/badge.svg)](https://github.com/detain/myadmin-cloudlinux-licensing/actions/workflows/tests.yml)
4+
[![Latest Stable Version](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/version)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing)
5+
[![Total Downloads](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/downloads)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing)
6+
[![License](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/license)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing)
47

5-
## Build Status and Code Analysis
8+
A MyAdmin plugin for managing CloudLinux, KernelCare, and Imunify360 license provisioning. This package integrates with the MyAdmin panel plugin system using Symfony EventDispatcher to handle license activation, deactivation, IP changes, and listing through the CloudLinux XML-RPC API.
69

7-
Site | Status
8-
--------------|---------------------------
9-
![Travis-CI](http://i.is.cc/storage/GYd75qN.png "Travis-CI") | [![Build Status](https://travis-ci.org/detain/myadmin-cloudlinux-licensing.svg?branch=master)](https://travis-ci.org/detain/myadmin-cloudlinux-licensing)
10-
![CodeClimate](http://i.is.cc/storage/GYlageh.png "CodeClimate") | [![Code Climate](https://codeclimate.com/github/detain/myadmin-cloudlinux-licensing/badges/gpa.svg)](https://codeclimate.com/github/detain/myadmin-cloudlinux-licensing) [![Test Coverage](https://codeclimate.com/github/detain/myadmin-cloudlinux-licensing/badges/coverage.svg)](https://codeclimate.com/github/detain/myadmin-cloudlinux-licensing/coverage) [![Issue Count](https://codeclimate.com/github/detain/myadmin-cloudlinux-licensing/badges/issue_count.svg)](https://codeclimate.com/github/detain/myadmin-cloudlinux-licensing)
11-
![Scrutinizer](http://i.is.cc/storage/GYeUnux.png "Scrutinizer") | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/myadmin-plugins/cloudlinux-licensing/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/myadmin-plugins/cloudlinux-licensing/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/myadmin-plugins/cloudlinux-licensing/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/myadmin-plugins/cloudlinux-licensing/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/myadmin-plugins/cloudlinux-licensing/badges/build.png?b=master)](https://scrutinizer-ci.com/g/myadmin-plugins/cloudlinux-licensing/build-status/master)
12-
![Codacy](http://i.is.cc/storage/GYi66Cx.png "Codacy") | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/226251fc068f4fd5b4b4ef9a40011d06)](https://www.codacy.com/app/detain/myadmin-cloudlinux-licensing) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/25fa74eb74c947bf969602fcfe87e349)](https://www.codacy.com/app/detain/myadmin-cloudlinux-licensing?utm_source=github.com&utm_medium=referral&utm_content=detain/myadmin-cloudlinux-licensing&utm_campaign=Badge_Coverage)
13-
![Coveralls](http://i.is.cc/storage/GYjNSim.png "Coveralls") | [![Coverage Status](https://coveralls.io/repos/github/detain/db_abstraction/badge.svg?branch=master)](https://coveralls.io/github/detain/myadmin-cloudlinux-licensing?branch=master)
14-
![Packagist](http://i.is.cc/storage/GYacBEX.png "Packagist") | [![Latest Stable Version](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/version)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing) [![Total Downloads](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/downloads)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing) [![Latest Unstable Version](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/v/unstable)](//packagist.org/packages/detain/myadmin-cloudlinux-licensing) [![Monthly Downloads](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/d/monthly)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing) [![Daily Downloads](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/d/daily)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing) [![License](https://poser.pugx.org/detain/myadmin-cloudlinux-licensing/license)](https://packagist.org/packages/detain/myadmin-cloudlinux-licensing)
10+
## Features
1511

12+
- Automated provisioning of CloudLinux, KernelCare, and Imunify360 licenses
13+
- License activation and deactivation with IP address management
14+
- IP address change support with automatic license migration
15+
- Admin-only license listing interface
16+
- Out-of-stock control via settings
17+
- Email notifications for failed deactivations
1618

17-
## Installation
19+
## Supported License Types
20+
21+
| Product | Type ID |
22+
|-------------------------------|---------|
23+
| CloudLinux License | 1 |
24+
| KernelCare License | 16 |
25+
| ImunityAV+ | 40 |
26+
| Imunity360 Single User | 41 |
27+
| Imunity360 Up to 30 Users | 42 |
28+
| Imunity360 Up to 250 Users | 43 |
29+
| Imunity360 Unlimited Users | 49 |
30+
31+
## Requirements
1832

19-
Install with composer like
33+
- PHP >= 5.3.0
34+
- ext-curl
35+
- `detain/cloudlinux-licensing` (CloudLinux API client)
36+
- `symfony/event-dispatcher` ^5.0
37+
38+
## Installation
2039

2140
```sh
2241
composer require detain/myadmin-cloudlinux-licensing
2342
```
2443

25-
## License
44+
## Configuration
45+
46+
The plugin requires the following constants to be defined in your application:
47+
48+
```php
49+
define('CLOUDLINUX_LOGIN', 'your-login');
50+
define('CLOUDLINUX_KEY', 'your-api-key');
51+
define('OUTOFSTOCK_LICENSES_CLOUDLINUX', 0); // 0 = in stock, 1 = out of stock
52+
```
53+
54+
## Usage
55+
56+
Register the plugin hooks with your Symfony EventDispatcher instance:
57+
58+
```php
59+
use Detain\MyAdminCloudlinux\Plugin;
2660

27-
The Cloudlinux Licensing Class class is licensed under the LGPL-v2.1 license.
61+
$hooks = Plugin::getHooks();
62+
foreach ($hooks as $event => $handler) {
63+
$dispatcher->addListener($event, $handler);
64+
}
65+
```
66+
67+
## Running Tests
68+
69+
```sh
70+
composer install
71+
vendor/bin/phpunit
72+
```
73+
74+
To generate a coverage report:
75+
76+
```sh
77+
vendor/bin/phpunit --coverage-text
78+
```
79+
80+
## License
2881

82+
This package is licensed under the [LGPL-2.1-only](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html) license.

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
"detain/cloudlinux-licensing": "dev-master"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "*",
31-
"phpunit/phpunit-mock-objects": "*",
32-
"vlucas/phpdotenv": "*",
33-
"codeclimate/php-test-reporter": "*",
34-
"satooshi/php-coveralls": "*",
35-
"codacy/coverage": "*"
30+
"phpunit/phpunit": "^9.6"
3631
},
3732
"autoload": {
3833
"psr-4": {
3934
"Detain\\MyAdminCloudlinux\\": "src/"
4035
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"Detain\\MyAdminCloudlinux\\Tests\\": "tests/"
40+
}
4141
}
4242
}

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true"
6+
verbose="true"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
>
10+
<testsuites>
11+
<testsuite name="Unit Tests">
12+
<directory suffix="Test.php">tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<coverage processUncoveredFiles="true">
16+
<include>
17+
<directory suffix=".php">src</directory>
18+
</include>
19+
</coverage>
20+
</phpunit>

tests/ComposerConfigTest.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
namespace Detain\MyAdminCloudlinux\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
/**
8+
* Tests that verify the composer.json configuration is correct.
9+
*
10+
* Ensures proper autoloading, dependencies, and package metadata.
11+
*/
12+
class ComposerConfigTest extends TestCase
13+
{
14+
/**
15+
* @var array Parsed composer.json contents
16+
*/
17+
private $composerConfig;
18+
19+
/**
20+
* @var string Path to composer.json
21+
*/
22+
private $composerPath;
23+
24+
protected function setUp(): void
25+
{
26+
$this->composerPath = dirname(__DIR__) . '/composer.json';
27+
$content = file_get_contents($this->composerPath);
28+
$this->composerConfig = json_decode($content, true);
29+
$this->assertNotNull($this->composerConfig, 'composer.json should be valid JSON');
30+
}
31+
32+
/**
33+
* Tests that composer.json exists and is readable.
34+
*/
35+
public function testComposerJsonExists(): void
36+
{
37+
$this->assertFileExists($this->composerPath);
38+
$this->assertFileIsReadable($this->composerPath);
39+
}
40+
41+
/**
42+
* Tests that the package name follows the vendor/package convention.
43+
*/
44+
public function testPackageName(): void
45+
{
46+
$this->assertSame('detain/myadmin-cloudlinux-licensing', $this->composerConfig['name']);
47+
}
48+
49+
/**
50+
* Tests that the package type is set to myadmin-plugin.
51+
* This type is used by the custom installer for MyAdmin plugins.
52+
*/
53+
public function testPackageType(): void
54+
{
55+
$this->assertSame('myadmin-plugin', $this->composerConfig['type']);
56+
}
57+
58+
/**
59+
* Tests that the license is correctly set to LGPL-2.1-only.
60+
*/
61+
public function testLicense(): void
62+
{
63+
$this->assertSame('LGPL-2.1-only', $this->composerConfig['license']);
64+
}
65+
66+
/**
67+
* Tests that autoloading is configured with PSR-4 for the correct namespace.
68+
*/
69+
public function testAutoloadPsr4(): void
70+
{
71+
$this->assertArrayHasKey('autoload', $this->composerConfig);
72+
$this->assertArrayHasKey('psr-4', $this->composerConfig['autoload']);
73+
$this->assertArrayHasKey('Detain\\MyAdminCloudlinux\\', $this->composerConfig['autoload']['psr-4']);
74+
$this->assertSame('src/', $this->composerConfig['autoload']['psr-4']['Detain\\MyAdminCloudlinux\\']);
75+
}
76+
77+
/**
78+
* Tests that PHPUnit is listed as a dev dependency.
79+
*/
80+
public function testPhpunitInRequireDev(): void
81+
{
82+
$this->assertArrayHasKey('require-dev', $this->composerConfig);
83+
$this->assertArrayHasKey('phpunit/phpunit', $this->composerConfig['require-dev']);
84+
}
85+
86+
/**
87+
* Tests that the required runtime dependencies are present.
88+
*/
89+
public function testRequiredDependencies(): void
90+
{
91+
$this->assertArrayHasKey('require', $this->composerConfig);
92+
$this->assertArrayHasKey('php', $this->composerConfig['require']);
93+
$this->assertArrayHasKey('detain/cloudlinux-licensing', $this->composerConfig['require']);
94+
$this->assertArrayHasKey('symfony/event-dispatcher', $this->composerConfig['require']);
95+
}
96+
97+
/**
98+
* Tests that authors section has at least one entry.
99+
*/
100+
public function testAuthorsSection(): void
101+
{
102+
$this->assertArrayHasKey('authors', $this->composerConfig);
103+
$this->assertNotEmpty($this->composerConfig['authors']);
104+
$this->assertArrayHasKey('name', $this->composerConfig['authors'][0]);
105+
}
106+
107+
/**
108+
* Tests that the package has relevant keywords for discoverability.
109+
*/
110+
public function testKeywords(): void
111+
{
112+
$this->assertArrayHasKey('keywords', $this->composerConfig);
113+
$this->assertContains('cloudlinux', $this->composerConfig['keywords']);
114+
$this->assertContains('license', $this->composerConfig['keywords']);
115+
}
116+
117+
/**
118+
* Tests that a description is provided in composer.json.
119+
*/
120+
public function testDescription(): void
121+
{
122+
$this->assertArrayHasKey('description', $this->composerConfig);
123+
$this->assertNotEmpty($this->composerConfig['description']);
124+
}
125+
}

0 commit comments

Comments
 (0)