Improve code and examples

This commit is contained in:
Shivam Mathur 2019-10-08 18:12:54 +05:30
parent 7e81c058fb
commit 46a875ad7e
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
31 changed files with 1049 additions and 589 deletions

View File

@ -30,8 +30,8 @@ jobs:
run: node lib/install.js
env:
php-version: ${{ matrix.php-versions }}
extension-csv: "mbstring, xdebug, pcov" #optional
ini-values-csv: "post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata" #optional
extension-csv: mbstring, xdebug, pcov #optional
ini-values-csv: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata #optional
- name: Testing PHP version
run: php -v

View File

@ -15,7 +15,7 @@
<a href="https://www.codementor.io/shivammathur?utm_source=github&utm_medium=button&utm_term=shivammathur&utm_campaign=github"><img alt="Contact me on Codementor" src="https://cdn.codementor.io/badges/contact_me_github.svg"></a>
</p>
Setup PHP with required extensions, php.ini configuration and composer in [GitHub Actions](https://github.com/features/actions). This action can be added as a step in your action workflow and it will setup the PHP environment you need to test your application. Refer to [Usage](#memo-usage) section to see how to use this.
Setup PHP with required extensions, php.ini configuration and composer in [GitHub Actions](https://github.com/features/actions). This action can be added as a step in your action workflow and it will setup the PHP environment you need to test your application. Refer to [Usage](#memo-usage) section and [examples](#examples) to see how to use this.
## :tada: PHP Support
@ -26,7 +26,7 @@ Setup PHP with required extensions, php.ini configuration and composer in [GitHu
|7.1|`Stable`|`Security fixes only`|
|7.2|`Stable`|`Active`|
|7.3|`Stable`|`Active`|
|7.4|`Beta`/`RC`|`Active`|
|7.4|`RC3`|`Active`|
**Note:** PHP 7.4 is currently in development, do not use in production/release branches.
@ -40,7 +40,6 @@ Setup PHP with required extensions, php.ini configuration and composer in [GitHu
|Ubuntu 16.04|`ubuntu-16.04`|
|macOS X Mojave 10.14|`macOS-latest` or `macOS-10.14`|
## :wrench: PHP Extension Support
- On `ubuntu` extensions which have the package in apt are installed.
- On `windows` and `macOS` PECL extensions are installed.
@ -53,10 +52,11 @@ Setup PHP with required extensions, php.ini configuration and composer in [GitHu
Specify `coverage: xdebug` to use `Xdebug`.
Runs on all [PHP versions supported](#tada-php-support)
```
```yaml
uses: shivammathur/setup-php@master
with:
php-version: 7.3
php-version: '7.3'
coverage: xdebug
```
@ -65,20 +65,22 @@ with:
Specify `coverage: pcov` to use `PCOV`. `PCOV` is way faster than `Xdebug`.
For `pcov.directory` to be other than `src`, `lib` or, `app`, specify it using the `ini-values-csv` input.
`PCOV` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV`
```
```yaml
uses: shivammathur/setup-php@master
with:
php-version: 7.3
ini-values-csv: 'pcov.directory=api' #optional, see above for usage.
php-version: '7.3'
ini-values-csv: pcov.directory=api #optional, see above for usage.
coverage: pcov
```
### Disable coverage
Specify `coverage: none` to disable both `Xdebug` and `PCOV`.
```
```yaml
uses: shivammathur/setup-php@master
with:
php-version: 7.3
php-version: '7.3'
coverage: none
```
@ -91,7 +93,7 @@ Inputs supported by this GitHub Action.
- ini-values-csv `optional`
- coverage `optional`
See [action.yml](action.yml) for more info
See [action.yml](action.yml) and usage below for more info.
### Basic Usage
@ -102,9 +104,9 @@ steps:
- name: Installing PHP
uses: shivammathur/setup-php@master
with:
php-version: 7.3
php-version: '7.3'
extension-csv: mbstring, xdebug #optional
ini-values-csv: "post_max_size=256M, short_open_tag=On" #optional
ini-values-csv: post_max_size=256M, short_open_tag=On #optional
coverage: xdebug #optional
- name: Check PHP Version
run: php -v
@ -134,7 +136,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, xdebug #optional
ini-values-csv: "post_max_size=256M, short_open_tag=On" #optional
ini-values-csv: post_max_size=256M, short_open_tag=On #optional
coverage: xdebug #optional
- name: Check PHP Version
run: php -v
@ -149,11 +151,18 @@ jobs:
Examples for setting up this GitHub Action with different PHP Frameworks/Packages.
**Note:** Make sure you add steps to run your tests after the setup steps given in these examples.
- [Laravel with MySQL](./examples/laravel-mysql.yml)
- [Laravel with PostgreSQL](./examples/laravel-postgres.yml)
- [Slim Framework](./examples/slim-framework.yml)
|Framework/Package|Workflow|
|--- |--- |
|CodeIgniter|[codeigniter.yml](./examples/codeigniter.yml)|
|Laravel `MySQL` `Redis`|[laravel-mysql.yml](./examples/laravel-mysql.yml)|
|Laravel `PostgreSQL` `Redis`|[laravel-postgres.yml](./examples/laravel-postgres.yml)|
|Laravel|[laravel.yml](./examples/laravel.yml)|
|Slim Framework|[slim-framework.yml](./examples/slim-framework.yml)|
|Symfony `MySQL`|[symfony-mysql.yml](./examples/symfony-mysql.yml)|
|Symfony `PostgreSQL`|[symfony-postgres.yml](./examples/symfony-postgres.yml)|
|Yii2 Starter Kit `MySQL`|[yii2-mysql.yml](./examples/yii2-mysql.yml)|
|Yii2 Starter Kit `PostgreSQL`|[yii2-postgres.yml](./examples/yii2-postgres.yml)|
|Zend Framework|[zend-framework.yml](./examples/zend-framework.yml)|
## :scroll: License

57
__tests__/config.test.ts Normal file
View File

@ -0,0 +1,57 @@
import * as config from '../src/config';
describe('Config tests', () => {
it('checking addINIValuesOnWindows', async () => {
let win32: string = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'win32'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M"'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "short_open_tag=On"'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "date.timezone=Asia/Kolkata"'
);
win32 = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'fedora'
);
expect(win32).toContain('Platform fedora is not supported');
});
it('checking addINIValuesOnLinux', async () => {
let linux: string = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'linux'
);
expect(linux).toContain('echo "post_max_size=256M" >> $ini_file');
expect(linux).toContain('echo "short_open_tag=On" >> $ini_file');
expect(linux).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
linux = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'fedora'
);
expect(linux).toContain('Platform fedora is not supported');
});
it('checking addINIValuesOnDarwin', async () => {
let darwin: string = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'darwin'
);
expect(darwin).toContain('echo "post_max_size=256M" >> $ini_file');
expect(darwin).toContain('echo "short_open_tag=On" >> $ini_file');
expect(darwin).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
darwin = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'fedora'
);
expect(darwin).toContain('Platform fedora is not supported');
});
});

