1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-05 20:57:41 +02:00

feat(core): add tests for Flextype Core Functionality. #477

This commit is contained in:
Awilum
2020-10-16 14:21:05 +03:00
parent e2d25f1737
commit a6b6e80897
5 changed files with 115 additions and 0 deletions

12
.github/workflows/static.yml vendored Normal file
View File

@@ -0,0 +1,12 @@
name: Static Analysis
on: [push, pull_request]
jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
args: analyse src/

40
.github/workflows/tests.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: Tests
on: ['push', 'pull_request']
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: ['7.3', '7.4', '8.0']
dependency-version: [prefer-lowest, prefer-stable]
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: fileinfo, spl, json, dom, mbstring
tools: composer:v2
coverage: none
- name: Setup Problem Matches
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install PHP 7 dependencies
run: composer update --dev --${{ matrix.dependency-version }} --no-interaction --no-progress
if: "matrix.php < 8"
- name: Install PHP 8 dependencies
run: composer update --dev --${{ matrix.dependency-version }} --ignore-platform-req=php --no-interaction --no-progress
if: "matrix.php >= 8"
- name: Run Tests
run: ./vendor/bin/pest

View File

@@ -0,0 +1,46 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
use Atomastic\Strings\Strings;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('test create single entry', function () {
$this->assertTrue(flextype('entries')->create('foo', []));
$this->assertFalse(flextype('entries')->create('foo', []));
});
test('test has single entry', function () {
flextype('entries')->create('foo', []);
$this->assertTrue(flextype('entries')->has('foo'));
$this->assertFalse(flextype('entries')->has('bar'));
});
test('test update single entry', function () {
flextype('entries')->create('foo', []);
$this->assertTrue(flextype('entries')->update('foo', ['title' => 'Test']));
$this->assertFalse(flextype('entries')->update('bar', ['title' => 'Test']));
});
test('test fetch single entry', function () {
// 1
flextype('entries')->create('foo', []);
$fetch = flextype('entries')->fetch('foo');
$this->assertTrue(count($fetch) > 0);
// 2
$this->assertEquals([], flextype('entries')->fetch('bar'));
// 3
flextype('entries')->create('zed', ['title' => 'Zed']);
$fetch = flextype('entries')->fetch('zed');
$this->assertEquals('Zed', $fetch['title']);
});

5
tests/Helpers.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
namespace Tests;
// ..

12
tests/Pest.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
define('FLEXTYPE_MINIMUM_PHP', '7.3.0');
define('ROOT_DIR', str_replace(DIRECTORY_SEPARATOR, '/', getcwd()));
define('PATH', [
'project' => ROOT_DIR . '/project',
'tmp' => ROOT_DIR . '/var/tmp',
]);
! is_file($flextype_autoload = ROOT_DIR . '/vendor/autoload.php') and exit('Please run: <i>composer install</i> for flextype');
$flextype_loader = require_once $flextype_autoload;
include ROOT_DIR . '/src/flextype/bootstrap.php';