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

FOUR-16341 Nayra - testing: We need to have the possibility to select the path in a gateway #229

Merged
merged 13 commits into from
Jun 28, 2024
14 changes: 9 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ version: 2
jobs:
build:
docker:
- image: circleci/php:7.1-node-browsers
- image: php:8.2.0-fpm
steps:
- checkout
- run: sudo composer self-update
- run: apt-get update && apt-get install -y git unzip
- run: pecl install xdebug && docker-php-ext-enable xdebug
- run: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- run: |
echo "error_reporting = E_ALL & ~E_DEPRECATED" > /usr/local/etc/php/conf.d/error_reporting.ini
- run: composer self-update
- restore_cache:
keys:
- composer-v1-{{ checksum "composer.json" }}
Expand All @@ -16,8 +21,7 @@ jobs:
key: composer-v1-{{ checksum "composer.json" }}
paths:
- vendor
- run: sudo docker-php-ext-enable xdebug
- run: ./vendor/bin/phpunit -d memory_limit=-1 --coverage-html coverage
- run: composer coverage
- run: ./check_coverage.php
- store_artifacts:
path: coverage
path: coverage
42 changes: 37 additions & 5 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,49 @@ on:
push:
branches:
- develop
- next
pull_request:
types: [opened, synchronize, reopened]
types: [opened, synchronize, reopened, edited]

jobs:
build:
name: Scan
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Update Composer
run: sudo composer self-update

- name: Cache Composer dependencies
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: composer-v1-${{ hashFiles('composer.json') }}
restore-keys: |
composer-v1-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
php-version: "8.2"
extensions: xdebug
coverage: xdebug
ini-values: xdebug.mode=coverage

- name: Install Composer dependencies
run: composer install -n --prefer-dist

- name: Run PHPUnit tests
run: ./vendor/bin/phpunit -d memory_limit=-1

- name: List coverage files
run: ls -l coverage

- uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ composer.lock
.vscode/
.php-cs-fixer.php
.php-cs-fixer.cache
.phpunit.result.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
},
"scripts": {
"test": "phpunit",
"coverage": "phpunit -d memory_limit=-1 --coverage-html coverage"
"coverage": "@php -d zend_extension=xdebug.so -d xdebug.mode=coverage -d xdebug.start_with_request=no vendor/bin/phpunit"
},
"require-dev": {
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^9.5"
}
}
35 changes: 23 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Features">
<directory>tests/Feature</directory>
<directory>tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
>
<coverage>
<report>
<text outputFile="php://stdout" showUncoveredFiles="true"/>
<html outputDirectory="coverage" />
<clover outputFile="coverage/clover.xml"/>
</report>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<testsuites>
<testsuite name="Features">
<directory>tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory>tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>
3 changes: 3 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
sonar.projectKey=ProcessMaker_nayra_AYq58Vs2xYvY_isvKv_4
sonar.php.coverage.reportPaths=./coverage/clover.xml
sonar.sources=src
sonar.tests=tests
12 changes: 11 additions & 1 deletion src/ProcessMaker/Nayra/Bpmn/ConditionedExclusiveTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class ConditionedExclusiveTransition implements TransitionInterface, ConditionedTransitionInterface
{
use TransitionTrait;
use ForceGatewayTransitionTrait;

/**
* @var callable
Expand All @@ -33,6 +34,15 @@ class ConditionedExclusiveTransition implements TransitionInterface, Conditioned
public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null)
{
try {
// If debug mode is enabled, the transition is triggered only if it is selected
if ($executionInstance && $this->shouldDebugTriggerThisTransition($executionInstance)) {
return true;
}
// If debug mode is enabled, the transition is not triggered if it is not selected
if ($executionInstance && $this->shouldDebugSkipThisTransition($executionInstance)) {
return false;
}

$result = false;
$myIndex = $this->owner->getConditionedTransitions()->indexOf($this);
$condition = $this->condition;
Expand Down Expand Up @@ -60,7 +70,7 @@ public function assertCondition(TokenInterface $token = null, ExecutionInstanceI

return $result;
} catch (Throwable $exception) {
throw new RuntimeException($exception->getMessage(), $exception->getCode(), $exception, $this->owner);
throw new RuntimeException($exception->getMessage(), $exception->getCode(), null, $this->owner);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/ProcessMaker/Nayra/Bpmn/ConditionedTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class ConditionedTransition implements TransitionInterface, ConditionedTransitionInterface
{
use TransitionTrait;
use ForceGatewayTransitionTrait;

/**
* @var callable
Expand All @@ -29,6 +30,15 @@ class ConditionedTransition implements TransitionInterface, ConditionedTransitio
*/
public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null)
{
// If debug mode is enabled, the transition is triggered only if it is selected
if ($executionInstance && $this->shouldDebugTriggerThisTransition($executionInstance)) {
return true;
}
// If debug mode is enabled, the transition is not triggered if it is not selected
if ($executionInstance && $this->shouldDebugSkipThisTransition($executionInstance)) {
return false;
}

$condition = $this->condition;
$dataStore = $executionInstance ? $executionInstance->getDataStore()
: $this->getOwnerProcess()->getEngine()->getDataStore();
Expand Down
10 changes: 10 additions & 0 deletions src/ProcessMaker/Nayra/Bpmn/DefaultTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class DefaultTransition implements TransitionInterface
{
use TransitionTrait;
use ForceGatewayTransitionTrait;

/**
* Returns true if the condition of the transition is met with the DataStore of the passed execution instance
Expand All @@ -24,6 +25,15 @@ class DefaultTransition implements TransitionInterface
*/
public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null)
{
// If debug mode is enabled, the transition is triggered only if it is selected
if ($this->shouldDebugTriggerThisTransition($executionInstance)) {
return true;
}
// If debug mode is enabled, the transition is not triggered if it is not selected
if ($this->shouldDebugSkipThisTransition($executionInstance)) {
return false;
}

$executeDefaultTransition = true;
foreach ($this->owner->getConditionedTransitions() as $transition) {
if ($transition->assertCondition($token, $executionInstance)) {
Expand Down
11 changes: 8 additions & 3 deletions src/ProcessMaker/Nayra/Bpmn/ExclusiveGatewayTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ExclusiveGatewayTransition implements TransitionInterface
{
use TransitionTrait;
use PauseOnGatewayTransitionTrait;

/**
* Initialize the tokens consumed property, the Exclusive Gateway consumes
Expand All @@ -34,7 +35,8 @@ protected function initExclusiveGatewayTransition()
*/
public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null)
{
return true;
// Execution is paused if Engine is in demo mode and the gateway choose is not selected
return !$this->shouldPauseGatewayTransition($executionInstance);
}

/**
Expand All @@ -46,11 +48,14 @@ public function assertCondition(TokenInterface $token = null, ExecutionInstanceI
*/
protected function hasAllRequiredTokens(ExecutionInstanceInterface $executionInstance)
{
if ($this->doesDemoHasAllRequiredTokens($executionInstance)) {
return true;
}

$withToken = $this->incoming()->find(function (Connection $flow) use ($executionInstance) {
return $flow->originState()->getTokens($executionInstance)->count() > 0;
});
$rule = $withToken->count() > 0;

return $rule;
return $withToken->count() > 0;
}
}
77 changes: 77 additions & 0 deletions src/ProcessMaker/Nayra/Bpmn/ForceGatewayTransitionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace ProcessMaker\Nayra\Bpmn;

use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;

/**
* Process base implementation.
*/
trait ForceGatewayTransitionTrait
{
use TransitionTrait;

/**
* Check if the transition should be triggered in debug mode.
*
* @param ExecutionInstanceInterface $executionInstance
*
* @return bool
*/
function shouldDebugTriggerThisTransition(ExecutionInstanceInterface $executionInstance)
{
$engine = $executionInstance->getEngine();
$demoMode = $engine->isDemoMode();
$gateway = $this->getOwner();
$connection = $this->outgoing()->item(0);
$targetEntrypoint = $connection->target()->getOwner();
return $demoMode && $engine->getSelectedDemoFlow($gateway)->getTarget() === $targetEntrypoint;
}

/**
* Check if the transition should be skipped in debug mode.
*
* @param ExecutionInstanceInterface $executionInstance
*
* @return bool
*/
function shouldDebugSkipThisTransition(ExecutionInstanceInterface $executionInstance)
{
$engine = $executionInstance->getEngine();
$demoMode = $engine->isDemoMode();
$gateway = $this->getOwner();
$connection = $this->outgoing()->item(0);
$targetEntrypoint = $connection->target()->getOwner();
return $demoMode && $engine->getSelectedDemoFlow($gateway)->getTarget() !== $targetEntrypoint;
}

/**
* If the condition is not met.
*
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $executionInstance
*
* @return bool
*/
protected function conditionIsFalse()
{
$executionInstance = func_get_arg(0);
$this->collect($executionInstance);

return true;
}

/**
* Consume the input tokens.
*
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $executionInstance
*/
private function collect(ExecutionInstanceInterface $executionInstance)
{
return $this->incoming()->sum(function (Connection $flow) use ($executionInstance) {
return $flow->origin()->getTokens($executionInstance)->sum(function (TokenInterface $token) {
return $token->getOwner()->consumeToken($token) ? 1 : 0;
});
});
}
}
9 changes: 8 additions & 1 deletion src/ProcessMaker/Nayra/Bpmn/InclusiveGatewayTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
use ProcessMaker\Nayra\Engine\DemoModeTrait;

/**
* Transition rule for a inclusive gateway.
*/
class InclusiveGatewayTransition implements TransitionInterface
{
use TransitionTrait;
use PauseOnGatewayTransitionTrait;

/**
* Initialize the tokens consumed property, the Inclusive Gateway consumes
Expand All @@ -34,7 +36,8 @@ protected function initExclusiveGatewayTransition()
*/
public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null)
{
return true;
// Execution is paused if Engine is in demo mode and the gateway choose is not selected
return !$this->shouldPauseGatewayTransition($executionInstance);
}

/**
Expand All @@ -54,6 +57,10 @@ public function assertCondition(TokenInterface $token = null, ExecutionInstanceI
*/
protected function hasAllRequiredTokens(ExecutionInstanceInterface $executionInstance)
{
if ($this->doesDemoHasAllRequiredTokens($executionInstance)) {
return true;
}

$withToken = $this->incoming()->find(function (Connection $flow) use ($executionInstance) {
return $flow->originState()->getTokens($executionInstance)->count() > 0;
});
Expand Down
2 changes: 2 additions & 0 deletions src/ProcessMaker/Nayra/Bpmn/Models/DatePeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class DatePeriod implements DatePeriodInterface

public $include_start_date = true;

public $include_end_date = false;

private $position = 0;

private $last;
Expand Down
2 changes: 1 addition & 1 deletion src/ProcessMaker/Nayra/Bpmn/ParallelGatewayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getInputPlace(FlowInterface $targetFlow = null)
protected function buildConnectionTo(FlowInterface $targetFlow)
{
$outgoingPlace = new State($this, GatewayInterface::TOKEN_STATE_OUTGOING);
$outgoingTransition = new Transition($this);
$outgoingTransition = new ParallelOutputTransition($this);
$outgoingTransition->attachEvent(
TransitionInterface::EVENT_AFTER_CONSUME,
function (TransitionInterface $transition, Collection $consumedTokens) {
Expand Down
Loading
Loading