View File

@ -0,0 +1,80 @@
import * as config from '../src/config';
import * as coverage from '../src/coverage';
import * as extensions from '../src/coverage';
jest.mock('../src/extensions', () => ({
addExtension: jest.fn().mockImplementation(extension => {
return 'addExtension ' + extension + '\n';
})
}));
describe('Config tests', () => {
it('checking addCoverage with PCOV on windows', async () => {
let win32: string = await coverage.addCoverage('pcov', '7.4', 'win32');
expect(win32).toContain('addExtension pcov');
expect(win32).toContain(
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php'
);
win32 = await coverage.addCoverage('pcov', '7.0', 'win32');
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
win32 = await coverage.addCoverage('pcov', '5.6', 'win32');
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
});
it('checking addCoverage with PCOV on linux', async () => {
let linux: string = await coverage.addCoverage('pcov', '7.4', 'linux');
expect(linux).toContain('addExtension pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
expect(linux).toContain('sudo phpdismod xdebug');
});
it('checking addCoverage with PCOV on darwin', async () => {
let darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin');
expect(darwin).toContain('addExtension pcov');
});
it('checking addCoverage with Xdebug on windows', async () => {
let win32: string = await coverage.addCoverage('xdebug', '7.3', 'win32');
expect(win32).toContain('addExtension xdebug');
});
it('checking addCoverage with Xdebug on linux', async () => {
let linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux');
expect(linux).toContain('addExtension xdebug');
});
it('checking addCoverage with Xdebug on darwin', async () => {
let darwin: string = await coverage.addCoverage('xdebug', '7.4', 'darwin');
expect(darwin).toContain('addExtension xdebug');
});
it('checking disableCoverage windows', async () => {
let win32 = await coverage.addCoverage('none', '7.4', 'win32');
expect(win32).toContain('Disable-PhpExtension xdebug');
expect(win32).toContain('Disable-PhpExtension pcov');
});
it('checking disableCoverage on linux', async () => {
let linux: string = await coverage.addCoverage('none', '7.4', 'linux');
expect(linux).toContain('sudo phpdismod xdebug');
expect(linux).toContain('sudo phpdismod pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
expect(linux).toContain('sudo sed -i "/pcov/d" $ini_file');
});
it('checking disableCoverage on darwin', async () => {
let darwin: string = await coverage.addCoverage('none', '7.4', 'darwin');
expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" $ini_file');
expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" $ini_file');
});
it('checking no or invalid coverage driver', async () => {
let nocov: string = await coverage.addCoverage('nocov', '7.x', 'any');
expect(nocov).toEqual('');
nocov = await coverage.addCoverage('', '7.x', 'any');
expect(nocov).toEqual('');
});
});

View File

@ -0,0 +1,92 @@
import * as extensions from '../src/extensions';
let valid_extensions = ['xdebug', 'pcov'];
jest.mock('../src/pecl', () => ({
checkPECLExtension: jest.fn().mockImplementation(extension => {
return valid_extensions.indexOf(extension) !== -1;
})
}));
describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension(
'xdebug, pcov',
'7.2',
'win32'
);
expect(win32).toContain('Install-PhpExtension xdebug');
expect(win32).toContain('Install-PhpExtension pcov');
win32 = await extensions.addExtension('xdebug, pcov', '7.4', 'win32');
const extension_url: string =
'https://xdebug.org/files/php_xdebug-2.8.0beta2-7.4-vc15.dll';
expect(win32).toContain(
'Invoke-WebRequest -Uri ' +
extension_url +
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll'
);
expect(win32).toContain('Install-PhpExtension pcov');
win32 = await extensions.addExtension('does_not_exist', '7.2', 'win32');
expect(win32).toContain('Could not find does_not_exist for PHP7.2 on PECL');
win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(win32).toContain('Platform fedora is not supported');
});
it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension(
'xdebug, pcov',
'7.2',
'linux'
);
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-xdebug'
);
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-pcov'
);
linux = await extensions.addExtension('xdebug, pcov', '7.4', 'linux');
expect(linux).toContain('./xdebug.sh');
expect(linux).toContain('./pcov.sh');
linux = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(linux).toContain('Platform fedora is not supported');
});
it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension(
'xdebug, pcov',
'7.2',
'darwin'
);
expect(darwin).toContain('sudo pecl install xdebug');
expect(darwin).toContain('sudo pecl install pcov');
darwin = await extensions.addExtension('pcov', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install pcov');
darwin = await extensions.addExtension('pcov', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install pcov');
darwin = await extensions.addExtension('xdebug', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug-2.5.5');
darwin = await extensions.addExtension('xdebug', '7.4', 'darwin');
expect(darwin).toContain('sh ./xdebug_darwin.sh');
darwin = await extensions.addExtension('pcov', '7.4', 'darwin');
expect(darwin).toContain('sh ./pcov.sh');
darwin = await extensions.addExtension('xdebug', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug');
darwin = await extensions.addExtension('does_not_exist', '7.2', 'darwin');
expect(darwin).toContain(
'Could not find does_not_exist for PHP7.2 on PECL'
);
darwin = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(darwin).toContain('Platform fedora is not supported');
});
});

