Skip to content

Commit 776de71

Browse files
run phpunit in CI
1 parent 3410a15 commit 776de71

File tree

10 files changed

+105
-228
lines changed

10 files changed

+105
-228
lines changed

.github/workflows/php-run-tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Check PHP syntax
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
php-versions: ['8.3']
11+
steps:
12+
- name: Setup PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: ${{ matrix.php-versions }}
16+
tools: composer
17+
18+
- name: checkout repo
19+
uses: actions/checkout@v3
20+
21+
- run: composer install --no-progress
22+
- run: ./vendor/bin/phpunit

composer.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@
2121
"php": ">=7.2"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^9.5.4",
25-
"brain/monkey": "1.*",
26-
"wp-coding-standards/wpcs": "^2.3",
27-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1"
28-
},
29-
"config": {
30-
"allow-plugins": {
31-
"dealerdirect/phpcodesniffer-composer-installer": true
32-
}
24+
"phpunit/phpunit": "^10.5.40"
3325
},
3426
"scripts": {
3527
"check-syntax": "find . -name '*.php' -not -path './vendor/*' -not -path './node_modules/*' -print0 | xargs -0 -n1 php -l"

phpcs.xml

Lines changed: 0 additions & 48 deletions
This file was deleted.

phpunit.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
requireCoverageMetadata="true"
8+
beStrictAboutCoverageMetadata="true"
9+
beStrictAboutOutputDuringTests="true"
10+
displayDetailsOnPhpunitDeprecations="true"
11+
failOnPhpunitDeprecation="true"
12+
failOnRisky="true"
13+
failOnWarning="true">
14+
15+
<testsuites>
16+
<testsuite name="default">
17+
<directory>tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
22+
<include>
23+
<directory>src</directory>
24+
</include>
25+
</source>
26+
</phpunit>

phpunit.xml.dist

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/admin/MigrationsTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Boxzilla\Tests\Admin;
4+
5+
use Boxzilla\Admin\Migrations;
6+
7+
/**
8+
* Class MigrationsTest
9+
*
10+
* @ignore
11+
*/
12+
class MigrationsTest extends \PHPUnit\Framework\TestCase {
13+
14+
private $dir = '/tmp/boxzilla-tests/migrations';
15+
16+
/**
17+
* Create the sample migrations directory
18+
*/
19+
public function setUp() : void {
20+
if( ! file_exists( $this->dir ) ) {
21+
mkdir( $this->dir, 0700, true );
22+
}
23+
}
24+
25+
/**
26+
* @covers \Boxzilla\Admin\Migrations::find_migrations
27+
*/
28+
public function test_find_migrations() {
29+
$instance = new Migrations( '1.0', '1.1', $this->dir );
30+
self::assertEquals( $instance->find_migrations(), array() );
31+
32+
// create correct migration file
33+
$migration_file = $this->dir . '/1.1-do-something.php';
34+
file_put_contents( $migration_file, '' );
35+
self::assertEquals( $instance->find_migrations(), array( $migration_file ) );
36+
37+
// create incorrect migrations file
38+
$older_migration_file = $this->dir . '/1.0-do-something.php';
39+
file_put_contents( $older_migration_file, '' );
40+
self::assertEquals( $instance->find_migrations(), array( $migration_file ) );
41+
}
42+
43+
/**
44+
* Remove files after each test.
45+
*/
46+
public function tearDown() : void {
47+
array_map( 'unlink', glob( $this->dir . '/*.php' ) );
48+
if( file_exists( $this->dir ) ) {
49+
rmdir( $this->dir );
50+
}
51+
}
52+
53+
54+
}

tests/admin/class-migrations-test.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/bootstrap.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
22

33
// load autoloader
4-
require __DIR__ . '/../autoload.php';
5-
require __DIR__ . '/../vendor/autoload.php';
6-
require __DIR__ . '/class-wp-test-case.php';
7-
8-
// go!
9-
echo "Welcome to the Boxzilla PHP Test Suite." . PHP_EOL . PHP_EOL;
4+
require dirname(__DIR__) . '/autoload.php';
5+
require dirname(__DIR__) . '/vendor/autoload.php';

tests/class-plugin-test.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/class-wp-test-case.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)