Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing pipeline i hope #1

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6a58234
Resolves broken tests on local and adds gh actions pipeline
cnizzardini May 19, 2023
04e7919
additional cleanup
cnizzardini May 19, 2023
3b50803
remove sniffer config
cnizzardini May 19, 2023
1a441b4
remove static analyzers for now
cnizzardini May 19, 2023
4cd436a
updates pipeline to deal with cake4 requiring php 7.4
cnizzardini May 20, 2023
0c59741
cleanup and emit deprecation warning on deprecated method
cnizzardini May 20, 2023
dea5a3a
adds elastic search test into gh action pipeline with a custom integr…
cnizzardini May 20, 2023
9c6dc17
tests pipeline without elastic to debug
cnizzardini May 20, 2023
34bfd69
resolve timezone bug
cnizzardini May 20, 2023
d3bef2f
resolve timezone bug
cnizzardini May 20, 2023
456793a
resolve timezone bug
cnizzardini May 20, 2023
9113e5a
resolve timezone bug
cnizzardini May 20, 2023
92916b1
resolve timezone bug
cnizzardini May 20, 2023
48dcea9
resolve timezone bug
cnizzardini May 20, 2023
5c2167e
resolve timezone bug
cnizzardini May 20, 2023
9ee4554
resolve timezone bug
cnizzardini May 20, 2023
04fc603
resolve timezone bug
cnizzardini May 20, 2023
1644666
skip timezone bug and enable elastic again
cnizzardini May 20, 2023
7f96e98
debugging this: https://github.com/elastic/elastic-github-actions/iss…
cnizzardini May 20, 2023
091018d
bad copy pasta
cnizzardini May 20, 2023
604bb27
debug datetime issue
cnizzardini May 20, 2023
979c09a
oh well
cnizzardini May 20, 2023
2270458
oh well 2
cnizzardini May 20, 2023
dbcaaf8
adds #[\ReturnTypeWillChange] to suppress deprecation warnings 8.0/8.1
cnizzardini May 20, 2023
74adf1e
cleanup
cnizzardini May 20, 2023
6eeafa8
docblock updates
cnizzardini May 21, 2023
30292b7
re-adds integration test and removes a deprecation warning in php 8.1
cnizzardini Jun 1, 2023
cc273ff
testing pipeline
cnizzardini Jun 1, 2023
60c133a
fix test namespaces
cnizzardini Jun 1, 2023
f36d397
try getting elastc running in pipeline again using setup from cakephp…
cnizzardini Jun 1, 2023
feb25ee
try getting elastc running in pipeline again using setup from cakephp…
cnizzardini Jun 1, 2023
a79f06a
try getting elastc running in pipeline again using setup from cakephp…
cnizzardini Jun 1, 2023
3ae1a95
fix names
cnizzardini Jun 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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