View File

@ -1,225 +0,0 @@
import * as features from '../src/features';
let valid_extensions = ['xdebug', 'pcov'];
jest.mock('../src/pecl', () => ({
checkPECLExtension: jest.fn().mockImplementation(extension => {
return valid_extensions.indexOf(extension) !== -1;
})
}));
describe('Features tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await features.addExtension(
'xdebug, pcov',
'7.2',
'win32'
);
expect(win32).toContain('Install-PhpExtension xdebug');
expect(win32).toContain('Install-PhpExtension pcov');
win32 = await features.addExtension('xdebug, pcov', '7.4', 'win32');
const extension_url: string =
'https://xdebug.org/files/php_xdebug-2.8.0beta2-7.4-vc15.dll';
expect(win32).toContain(
'Invoke-WebRequest -Uri ' +
extension_url +
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll'
);
expect(win32).toContain('Install-PhpExtension pcov');
win32 = await features.addExtension('does_not_exist', '7.2', 'win32');
expect(win32).toContain('Could not find does_not_exist for PHP7.2 on PECL');
win32 = await features.addExtension('xdebug', '7.2', 'fedora');
expect(win32).toContain('Platform fedora is not supported');
});
it('checking addExtensionOnLinux', async () => {
let linux: string = await features.addExtension(
'xdebug, pcov',
'7.2',
'linux'
);
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-xdebug'
);
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-pcov'
);
linux = await features.addExtension('xdebug, pcov', '7.4', 'linux');
expect(linux).toContain('./xdebug.sh');
expect(linux).toContain('./pcov.sh');
linux = await features.addExtension('xdebug', '7.2', 'fedora');
expect(linux).toContain('Platform fedora is not supported');
});
it('checking addExtensionOnDarwin', async () => {
let darwin: string = await features.addExtension(
'xdebug, pcov',
'7.2',
'darwin'
);
expect(darwin).toContain('sudo pecl install xdebug');
expect(darwin).toContain('sudo pecl install pcov');
darwin = await features.addExtension('pcov', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install pcov');
darwin = await features.addExtension('pcov', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install pcov');
darwin = await features.addExtension('xdebug', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug-2.5.5');
darwin = await features.addExtension('xdebug', '7.4', 'darwin');
expect(darwin).toContain('sh ./xdebug_darwin.sh');
darwin = await features.addExtension('pcov', '7.4', 'darwin');
expect(darwin).toContain('sh ./pcov.sh');
darwin = await features.addExtension('xdebug', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug');
darwin = await features.addExtension('does_not_exist', '7.2', 'darwin');
expect(darwin).toContain(
'Could not find does_not_exist for PHP7.2 on PECL'
);
darwin = await features.addExtension('xdebug', '7.2', 'fedora');
expect(darwin).toContain('Platform fedora is not supported');
});
it('checking addINIValuesOnWindows', async () => {
let win32: string = await features.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'win32'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M"'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "short_open_tag=On"'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "date.timezone=Asia/Kolkata"'
);
win32 = await features.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'fedora'
);
expect(win32).toContain('Platform fedora is not supported');
});
it('checking addINIValuesOnLinux', async () => {
let linux: string = await features.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'linux'
);
expect(linux).toContain('echo "post_max_size=256M" >> $ini_file');
expect(linux).toContain('echo "short_open_tag=On" >> $ini_file');
expect(linux).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
linux = await features.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'fedora'
);
expect(linux).toContain('Platform fedora is not supported');
});
it('checking addINIValuesOnDarwin', async () => {
let darwin: string = await features.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'darwin'
);
expect(darwin).toContain('echo "post_max_size=256M" >> $ini_file');
expect(darwin).toContain('echo "short_open_tag=On" >> $ini_file');
expect(darwin).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
darwin = await features.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'fedora'
);
expect(darwin).toContain('Platform fedora is not supported');
});
it('checking addCoverage on windows', async () => {
let win32: string = await features.addCoverage('xdebug', '7.4', 'win32');
const extension_url: string =
'https://xdebug.org/files/php_xdebug-2.8.0beta2-7.4-vc15.dll';
expect(win32).toContain(
'Invoke-WebRequest -Uri ' +
extension_url +
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll'
);
win32 = await features.addCoverage('xdebug', '7.3', 'win32');
expect(win32).toContain('Install-PhpExtension xdebug');
win32 = await features.addCoverage('pcov', '7.4', 'win32');
expect(win32).toContain('Install-PhpExtension pcov');
expect(win32).toContain(
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php'
);
win32 = await features.addCoverage('pcov', '7.3', 'win32');
expect(win32).toContain('Install-PhpExtension pcov');
expect(win32).toContain(
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php'
);
win32 = await features.addCoverage('nocov', '7.3', 'win32');
expect(win32).toContain('');
win32 = await features.addCoverage('pcov', '7.0', 'win32');
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
win32 = await features.addCoverage('pcov', '5.6', 'win32');
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
win32 = await features.addCoverage('none', '7.4', 'win32');
expect(win32).toContain('Disable-PhpExtension xdebug');
expect(win32).toContain('Disable-PhpExtension pcov');
win32 = await features.addCoverage('', '7.4', 'win32');
expect(win32).toEqual('');
});
it('checking addCoverage on linux', async () => {
let linux: string = await features.addCoverage('xdebug', '7.4', 'linux');
expect(linux).toContain('./xdebug.sh');
linux = await features.addCoverage('pcov', '7.4', 'linux');
expect(linux).toContain('./pcov.sh');
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
expect(linux).toContain('sudo phpdismod xdebug');
linux = await features.addCoverage('none', '7.4', 'linux');
expect(linux).toContain('sudo phpdismod xdebug');
expect(linux).toContain('sudo phpdismod pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
expect(linux).toContain('sudo sed -i "/pcov/d" $ini_file');
linux = await features.addCoverage('', '7.4', 'linux');
expect(linux).toEqual('');
});
it('checking addCoverage on darwin', async () => {
let darwin: string = await features.addCoverage('xdebug', '7.4', 'darwin');
expect(darwin).toContain('sh ./xdebug_darwin.sh');
darwin = await features.addCoverage('xdebug', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug-2.5.5');
darwin = await features.addCoverage('pcov', '7.4', 'darwin');
expect(darwin).toContain('sh ./pcov.sh');
darwin = await features.addCoverage('none', '7.4', 'darwin');
expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" $ini_file');
expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" $ini_file');
darwin = await features.addCoverage('', '7.4', 'win32');
expect(darwin).toEqual('');
});
});

