Skip to content

Commit

Permalink
Adds phpcs and resolves phpcs errors (#77)
Browse files Browse the repository at this point in the history
* Adds phpcs and resolves phpcs errors

* oops

* move github actions into single ci file

---------

Co-authored-by: Chris Nizzardini <chris.nizzardini@thecmigroupa.ca>
  • Loading branch information
cnizzardini and Chris Nizzardini authored Jan 22, 2024
1 parent d8bb554 commit 68d1ee1
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 150 deletions.
96 changes: 93 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,112 @@ name: Pull Request

on:
push:
branches: [master]
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-latest

strategy:
matrix:
operating-system: [ ubuntu-20.04 ]
php-versions: ['8.1', '8.3']

name: PHP ${{ matrix.php-versions }} Test
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, xdebug

- name: PHP Version
run: php -v

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: |
composer self-update
composer validate
composer install --prefer-dist --no-progress
- name: Test Suite
run: |
composer check
#
# CakePHP version compatability
#
compatibility:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['~5.0.0']

name: CakePHP ${{ matrix.version }} Test
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, intl

- name: PHP Version
run: php -v

- name: CakePHP ${{matrix.version}} Compatability
run: |
composer self-update
rm -rf composer.lock
composer require cakephp/cakephp:${{matrix.version}} --no-update
composer install --prefer-dist --no-progress
composer test
elastic_integration_test:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['~5.0.0']

services:
elasticsearch:
image: elasticsearch:7.17.6
ports:
- 9200/tcp
env:
discovery.type: single-node
ES_JAVA_OPTS: -Xms500m -Xmx500m
options: >-
--health-cmd "curl http://127.0.0.1:9200/_cluster/health"
--health-interval 10s
--health-timeout 5s
--health-retries 10
name: Elastic Search Integration Test
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, intl

- name: PHP Version
run: php -v
- name: Install

- name: Test
env:
elastic_dsn: Cake\ElasticSearch\Datasource\Connection://127.0.0.1:${{ job.services.elasticsearch.ports['9200'] }}?driver=Cake\ElasticSearch\Datasource\Connection
run: |
composer self-update
rm -rf composer.lock
composer require cakephp/cakephp:${{matrix.version}} --no-update
composer install --prefer-dist --no-progress
vendor/bin/phpunit tests/TestCase/Persister/ElasticSearchPersisterIntegrationTest.php
113 changes: 0 additions & 113 deletions .github/workflows/pull-request.yml

This file was deleted.

30 changes: 30 additions & 0 deletions tests/AuditLogsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace AuditStash\Test;

use Cake\ORM\Table;

class AuditLogsTable extends Table
{
public function initialize(array $config): void
{
parent::initialize($config);

$this->setTable('audit_logs');
$this->setPrimaryKey('id');

$this->setSchema([
'id' => 'integer',
'transaction' => 'string',
'type' => 'string',
'primary_key' => 'integer',
'source' => 'string',
'parent_source' => 'string',
'original' => 'string',
'changed' => 'string',
'meta' => 'string',
'created' => 'datetime',
]);
}
}
13 changes: 13 additions & 0 deletions tests/DebugPersister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace AuditStash\Test;

use AuditStash\PersisterInterface;

class DebugPersister implements PersisterInterface
{
public function logEvents(array $events): void
{
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Meta/ApplicationMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testDataIsAdded()
$listener = new ApplicationMetadata('my_app', ['extra' => 'thing']);
$this->getEventManager()->on($listener);
$logs[] = new AuditDeleteEvent('1234', 1, 'articles');
$event = $this->dispatchEvent('AuditStash.beforeLog', ['logs' => $logs]);
$this->dispatchEvent('AuditStash.beforeLog', ['logs' => $logs]);

$expected = [
'app_name' => 'my_app',
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Meta/RequestMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testRequestDataIsAdded()
$request->expects($this->once())->method('clientIp')->will($this->returnValue('12345'));
$request->expects($this->once())->method('getRequestTarget')->will($this->returnValue('/things?a=b'));
$logs[] = new AuditDeleteEvent('1234', 1, 'articles');
$event = $this->dispatchEvent('AuditStash.beforeLog', ['logs' => $logs]);
$this->dispatchEvent('AuditStash.beforeLog', ['logs' => $logs]);

$expected = [
'ip' => '12345',
Expand Down
9 changes: 1 addition & 8 deletions tests/TestCase/Model/Behavior/AuditIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@
use AuditStash\Event\AuditDeleteEvent;
use AuditStash\Event\AuditUpdateEvent;
use AuditStash\Model\Behavior\AuditLogBehavior;
use AuditStash\PersisterInterface;
use AuditStash\Test\DebugPersister;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase;

class DebugPersister implements PersisterInterface
{
public function logEvents(array $events): void
{
}
}

class AuditIntegrationTest extends TestCase
{
use LocatorAwareTrait;
Expand Down
25 changes: 1 addition & 24 deletions tests/TestCase/Persister/TablePersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use AuditStash\Event\AuditCreateEvent;
use AuditStash\Persister\TablePersister;
use AuditStash\Test\AuditLogsTable;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Entity;
use Cake\ORM\Table;
Expand All @@ -13,30 +14,6 @@
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;

class AuditLogsTable extends Table
{
public function initialize(array $config): void
{
parent::initialize($config);

$this->setTable('audit_logs');
$this->setPrimaryKey('id');

$this->setSchema([
'id' => 'integer',
'transaction' => 'string',
'type' => 'string',
'primary_key' => 'integer',
'source' => 'string',
'parent_source' => 'string',
'original' => 'string',
'changed' => 'string',
'meta' => 'string',
'created' => 'datetime',
]);
}
}

class TablePersisterTest extends TestCase
{
/**
Expand Down

0 comments on commit 68d1ee1

Please sign in to comment.