mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-07-25 08:09:08 +07:00
Add support to fetch tool versions from packagist
This commit is contained in:
50
__tests__/packagist.test.ts
Normal file
50
__tests__/packagist.test.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import * as packagist from '../src/packagist';
|
||||
import nock = require('nock');
|
||||
|
||||
describe('search function', () => {
|
||||
const mockResponse = {
|
||||
packages: {
|
||||
'test-package': [
|
||||
{
|
||||
require: {
|
||||
php: '8.0.0'
|
||||
},
|
||||
version: '1.0.0'
|
||||
},
|
||||
{
|
||||
version: '2.0.0'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
test('should return the version if matching php version is found', async () => {
|
||||
nock('https://repo.packagist.org')
|
||||
.get('/p2/test-package.json')
|
||||
.reply(200, mockResponse);
|
||||
const result = await packagist.search('test-package', '8.0');
|
||||
expect(result).toBe('1.0.0');
|
||||
});
|
||||
|
||||
test('should return null if no matching php version is found', async () => {
|
||||
nock('https://repo.packagist.org')
|
||||
.get('/p2/test-package.json')
|
||||
.reply(200, mockResponse);
|
||||
const result = await packagist.search('test-package', '5.6');
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
test('should return null if fetch fails', async () => {
|
||||
nock('https://repo.packagist.org').get('/p2/test-package.json').reply(404);
|
||||
const result = await packagist.search('test-package', '8.0');
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
test('should return null if the response is empty', async () => {
|
||||
nock('https://repo.packagist.org')
|
||||
.get('/p2/test-package.json')
|
||||
.reply(200, {error: true, data: '[]'});
|
||||
const result = await packagist.search('test-package', '8.0');
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
@ -70,6 +70,22 @@ jest.mock('../src/fetch', () => ({
|
||||
)
|
||||
}));
|
||||
|
||||
jest.mock('../src/packagist', () => ({
|
||||
search: jest
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
async (
|
||||
package_name: string,
|
||||
php_version: string
|
||||
): Promise<string | null> => {
|
||||
if (package_name === 'phpunit/phpunit') {
|
||||
return php_version + '.0';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
)
|
||||
}));
|
||||
|
||||
describe('Tools tests', () => {
|
||||
it.each`
|
||||
token | version
|
||||
@ -387,7 +403,7 @@ describe('Tools tests', () => {
|
||||
'add_tool https://github.com/phpDocumentor/phpDocumentor/releases/latest/download/phpDocumentor.phar phpDocumentor "--version"',
|
||||
'add_composer_tool phplint phplint overtrue/',
|
||||
'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan "-V"',
|
||||
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"',
|
||||
'add_tool https://phar.phpunit.de/phpunit-7.4.0.phar phpunit "--version"',
|
||||
'add_pecl',
|
||||
'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"',
|
||||
'add_composer_tool phinx phinx robmorgan/ scoped',
|
||||
@ -513,7 +529,7 @@ describe('Tools tests', () => {
|
||||
it.each`
|
||||
tools_csv | script
|
||||
${'none'} | ${''}
|
||||
${'none, phpunit'} | ${'\nstep_log "Setup Tools"\nadd_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer latest\n\nadd_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"'}
|
||||
${'none, phpunit'} | ${'\nstep_log "Setup Tools"\nadd_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer latest\n\nadd_tool https://phar.phpunit.de/phpunit-7.4.0.phar phpunit "--version"'}
|
||||
${'composer:preview'} | ${'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-preview.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-preview.phar,https://getcomposer.org/composer-preview.phar composer preview'}
|
||||
${'composer, composer:v1'} | ${'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer'}
|
||||
${'composer:v1, composer:preview, composer:snapshot'} | ${'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-snapshot.phar,https://dl.cloudsmith.io/public/shivammathur/composer-cache/raw/files/composer-7.4-snapshot.phar,https://getcomposer.org/composer.phar composer snapshot'}
|
||||
@ -543,13 +559,13 @@ describe('Tools tests', () => {
|
||||
|
||||
it.each`
|
||||
tools_csv | php_version | resolved
|
||||
${'phpunit'} | ${'8.2'} | ${'/phpunit.phar'}
|
||||
${'phpunit'} | ${'8.1'} | ${'/phpunit.phar'}
|
||||
${'phpunit'} | ${'8.0'} | ${'/phpunit-9.6.8.phar'}
|
||||
${'phpunit'} | ${'7.3'} | ${'/phpunit-9.6.8.phar'}
|
||||
${'phpunit'} | ${'7.2'} | ${'/phpunit-8.5.33.phar'}
|
||||
${'phpunit'} | ${'7.1'} | ${'/phpunit-7.5.20.phar'}
|
||||
${'phpunit'} | ${'7.0'} | ${'/phpunit-6.5.14.phar'}
|
||||
${'phpunit'} | ${'8.2'} | ${'/phpunit-8.2.0.phar'}
|
||||
${'phpunit'} | ${'8.1'} | ${'/phpunit-8.1.0.phar'}
|
||||
${'phpunit'} | ${'8.0'} | ${'/phpunit-8.0.0.phar'}
|
||||
${'phpunit'} | ${'7.3'} | ${'/phpunit-7.3.0.phar'}
|
||||
${'phpunit'} | ${'7.2'} | ${'/phpunit-7.2.0.phar'}
|
||||
${'phpunit'} | ${'7.1'} | ${'/phpunit-7.1.0.phar'}
|
||||
${'phpunit'} | ${'7.0'} | ${'/phpunit-7.0.0.phar'}
|
||||
`(
|
||||
'checking error: $tools_csv',
|
||||
async ({tools_csv, php_version, resolved}) => {
|
||||
|
Reference in New Issue
Block a user