View File

@ -82,6 +82,7 @@ describe('Utils tests', () => {
'c',
'd'
]);
expect(await utils.extensionArray('')).toEqual([]);
expect(await utils.extensionArray(' ')).toEqual([]);
});

27
examples/codeigniter.yml Normal file
View File

@ -0,0 +1,27 @@
name: Testing CodeIgniter
on: [push, pull_request]
jobs:
build:
strategy:
max-parallel: 6
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.2', '7.3']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, intl, curl, dom
coverage: xdebug #optional
- name: Install dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Test with phpunit in windows
if: matrix.operating-system == 'windows-latest'
run: .\vendor\bin\phpunit --coverage-text
- name: Test with phpunit
if: matrix.operating-system != 'windows-latest'
run: vendor/bin/phpunit --coverage-text

View File

@ -2,7 +2,7 @@ name: Testing Laravel with MySQL
on: [push, pull_request]
jobs:
laravel:
name: Laravel (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
name: Laravel (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
DB_PASSWORD: password
@ -27,10 +27,9 @@ jobs:
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
max-parallel: 15
max-parallel: 3
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.2', '7.3']
php-versions: ['7.2', '7.3', '7.4']
steps:
- name: Checkout
uses: actions/checkout@v1
@ -38,17 +37,21 @@ jobs:
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring #optional
coverage: xdebug #optional
extension-csv: mbstring, dom, fileinfo, mysql
coverage: xdebug #optional
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Prepare the application
run: |
cp .env.example .env
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
- name: Clear Config
run: php artisan config:clear
run: php artisan config:clear
- name: Run Migration
run: php artisan migrate -v
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}

View File

@ -2,7 +2,7 @@ name: Testing Laravel with PostgreSQL
on: [push, pull_request]
jobs:
laravel:
name: Laravel (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
name: Laravel (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
BROADCAST_DRIVER: log
@ -31,10 +31,9 @@ jobs:
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
max-parallel: 15
max-parallel: 3
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.2', '7.3']
php-versions: ['7.2', '7.3', '7.4']
steps:
- name: Checkout
uses: actions/checkout@v1
@ -42,17 +41,21 @@ jobs:
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring #optional
extension-csv: mbstring, dom, fileinfo, pgsql
coverage: xdebug #optional
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Prepare the application
run: |
cp .env.example .env
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
- name: Clear Config
run: php artisan config:clear
- name: Run Migration
run: php artisan migrate -v
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}

35
examples/laravel.yml Normal file
View File

@ -0,0 +1,35 @@
name: Unit Testing Laravel
on: [push, pull_request]
jobs:
laravel:
name: Laravel (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
max-parallel: 6
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.2', '7.3']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, dom, fileinfo
coverage: xdebug #optional
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Prepare the application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
- name: Clear Config
run: php artisan config:clear
- name: Test with phpunit in windows
if: matrix.operating-system == 'windows-latest'
run: .\vendor\bin\phpunit --coverage-text
- name: Test with phpunit
if: matrix.operating-system != 'windows-latest'
run: vendor/bin/phpunit --coverage-text

View File

@ -6,7 +6,7 @@ jobs:
max-parallel: 6
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: [7.2, 7.3]
php-versions: ['7.2', '7.3']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
@ -15,7 +15,13 @@ jobs:
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: 'mbstring'
coverage: 'xdebug'
extension-csv: mbstring, simplexml, dom
coverage: xdebug #optional
- name: Install dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Test with phpunit in windows
if: matrix.operating-system == 'windows-latest'
run: .\vendor\bin\phpunit --coverage-text
- name: Test with phpunit
if: matrix.operating-system != 'windows-latest'
run: vendor/bin/phpunit --coverage-text

View File

@ -0,0 +1,44 @@
name: Testing Symfony with MySQL
on: [push, pull_request]
jobs:
laravel:
name: Symfony (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: symfony
MYSQL_DATABASE: symfony
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
max-parallel: 3
matrix:
php-versions: ['7.3']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, xml, ctype, iconv, mysql
coverage: xdebug #optional
- name: Install Composer dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Run Migration
run: |
composer require symfony/orm-pack
php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env:
DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony
- name: Run Tests
run: |
composer require phpunit
php bin/phpunit --coverage-text

View File

@ -0,0 +1,44 @@
name: Testing Symfony with PostgreSQL
on: [push, pull_request]
jobs:
laravel:
name: Symfony (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
services:
postgres:
image: postgres:10.8
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
strategy:
fail-fast: false
max-parallel: 3
matrix:
php-versions: ['7.3']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, xml, ctype, iconv, pgsql
coverage: xdebug #optional
- name: Install Composer dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Run Migration
run: |
composer require symfony/orm-pack
php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env:
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?charset=UTF-8
- name: Run Tests
run: |
composer require phpunit
php bin/phpunit --coverage-text

29
examples/symfony.yml Normal file
View File

@ -0,0 +1,29 @@
name: Unit Testing Symfony
on: [push, pull_request]
jobs:
laravel:
name: Symfony (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
max-parallel: 3
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.3']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, xml, ctype, iconv
coverage: xdebug #optional
- name: Install Composer dependencies
run: |
composer require symfony/orm-pack
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Run Tests
run: |
composer require phpunit
php bin/phpunit --coverage-text

60
examples/yii2-mysql.yml Normal file
View File

@ -0,0 +1,60 @@
name: Testing Yii2 with MySQL
on: [push, pull_request]
jobs:
laravel:
name: Yii2 (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
DB_USERNAME: root
DB_PASSWORD: yii
TEST_DB_USERNAME: root
TEST_DB_PASSWORD: yii
DB_CHARSET: utf8
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: yii
MYSQL_DATABASE: yii
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
max-parallel: 3
matrix:
php-versions: ['7.2', '7.3', '7.4']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Set Node.js 10.x
uses: actions/setup-node@master
with:
version: 10.x
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, intl, gd, imagick, zip, dom, mysql
coverage: xdebug #optional
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Prepare the application
run: |
php -r "file_exists('.env') || copy('.env.dist', '.env');"
php console/yii app/setup
npm install --development
npm run build
env:
DB_DSN: mysql:host=127.0.0.1;port=${{ job.services.mysql.ports['3306'] }};dbname=yii
TEST_DB_DSN: mysql:host=127.0.0.1;port=${{ job.services.mysql.ports['3306'] }};dbname=yii
- name: Run Tests
run: |
vendor/bin/codecept build
php tests/bin/yii app/setup --interactive=0
nohup php -S localhost:8080 > yii.log 2>&1 &
vendor/bin/codecept run
env:
DB_DSN: mysql:host=127.0.0.1;port=${{ job.services.mysql.ports['3306'] }};dbname=yii
TEST_DB_DSN: mysql:host=127.0.0.1;port=${{ job.services.mysql.ports['3306'] }};dbname=yii

View File

@ -0,0 +1,60 @@
name: Testing Yii2 with PostgreSQL
on: [push, pull_request]
jobs:
laravel:
name: Yii2 (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
DB_USERNAME: postgres
DB_PASSWORD: postgres
TEST_DB_USERNAME: postgres
TEST_DB_PASSWORD: postgres
DB_CHARSET: utf8
services:
postgres:
image: postgres:10.8
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
strategy:
fail-fast: false
max-parallel: 3
matrix:
php-versions: ['7.2', '7.3', '7.4']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Set Node.js 10.x
uses: actions/setup-node@master
with:
version: 10.x
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, intl, gd, imagick, zip, dom, pgsql
coverage: xdebug #optional
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Prepare the application
run: |
php -r "file_exists('.env') || copy('.env.dist', '.env');"
php console/yii app/setup
npm install --development
npm run build
env:
DB_DSN: pgsql:host=127.0.0.1;port=${{ job.services.postgres.ports['5432'] }};dbname=postgres
TEST_DB_DSN: pgsql:host=127.0.0.1;port=${{ job.services.postgres.ports['5432'] }};dbname=postgres
- name: Run Tests
run: |
vendor/bin/codecept build
php tests/bin/yii app/setup --interactive=0
nohup php -S localhost:8080 > yii.log 2>&1 &
vendor/bin/codecept run
env:
DB_DSN: pgsql:host=127.0.0.1;port=${{ job.services.postgres.ports['5432'] }};dbname=postgres
TEST_DB_DSN: pgsql:host=127.0.0.1;port=${{ job.services.postgres.ports['5432'] }};dbname=postgres

View File

@ -0,0 +1,29 @@
name: Testing Zend Framework
on: [push, pull_request]
jobs:
build:
strategy:
max-parallel: 6
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.2', '7.3']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, bcmath, curl, intl
coverage: xdebug #optional
- name: Install dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
composer require --dev phpunit/phpunit squizlabs/php_codesniffer zendframework/zend-test
- name: Test with phpunit in windows
if: matrix.operating-system == 'windows-latest'
run: .\vendor\bin\phpunit --coverage-text
- name: Test with phpunit
if: matrix.operating-system != 'windows-latest'
run: vendor/bin/phpunit --coverage-text

77
lib/config.js Normal file
View File

@ -0,0 +1,77 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils = __importStar(require("./utils"));
/**
* Function to add custom ini values
*
* @param ini_values_csv
* @param os_version
*/
function addINIValues(ini_values_csv, os_version) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return yield addINIValuesWindows(ini_values_csv);
case 'darwin':
case 'linux':
return yield addINIValuesUnix(ini_values_csv);
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error', 'Add Config');
}
});
}
exports.addINIValues = addINIValues;
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
function addINIValuesUnix(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
let ini_values = yield utils.INIArray(ini_values_csv);
yield utils.asyncForEach(ini_values, function (ini_value) {
return __awaiter(this, void 0, void 0, function* () {
// add script to set ini value
script += 'echo "' + ini_value + '" >> $ini_file\n';
});
});
return script;
});
}
exports.addINIValuesUnix = addINIValuesUnix;
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
function addINIValuesWindows(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
let ini_values = yield utils.INIArray(ini_values_csv);
yield utils.asyncForEach(ini_values, function (ini_value) {
return __awaiter(this, void 0, void 0, function* () {
// add script to set ini value
script += 'Add-Content C:\\tools\\php\\php.ini "' + ini_value + '"\n';
});
});
return script;
});
}
exports.addINIValuesWindows = addINIValuesWindows;

