From f30f1506a43adc62a7eb98532c869f3171c06b92 Mon Sep 17 00:00:00 2001 From: Alex Zecca Date: Tue, 28 Apr 2020 09:38:53 +0000 Subject: [PATCH 1/5] fix divide test --- .../Actions/Arithmetics/DivideTest.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/Elements/Actions/Arithmetics/DivideTest.php diff --git a/tests/Elements/Actions/Arithmetics/DivideTest.php b/tests/Elements/Actions/Arithmetics/DivideTest.php new file mode 100644 index 0000000..425d5c0 --- /dev/null +++ b/tests/Elements/Actions/Arithmetics/DivideTest.php @@ -0,0 +1,38 @@ +scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker(); + } + + /** + * @dataProvider argDatasetProvider + */ + public function testIsValidWithDifferentArgs($args, $expected) + { + $divide = \Ezweb\Workflow\Elements\Actions\Arithmetics\Divide::create(); + foreach ($args as $arg) { + $scalarMock = $this->scalarBuilder->getMockWithValue($arg); + $divide->addArgs($scalarMock); + } + $method = new \ReflectionMethod($divide, 'isValid'); + $method->setAccessible(true); + + $this->assertSame($expected, $method->invokeArgs($divide, [[], $args])); + } + + public function argDatasetProvider() + { + return [ + [[6, 2], true] + ]; + } +} From 2956dad4d7553626f4c97dcd1127793c01a3674d Mon Sep 17 00:00:00 2001 From: Alex Zecca Date: Wed, 29 Apr 2020 12:19:12 +0000 Subject: [PATCH 2/5] add tests --- src/Elements/Types/ParentTypes/Action.php | 2 +- .../Actions/Arithmetics/DivideTest.php | 65 ++++++++++-- .../Actions/Arithmetics/MinusTest.php | 86 ++++++++++++++++ .../Actions/Arithmetics/ModuloTest.php | 98 +++++++++++++++++++ .../Elements/Actions/Arithmetics/PlusTest.php | 86 ++++++++++++++++ .../Elements/Actions/Arithmetics/PowTest.php | 86 ++++++++++++++++ .../Actions/Arithmetics/TimesTest.php | 86 ++++++++++++++++ tests/Elements/Operators/Equal.php | 74 ++++++++++++++ tests/Elements/Operators/Greater.php | 76 ++++++++++++++ tests/Elements/Operators/GreaterOrEqual.php | 76 ++++++++++++++ tests/Elements/Operators/LessOrEqual.php | 76 ++++++++++++++ tests/Elements/Operators/LessThan.php | 77 +++++++++++++++ tests/Elements/Operators/Not.php | 68 +++++++++++++ .../Types/Condition/Operators/All.php | 72 ++++++++++++++ .../Types/Condition/Operators/Any.php | 72 ++++++++++++++ tests/Elements/Types/ParentTypes/Action.php | 46 +++++++++ 16 files changed, 1135 insertions(+), 11 deletions(-) create mode 100644 tests/Elements/Actions/Arithmetics/MinusTest.php create mode 100644 tests/Elements/Actions/Arithmetics/ModuloTest.php create mode 100644 tests/Elements/Actions/Arithmetics/PlusTest.php create mode 100644 tests/Elements/Actions/Arithmetics/PowTest.php create mode 100644 tests/Elements/Actions/Arithmetics/TimesTest.php create mode 100644 tests/Elements/Operators/Equal.php create mode 100644 tests/Elements/Operators/Greater.php create mode 100644 tests/Elements/Operators/GreaterOrEqual.php create mode 100644 tests/Elements/Operators/LessOrEqual.php create mode 100644 tests/Elements/Operators/LessThan.php create mode 100644 tests/Elements/Operators/Not.php create mode 100644 tests/Elements/Types/Condition/Operators/All.php create mode 100644 tests/Elements/Types/Condition/Operators/Any.php create mode 100644 tests/Elements/Types/ParentTypes/Action.php diff --git a/src/Elements/Types/ParentTypes/Action.php b/src/Elements/Types/ParentTypes/Action.php index cd0ec0f..9fe0eff 100644 --- a/src/Elements/Types/ParentTypes/Action.php +++ b/src/Elements/Types/ParentTypes/Action.php @@ -44,7 +44,7 @@ public function getJSONData(): ?array public function __toString(): string { - return '('.$this->function.')'; + return '(' . $this->function . ')'; } public function getValues(): array diff --git a/tests/Elements/Actions/Arithmetics/DivideTest.php b/tests/Elements/Actions/Arithmetics/DivideTest.php index 425d5c0..5548786 100644 --- a/tests/Elements/Actions/Arithmetics/DivideTest.php +++ b/tests/Elements/Actions/Arithmetics/DivideTest.php @@ -2,7 +2,6 @@ namespace Ezweb\Workflow\Test\Elements\Action\Arithmetics; -use Ezweb\Workflow\Providers\Provider; class DivideTest extends \PHPUnit\Framework\TestCase { @@ -13,26 +12,72 @@ protected function setUp(): void $this->scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker(); } + public function testCreateANewDivideElement() + { + $divide = \Ezweb\Workflow\Elements\Actions\Arithmetics\Divide::create(); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Divide::class, $divide); + } + + public function testAddArg() + { + $divide = \Ezweb\Workflow\Elements\Actions\Arithmetics\Divide::create(); + + $divide->addArgs($this->scalarBuilder->getMockWithValue(1)); + $divide->addArgs($this->scalarBuilder->getMockWithValue(2)); + $this->assertCount(2, $divide->getArgs()); + } + + /** + * @dataProvider resultIsOkProvider + */ + public function testResultIsOk($a, $b, $expected) + { + $divide = \Ezweb\Workflow\Elements\Actions\Arithmetics\Divide::create(); + + $method = new \ReflectionMethod($divide, 'getResult'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invoke($divide, [], [$a, $b]), + 'getResult for ' . $a . ' / ' . $b . ' = ' . $expected + ); + } + + public function resultIsOkProvider() + { + return [ + [4, 2, 2], + [4.5, 2, 2.25], + [4.5, 2.5, 1.8], + ]; + } + /** - * @dataProvider argDatasetProvider + * @dataProvider isValidValuesProvider */ - public function testIsValidWithDifferentArgs($args, $expected) + public function testIsValid($a, $b, $expected) { $divide = \Ezweb\Workflow\Elements\Actions\Arithmetics\Divide::create(); - foreach ($args as $arg) { - $scalarMock = $this->scalarBuilder->getMockWithValue($arg); - $divide->addArgs($scalarMock); - } + $method = new \ReflectionMethod($divide, 'isValid'); $method->setAccessible(true); - $this->assertSame($expected, $method->invokeArgs($divide, [[], $args])); + $this->assertSame( + $expected, + $method->invokeArgs($divide, [[], [$a, $b]]), + 'isValid for ' . $a . ' and ' . $b . ' expect ' . ($expected ? "true" : "false") + ); } - public function argDatasetProvider() + public function isValidValuesProvider() { return [ - [[6, 2], true] + [1, 2, true], + [1.1, 2.2, true], + ['a', 2, false], + [1.1, 'b', false], + ['a', 'b', false] ]; } } diff --git a/tests/Elements/Actions/Arithmetics/MinusTest.php b/tests/Elements/Actions/Arithmetics/MinusTest.php new file mode 100644 index 0000000..e5fc5c5 --- /dev/null +++ b/tests/Elements/Actions/Arithmetics/MinusTest.php @@ -0,0 +1,86 @@ +scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker(); + } + + public function testCreateANewMinusElement() + { + $minus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Minus::create(); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Minus::class, $minus); + } + + public function testAddArg() + { + $minus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Minus::create(); + + $minus->addArgs($this->scalarBuilder->getMockWithValue(1)); + $minus->addArgs($this->scalarBuilder->getMockWithValue(2)); + $this->assertCount(2, $minus->getArgs()); + } + + /** + * @dataProvider resultIsOkProvider + */ + public function testResultIsOk($a, $b, $expected) + { + $minus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Minus::create(); + + $method = new \ReflectionMethod($minus, 'getResult'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invoke($minus, [], [$a, $b]), + 'getResult for ' . $a . ' % ' . $b . ' = ' . $expected + ); + } + + public function resultIsOkProvider() + { + return [ + [4, 2, 2], + [2, 3, -1], + [4.5, 2, 2.5], + [2.5, 4.5, -2.0], + [3.1415, 3.1415, 0.0], + [9, 7, 2], + ]; + } + + /** + * @dataProvider isValidValuesProvider + */ + public function testIsValid($a, $b, $expected) + { + $minus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Minus::create(); + + $method = new \ReflectionMethod($minus, 'isValid'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invokeArgs($minus, [[], [$a, $b]]), + 'isValid for ' . $a . ' and ' . $b . ' expect ' . ($expected ? "true" : "false") + ); + } + + public function isValidValuesProvider() + { + return [ + [1, 2, true], + [1.1, 2.2, true], + ['a', 2, false], + [1.1, 'b', false], + ['a', 'b', false] + ]; + } +} diff --git a/tests/Elements/Actions/Arithmetics/ModuloTest.php b/tests/Elements/Actions/Arithmetics/ModuloTest.php new file mode 100644 index 0000000..a5fa956 --- /dev/null +++ b/tests/Elements/Actions/Arithmetics/ModuloTest.php @@ -0,0 +1,98 @@ +scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker(); + } + + public function testCreateANewModuloElement() + { + $modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create(); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::class, $modulo); + } + + public function testAddArg() + { + $modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create(); + + $modulo->addArgs($this->scalarBuilder->getMockWithValue(1)); + $modulo->addArgs($this->scalarBuilder->getMockWithValue(2)); + $this->assertCount(2, $modulo->getArgs()); + } + + /** + * @dataProvider resultIsOkProvider + */ + public function testResultIsOk($a, $b, $expected) + { + $modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create(); + $modulo->addArgs($this->scalarBuilder->getMockWithValue(4)); + $modulo->addArgs($this->scalarBuilder->getMockWithValue(2)); + + $method = new \ReflectionMethod($modulo, 'getResult'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invoke($modulo, [], [$a, $b]), + 'getResult for ' . $a . ' % ' . $b . ' = ' . $expected + ); + } + + public function resultIsOkProvider() + { + return [ + [4, 2, 0], + [5, 2, 1], + [2, 5, 2], + [4.0, 2.0, 0], + [4.0, 2.1, 0], + [4.2, 2.2, 0], + [4.5, 2.2, 0], + [4.6, 2.2, 0], + [4.6, 2, 0], + ["4.6", "2", 0], + [5.2, 2.2, 1], + [5.6, 2.2, 1], + [5.2, 2.5, 1], + [5.2, 2.8, 1], + [2.8, 5.2, 2], + ]; + } + + /** + * @dataProvider isValidValuesProvider + */ + public function testIsValid($a, $b, $expected) + { + $modulo = \Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::create(); + $modulo->addArgs($this->scalarBuilder->getMockWithValue(4)); + $modulo->addArgs($this->scalarBuilder->getMockWithValue(2)); + + $method = new \ReflectionMethod($modulo, 'isValid'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invokeArgs($modulo, [[], [$a, $b]]), + 'isValid for ' . $a . ' and ' . $b . ' expect ' . ($expected ? "true" : "false") + ); + } + + public function isValidValuesProvider() + { + return [ + [1, 2, true], + [1.1, 2.2, true], + ['a', 2, false], + [1.1, 'b', false], + ['a', 'b', false] + ]; + } +} diff --git a/tests/Elements/Actions/Arithmetics/PlusTest.php b/tests/Elements/Actions/Arithmetics/PlusTest.php new file mode 100644 index 0000000..7ed2b3a --- /dev/null +++ b/tests/Elements/Actions/Arithmetics/PlusTest.php @@ -0,0 +1,86 @@ +scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker(); + } + + public function testCreateANewPlusElement() + { + $plus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Plus::create(); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Plus::class, $plus); + } + + public function testAddArg() + { + $plus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Plus::create(); + + $plus->addArgs($this->scalarBuilder->getMockWithValue(1)); + $plus->addArgs($this->scalarBuilder->getMockWithValue(2)); + $this->assertCount(2, $plus->getArgs()); + } + + /** + * @dataProvider resultIsOkProvider + */ + public function testResultIsOk($a, $b, $expected) + { + $plus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Plus::create(); + + $method = new \ReflectionMethod($plus, 'getResult'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invoke($plus, [], [$a, $b]), + 'getResult for ' . $a . '+' . $b . ' = ' . $expected + ); + } + + public function resultIsOkProvider() + { + return [ + [4, 2, 6], + [2, 3, 5], + [4.5, 2, 6.5], + [2.5, 4.5, 7.0], + [3.1415, 3.1415, 6.283], + [9, 7, 16], + ]; + } + + /** + * @dataProvider isValidValuesProvider + */ + public function testIsValid($a, $b, $expected) + { + $plus = \Ezweb\Workflow\Elements\Actions\Arithmetics\Plus::create(); + + $method = new \ReflectionMethod($plus, 'isValid'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invokeArgs($plus, [[], [$a, $b]]), + 'isValid for ' . $a . ' and ' . $b . ' expect ' . ($expected ? "true" : "false") + ); + } + + public function isValidValuesProvider() + { + return [ + [1, 2, true], + [1.1, 2.2, true], + ['a', 2, false], + [1.1, 'b', false], + ['a', 'b', false] + ]; + } +} diff --git a/tests/Elements/Actions/Arithmetics/PowTest.php b/tests/Elements/Actions/Arithmetics/PowTest.php new file mode 100644 index 0000000..044f7ff --- /dev/null +++ b/tests/Elements/Actions/Arithmetics/PowTest.php @@ -0,0 +1,86 @@ +scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker(); + } + + public function testCreateANewPowElement() + { + $pow = \Ezweb\Workflow\Elements\Actions\Arithmetics\Pow::create(); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Pow::class, $pow); + } + + public function testAddArg() + { + $pow = \Ezweb\Workflow\Elements\Actions\Arithmetics\Pow::create(); + + $pow->addArgs($this->scalarBuilder->getMockWithValue(1)); + $pow->addArgs($this->scalarBuilder->getMockWithValue(2)); + $this->assertCount(2, $pow->getArgs()); + } + + /** + * @dataProvider resultIsOkProvider + */ + public function testResultIsOk($a, $b, $expected) + { + $pow = \Ezweb\Workflow\Elements\Actions\Arithmetics\Pow::create(); + + $method = new \ReflectionMethod($pow, 'getResult'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invoke($pow, [], [$a, $b]), + 'getResult for ' . $a . ' ** ' . $b . ' = ' . $expected + ); + } + + public function resultIsOkProvider() + { + return [ + [4, 2, 16], + [2, 3, 8], + [4.5, 2, 20.25], + [2.5, 4.5, 61.76323555016366], + [3.1415, 3.1415, 36.45491472872008], + [9, 7, 4782969], + ]; + } + + /** + * @dataProvider isValidValuesProvider + */ + public function testIsValid($a, $b, $expected) + { + $pow = \Ezweb\Workflow\Elements\Actions\Arithmetics\Pow::create(); + + $method = new \ReflectionMethod($pow, 'isValid'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invokeArgs($pow, [[], [$a, $b]]), + 'isValid for ' . $a . ' and ' . $b . ' expect ' . ($expected ? "true" : "false") + ); + } + + public function isValidValuesProvider() + { + return [ + [1, 2, true], + [1.1, 2.2, true], + ['a', 2, false], + [1.1, 'b', false], + ['a', 'b', false] + ]; + } +} diff --git a/tests/Elements/Actions/Arithmetics/TimesTest.php b/tests/Elements/Actions/Arithmetics/TimesTest.php new file mode 100644 index 0000000..002394f --- /dev/null +++ b/tests/Elements/Actions/Arithmetics/TimesTest.php @@ -0,0 +1,86 @@ +scalarBuilder = new \Ezweb\Workflow\Test\Mocker\ScalarMocker(); + } + + public function testCreateANewTimesElement() + { + $times = \Ezweb\Workflow\Elements\Actions\Arithmetics\Times::create(); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Times::class, $times); + } + + public function testAddArg() + { + $times = \Ezweb\Workflow\Elements\Actions\Arithmetics\Times::create(); + + $times->addArgs($this->scalarBuilder->getMockWithValue(1)); + $times->addArgs($this->scalarBuilder->getMockWithValue(2)); + $this->assertCount(2, $times->getArgs()); + } + + /** + * @dataProvider resultIsOkProvider + */ + public function testResultIsOk($a, $b, $expected) + { + $times = \Ezweb\Workflow\Elements\Actions\Arithmetics\Times::create(); + + $method = new \ReflectionMethod($times, 'getResult'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invoke($times, [], [$a, $b]), + 'getResult for ' . $a . ' * ' . $b . ' = ' . $expected + ); + } + + public function resultIsOkProvider() + { + return [ + [4, 2, 8], + [2, 3, 6], + [4.5, 2, 9.0], + [2.5, 4.5, 11.25], + [3.1415, 3.1415, 9.86902225], + [9, 7, 63], + ]; + } + + /** + * @dataProvider isValidValuesProvider + */ + public function testIsValid($a, $b, $expected) + { + $times = \Ezweb\Workflow\Elements\Actions\Arithmetics\Times::create(); + + $method = new \ReflectionMethod($times, 'isValid'); + $method->setAccessible(true); + + $this->assertSame( + $expected, + $method->invokeArgs($times, [[], [$a, $b]]), + 'isValid for ' . $a . ' and ' . $b . ' expect ' . ($expected ? "true" : "false") + ); + } + + public function isValidValuesProvider() + { + return [ + [1, 2, true], + [1.1, 2.2, true], + ['a', 2, false], + [1.1, 'b', false], + ['a', 'b', false] + ]; + } +} diff --git a/tests/Elements/Operators/Equal.php b/tests/Elements/Operators/Equal.php new file mode 100644 index 0000000..064bdba --- /dev/null +++ b/tests/Elements/Operators/Equal.php @@ -0,0 +1,74 @@ +setAccessible(true); + + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a])); + } + + public function getResultProvider() + { + return + [ + [[1, 1], true], + [[1, '1'], true], + [[1, '1', 1.0], true], + [['ab', 'ab'], true], + [[1, 1, 1, 1], true], + [[1, true], true], + [[false, 0], true], + + [[1, 2], false], + [['a', 1], false], + [[true, false], false], + [[1, false], false], + [[1, 1, 2, 1], false], + [['ab', 'a'], false], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Operators\Equal::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $operator->attachNewScalar(2); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + $operator->attachNewScalar(2); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\Equal::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Operators\Equal::create(); + $operator->attachNewScalar(2); + $operator->attachNewVars('toto'); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Operators\Equal::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Operators/Greater.php b/tests/Elements/Operators/Greater.php new file mode 100644 index 0000000..38df436 --- /dev/null +++ b/tests/Elements/Operators/Greater.php @@ -0,0 +1,76 @@ +setAccessible(true); + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a])); + } + + public function getResultProvider() + { + return + [ + [['b', 'a'], true], + [[true, false], true], + [[2, 1], true], + [['2', 1], true], + + [[1, 1], false], + [[1, '1'], false], + [[1, '1', 1.0], false], + [['ab', 'ab'], false], + [[1, 1, 1, 1], false], + [[1, true], false], + [[false, 0], false], + [['a', 'b'], false], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Operators\Greater::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\Greater::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Operators\Greater::create(); + $operator->attachNewScalar(2); + $operator->attachNewVars('toto'); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Operators\Greater::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Operators/GreaterOrEqual.php b/tests/Elements/Operators/GreaterOrEqual.php new file mode 100644 index 0000000..4340be5 --- /dev/null +++ b/tests/Elements/Operators/GreaterOrEqual.php @@ -0,0 +1,76 @@ +setAccessible(true); + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a])); + } + + public function getResultProvider() + { + return + [ + [['b', 'a'], true], + [[true, false], true], + [[2, 1], true], + [['2', 1], true], + [[1, 1], true], + [[1, '1'], true], + [[1, '1', 1.0], true], + [['ab', 'ab'], true], + [[1, 1, 1, 1], true], + [[1, true], true], + [[false, 0], true], + + [['a', 'b'], false], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Operators\GreaterOrEqual::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\GreaterOrEqual::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Operators\GreaterOrEqual::create(); + $operator->attachNewScalar(2); + $operator->attachNewVars('toto'); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Operators\GreaterOrEqual::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Operators/LessOrEqual.php b/tests/Elements/Operators/LessOrEqual.php new file mode 100644 index 0000000..b4d7726 --- /dev/null +++ b/tests/Elements/Operators/LessOrEqual.php @@ -0,0 +1,76 @@ +setAccessible(true); + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a])); + } + + public function getResultProvider() + { + return + [ + [[1, 1], true], + [[1, '1'], true], + [[1, '1', 1.0], true], + [['ab', 'ab'], true], + [[1, 1, 1, 1], true], + [[1, true], true], + [[false, 0], true], + [['a', 'b'], true], + + [['b', 'a'], false], + [[true, false], false], + [[2, 1], false], + [['2', 1], false], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Operators\LessOrEqual::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\LessOrEqual::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Operators\LessOrEqual::create(); + $operator->attachNewScalar(2); + $operator->attachNewVars('toto'); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Operators\LessOrEqual::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Operators/LessThan.php b/tests/Elements/Operators/LessThan.php new file mode 100644 index 0000000..9b81799 --- /dev/null +++ b/tests/Elements/Operators/LessThan.php @@ -0,0 +1,77 @@ +setAccessible(true); + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a]), var_export($a, true)); + } + + public function getResultProvider() + { + return + [ + [['a', 'b'], true], + [[1, 2], true], + [[1, 1], false], + [[1, '1'], false], + [[1, '1', 1.0], false], + [['ab', 'ab'], false], + [[1, 1, 1, 1], false], + [[1, true], false], + [[false, 0], false], + + [['b', 'a'], false], + [[true, false], false], + [[2, 1], false], + [['2', 1], false], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Operators\LessThan::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\LessThan::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Operators\LessThan::create(); + $operator->attachNewScalar(2); + $operator->attachNewVars('toto'); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Operators\LessThan::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Operators/Not.php b/tests/Elements/Operators/Not.php new file mode 100644 index 0000000..dbff0d8 --- /dev/null +++ b/tests/Elements/Operators/Not.php @@ -0,0 +1,68 @@ +setAccessible(true); + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a]), var_export($a, true)); + } + + public function getResultProvider() + { + return + [ + [[true], false], + [[false], true], + [[1], false], + [[2], false], + [['a'], false], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Operators\Not::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $operator->attachNewScalar(2); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator->attachNewScalar(2); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\Not::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Operators\Not::create(); + $operator->attachNewScalar(2); + $operator->attachNewVars('toto'); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Operators\Not::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Types/Condition/Operators/All.php b/tests/Elements/Types/Condition/Operators/All.php new file mode 100644 index 0000000..920c6c3 --- /dev/null +++ b/tests/Elements/Types/Condition/Operators/All.php @@ -0,0 +1,72 @@ +setAccessible(true); + + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a]), var_export($a, true)); + } + + public function getResultProvider() + { + return + [ + [[1, 1], false], + [[false, false], false], + [[true, false], false], + [[false, true], false], + [['a', 'a'], false], + + [[true, true], true], + [[true, true, true, true], true], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Types\Condition\Operators\All::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator->attachNewOperand(\Ezweb\Workflow\Elements\Types\ParentTypes\Operator::class); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator->attachNewOperand(\Ezweb\Workflow\Elements\Types\ParentTypes\Operator::class); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\Equal::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Types\Condition\Operators\All::create(); + $operator->attachNewOperand(\Ezweb\Workflow\Elements\Types\ParentTypes\Operator::class); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Types\Condition\Operators\All::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Types/Condition/Operators/Any.php b/tests/Elements/Types/Condition/Operators/Any.php new file mode 100644 index 0000000..07d9c14 --- /dev/null +++ b/tests/Elements/Types/Condition/Operators/Any.php @@ -0,0 +1,72 @@ +setAccessible(true); + + $this->assertSame($expected, $method->invokeArgs($operator, [[], $a]), var_export($a, true)); + } + + public function getResultProvider() + { + return + [ + [[1, 1], false], + [[false, false], false], + [['a', 'a'], false], + + [[true, false], true], + [[false, true], true], + [[true, true], true], + [[true, true, true, true], true], + ]; + } + + public function testIsValid() + { + $operator = \Ezweb\Workflow\Elements\Types\Condition\Operators\Any::create(); + + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + $this->assertFalse($method->invokeArgs($operator, [[], []])); + + $operator->attachNewOperand(\Ezweb\Workflow\Elements\Types\ParentTypes\Operator::class); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator->attachNewOperand(\Ezweb\Workflow\Elements\Types\ParentTypes\Operator::class); + $this->assertTrue($method->invokeArgs($operator, [[], []])); + + $operator = \Ezweb\Workflow\Elements\Operators\Equal::create(); + $method = new \ReflectionMethod($operator, 'isValid'); + $method->setAccessible(true); + + $this->assertFalse($method->invokeArgs($operator, [[], []])); + } + + public function testGetJSONData() + { + $operator = \Ezweb\Workflow\Elements\Types\Condition\Operators\Any::create(); + $operator->attachNewOperand(\Ezweb\Workflow\Elements\Types\ParentTypes\Operator::class); + + $expected = [ + 'type' => \Ezweb\Workflow\Elements\Types\Condition\Operators\Any::getName(), + 'value' => $operator->getOperands() + ]; + + $this->assertSame($expected, $operator->getJSONData()); + } +} diff --git a/tests/Elements/Types/ParentTypes/Action.php b/tests/Elements/Types/ParentTypes/Action.php new file mode 100644 index 0000000..e7896f8 --- /dev/null +++ b/tests/Elements/Types/ParentTypes/Action.php @@ -0,0 +1,46 @@ +setAccessible(true); + + $vars = [1, 2]; + $childrenValues = ['a', 'b']; + + $function = $this + ->getMockBuilder(\Ezweb\Workflow\Elements\Actions\Action::class) + ->disableOriginalConstructor() + ->getMock(); + + $function + ->expects($this->once()) + ->method('getResult') + ->with($vars, $childrenValues); + + $action->function = $function; + + $method->invokeArgs($action, [$vars, $childrenValues]); + } + + public function testAddValue() + { + $action = \Ezweb\Workflow\Elements\Types\ParentTypes\Action::create(); + + $type = $this->getMockBuilder(\Ezweb\Workflow\Elements\Types\Type::class)->disableOriginalConstructor()->getMock(); + + $function = $this->getMockBuilder(\Ezweb\Workflow\Elements\Actions\Action::class)->disableOriginalConstructor()->getMock(); + $function->expects($this->once())->method('addArgs')->with($type); + + $action->function = $function; + + $action->addValue($type); + } +} From 713fc580a09fe0dd3007b8b65c2eb239d63c292c Mon Sep 17 00:00:00 2001 From: Alex Zecca Date: Wed, 29 Apr 2020 14:28:51 +0000 Subject: [PATCH 3/5] add tests --- src/Elements/Element.php | 2 +- src/Elements/Types/ParentTypes/Action.php | 2 +- tests/Elements/Types/ParentTypes/Action.php | 65 +++++++++++++++++++-- tests/ParserTest.php | 7 --- 4 files changed, 61 insertions(+), 15 deletions(-) delete mode 100644 tests/ParserTest.php diff --git a/src/Elements/Element.php b/src/Elements/Element.php index b4346f0..d9f376e 100644 --- a/src/Elements/Element.php +++ b/src/Elements/Element.php @@ -15,7 +15,7 @@ protected function hash(array $elements) $hashes[] = $value->getHash(); } sort($hashes, SORT_STRING); - return md5($this->getName() . '.' . implode('.', $hashes)); + return md5(static::getName() . '.' . implode('.', $hashes)); } final public function jsonSerialize() diff --git a/src/Elements/Types/ParentTypes/Action.php b/src/Elements/Types/ParentTypes/Action.php index 9fe0eff..ce0bf93 100644 --- a/src/Elements/Types/ParentTypes/Action.php +++ b/src/Elements/Types/ParentTypes/Action.php @@ -7,7 +7,7 @@ class Action extends ParentType /** * @var \Ezweb\Workflow\Elements\Actions\Action */ - public \Ezweb\Workflow\Elements\Actions\Action $function; + protected \Ezweb\Workflow\Elements\Actions\Action $function; public static function getName(): string { diff --git a/tests/Elements/Types/ParentTypes/Action.php b/tests/Elements/Types/ParentTypes/Action.php index e7896f8..dbdfe02 100644 --- a/tests/Elements/Types/ParentTypes/Action.php +++ b/tests/Elements/Types/ParentTypes/Action.php @@ -2,6 +2,9 @@ namespace Ezweb\Workflow\Test\Elements\Types\ParentTypes; +use Ezweb\Workflow\Loader; +use Ezweb\Workflow\Parser; + class Action extends \PHPUnit\Framework\TestCase { @@ -12,35 +15,85 @@ public function testGetResult() $method = new \ReflectionMethod($action, 'getResult'); $method->setAccessible(true); + $property = new \ReflectionProperty($action, 'function'); + $property->setAccessible(true); + $vars = [1, 2]; $childrenValues = ['a', 'b']; $function = $this ->getMockBuilder(\Ezweb\Workflow\Elements\Actions\Action::class) - ->disableOriginalConstructor() ->getMock(); $function ->expects($this->once()) ->method('getResult') + ->willReturn(2) ->with($vars, $childrenValues); - $action->function = $function; + $property->setValue($action, $function); - $method->invokeArgs($action, [$vars, $childrenValues]); + $this->assertSame(2, $method->invokeArgs($action, [$vars, $childrenValues])); } public function testAddValue() { $action = \Ezweb\Workflow\Elements\Types\ParentTypes\Action::create(); - $type = $this->getMockBuilder(\Ezweb\Workflow\Elements\Types\Type::class)->disableOriginalConstructor()->getMock(); + $property = new \ReflectionProperty($action, 'function'); + $property->setAccessible(true); + + $type = $this->getMockBuilder(\Ezweb\Workflow\Elements\Types\Type::class)->getMock(); - $function = $this->getMockBuilder(\Ezweb\Workflow\Elements\Actions\Action::class)->disableOriginalConstructor()->getMock(); + $function = $this->getMockBuilder(\Ezweb\Workflow\Elements\Actions\Action::class)->getMock(); $function->expects($this->once())->method('addArgs')->with($type); - $action->function = $function; + $property->setValue($action, $function); $action->addValue($type); } + + public function testCreateFromParser() + { + $functionParsed = new \stdClass(); + $functionParsed->name = ''; + + $providerAction = $this->getMockBuilder(\Ezweb\Workflow\Providers\Action::class)->getMock(); + $providerAction->method('getClass')->willReturn(\Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::class); + + $loader = $this->getMockBuilder(\Ezweb\Workflow\Loader::class)->getMock(); + $loader->method('getActionProviderConfig')->willReturn($providerAction); + + $action = \Ezweb\Workflow\Elements\Types\ParentTypes\Action::createFromParser($functionParsed, $loader); + $property = new \ReflectionProperty($action, 'function'); + $property->setAccessible(true); + + $function = $property->getValue($action); + + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Types\ParentTypes\Action::class, $action); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::class, $function); + } + + public function testGetValues() + { + $scalar = new \stdClass(); + $scalar->type = 'scalar'; + $scalar->value = 2; + + $vars = new \stdClass(); + $vars->type = 'scalar'; + $vars->value = 'toto'; + + $object = new \stdClass(); + $object->type = 'action'; + $object->name = 'modulo'; + $object->value = [ + $scalar, + $vars + ]; + + $action = \Ezweb\Workflow\Elements\Types\ParentTypes\Action::createFromParser($object, new Loader()); + + dump($action); + } } diff --git a/tests/ParserTest.php b/tests/ParserTest.php deleted file mode 100644 index 5bec139..0000000 --- a/tests/ParserTest.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Thu, 30 Apr 2020 12:06:22 +0000 Subject: [PATCH 4/5] add tests --- tests/Elements/Types/ParentTypes/Action.php | 25 ------ .../Elements/Types/ParentTypes/Condition.php | 82 ++++++++++++++++++ tests/Elements/Types/ParentTypes/Operator.php | 85 +++++++++++++++++++ 3 files changed, 167 insertions(+), 25 deletions(-) create mode 100644 tests/Elements/Types/ParentTypes/Condition.php create mode 100644 tests/Elements/Types/ParentTypes/Operator.php diff --git a/tests/Elements/Types/ParentTypes/Action.php b/tests/Elements/Types/ParentTypes/Action.php index dbdfe02..f89f00f 100644 --- a/tests/Elements/Types/ParentTypes/Action.php +++ b/tests/Elements/Types/ParentTypes/Action.php @@ -2,8 +2,6 @@ namespace Ezweb\Workflow\Test\Elements\Types\ParentTypes; -use Ezweb\Workflow\Loader; -use Ezweb\Workflow\Parser; class Action extends \PHPUnit\Framework\TestCase { @@ -73,27 +71,4 @@ public function testCreateFromParser() $this->assertInstanceOf(\Ezweb\Workflow\Elements\Types\ParentTypes\Action::class, $action); $this->assertInstanceOf(\Ezweb\Workflow\Elements\Actions\Arithmetics\Modulo::class, $function); } - - public function testGetValues() - { - $scalar = new \stdClass(); - $scalar->type = 'scalar'; - $scalar->value = 2; - - $vars = new \stdClass(); - $vars->type = 'scalar'; - $vars->value = 'toto'; - - $object = new \stdClass(); - $object->type = 'action'; - $object->name = 'modulo'; - $object->value = [ - $scalar, - $vars - ]; - - $action = \Ezweb\Workflow\Elements\Types\ParentTypes\Action::createFromParser($object, new Loader()); - - dump($action); - } } diff --git a/tests/Elements/Types/ParentTypes/Condition.php b/tests/Elements/Types/ParentTypes/Condition.php new file mode 100644 index 0000000..630078f --- /dev/null +++ b/tests/Elements/Types/ParentTypes/Condition.php @@ -0,0 +1,82 @@ +setAccessible(true); + + $method = new \ReflectionMethod($condition, 'getResult'); + $method->setAccessible(true); + + $vars = [1, 2]; + $childrenValues = ['a', 'b']; + + $operator = $this + ->getMockBuilder(\Ezweb\Workflow\Elements\Types\Condition\Operators\Operator::class) + ->disableOriginalConstructor() + ->getMock(); + $operator->expects($this->once()) + ->method('getResult') + ->with($vars, $childrenValues) + ->willReturn(2); + + $property->setValue($condition, $operator); + + $this->assertSame(2, $method->invokeArgs($condition, [$vars, $childrenValues])); + } + + public function testAddValue() + { + $condition = \Ezweb\Workflow\Elements\Types\ParentTypes\Condition::create(); + + $property = new \ReflectionProperty($condition, 'operator'); + $property->setAccessible(true); + + $method = new \ReflectionMethod($condition, 'addValue'); + $method->setAccessible(true); + + $typeMock = $this->getMockBuilder(\Ezweb\Workflow\Elements\Types\Type::class) + ->getMock(); + + $operator = $this + ->getMockBuilder(\Ezweb\Workflow\Elements\Types\Condition\Operators\Operator::class) + ->disableOriginalConstructor() + ->getMock(); + $operator->expects($this->once()) + ->method('addOperand') + ->with($typeMock) + ->willReturn($condition); + + $property->setValue($condition, $operator); + + $this->assertSame($condition, $method->invokeArgs($condition, [$typeMock])); + } + + public function testCreateFromParser() + { + $parsedData = new \stdClass(); + $parsedData->operator = ''; + + $providerType = $this->getMockBuilder(\Ezweb\Workflow\Providers\Type::class)->getMock(); + $providerType->method('getClass')->willReturn(\Ezweb\Workflow\Elements\Types\Condition\Operators\Any::class); + + $loader = $this->getMockBuilder(\Ezweb\Workflow\Loader::class)->getMock(); + $loader->method('getTypeProviderConfig')->willReturn($providerType); + + $condition = \Ezweb\Workflow\Elements\Types\ParentTypes\Condition::createFromParser($parsedData, $loader); + + $property = new \ReflectionProperty($condition, 'operator'); + $property->setAccessible(true); + + $operator = $property->getValue($condition); + + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Types\ParentTypes\Condition::class, $condition); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Types\Condition\Operators\Any::class, $operator); + } +} diff --git a/tests/Elements/Types/ParentTypes/Operator.php b/tests/Elements/Types/ParentTypes/Operator.php new file mode 100644 index 0000000..336bb6f --- /dev/null +++ b/tests/Elements/Types/ParentTypes/Operator.php @@ -0,0 +1,85 @@ +setAccessible(true); + + $method = new \ReflectionMethod($condition, 'getResult'); + $method->setAccessible(true); + + $vars = [1, 2]; + $childrenValues = ['a', 'b']; + + $operator = $this + ->getMockBuilder(\Ezweb\Workflow\Elements\Operators\Operator::class) + ->disableOriginalConstructor() + ->getMock(); + + $operator->expects($this->once()) + ->method('getResult') + ->with($vars, $childrenValues) + ->willReturn(2); + + $property->setValue($condition, $operator); + + $this->assertSame(2, $method->invokeArgs($condition, [$vars, $childrenValues])); + } + + public function testAddValue() + { + $operatorType = \Ezweb\Workflow\Elements\Types\ParentTypes\Operator::create(); + + $property = new \ReflectionProperty($operatorType, 'operator'); + $property->setAccessible(true); + + $method = new \ReflectionMethod($operatorType, 'addValue'); + $method->setAccessible(true); + + $typeMock = $this->getMockBuilder(\Ezweb\Workflow\Elements\Types\Type::class) + ->getMock(); + + $operator = $this + ->getMockBuilder(\Ezweb\Workflow\Elements\Operators\Operator::class) + ->disableOriginalConstructor() + ->getMock(); + + $operator->expects($this->once()) + ->method('addOperand') + ->with($typeMock) + ->willReturn($operatorType); + + $property->setValue($operatorType, $operator); + + $this->assertSame($operatorType, $method->invokeArgs($operatorType, [$typeMock])); + } + + public function testCreateFromParser() + { + $parsedData = new \stdClass(); + $parsedData->operator = ''; + + $providerType = $this->getMockBuilder(\Ezweb\Workflow\Providers\Operator::class)->getMock(); + $providerType->method('getClass')->willReturn(\Ezweb\Workflow\Elements\Operators\Equal::class); + + $loader = $this->getMockBuilder(\Ezweb\Workflow\Loader::class)->getMock(); + $loader->method('getOperatorProviderConfig')->willReturn($providerType); + + $condition = \Ezweb\Workflow\Elements\Types\ParentTypes\Operator::createFromParser($parsedData, $loader); + + $property = new \ReflectionProperty($condition, 'operator'); + $property->setAccessible(true); + + $operator = $property->getValue($condition); + + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Types\ParentTypes\Operator::class, $condition); + $this->assertInstanceOf(\Ezweb\Workflow\Elements\Operators\Equal::class, $operator); + } +} From 1df7a7efdfaeb34539b689dc0ed6b59f93860ed9 Mon Sep 17 00:00:00 2001 From: Alex Zecca Date: Mon, 4 May 2020 08:20:45 +0000 Subject: [PATCH 5/5] fix operator name --- composer.json | 2 +- src/Elements/Operators/Greater.php | 2 +- src/Elements/Operators/GreaterOrEqual.php | 2 +- src/Elements/Operators/LessOrEqual.php | 2 +- src/Elements/Operators/LessThan.php | 2 +- src/Elements/Types/Condition/Operators/All.php | 2 +- src/Elements/Types/Condition/Operators/Any.php | 2 +- src/Elements/Types/ScalarTypes/Scalar.php | 5 ++++- src/Elements/Types/ScalarTypes/ScalarType.php | 2 +- 9 files changed, 12 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 0fdcc05..c581626 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "scripts": { "tests": "vendor/bin/phpunit", - "phpstan": "vendor/bin/phpstan analyse", + "phpstan": "vendor/bin/phpstan analyse" } } diff --git a/src/Elements/Operators/Greater.php b/src/Elements/Operators/Greater.php index f0a4fd6..708ed9b 100644 --- a/src/Elements/Operators/Greater.php +++ b/src/Elements/Operators/Greater.php @@ -6,7 +6,7 @@ class Greater extends Operator { public static function getName(): string { - return 'greaterThan'; + return 'greater'; } protected function getResult(array $vars, array $childrenValues) diff --git a/src/Elements/Operators/GreaterOrEqual.php b/src/Elements/Operators/GreaterOrEqual.php index d566405..533dd1b 100644 --- a/src/Elements/Operators/GreaterOrEqual.php +++ b/src/Elements/Operators/GreaterOrEqual.php @@ -6,7 +6,7 @@ class GreaterOrEqual extends Operator { public static function getName(): string { - return 'greaterOrEqualThan'; + return 'greaterOrEqual'; } protected function getResult(array $vars, array $childrenValues): bool diff --git a/src/Elements/Operators/LessOrEqual.php b/src/Elements/Operators/LessOrEqual.php index d42e3da..f68a3b9 100644 --- a/src/Elements/Operators/LessOrEqual.php +++ b/src/Elements/Operators/LessOrEqual.php @@ -6,7 +6,7 @@ class LessOrEqual extends Operator { public static function getName(): string { - return 'lessOrEqualThan'; + return 'lessOrEqual'; } protected function getResult(array $vars, array $childrenValues) diff --git a/src/Elements/Operators/LessThan.php b/src/Elements/Operators/LessThan.php index 8c45469..b7efd10 100644 --- a/src/Elements/Operators/LessThan.php +++ b/src/Elements/Operators/LessThan.php @@ -6,7 +6,7 @@ class LessThan extends Operator { public static function getName(): string { - return 'greaterThan'; + return 'less'; } protected function getResult(array $vars, array $childrenValues) diff --git a/src/Elements/Types/Condition/Operators/All.php b/src/Elements/Types/Condition/Operators/All.php index 88310f6..9e5d56d 100644 --- a/src/Elements/Types/Condition/Operators/All.php +++ b/src/Elements/Types/Condition/Operators/All.php @@ -29,7 +29,7 @@ public function getJSONData(): ?array public function __toString(): string { - return implode(' AND ', $this->getOperands()); + return '(' . implode(' AND ', $this->getOperands()) . ')'; } protected function isValid(array $vars, array $childrenValues): bool diff --git a/src/Elements/Types/Condition/Operators/Any.php b/src/Elements/Types/Condition/Operators/Any.php index 73c874e..9185a19 100644 --- a/src/Elements/Types/Condition/Operators/Any.php +++ b/src/Elements/Types/Condition/Operators/Any.php @@ -31,7 +31,7 @@ public function getJSONData(): ?array public function __toString(): string { - return implode(' OR ', $this->getOperands()); + return '(' . implode(' OR ', $this->getOperands()) . ')'; } protected function isValid(array $vars, array $childrenValues): bool diff --git a/src/Elements/Types/ScalarTypes/Scalar.php b/src/Elements/Types/ScalarTypes/Scalar.php index 1587444..e5fd6c2 100644 --- a/src/Elements/Types/ScalarTypes/Scalar.php +++ b/src/Elements/Types/ScalarTypes/Scalar.php @@ -29,7 +29,10 @@ public function getJSONData(): ?array public function __toString(): string { - return (string) $this->getValue(); + if (is_string($this->getValue())) { + return (string)'"' . $this->getValue() . '"'; + } + return (string)$this->getValue(); } protected function isValid(array $vars, array $childrenValues): bool diff --git a/src/Elements/Types/ScalarTypes/ScalarType.php b/src/Elements/Types/ScalarTypes/ScalarType.php index 688b0e4..097ea63 100644 --- a/src/Elements/Types/ScalarTypes/ScalarType.php +++ b/src/Elements/Types/ScalarTypes/ScalarType.php @@ -34,7 +34,7 @@ public function setScalarValue($scalarValue) public static function createFromParser(\stdClass $config, \Ezweb\Workflow\Loader $configLoader): self { $instance = new static(); - if (!is_scalar($config->value) && $config->value !== null) { + if ((!is_scalar($config->value) || is_array($config->value)) && $config->value !== null) { throw new \InvalidArgumentException('ScalarType must have a scalar value'); } $instance->scalarValue = $config->value;