Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 13 additions & 59 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,79 +1,33 @@
name: Unit Tests
name: Tests

on:
push:
branches:
- main
- 'main'
- 'wip/1.3'
pull_request:

concurrency:
group: tests-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
phpUnitTests:
runs-on: ubuntu-latest
name: PHP ${{ matrix.phpVersions }}
runs-on: ${{ matrix.operatingSystem }}
strategy:
max-parallel: 4
matrix:
phpVersions: ['8.1', '8.2', '8.3', '8.4']
fail-fast: false
env:
phpExtensions: mbstring, intl, gd, xml, sqlite
cacheKey: ext-cache-v2
winterCmsRelease: develop
steps:
- name: Checkout changes
uses: actions/checkout@v4
with:
path: builder-plugin

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
- name: Setup Winter
uses: wintercms/setup-winter-action@v1
with:
php-version: ${{ matrix.phpVersions }}
extensions: ${{ env.phpExtensions }}
key: ${{ env.cacheKey }}

- name: Cache extensions
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Install PHP and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.phpVersions }}
extensions: ${{ env.phpExtensions }}
tools: composer:v2
coverage: none

- name: Install Winter CMS
run: |
wget https://github.com/wintercms/winter/archive/${{ env.winterCmsRelease }}.zip
unzip ${{ env.winterCmsRelease }}.zip
rm ${{ env.winterCmsRelease }}.zip
shopt -s dotglob
mv winter-${{ env.winterCmsRelease }}/* ./
rmdir winter-${{ env.winterCmsRelease }}
shopt -u dotglob
cp config/cms.php config/testing/cms.php
mkdir -p plugins/winter
mv builder-plugin plugins/winter/builder
- name: Get Composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

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

- name: Install Composer dependencies
run: composer install --no-interaction --no-progress
winter-ref: wip/1.3
plugin-author: winter
plugin-name: builder

- name: Run unit tests
run: php artisan winter:test -p Winter.Builder -- --testdox
18 changes: 2 additions & 16 deletions classes/PhpSourceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Winter\Builder\Classes;

use PhpParser\Error;
use PhpParser\Lexer\Emulative;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\CloningVisitor;
use PhpParser\NodeVisitor\NameResolver;
Expand Down Expand Up @@ -41,11 +40,6 @@ abstract class PhpSourceParser
*/
protected \PhpParser\NodeTraverser $traverser;

/**
* The lexer used to manipulate code.
*/
protected \PhpParser\Lexer\Emulative $lexer;

/**
* The path to the parsed file, if loaded from a file.
*/
Expand All @@ -58,15 +52,7 @@ abstract class PhpSourceParser
*/
public function __construct(string $source, string $file = null)
{
$this->lexer = new Emulative([
'usedAttributes' => [
'comments',
'startLine', 'endLine',
'startTokenPos', 'endTokenPos',
],
]);

$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $this->lexer);
$parser = (new ParserFactory())->createForHostVersion();

try {
$this->originalAst = $parser->parse($source);
Expand All @@ -78,7 +64,7 @@ public function __construct(string $source, string $file = null)
);
}

$this->originalTokens = $this->lexer->getTokens();
$this->originalTokens = $parser->getTokens();
$this->traverser = new NodeTraverser;
$this->traverser->addVisitor(new CloningVisitor);
$this->traverser->addVisitor(new NameResolver(null, [
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"require": {
"php": ">=7.0",
"composer/installers": "~1.0",
"nikic/php-parser": "^4.13.2"
"nikic/php-parser": "^5.5"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/classes/FilesystemGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function setUp(): void

public function tearDown(): void
{
parent::tearDown();

$this->cleanUp();
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/classes/ModelModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ModelModelTest extends BuilderPluginTestCase
{
public function tearDown(): void
{
parent::tearDown();

// Ensure cleanup for testGetModelFields
@unlink(__DIR__.'/../../../models/MyMock.php');
}
Expand Down