115
lib/coverage.js Normal file
View File

@ -0,0 +1,115 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils = __importStar(require("./utils"));
const extensions = __importStar(require("./extensions"));
const config = __importStar(require("./config"));
function addCoverage(coverage_driver, version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
coverage_driver.toLowerCase();
switch (coverage_driver) {
case 'pcov':
return addCoveragePCOV(version, os_version);
case 'xdebug':
return addCoverageXdebug(version, os_version);
case 'none':
return disableCoverage(version, os_version);
default:
return '';
}
});
}
exports.addCoverage = addCoverage;
function addCoverageXdebug(version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
script += yield extensions.addExtension('xdebug', version, os_version, 'Set Coverage Driver');
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
return script;
});
}
exports.addCoverageXdebug = addCoverageXdebug;
function addCoveragePCOV(version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
switch (version) {
default:
script += yield extensions.addExtension('pcov', version, os_version, 'Set Coverage Driver');
script += yield config.addINIValues('pcov.enabled=1', os_version);
// add command to disable xdebug and enable pcov
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
break;
}
// success
script += yield utils.log('PCOV enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
// version is not supported
break;
case '5.6':
case '7.0':
script += yield utils.log('PCOV requires PHP 7.1 or newer', os_version, 'warning', 'Set Coverage Driver');
break;
}
return script;
});
}
exports.addCoveragePCOV = addCoveragePCOV;
function disableCoverage(version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
script += 'sudo sed -i "/pcov/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
script +=
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
break;
}
script += yield utils.log('Disabled Xdebug and PCOV', os_version, 'success', 'Set Coverage Driver');
return script;
});
}
exports.disableCoverage = disableCoverage;

