Skip to content

Commit 4fdca73

Browse files
committed
update tests & add back coveralls
1 parent caab7eb commit 4fdca73

8 files changed

Lines changed: 119 additions & 17 deletions

File tree

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ updates:
55
schedule:
66
interval: "weekly"
77
open-pull-requests-limit: 10
8-
target-branch: "main"
8+
target-branch: "master"
99
versioning-strategy: "auto"
1010
allow:
1111
- dependency-type: "direct"
@@ -19,7 +19,7 @@ updates:
1919
schedule:
2020
interval: "weekly"
2121
open-pull-requests-limit: 10
22-
target-branch: "main"
22+
target-branch: "master"
2323
labels:
2424
- "dependencies"
2525
- "github-actions"

.github/workflows/tests.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
php-version: ${{ matrix.php-versions }}
2828
extensions: mbstring, intl
29-
coverage: xdebug
29+
coverage: pcov
3030

3131
- name: Validate composer.json and composer.lock
3232
run: composer validate --strict
@@ -43,8 +43,8 @@ jobs:
4343
- name: Install dependencies
4444
run: composer update ${{ matrix.composer-flags }}
4545

46-
- name: Run test suite
47-
run: composer run-script test
46+
- name: Run test suite with coverage
47+
run: vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
4848

4949
- name: Check coding standards
5050
run: composer run-script cs-check
@@ -54,3 +54,11 @@ jobs:
5454

5555
- name: Check PHP compatibility
5656
run: composer run-script compat
57+
58+
- name: Upload coverage to Coveralls
59+
if: matrix.php-versions == '8.4'
60+
env:
61+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
mkdir -p build/logs
64+
vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/vendor
22
composer.lock
33
/.phpunit.cache
4+
/coverage
5+
/build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Composer Installer
22

