Skip to content

Commit

Permalink
added tests, linting and static analasis
Browse files Browse the repository at this point in the history
  • Loading branch information
MordiSacks committed Aug 17, 2024
1 parent a495b94 commit 462f08b
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 153 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: run-tests

on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3 ]
stability: [ prefer-lowest, prefer-stable ]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List Installed Dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/pest --ci --coverage
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,15 @@
"psr-4": {
"ParseHolyLandPhone\\": "src/"
}
},
"require-dev": {
"laravel/pint": "^1.17",
"pestphp/pest": "^2.35",
"phpstan/phpstan": "^1.11"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
30 changes: 15 additions & 15 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

use ParseHolyLandPhone\ParsePhone;

require_once('vendor/autoload.php');

// via new instance
$number = new ParsePhone('025121234');

// via static method
$number = ParsePhone::create('025121234');

$number->isValid();

$number->isNotValid();
<?php

use ParseHolyLandPhone\ParsePhone;

require_once 'vendor/autoload.php';

// via new instance
$number = new ParsePhone('025121234');

// via static method
$number = ParsePhone::create('025121234');

$number->isValid();

$number->isNotValid();
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:

paths:
- src/

# Level 9 is the highest level
level: 5
17 changes: 17 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
41 changes: 41 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"preset": "laravel",
"rules": {
"not_operator_with_successor_space": false,
"control_structure_braces": false,
"cast_spaces": {
"space": "none"
},
"binary_operator_spaces": {
"operators": {
"=>": "align"
}
},
"braces_position": {
"allow_single_line_anonymous_functions": true,
"allow_single_line_empty_anonymous_classes": true,
"functions_opening_brace": "same_line"
},
"function_declaration": {
"closure_fn_spacing": "none"
},
"concat_space": {
"spacing": "one"
},
"phpdoc_align": {
"align": "vertical",
"tags": []
},
"phpdoc_line_span": {
"method": "single",
"property": "single",
"const": "single"
},
"simplified_null_return": true,
"braces": false,
"new_with_braces": {
"anonymous_class": false,
"named_class": false
}
}
}
Loading

0 comments on commit 462f08b

Please sign in to comment.