View File

@ -33,20 +33,6 @@ function addExtension(extension_csv, version, os_version, log_prefix = 'Add Exte
});
}
exports.addExtension = addExtension;
function addINIValues(ini_values_csv, os_version) {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return yield addINIValuesWindows(ini_values_csv);
case 'darwin':
case 'linux':
return yield addINIValuesUnix(ini_values_csv);
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error', 'Add Config');
}
});
}
exports.addINIValues = addINIValues;
/**
* Enable extensions which are installed but not enabled on windows
*
@ -257,119 +243,3 @@ function addExtensionLinux(extension_csv, version, log_prefix) {
});
}
exports.addExtensionLinux = addExtensionLinux;
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
function addINIValuesUnix(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
let ini_values = yield utils.INIArray(ini_values_csv);
yield utils.asyncForEach(ini_values, function (ini_value) {
return __awaiter(this, void 0, void 0, function* () {
// add script to set ini value
script += 'echo "' + ini_value + '" >> $ini_file\n';
});
});
return script;
});
}
exports.addINIValuesUnix = addINIValuesUnix;
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
function addINIValuesWindows(ini_values_csv) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
let ini_values = yield utils.INIArray(ini_values_csv);
yield utils.asyncForEach(ini_values, function (ini_value) {
return __awaiter(this, void 0, void 0, function* () {
// add script to set ini value
script += 'Add-Content C:\\tools\\php\\php.ini "' + ini_value + '"\n';
});
});
return script;
});
}
exports.addINIValuesWindows = addINIValuesWindows;
function addCoverage(coverage, version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
let script = '\n';
coverage = coverage.toLowerCase();
// pcov
switch (coverage) {
case 'pcov':
// if version is 7.1 or newer
switch (version) {
default:
script += yield addExtension('pcov', version, os_version, 'Set Coverage Driver');
script += yield addINIValues('pcov.enabled=1', os_version);
// add command to disable xdebug and enable pcov
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
break;
}
// success
script += yield utils.log('PCOV enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
// version is not supported
break;
case '5.6':
case '7.0':
script += yield utils.log('PCOV requires PHP 7.1 or newer', os_version, 'warning', 'Set Coverage Driver');
break;
}
break;
//xdebug
case 'xdebug':
script += yield addExtension('xdebug', version, os_version, 'Set Coverage Driver');
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
break;
case 'none':
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
script += 'sudo sed -i "/pcov/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
script +=
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
break;
}
script += yield utils.log('Disabled Xdebug and PCOV', os_version, 'success', 'Set Coverage Driver');
break;
default:
script = '';
}
return script;
});
}
exports.addCoverage = addCoverage;

View File

@ -19,7 +19,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
const exec_1 = require("@actions/exec/lib/exec");
const core = __importStar(require("@actions/core"));
const utils = __importStar(require("./utils"));
const features = __importStar(require("./features"));
const extensions = __importStar(require("./extensions"));
const config = __importStar(require("./config"));
const coverage = __importStar(require("./coverage"));
/**
* Run the script
*/
@ -30,30 +32,30 @@ function run() {
let version = yield utils.getInput('php-version', true);
let extension_csv = yield utils.getInput('extension-csv', false);
let ini_values_csv = yield utils.getInput('ini-values-csv', false);
let coverage = yield utils.getInput('coverage', false);
let coverage_driver = yield utils.getInput('coverage', false);
let os_version = process.platform;
// check the os version and run the respective script
if (os_version == 'darwin') {
let darwin = yield utils.readScript('darwin.sh', version, os_version);
darwin += yield features.addExtension(extension_csv, version, os_version);
darwin += yield features.addINIValues(ini_values_csv, os_version);
darwin += yield features.addCoverage(coverage, version, os_version);
darwin += yield extensions.addExtension(extension_csv, version, os_version);
darwin += yield config.addINIValues(ini_values_csv, os_version);
darwin += yield coverage.addCoverage(coverage_driver, version, os_version);
yield utils.writeScript('darwin.sh', version, darwin);
yield exec_1.exec('sh ./' + version + 'darwin.sh ' + version);
}
else if (os_version == 'win32') {
let windows = yield utils.readScript('win32.ps1', version, os_version);
windows += yield features.addExtension(extension_csv, version, os_version);
windows += yield features.addINIValues(ini_values_csv, os_version);
windows += yield features.addCoverage(coverage, version, os_version);
windows += yield extensions.addExtension(extension_csv, version, os_version);
windows += yield config.addINIValues(ini_values_csv, os_version);
windows += yield coverage.addCoverage(coverage_driver, version, os_version);
yield utils.writeScript('win32.ps1', version, windows);
yield exec_1.exec('powershell .\\' + version + 'win32.ps1 -version ' + version);
}
else if (os_version == 'linux') {
let linux = yield utils.readScript('linux.sh', version, os_version);
linux += yield features.addExtension(extension_csv, version, os_version);
linux += yield features.addINIValues(ini_values_csv, os_version);
linux += yield features.addCoverage(coverage, version, os_version);
linux += yield extensions.addExtension(extension_csv, version, os_version);
linux += yield config.addINIValues(ini_values_csv, os_version);
linux += yield coverage.addCoverage(coverage_driver, version, os_version);
yield utils.writeScript('linux.sh', version, linux);
yield exec_1.exec('./' + version + 'linux.sh ' + version);
}

View File

@ -28,7 +28,7 @@ function checkPECLExtension(extension) {
allowRetries: true,
maxRetries: 2
});
const response = yield http.get('https://pecl.php.net/package/' + extension);
const response = yield http.get('https://pecl.php.net/json.php?package=' + extension);
return response.message.statusCode === 200;
});
}

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "setup-php",
"version": "1.3.9",
"version": "1.4.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "setup-php",
"version": "1.3.9",
"version": "1.4.0",
"private": false,
"description": "Setup php action",
"main": "lib/setup-php.js",