33
[![Tests](https://github.com/blesta/composer-installer/actions/workflows/tests.yml/badge.svg)](https://github.com/blesta/composer-installer/actions/workflows/tests.yml)
4-
[![PHPStan](https://img.shields.io/badge/PHPStan-level%207-brightgreen.svg)](https://phpstan.org/)
4+
[![Coverage Status](https://coveralls.io/repos/blesta/composer-installer/badge.svg?branch=master&service=github)](https://coveralls.io/github/blesta/composer-installer?branch=master)
55

66
A library for installing Blesta extensions using [composer](http://getcomposer.org).
77

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"squizlabs/php_codesniffer": "^3.13",
1414
"composer/composer": "^2.0",
1515
"phpstan/phpstan": "^2.1",
16-
"phpcompatibility/php-compatibility": "^9.3"
16+
"phpcompatibility/php-compatibility": "^9.3",
17+
"php-coveralls/php-coveralls": "^2.8"
1718
},
1819
"autoload": {
1920
"psr-4": {

tests/Unit/BlestaInstallerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp(): void
2828
}
2929

3030
/**
31-
* @covers ::getLocations
31+
* Test getLocations property
3232
*/
3333
public function testGetLocations(): void
3434
{

tests/Unit/InstallerPluginTest.php

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use InvalidArgumentException;
1515
use PHPUnit\Framework\MockObject\MockObject;
1616
use React\Promise\PromiseInterface;
17+
use RuntimeException;
1718

1819
/**
1920
* @covers \Blesta\Composer\Installer\InstallerPlugin
@@ -67,8 +68,7 @@ public function testGetInstallPath(): void
6768
}
6869

6970
/**
70-
* @covers ::getInstallPath
71-
* @covers ::supportedType
71+
* Test getInstallPath throws exception for invalid types
7272
*/
7373
public function testGetInstallPathException(): void
7474
{
@@ -84,9 +84,7 @@ public function testGetInstallPathException(): void
8484
}
8585

8686
/**
87-
* @covers ::uninstall
88-
* @covers ::getInstallPath
89-
* @covers ::supportedType
87+
* Test uninstall functionality
9088
*/
9189
public function testUninstall(): void
9290
{
@@ -118,7 +116,7 @@ public function testUninstall(): void
118116
}
119117

120118
/**
121-
* @covers ::uninstall
119+
* Test uninstall throws exception when package not found
122120
*/
123121
public function testUninstallException(): void
124122
{
@@ -197,5 +195,98 @@ public function testSupportedType(): void
197195
// Test invalid types
198196
$this->assertFalse($method->invoke($installer, 'invalid'));
199197
$this->assertFalse($method->invoke($installer, 'blesta')); // No hyphen
198+
$this->assertFalse($method->invoke($installer, 'unknown-type')); // Unknown base type with hyphen
199+
}
200+
201+
/**
202+
* Test getInstallPath with a custom type that doesn't have an installer class
203+
*/
204+
public function testGetInstallPathWithMissingInstallerClass(): void
205+
{
206+
// Override the supportedTypes array to have a non-existent installer class
207+
$installer = new class ($this->io, $this->composer) extends InstallerPlugin {
208+
protected array $supportedTypes = [
209+
'custom' => 'NonExistentInstaller'
210+
];
211+
212+
protected function supportedType(string $type): string|false
213+
{
214+
if ($type === 'test-invalid-type') {
215+
return 'custom';
216+
}
217+
return false;
218+
}
219+
};
220+
221+
$package = $this->createMock(PackageInterface::class);
222+
$package->expects($this->once())
223+
->method('getType')
224+
->willReturn('test-invalid-type');
225+
226+
$this->expectException(RuntimeException::class);
227+
$this->expectExceptionMessage('Failed to create installer for package type "test-invalid-type":');
228+
229+
$installer->getInstallPath($package);
230+
}
231+
232+
/**
233+
* Test uninstall with exception during getInstallPath
234+
*/
235+
public function testUninstallWithGetInstallPathException(): void
236+
{
237+
$package = $this->createMock(PackageInterface::class);
238+
$package->expects($this->once())
239+
->method('getType')
240+
->willReturn('invalid-type');
241+
$package->expects($this->once())
242+
->method('getName')
243+
->willReturn('test/package');
244+
245+
$repo = $this->createMock(InstalledRepositoryInterface::class);
246+
$repo->expects($this->once())
247+
->method('hasPackage')
248+
->willReturn(true);
249+
$repo->expects($this->once())
250+
->method('removePackage')
251+
->with($package);
252+
253+
$installer = new InstallerPlugin($this->io, $this->composer);
254+
255+
// Expect error to be written
256+
$this->io->expects($this->once())
257+
->method('writeError')
258+
->with($this->stringContains('Error during uninstall of test/package:'));
259+
260+
$result = $installer->uninstall($repo, $package);
261+
$this->assertNull($result);
262+
}
263+
264+
/**
265+
* Test supports method with exception during installer creation
266+
*/
267+
public function testSupportsWithException(): void
268+
{
269+
// Create a custom installer that will throw an exception
270+
$installer = new class ($this->io, $this->composer) extends InstallerPlugin {
271+
protected array $supportedTypes = [
272+
'custom' => 'NonExistentInstaller'
273+
];
274+
275+
protected function supportedType(string $type): string|false
276+
{
277+
if ($type === 'test-invalid-type') {
278+
return 'custom';
279+
}
280+
return false;
281+
}
282+
};
283+
284+
// Expect error to be written
285+
$this->io->expects($this->once())
286+
->method('writeError')
287+
->with($this->stringContains('Error checking support for package type "test-invalid-type":'));
288+
289+
$result = $installer->supports('test-invalid-type');
290+
$this->assertFalse($result);
200291
}
201292
}

tests/Unit/InstallerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp(): void
3737
}
3838

3939
/**
40-
* @covers ::activate
40+
* Test activate method
4141
*/
4242
public function testActivate(): void
4343
{
@@ -68,7 +68,7 @@ public function testActivate(): void
6868
}
6969

7070
/**
71-
* @covers ::deactivate
71+
* Test deactivate method
7272
*/
7373
public function testDeactivate(): void
7474
{
@@ -89,7 +89,7 @@ public function testDeactivate(): void
8989
}
9090

9191
/**
92-
* @covers ::uninstall
92+
* Test uninstall method
9393
*/
9494
public function testUninstall(): void
9595
{

0 commit comments

Comments
 (0)