Skip to content

Commit

Permalink
GitHub actions (#2)
Browse files Browse the repository at this point in the history
Use Github Actions for CI pipeline
  • Loading branch information
Mark Baker authored Dec 21, 2020
1 parent e4b7f0e commit aab155f
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 167 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: main
on: [ push, pull_request ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-version:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'

name: PHP ${{ matrix.php-version }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Set composer flags
id: composer-lock
if: ${{ matrix.php-version == '8.0' || matrix.php-version == '8.1' }}
run: |
echo "::set-output name=flags::--ignore-platform-reqs"
- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader ${{ steps.composer-lock.outputs.flags }}

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Test with PHPUnit
run: ./vendor/bin/phpunit

phpcs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib
coverage: none
tools: cs2pr

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Code style with PHP_CodeSniffer
run: ./vendor/bin/phpcs -q --report=checkstyle | cs2pr --graceful-warnings --colorize

coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Coverage
run: |
./vendor/bin/phpunit --coverage-text
3 changes: 3 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

<!-- Do not check the vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/examples/sampleClasses/*</exclude-pattern>
<exclude-pattern>/unitTests/data/*</exclude-pattern>
<exclude-pattern>/unitTests/bootstrap.php</exclude-pattern>

<!-- Show progress & sniff codes. -->
<arg value="ps"/>
Expand Down
71 changes: 0 additions & 71 deletions .travis.yml

This file was deleted.

19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
}
],
"require": {
"php": "^7.0.0"
"php": "^7.0 || ^8.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.3.2",
"phpmd/phpmd": "2.6.0",
"phpunit/phpunit": "^5.4.0",
"squizlabs/php_codesniffer": "^3.4",
"phpmd/phpmd": "2.*",
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.3",
"phpdocumentor/phpdocumentor":"2.*",
"sebastian/phpcpd": "2.*",
"phploc/phploc": "2.*",
"phpcompatibility/php-compatibility": "^8.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3"
"sebastian/phpcpd": "^3.0 || ^4.0 || ^6.0",
"phploc/phploc": "^4.0",
"phpcompatibility/php-compatibility": "^9.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"yoast/phpunit-polyfills": "1.x-dev"
},
"autoload": {
"psr-4": {
Expand All @@ -47,4 +48,4 @@
]
},
"minimum-stability": "dev"
}
}
11 changes: 3 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
syntaxCheck="true"
verbose="true"
strict="true"
verbose="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
Expand All @@ -21,15 +19,12 @@
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../unitTests/classes</directory>
<directory suffix=".php">./classes/src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./unitTests/codeCoverage" charset="UTF-8"
yui="true" highlight="false"
<log type="coverage-html" target="./unitTests/codeCoverage"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="./unitTests/codeCoverage/codeCoverage.xml"/>
<log type="metrics-xml" target="./unitTests/metrics/metrics.xml"/>
<log type="test-xml" target="./unitTests/testResults/logfile.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
2 changes: 2 additions & 0 deletions unitTests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
get_include_path(),
)));

require_once('./vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php');

/**
* @todo Sort out xdebug in vagrant so that this works in all sandboxes
* For now, it is safer to test for it rather then remove it.
Expand Down
40 changes: 21 additions & 19 deletions unitTests/classes/SpyMasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

namespace SpyMaster;

use Yoast\PHPUnitPolyfills\TestCases\XTestCase;

include APPLICATION_DATA_PATH . '/testClassForSpyMaster.php';

class SpyMasterTest extends \PHPUnit\Framework\TestCase
class SpyMasterTest extends XTestCase
{

protected $targetObject;

protected function setUp()
/**
* @before
*/
public function setUpFixtures()
{
parent::setUpFixtures();

$this->targetObject = new \testing\testClassForSpyMaster();
}

Expand All @@ -22,30 +29,27 @@ public function testInstantiate()
self::assertInstanceOf('SpyMaster\\SpyMaster', $spyMaster);
}

/**
* @expectedException Exception
* @expectedExceptionMessage You must specify the object that you want to spy on
*/
public function testInstantiateWithoutObject()
{
self::expectException(Exception::class);
self::expectExceptionMessage('You must specify the object that you want to spy on');

$spyMaster = new SpyMaster();
}

/**
* @expectedException Exception
* @expectedExceptionMessage Argument must be an object
*/
public function testInstantiateWithNonObject()
{
self::expectException(Exception::class);
self::expectExceptionMessage('Argument must be an object');

$spyMaster = new SpyMaster(true);
}

/**
* @expectedException Exception
* @expectedExceptionMessage SpyMaster is unable to access PHP internal classes
*/
public function testInstantiateWithInternalObject()
{
self::expectException(Exception::class);
self::expectExceptionMessage('SpyMaster is unable to access PHP internal classes');

$dto = new \DateTime();

$spyMaster = new SpyMaster($dto);
Expand All @@ -71,15 +75,13 @@ public function testInfiltrateReadWriteSpy()
self::assertInstanceOf('SpyMaster\\Spy', $spy);
}

/**
* @expectedException Exception
* @expectedExceptionMessage SpyMaster does not support Saboteur spies
*/
public function testInfiltrateInvalidSpy()
{
self::expectException(Exception::class);
self::expectExceptionMessage('SpyMaster does not support Saboteur spies');

$spyMaster = new SpyMaster($this->targetObject);

$spy = $spyMaster->infiltrate('Saboteur');
}

}
Loading

0 comments on commit aab155f

Please sign in to comment.