58
src/config.ts Normal file
View File

@ -0,0 +1,58 @@
import * as utils from './utils';
/**
* Function to add custom ini values
*
* @param ini_values_csv
* @param os_version
*/
export async function addINIValues(ini_values_csv: string, os_version: string) {
switch (os_version) {
case 'win32':
return await addINIValuesWindows(ini_values_csv);
case 'darwin':
case 'linux':
return await addINIValuesUnix(ini_values_csv);
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error',
'Add Config'
);
}
}
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
export async function addINIValuesUnix(
ini_values_csv: string
): Promise<string> {
let script: string = '\n';
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
await utils.asyncForEach(ini_values, async function(ini_value: string) {
// add script to set ini value
script += 'echo "' + ini_value + '" >> $ini_file\n';
});
return script;
}
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
export async function addINIValuesWindows(
ini_values_csv: string
): Promise<string> {
let script: string = '\n';
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
await utils.asyncForEach(ini_values, async function(ini_value: string) {
// add script to set ini value
script += 'Add-Content C:\\tools\\php\\php.ini "' + ini_value + '"\n';
});
return script;
}

129
src/coverage.ts Normal file
View File

@ -0,0 +1,129 @@
import * as utils from './utils';
import * as pecl from './pecl';
import * as extensions from './extensions';
import * as config from './config';
export async function addCoverage(
coverage_driver: string,
version: string,
os_version: string
): Promise<string> {
coverage_driver.toLowerCase();
switch (coverage_driver) {
case 'pcov':
return addCoveragePCOV(version, os_version);
case 'xdebug':
return addCoverageXdebug(version, os_version);
case 'none':
return disableCoverage(version, os_version);
default:
return '';
}
}
export async function addCoverageXdebug(version: string, os_version: string) {
let script: string = '\n';
script += await extensions.addExtension(
'xdebug',
version,
os_version,
'Set Coverage Driver'
);
script += await utils.log(
'Xdebug enabled as coverage driver',
os_version,
'success',
'Set Coverage Driver'
);
return script;
}
export async function addCoveragePCOV(version: string, os_version: string) {
let script: string = '\n';
switch (version) {
default:
script += await extensions.addExtension(
'pcov',
version,
os_version,
'Set Coverage Driver'
);
script += await config.addINIValues('pcov.enabled=1', os_version);
// add command to disable xdebug and enable pcov
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
break;
}
// success
script += await utils.log(
'PCOV enabled as coverage driver',
os_version,
'success',
'Set Coverage Driver'
);
// version is not supported
break;
case '5.6':
case '7.0':
script += await utils.log(
'PCOV requires PHP 7.1 or newer',
os_version,
'warning',
'Set Coverage Driver'
);
break;
}
return script;
}
export async function disableCoverage(version: string, os_version: string) {
let script: string = '\n';
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
script += 'sudo sed -i "/pcov/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
script +=
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
break;
}
script += await utils.log(
'Disabled Xdebug and PCOV',
os_version,
'success',
'Set Coverage Driver'
);
return script;
}

View File

@ -24,23 +24,6 @@ export async function addExtension(
}
}
export async function addINIValues(ini_values_csv: string, os_version: string) {
switch (os_version) {
case 'win32':
return await addINIValuesWindows(ini_values_csv);
case 'darwin':
case 'linux':
return await addINIValuesUnix(ini_values_csv);
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error',
'Add Config'
);
}
}
/**
* Enable extensions which are installed but not enabled on windows
*
@ -324,149 +307,3 @@ export async function addExtensionLinux(
});
return script;
}
/**
* Add script to set custom ini values for unix
*
* @param ini_values_csv
*/
export async function addINIValuesUnix(
ini_values_csv: string
): Promise<string> {
let script: string = '\n';
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
await utils.asyncForEach(ini_values, async function(ini_value: string) {
// add script to set ini value
script += 'echo "' + ini_value + '" >> $ini_file\n';
});
return script;
}
/**
* Add script to set custom ini values for windows
*
* @param ini_values_csv
*/
export async function addINIValuesWindows(
ini_values_csv: string
): Promise<string> {
let script: string = '\n';
let ini_values: Array<string> = await utils.INIArray(ini_values_csv);
await utils.asyncForEach(ini_values, async function(ini_value: string) {
// add script to set ini value
script += 'Add-Content C:\\tools\\php\\php.ini "' + ini_value + '"\n';
});
return script;
}
export async function addCoverage(
coverage: string,
version: string,
os_version: string
): Promise<string> {
let script: string = '\n';
coverage = coverage.toLowerCase();
// pcov
switch (coverage) {
case 'pcov':
// if version is 7.1 or newer
switch (version) {
default:
script += await addExtension(
'pcov',
version,
os_version,
'Set Coverage Driver'
);
script += await addINIValues('pcov.enabled=1', os_version);
// add command to disable xdebug and enable pcov
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
break;
}
// success
script += await utils.log(
'PCOV enabled as coverage driver',
os_version,
'success',
'Set Coverage Driver'
);
// version is not supported
break;
case '5.6':
case '7.0':
script += await utils.log(
'PCOV requires PHP 7.1 or newer',
os_version,
'warning',
'Set Coverage Driver'
);
break;
}
break;
//xdebug
case 'xdebug':
script += await addExtension(
'xdebug',
version,
os_version,
'Set Coverage Driver'
);
script += await utils.log(
'Xdebug enabled as coverage driver',
os_version,
'success',
'Set Coverage Driver'
);
break;
case 'none':
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
script += 'sudo sed -i "/pcov/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
script +=
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
break;
}
script += await utils.log(
'Disabled Xdebug and PCOV',
os_version,
'success',
'Set Coverage Driver'
);
break;
default:
script = '';
}
return script;
}

