Skip to content

Commit

Permalink
CI skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Apr 11, 2020
1 parent f4c7a77 commit ca51ea2
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
'env': {
'browser': true,
'es6': true,
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module',
},
'plugins': [
'import',
],
'extends': [
'@nepada',
],
};
42 changes: 42 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0"?>
<ruleset>
<config name="installed_paths" value="../../nepada/coding-standard/src"/><!-- relative path from PHPCS source location -->

<arg value="ps"/><!-- show progress of the run, show sniff names -->
<arg name="cache" value=".phpcs-cache"/>

<arg name="extensions" value="php,phpt"/>
<file>src</file>
<file>tests</file>

<rule ref="Nepada">
</rule>

<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array">
<element key="src" value="Nepada"/>
<element key="tests" value="NepadaTests"/>
</property>
<property name="extensions" type="array">
<element value="php"/>
<element value="phpt"/>
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="ignoredAnnotationNames" type="array">
<element value="@testCase"/>
<element value="@dataProvider"/>
</property>
</properties>
</rule>

<!-- special settings for tests and bootstrap -->
<exclude-pattern>*/tests/temp/*</exclude-pattern>
<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>*.phpt</exclude-pattern>
<exclude-pattern>*/bootstrap.php</exclude-pattern>
</rule>
</ruleset>
51 changes: 51 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
language: php
php:
- 7.4

env:
- COMPOSER_ARGS=""
- COMPOSER_ARGS="--prefer-stable"
- COMPOSER_ARGS="--prefer-stable --prefer-lowest"

jobs:
include:
- name: JS test + Code Standard Checker
language: node_js
node_js: lts/*
install:
- travis_retry npm install
script:
- npm run lint
- npm run build
- stage: Code Standard Checker
php: 7.4
script:
- vendor/bin/phpcs
- stage: Code Coverage
php: 7.4
script:
- vendor/bin/tester -p phpdbg tests -s --coverage ./coverage.xml --coverage-src ./src
after_script:
- travis_retry wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar
- php php-coveralls.phar --verbose --config tests/coveralls.yml
allow_failures:
- stage: Code Coverage

install:
- travis_retry composer update --no-interaction --prefer-dist $COMPOSER_ARGS

script:
- vendor/bin/parallel-lint -e php,phpt --exclude tests/temp src tests
- vendor/bin/tester -s -p php -c tests/php.ini tests
- vendor/bin/phpstan.phar analyse
- vendor/bin/phpstan.phar analyse -c phpstan.tests.neon.dist

after_failure:
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done

sudo: false

cache:
directories:
- $HOME/.composer/cache
- $HOME/.npm
12 changes: 12 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
'presets': [
[
'@babel/preset-env',
{
'targets': {
'node': 'current',
},
},
],
],
};
16 changes: 16 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/pepakriz/phpstan-exception-rules/extension.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- tests/phpstan/disallowed-calls-rules.neon

parameters:
level: max
paths:
- src

exceptionRules:
uncheckedExceptions:
- LogicException
- Nette\InvalidStateException
26 changes: 26 additions & 0 deletions phpstan.tests.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-nette/extension.neon
- vendor/phpstan/phpstan-nette/rules.neon
- vendor/nepada/phpstan-nette-tester/extension.neon
- vendor/phpstan/phpstan-mockery/extension.neon
- tests/phpstan/disallowed-calls-rules.neon

parameters:
level: max
paths:
- tests

fileExtensions:
- php
- phpt

autoload_directories:
- tests

excludes_analyse:
- tests/bootstrap.php
- tests/temp/*

ignoreErrors:
# - '~Call to static method Tester\\Assert::(type|count|same|notSame)\(\) with .* and .* will always evaluate to true\.~'
3 changes: 3 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/temp
/*.log
output/
27 changes: 27 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types = 1);

namespace NepadaTests;

use Mockery;
use Tester;

abstract class TestCase extends Tester\TestCase
{

public function run(): void
{
if ($_ENV['IS_PHPSTAN'] ?? false) {
return;
}

parent::run();
}

protected function tearDown(): void
{
parent::tearDown();
Mockery::close();
}

}
28 changes: 28 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types = 1);

require __DIR__ . '/../vendor/autoload.php';

// detect PHPStan
if (getenv('IS_PHPSTAN') !== false) {
$_ENV['IS_PHPSTAN'] = in_array(strtolower(getenv('IS_PHPSTAN')), ['1', 'true', 'yes', 'on'], true);
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$_ENV['IS_PHPSTAN'] = (bool) preg_match('~[/\\\\]phpstan(?:\.phar)?$~', end($trace)['file'] ?? '');
}


// configure environment
if (! $_ENV['IS_PHPSTAN']) {
Tester\Environment::setup();
date_default_timezone_set('Europe/Prague');
}


// create temporary directory
define('TEMP_DIR', __DIR__ . '/temp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()));
if (! $_ENV['IS_PHPSTAN']) {
@mkdir(dirname(TEMP_DIR)); // @ - directory may already exist
Tester\Helpers::purge(TEMP_DIR);
ini_set('session.save_path', TEMP_DIR);
}
4 changes: 4 additions & 0 deletions tests/coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# for php-coveralls
service_name: travis-ci
coverage_clover: coverage.xml
json_path: coverage.json
Empty file added tests/php.ini
Empty file.
11 changes: 11 additions & 0 deletions tests/phpstan/disallowed-calls-rules.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
-
type: Spaze\PHPStan\Rules\Disallowed\FunctionCalls
tags:
- phpstan.rules.rule
arguments:
forbiddenCalls:
-
function: 'var_dump()'
-
function: 'print_r()'

0 comments on commit ca51ea2

Please sign in to comment.