Skip to content

Commit

Permalink
Resolves broken tests on local and adds GH actions pipeline (#63)
Browse files Browse the repository at this point in the history
* Resolves broken tests on local and adds gh actions pipeline

* additional cleanup

* remove sniffer config

* remove static analyzers for now

* updates pipeline to deal with cake4 requiring php 7.4

* cleanup and emit deprecation warning on deprecated method

* adds elastic search test into gh action pipeline with a custom integration test, uses mocks for testing elastic locally, some other cleanup

* tests pipeline without elastic to debug

* resolve timezone bug

* resolve timezone bug

* resolve timezone bug

* resolve timezone bug

* resolve timezone bug

* resolve timezone bug

* resolve timezone bug

* resolve timezone bug

* resolve timezone bug

* skip timezone bug and enable elastic again

* debugging this: elastic/elastic-github-actions#23

* bad copy pasta

* debug datetime issue

* oh well

* oh well 2

* adds #[\ReturnTypeWillChange] to suppress deprecation warnings 8.0/8.1

* cleanup

* docblock updates

* re-adds integration test and removes a deprecation warning in php 8.1

* testing pipeline

* fix test namespaces

* try getting elastc running in pipeline again using setup from cakephp/elastic

* try getting elastc running in pipeline again using setup from cakephp/elastic

* try getting elastc running in pipeline again using setup from cakephp/elastic

* fix names
  • Loading branch information
cnizzardini committed Sep 11, 2023
1 parent 58f0c65 commit c03812d
Show file tree
Hide file tree
Showing 24 changed files with 505 additions and 320 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Pull Request

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
operating-system: [ ubuntu-20.04 ]
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

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 test
#
# CakePHP version compatability
#
compatibility:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['~4.0.0', '~4.1.0', '~4.2.0', '~4.3.0']

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
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
compatibility_cakephp4:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['~4.4.0']

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
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: ['~4.4.0']

services:
elasticsearch:
image: elasticsearch:7.11.1
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: '7.4'
extensions: mbstring, intl

- name: PHP Version
run: php -v

- 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
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"type": "cakephp-plugin",
"license": "MIT",
"require": {
"php": ">=7.2",
"cakephp/orm": "^4.0"
"php": "^7.2|^8.0",
"cakephp/orm": "^4.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
Expand All @@ -25,8 +26,11 @@
},
"autoload-dev": {
"psr-4": {
"AuditStash\\Test\\": "tests",
"AuditStash\\Test\\": "tests/",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
}
},
"scripts": {
"test": "phpunit --colors=always"
}
}
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<testsuites>
<testsuite name="AuditStash Test Suite">
<directory>./tests/TestCase</directory>
<exclude>./tests/TestCase/Persister/ElasticSearchPersisterIntegrationTest.php</exclude>
</testsuite>
</testsuites>

Expand Down
4 changes: 2 additions & 2 deletions src/Event/AuditDeleteEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class AuditDeleteEvent implements EventInterface
}