View File

@ -1,7 +1,9 @@
import {exec} from '@actions/exec/lib/exec';
import * as core from '@actions/core';
import * as utils from './utils';
import * as features from './features';
import * as extensions from './extensions';
import * as config from './config';
import * as coverage from './coverage';
/**
* Run the script
@ -12,7 +14,7 @@ async function run() {
let version: string = await utils.getInput('php-version', true);
let extension_csv: string = await utils.getInput('extension-csv', false);
let ini_values_csv: string = await utils.getInput('ini-values-csv', false);
let coverage: string = await utils.getInput('coverage', false);
let coverage_driver: string = await utils.getInput('coverage', false);
let os_version: string = process.platform;
// check the os version and run the respective script
@ -23,9 +25,17 @@ async function run() {
os_version
);
darwin += await features.addExtension(extension_csv, version, os_version);
darwin += await features.addINIValues(ini_values_csv, os_version);
darwin += await features.addCoverage(coverage, version, os_version);
darwin += await extensions.addExtension(
extension_csv,
version,
os_version
);
darwin += await config.addINIValues(ini_values_csv, os_version);
darwin += await coverage.addCoverage(
coverage_driver,
version,
os_version
);
await utils.writeScript('darwin.sh', version, darwin);
await exec('sh ./' + version + 'darwin.sh ' + version);
} else if (os_version == 'win32') {
@ -34,13 +44,17 @@ async function run() {
version,
os_version
);
windows += await features.addExtension(
windows += await extensions.addExtension(
extension_csv,
version,
os_version
);
windows += await features.addINIValues(ini_values_csv, os_version);
windows += await features.addCoverage(coverage, version, os_version);
windows += await config.addINIValues(ini_values_csv, os_version);
windows += await coverage.addCoverage(
coverage_driver,
version,
os_version
);
await utils.writeScript('win32.ps1', version, windows);
await exec('powershell .\\' + version + 'win32.ps1 -version ' + version);
} else if (os_version == 'linux') {
@ -49,9 +63,13 @@ async function run() {
version,
os_version
);
linux += await features.addExtension(extension_csv, version, os_version);
linux += await features.addINIValues(ini_values_csv, os_version);
linux += await features.addCoverage(coverage, version, os_version);
linux += await extensions.addExtension(
extension_csv,
version,
os_version
);
linux += await config.addINIValues(ini_values_csv, os_version);
linux += await coverage.addCoverage(coverage_driver, version, os_version);
await utils.writeScript('linux.sh', version, linux);
await exec('./' + version + 'linux.sh ' + version);
}

View File

@ -11,7 +11,7 @@ export async function checkPECLExtension(extension: string): Promise<boolean> {
maxRetries: 2
});
const response: hc.HttpClientResponse = await http.get(
'https://pecl.php.net/package/' + extension
'https://pecl.php.net/json.php?package=' + extension
);
return response.message.statusCode === 200;
}

View File

@ -6,26 +6,26 @@ if($version -eq '7.4') {
$version = '7.4RC'
}
echo "Installing PhpManager"
Write-Host "Installing PhpManager" -ForegroundColor Blue
Install-Module -Name PhpManager -Force -Scope CurrentUser
$installed = $($(php -v)[0] -join '')[4..6] -join ''
if($installed -ne $version) {
if($version -lt '7.0') {
echo "Installing VcRedist"
Write-Host "Installing VcRedist"
Install-Module -Name VcRedist -Force
}
echo "Installing PHP"
Write-Host "Installing PHP" -ForegroundColor Blue
Uninstall-Php C:\tools\php
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path C:\tools\php$version -TimeZone UTC -InitialPhpIni Production -Force
echo "Switch PHP"
Write-Host "Switch PHP" -ForegroundColor Blue
(Get-PhpSwitcher).targets
Initialize-PhpSwitcher -Alias C:\tools\php -Scope CurrentUser -Force
Add-PhpToSwitcher -Name $version -Path C:\tools\php$version -Force
Switch-Php $version -Force
}
echo "Housekeeping in PHP.ini, enabling openssl"
Write-Host "Housekeeping in PHP.ini, enabling openssl" -ForegroundColor Blue
$ext_dir = "C:\tools\php\ext"
Add-Content C:\tools\php\php.ini "date.timezone = 'UTC'"
Set-PhpIniKey extension_dir $ext_dir
@ -37,7 +37,7 @@ if($version -lt '7.4') {
Copy-Item "php_pcov.dll" -Destination $ext_dir"\php_pcov.dll"
}
echo "Installing Composer"
Write-Host "Installing Composer" -ForegroundColor Blue
Install-Composer -Scope System -Path C:\tools\php
php -v
composer -V