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:
12
.github/workflows/static.yml
vendored
Normal file
12
.github/workflows/static.yml
vendored
Normal 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
40
.github/workflows/tests.yml
vendored
Normal 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
|
46
tests/Entries/EntriesTest.php
Normal file
46
tests/Entries/EntriesTest.php
Normal 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
5
tests/Helpers.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
// ..
|
12
tests/Pest.php
Normal file
12
tests/Pest.php
Normal 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';
|
Reference in New Issue
Block a user