/**
* Construnctor.
* Constructor.
*
* @param string $transationId The global transaction id
* @param string $transactionId The global transaction id
* @param mixed $id The primary key record that got deleted
* @param string $source The name of the source (table) where the record was deleted
* @param string $parentSource The name of the source (table) that triggered this change
Expand Down
9 changes: 5 additions & 4 deletions src/Event/BaseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ abstract class BaseEvent implements EventInterface
protected $original;

/**
* Construnctor.
* Constructor.
*
* @param string $transationId The global transaction id
* @param string $transactionId The global transaction id
* @param mixed $id The entities primary key
* @param string $source The name of the source (table)
* @param array $changed The array of changes that got detected for the entity
Expand Down Expand Up @@ -77,9 +77,10 @@ abstract public function getEventType();
/**
* Returns the array to be used for encoding this object as json.
*
* @return array
* @return mixed
*/
public function jsonSerialize(): mixed
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->basicSerialize() + [
'original' => $this->original,
Expand Down
17 changes: 4 additions & 13 deletions src/Event/SerializableEventTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait SerializableEventTrait
*/
public function serialize()
{
return $this->__serialize();
return serialize(get_object_vars($this));
}

/**
Expand All @@ -28,16 +28,6 @@ public function unserialize($data)
$this->__unserialize($data);
}

/**
* Returns the string representation of this object.
*
* @return string
*/
public function __serialize()
{
return serialize(get_object_vars($this));
}

/**
* Takes the string representation of this object so it can be reconstructed.
*
Expand All @@ -55,9 +45,10 @@ public function __unserialize($data)
/**
* Returns an array with the basic variables that should be json serialized.
*
* @return array
* @return mixed
*/
protected function basicSerialize(): mixed
#[\ReturnTypeWillChange]
protected function basicSerialize()
{
return [
'type' => $this->getEventType(),
Expand Down
3 changes: 2 additions & 1 deletion src/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class EventFactory
* converts it into an AuditStash\EventInterface object.
*
* @param array $data The array data from elastic search
* @return AuditStash\EventInterface
* @return \AuditStash\EventInterface
* @throws \ReflectionException
*/
public function create(array $data)
{
Expand Down
5 changes: 2 additions & 3 deletions src/Meta/ApplicationMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public function implementedEvents(): array
}

/**
* Enriches all of the passed audit logs to add the request
* info metadata.
* Enriches all the passed audit logs to add the request info metadata.
*
* @param Event The AuditStash.beforeLog event
* @param Event $event The AuditStash.beforeLog event
* @param array $logs The audit log event objects
* @return void
*/
Expand Down
5 changes: 2 additions & 3 deletions src/Meta/RequestMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ public function implementedEvents(): array
}

/**
* Enriches all of the passed audit logs to add the request
* info metadata.
* Enriches all the passed audit logs to add the request info metadata.
*
* @param Event The AuditStash.beforeLog event
* @param Event $event The AuditStash.beforeLog event
* @param array $logs The audit log event objects
* @return void
*/
Expand Down
20 changes: 10 additions & 10 deletions src/Model/Behavior/AuditLogBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function implementedEvents(): array
* Conditionally adds the `_auditTransaction` and `_auditQueue` keys to $options. They are
* used to track all changes done inside the same transaction.
*
* @param Cake\Event\Event The Model event that is enclosed inside a transaction
* @param Cake\Datasource\EntityInterface $entity The entity that is to be saved
* @param \Cake\Event\Event $event The Model event that is enclosed inside a transaction
* @param \Cake\Datasource\EntityInterface $entity The entity that is to be saved
* @param ArrayObject $options The options to be passed to the save or delete operation
* @return void
*/
Expand All @@ -82,8 +82,8 @@ public function injectTracking(Event $event, EntityInterface $entity, ArrayObjec
* Calculates the changes done to the entity and stores the audit log event object into the
* log queue inside the `_auditQueue` key in $options.
*
* @param Cake\Event\Event The Model event that is enclosed inside a transaction
* @param Cake\Datasource\EntityInterface $entity The entity that is to be saved
* @param \Cake\Event\Event $event The Model event that is enclosed inside a transaction
* @param \Cake\Datasource\EntityInterface $entity The entity that is to be saved
* @param ArrayObject $options Options array containing the `_auditQueue` key
* @return void
*/
Expand Down Expand Up @@ -135,8 +135,8 @@ public function afterSave(Event $event, EntityInterface $entity, $options)
/**
* Persists all audit log events stored in the `_eventQueue` key inside $options.
*
* @param Cake\Event\Event The Model event that is enclosed inside a transaction
* @param Cake\Datasource\EntityInterface $entity The entity that is to be saved or deleted
* @param \Cake\Event\Event $event The Model event that is enclosed inside a transaction
* @param \Cake\Datasource\EntityInterface $entity The entity that is to be saved or deleted
* @param ArrayObject $options Options array containing the `_auditQueue` key
* @return void
*/
Expand All @@ -163,8 +163,8 @@ public function afterCommit(Event $event, EntityInterface $entity, $options)
/**
* Persists all audit log events stored in the `_eventQueue` key inside $options.
*
* @param Cake\Event\Event The Model event that is enclosed inside a transaction
* @param Cake\Datasource\EntityInterface $entity The entity that is to be saved or deleted
* @param \Cake\Event\Event $event The Model event that is enclosed inside a transaction
* @param \Cake\Datasource\EntityInterface $entity The entity that is to be saved or deleted
* @param ArrayObject $options Options array containing the `_auditQueue` key
* @return void
*/
Expand All @@ -184,8 +184,8 @@ public function afterDelete(Event $event, EntityInterface $entity, $options)
* Sets the persister object to use for logging all audit events.
* If called with no arguments, it will return the currently configured persister.
*
* @param PersisterInterface $persister The persister object to use
* @return PersisterInterface The configured persister
* @param \AuditStash\PersisterInterface $persister The persister object to use
* @return \AuditStash\PersisterInterface The configured persister
*/
public function persister(PersisterInterface $persister = null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Persister/DatabasePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class DatabasePersister implements PersisterInterface
use ModelAwareTrait;

/**
* Persists all of the audit log event objects that are provided
* Persists all the audit log event objects that are provided
*
* @param array $auditLogs An array of EventInterface objects
* @param \AuditStash\EventInterface[] $auditLogs An array of EventInterface objects
* @return void
*/
public function logEvents(array $auditLogs)
{
deprecationWarning('Use \AuditStash\Persister\TablePersister instead');
foreach ($auditLogs as $log) {
$eventType = $log->getEventType();
$primaryKey = $log->getId();
Expand Down
Loading

0 comments on commit c03812d

Please sign in to comment.