Skip to content

Commit

Permalink
Test conditions with global data store
Browse files Browse the repository at this point in the history
  • Loading branch information
caleeli committed Jun 26, 2024
1 parent b48ba13 commit 3d567ec
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace ProcessMaker\Nayra\Bpmn;

use PHPUnit\Framework\TestCase;
use ProcessMaker\Nayra\Bpmn\Models\DataStore;
use ProcessMaker\Nayra\Bpmn\Models\ExclusiveGateway;
use ProcessMaker\Nayra\Bpmn\Models\Process;
use ProcessMaker\Nayra\Contracts\Engine\EngineInterface;

/**
* Tests for the ConditionedTransition class
*/
class ConditionedExclusiveTransitionTest extends TestCase
{
/**
* Tests that setters and getters are working properly
*/
public function testAssertCondition()
{
$gateway = new ExclusiveGateway();
$conditionedTransition = new ConditionedExclusiveTransition($gateway);
$conditionedTransition->setCondition(function ($data) {
return $data['foo'];
});

// Mock a engine data store
$process = new Process();
$engine = $this->getMockBuilder(EngineInterface::class)->getMock();
$dataStore = new DataStore();
$dataStore->setData(['foo' => 'bar']);
$engine->method('getDataStore')->willReturn($dataStore);
$process->setEngine($engine);
$conditionedTransition->setOwnerProcess($process);

// Assertion: The condition should return 'bar'
$this->assertEquals('bar', $conditionedTransition->assertCondition());
}
}
39 changes: 39 additions & 0 deletions tests/unit/ProcessMaker/Nayra/Bpmn/ConditionedTransitionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace ProcessMaker\Nayra\Bpmn;

use PHPUnit\Framework\TestCase;
use ProcessMaker\Nayra\Bpmn\Models\DataStore;
use ProcessMaker\Nayra\Bpmn\Models\ExclusiveGateway;
use ProcessMaker\Nayra\Bpmn\Models\Process;
use ProcessMaker\Nayra\Contracts\Engine\EngineInterface;

/**
* Tests for the ConditionedTransition class
*/
class ConditionedTransitionTest extends TestCase
{
/**
* Tests that setters and getters are working properly
*/
public function testAssertCondition()
{
$gateway = new ExclusiveGateway();
$conditionedTransition = new ConditionedTransition($gateway);
$conditionedTransition->setCondition(function ($data) {
return $data['foo'];
});

// Mock a engine data store
$process = new Process();
$engine = $this->getMockBuilder(EngineInterface::class)->getMock();
$dataStore = new DataStore();
$dataStore->setData(['foo' => 'bar']);
$engine->method('getDataStore')->willReturn($dataStore);
$process->setEngine($engine);
$conditionedTransition->setOwnerProcess($process);

// Assertion: The condition should return 'bar'
$this->assertEquals('bar', $conditionedTransition->assertCondition());
}
}

0 comments on commit 3d567ec

Please sign in to comment.