From a6b6e808975aebe2a865c1ec5b2dedc55363e40d Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 16 Oct 2020 14:21:05 +0300 Subject: [PATCH] feat(core): add tests for Flextype Core Functionality. #477 --- .github/workflows/static.yml | 12 +++++++++ .github/workflows/tests.yml | 40 ++++++++++++++++++++++++++++++ tests/Entries/EntriesTest.php | 46 +++++++++++++++++++++++++++++++++++ tests/Helpers.php | 5 ++++ tests/Pest.php | 12 +++++++++ 5 files changed, 115 insertions(+) create mode 100644 .github/workflows/static.yml create mode 100644 .github/workflows/tests.yml create mode 100644 tests/Entries/EntriesTest.php create mode 100644 tests/Helpers.php create mode 100644 tests/Pest.php diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 00000000..c7807a30 --- /dev/null +++ b/.github/workflows/static.yml @@ -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/ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..695241e2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/tests/Entries/EntriesTest.php b/tests/Entries/EntriesTest.php new file mode 100644 index 00000000..21a13d75 --- /dev/null +++ b/tests/Entries/EntriesTest.php @@ -0,0 +1,46 @@ +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']); +}); diff --git a/tests/Helpers.php b/tests/Helpers.php new file mode 100644 index 00000000..b63c4fb0 --- /dev/null +++ b/tests/Helpers.php @@ -0,0 +1,5 @@ + ROOT_DIR . '/project', + 'tmp' => ROOT_DIR . '/var/tmp', +]); + +! is_file($flextype_autoload = ROOT_DIR . '/vendor/autoload.php') and exit('Please run: composer install for flextype'); +$flextype_loader = require_once $flextype_autoload; +include ROOT_DIR . '/src/flextype/bootstrap.php';