diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 6838962..575913a 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -20,12 +20,11 @@ jobs:
- name: Install composer dependencies
run: |
+ # Install code check tools
composer run cs:install
-
# Install app dependencies
composer install --no-interaction --prefer-dist
- # Check code checker and coding standards
- name: Check coding standards
run: |
composer run cs:check
@@ -37,7 +36,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- php: ['7.2', '7.3', '7.4'] # 8.0
+ php: ['7.2', '7.3', '7.4', '8.0']
name: PHP ${{ matrix.php }} tests
steps:
@@ -52,6 +51,9 @@ jobs:
- name: Install composer dependencies
run: |
+ # Remove unnecesery packages
+ composer remove phpstan/phpstan phpstan/phpstan-nette --dev --no-interaction
+ # Install app dependencies
composer install --no-interaction --prefer-dist
- name: Run tests
@@ -65,3 +67,29 @@ jobs:
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
+
+ benchmark:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ php: ['7.4']
+
+ name: Benchmark on PHP ${{ matrix.php }}
+ steps:
+ - name: Git clone
+ uses: actions/checkout@master
+
+ - name: Install PHP
+ uses: shivammathur/setup-php@master
+ with:
+ php-version: ${{ matrix.php }}
+
+ - name: Install composer dependencies
+ run: |
+ # Install benchmarking tool
+ composer global require phpbench/phpbench @dev
+ # Install app dependencies
+ composer install --no-interaction --prefer-dist
+
+ - name: Run benchmarks
+ run: phpbench run
diff --git a/README.md b/README.md
index 7ef0d7c..3c50fd9 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
- Math PHP computational engine
+ Mathematicator Framework Engine
@@ -10,20 +10,21 @@
[](https://github.com/mathematicator-core/engine/actions?query=workflow%3A%22Integrity+check%22)
[](https://codecov.io/gh/mathematicator-core/engine)
+[](https://packagist.org/packages/mathematicator-core/engine)
[](./LICENSE)
[](https://phpstan.org/)
-Extremely complex library for advance work with math patterns, tokens and computing.
+This is a Mathematicator Framework common library for advance work with
+math patterns, tokens and computing. The library is considered as
+a sublayer for other tools in Mathematicator Framework.
-> Please help improve this documentation by sending a Pull request.
-
-Install by Composer:
+## Installation
```
composer require mathematicator-core/engine
```
-### What is this package responsible for?
+## Features
This package contains set of tools that other [mathematicator-core](https://github.com/mathematicator-core)
packages have in common.
@@ -141,8 +142,31 @@ one to the most abstract one:
+**Third-party packages:**
+
+⚠️ Not guaranteed!
+
+
+
+ |
+
+
+ REST API
+
+
+ |
+
+ Install the whole pack as a REST API service
+ on your server (Docker ready) or
+ access it via public cloud REST API.
+ |
+
+
+
## Contribution
+> Please help to improve this documentation by sending a Pull request.
+
### Tests
All new contributions should have its unit tests in `/tests` directory.
@@ -154,6 +178,13 @@ This package uses [Nette Tester](https://tester.nette.org/). You can run tests v
composer test
````
+For benchmarking, we use [phpbench](https://github.com/phpbench/phpbench).
+You can run benchmarks this way:
+```bash
+composer global require phpbench/phpbench @dev # only the first time
+phpbench run
+````
+
Before PR, please run complete code check via command:
```bash
composer cs:install # only first time
diff --git a/benchmarks/.gitkeep b/benchmarks/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/common.neon b/common.neon
index c369e7b..7f08455 100644
--- a/common.neon
+++ b/common.neon
@@ -16,7 +16,3 @@ services:
extensions:
psr11: Contributte\Psr11\DI\Psr11ContainerExtension
-
-orm.annotations:
- paths:
- Mathematicator: %appDir%/../vendor/mathematicator-core/engine/src
diff --git a/composer.json b/composer.json
index 29af2a6..f546b44 100644
--- a/composer.json
+++ b/composer.json
@@ -17,17 +17,15 @@
],
"require": {
"php": ">=7.2",
- "baraja-core/localization": "^1.0",
"contributte/psr11-container-interface": "^0.4.1",
- "mathematicator-core/numbers": "^2.0@dev",
- "mathematicator-core/tokenizer": "^2.0@dev",
+ "mathematicator-core/numbers": "^2.1@dev",
+ "mathematicator-core/tokenizer": "^2.1@dev",
"nette/di": "^3.0",
"nette/utils": "^3.0",
"symfony/yaml": "^5.0",
- "symfony/translation": "^4.0 || ^5.0"
+ "symfony/translation": "^5.0"
},
"require-dev": {
- "baraja-core/doctrine": "^2.0",
"brainmaestro/composer-git-hooks": "^2.8",
"nette/bootstrap": "^3.0.1",
"nette/tester": "^2.3",
@@ -56,12 +54,12 @@
"composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress"
],
"cs:check": [
- "php temp/code-checker/code-checker --short-arrays --strict-types --no-progress",
- "php temp/coding-standard/ecs check src --config temp/coding-standard/coding-standard-php71.yml"
+ "php temp/code-checker/code-checker -d src -d tests -d benchmarks --short-arrays --strict-types --no-progress",
+ "php temp/coding-standard/ecs check src tests benchmarks --config temp/coding-standard/coding-standard-php71.yml"
],
"cs:fix": [
- "php temp/code-checker/code-checker -d src -d tests --short-arrays --strict-types --fix --no-progress",
- "php temp/coding-standard/ecs check src --config temp/coding-standard/coding-standard-php71.yml --fix"
+ "php temp/code-checker/code-checker -d src -d tests -d benchmarks --short-arrays --strict-types --fix --no-progress",
+ "php temp/coding-standard/ecs check src tests benchmarks --config temp/coding-standard/coding-standard-php71.yml --fix"
],
"phpstan": "vendor/bin/phpstan analyse src -c phpstan.neon --level 8 --no-progress",
"fix": [
@@ -79,7 +77,7 @@
},
"extra": {
"branch-alias": {
- "dev-master": "2.0.x-dev"
+ "dev-master": "2.1.x-dev"
},
"hooks": {
"post-merge": "composer install",
diff --git a/phpbench.json b/phpbench.json
new file mode 100644
index 0000000..1f88d1c
--- /dev/null
+++ b/phpbench.json
@@ -0,0 +1,4 @@
+{
+ "bootstrap": "vendor/autoload.php",
+ "path": "benchmarks"
+}
diff --git a/tests/bootstrap.php b/tests/Bootstrap.php
similarity index 88%
rename from tests/bootstrap.php
rename to tests/Bootstrap.php
index 2bffd3f..ff47ac7 100644
--- a/tests/bootstrap.php
+++ b/tests/Bootstrap.php
@@ -26,12 +26,11 @@ public static function boot(): Container
$configurator->createRobotLoader()
->addDirectory(__DIR__ . '/../src')
- ->addDirectory(__DIR__ . '/Mocks')
->register();
$configurator
- // TODO make this work: ->addConfig(__DIR__ . '/../common.neon')
- ->addConfig(__DIR__ . '/test.common.neon');
+ ->addConfig(__DIR__ . '/../common.neon')
+ ->addConfig(__DIR__ . '/../vendor/mathematicator-core/tokenizer/common.neon');
$container = $configurator->createContainer();
diff --git a/tests/EngineTests/EngineTest.php b/tests/EngineTests/EngineTest.php
index 02b0982..7fc9314 100644
--- a/tests/EngineTests/EngineTest.php
+++ b/tests/EngineTests/EngineTest.php
@@ -5,15 +5,15 @@
namespace Mathematicator\Engine\Tests;
-use Mathematicator\Engine\Entity\Box;
use Mathematicator\Engine\Engine;
+use Mathematicator\Engine\Entity\Box;
use Mathematicator\Engine\Entity\EngineMultiResult;
use Mathematicator\Engine\Entity\EngineSingleResult;
use Nette\DI\Container;
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../bootstrap.php';
+require __DIR__ . '/../Bootstrap.php';
class EngineTest extends TestCase
{
diff --git a/tests/EngineTests/Entity/BoxTest.php b/tests/EngineTests/Entity/BoxTest.php
index 91db19e..af92c63 100644
--- a/tests/EngineTests/Entity/BoxTest.php
+++ b/tests/EngineTests/Entity/BoxTest.php
@@ -14,7 +14,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class BoxTest extends TestCase
{
diff --git a/tests/EngineTests/Entity/ContextTest.php b/tests/EngineTests/Entity/ContextTest.php
index b366f7a..377886b 100644
--- a/tests/EngineTests/Entity/ContextTest.php
+++ b/tests/EngineTests/Entity/ContextTest.php
@@ -13,7 +13,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class ContextTest extends TestCase
{
diff --git a/tests/EngineTests/Entity/DynamicConfigurationTest.php b/tests/EngineTests/Entity/DynamicConfigurationTest.php
index 286eae9..1e466be 100644
--- a/tests/EngineTests/Entity/DynamicConfigurationTest.php
+++ b/tests/EngineTests/Entity/DynamicConfigurationTest.php
@@ -9,7 +9,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class DynamicConfigurationTest extends TestCase
{
diff --git a/tests/EngineTests/Entity/EngineResultTest.php b/tests/EngineTests/Entity/EngineResultTest.php
index 3ad87a9..dd9b229 100644
--- a/tests/EngineTests/Entity/EngineResultTest.php
+++ b/tests/EngineTests/Entity/EngineResultTest.php
@@ -8,13 +8,13 @@
use Mathematicator\Engine\Entity\Box;
use Mathematicator\Engine\Entity\EngineMultiResult;
use Mathematicator\Engine\Entity\EngineSingleResult;
-use Mathematicator\Engine\Exception\NoResultsException;
use Mathematicator\Engine\Entity\Source;
+use Mathematicator\Engine\Exception\NoResultsException;
use Mathematicator\Engine\Router\DynamicRoute;
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class EngineResultTest extends TestCase
{
diff --git a/tests/EngineTests/Entity/QueryTest.php b/tests/EngineTests/Entity/QueryTest.php
index a42bbcf..86d6afd 100644
--- a/tests/EngineTests/Entity/QueryTest.php
+++ b/tests/EngineTests/Entity/QueryTest.php
@@ -10,7 +10,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class QueryTest extends TestCase
{
diff --git a/tests/EngineTests/Entity/SourceTest.php b/tests/EngineTests/Entity/SourceTest.php
index 7427ed7..d9b8955 100644
--- a/tests/EngineTests/Entity/SourceTest.php
+++ b/tests/EngineTests/Entity/SourceTest.php
@@ -9,7 +9,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class SourceTest extends TestCase
{
diff --git a/tests/EngineTests/Formatter/FixSpacesTest.php b/tests/EngineTests/Formatter/FixSpacesTest.php
index f7c2c54..e27ab0a 100644
--- a/tests/EngineTests/Formatter/FixSpacesTest.php
+++ b/tests/EngineTests/Formatter/FixSpacesTest.php
@@ -9,7 +9,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class FixSpacesTest extends TestCase
{
diff --git a/tests/EngineTests/Formatter/NaturalTextFormatterTest.php b/tests/EngineTests/Formatter/NaturalTextFormatterTest.php
index b4b502a..e468673 100644
--- a/tests/EngineTests/Formatter/NaturalTextFormatterTest.php
+++ b/tests/EngineTests/Formatter/NaturalTextFormatterTest.php
@@ -11,7 +11,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class NaturalTextFormatterTest extends TestCase
{
diff --git a/tests/EngineTests/Helper/CzechTest.php b/tests/EngineTests/Helper/CzechTest.php
index c05d02e..818906f 100644
--- a/tests/EngineTests/Helper/CzechTest.php
+++ b/tests/EngineTests/Helper/CzechTest.php
@@ -13,7 +13,7 @@
use Tester\TestCase;
use function time;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class CzechTest extends TestCase
{
diff --git a/tests/EngineTests/Helper/DateTimeTest.php b/tests/EngineTests/Helper/DateTimeTest.php
index 0f9a209..97729de 100644
--- a/tests/EngineTests/Helper/DateTimeTest.php
+++ b/tests/EngineTests/Helper/DateTimeTest.php
@@ -6,12 +6,12 @@
use Error;
-use Mathematicator\Engine\Helper\DateTime;
use Mathematicator\Engine\Exception\MathematicatorException;
+use Mathematicator\Engine\Helper\DateTime;
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class DateTimeTest extends TestCase
{
diff --git a/tests/EngineTests/HelpersTest.php b/tests/EngineTests/HelpersTest.php
index 1822aed..7725195 100644
--- a/tests/EngineTests/HelpersTest.php
+++ b/tests/EngineTests/HelpersTest.php
@@ -6,17 +6,16 @@
use Error;
-use Mathematicator\Engine\Helpers;
use Mathematicator\Engine\Entity\Query;
+use Mathematicator\Engine\Helpers;
use Nette\Utils\ArrayHash;
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../bootstrap.php';
+require __DIR__ . '/../Bootstrap.php';
class HelpersTest extends TestCase
{
-
public function testCreateInstance(): void
{
Assert::exception(function () {
diff --git a/tests/EngineTests/MathFunction/FunctionManagerTest.php b/tests/EngineTests/MathFunction/FunctionManagerTest.php
index 3af6c2f..45cf65c 100644
--- a/tests/EngineTests/MathFunction/FunctionManagerTest.php
+++ b/tests/EngineTests/MathFunction/FunctionManagerTest.php
@@ -5,17 +5,16 @@
namespace Mathematicator\Engine\Tests\MathFunction;
-use Mathematicator\Engine\MathFunction\FunctionManager;
use Mathematicator\Engine\MathFunction\Entity\Sin ;
+use Mathematicator\Engine\MathFunction\FunctionManager;
use RuntimeException;
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class FunctionManagerTest extends TestCase
{
-
public function testBasic(): void
{
$sin = FunctionManager::getFunction('sin');
diff --git a/tests/EngineTests/NumberRewriterTest.php b/tests/EngineTests/NumberRewriterTest.php
index 3402d07..13b647e 100644
--- a/tests/EngineTests/NumberRewriterTest.php
+++ b/tests/EngineTests/NumberRewriterTest.php
@@ -10,7 +10,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../bootstrap.php';
+require __DIR__ . '/../Bootstrap.php';
class NumberRewriterTest extends TestCase
{
@@ -18,6 +18,7 @@ class NumberRewriterTest extends TestCase
/** @var NumberRewriter */
private $numberRewriter;
+
public function __construct(Container $container)
{
$this->numberRewriter = $container->getByType(NumberRewriter::class);
diff --git a/tests/EngineTests/QueryNormalizerTest.php b/tests/EngineTests/QueryNormalizerTest.php
index b5f9145..81bfe64 100644
--- a/tests/EngineTests/QueryNormalizerTest.php
+++ b/tests/EngineTests/QueryNormalizerTest.php
@@ -10,7 +10,7 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../bootstrap.php';
+require __DIR__ . '/../Bootstrap.php';
class QueryNormalizerTest extends TestCase
{
diff --git a/tests/EngineTests/Router/RouterTest.php b/tests/EngineTests/Router/RouterTest.php
index 449551b..bb0a81b 100644
--- a/tests/EngineTests/Router/RouterTest.php
+++ b/tests/EngineTests/Router/RouterTest.php
@@ -5,24 +5,23 @@
namespace Mathematicator\Engine\Tests\Router;
-use Mathematicator\Engine\Entity\Box;
-use Mathematicator\Engine\Entity\Context;
use Mathematicator\Engine\Controller\ErrorTooLongController;
use Mathematicator\Engine\Controller\OtherController;
+use Mathematicator\Engine\Entity\Box;
+use Mathematicator\Engine\Entity\Context;
use Mathematicator\Engine\Entity\DynamicConfiguration;
use Mathematicator\Engine\Entity\Query;
use Mathematicator\Engine\Entity\Source;
-use Mathematicator\Engine\Tests\Bootstrap;
-use Mathematicator\Engine\Translator;
use Mathematicator\Engine\Router\DynamicRoute;
use Mathematicator\Engine\Router\Router;
-use Mathematicator\Search\Translation\TranslatorHelper;
+use Mathematicator\Engine\Tests\Bootstrap;
+use Mathematicator\Engine\Translator;
use Nette\DI\Container;
use RuntimeException;
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class RouterTest extends TestCase
{
@@ -30,6 +29,7 @@ class RouterTest extends TestCase
/** @var Container */
private $container;
+
/**
* @param Container $container
*/
diff --git a/tests/EngineTests/Step/StepTest.php b/tests/EngineTests/Step/StepTest.php
index 675e8b7..18837af 100644
--- a/tests/EngineTests/Step/StepTest.php
+++ b/tests/EngineTests/Step/StepTest.php
@@ -9,11 +9,10 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class StepTest extends TestCase
{
-
public function testStep(): void
{
$step = new Step('Add 2 numbers', '1 + 1', 'Use an addition operation.');
diff --git a/tests/EngineTests/Translation/TranslationTest.php b/tests/EngineTests/Translation/TranslationTest.php
index bcd2d9f..37de4df 100644
--- a/tests/EngineTests/Translation/TranslationTest.php
+++ b/tests/EngineTests/Translation/TranslationTest.php
@@ -12,23 +12,21 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../../bootstrap.php';
+require __DIR__ . '/../../Bootstrap.php';
class TranslationTest extends TestCase
{
- /**
- * @var TranslatorInterface
- */
+ /** @var TranslatorInterface */
private $translator;
public function __construct(
Container $container
- )
- {
+ ) {
$this->translator = $container->getByType(TranslatorHelper::class)->translator;
}
+
public function testTranslate(): void
{
// Check simple translation
@@ -47,7 +45,6 @@ public function testTranslate(): void
// Test hierarchy
Assert::same('Child of a parent.', $this->translator->trans('parent.child', [], 'test'));
}
-
}
$container = (new Bootstrap())::boot();
diff --git a/tests/EngineTests/TranslatorTest.php b/tests/EngineTests/TranslatorTest.php
index 1c06dde..0902684 100644
--- a/tests/EngineTests/TranslatorTest.php
+++ b/tests/EngineTests/TranslatorTest.php
@@ -10,23 +10,21 @@
use Tester\Assert;
use Tester\TestCase;
-require __DIR__ . '/../bootstrap.php';
+require __DIR__ . '/../Bootstrap.php';
class TranslatorTest extends TestCase
{
- /**
- * @var TranslatorInterface
- */
+ /** @var TranslatorInterface */
private $translator;
public function __construct(
Container $container
- )
- {
+ ) {
$this->translator = $container->getByType(Translator::class);
}
+
public function testTranslate(): void
{
// Check simple translation
@@ -38,7 +36,6 @@ public function testTranslate(): void
// Sequential parameters
Assert::same('Sample FIRST | THIRD | SECOND', $this->translator->translate('test.sequentialParams.sample', 'FIRST', 'SECOND', 'THIRD'));
}
-
}
$container = (new Bootstrap())::boot();
diff --git a/tests/Mocks/RouterFactory.php b/tests/Mocks/RouterFactory.php
deleted file mode 100644
index dcc3d53..0000000
--- a/tests/Mocks/RouterFactory.php
+++ /dev/null
@@ -1,38 +0,0 @@
-/', 'Homepage:default');
-
- return $router;
- }
-}
diff --git a/tests/test.common.neon b/tests/test.common.neon
deleted file mode 100644
index fad845d..0000000
--- a/tests/test.common.neon
+++ /dev/null
@@ -1,24 +0,0 @@
-services:
- mathematicator.engine:
- factory: Mathematicator\Engine\Engine
- setup:
- - addExtraModule(@Mathematicator\Engine\ExtraModule\SampleModule)
- mathematicator.queryNormalizer:
- factory: Mathematicator\Engine\QueryNormalizer
- - Mathematicator\Engine\NumberRewriter
- - Mathematicator\Engine\Formatter\NaturalTextFormatter
- - Mathematicator\Engine\ExtraModule\SampleModule
- - Mathematicator\Engine\Controller\OtherController
- - Mathematicator\Engine\Controller\ErrorTooLongController
- # Added for tests
- - Mathematicator\Engine\Router\Router
- - Mathematicator\Tokenizer\Tokenizer
- - Mathematicator\Tokenizer\TokensToLatex
- - Mathematicator\Tokenizer\TokensToObject
- - Mathematicator\Numbers\NumberFactory
- # other
- - Mathematicator\Engine\Translator
- - Mathematicator\Engine\Translation\TranslatorHelper
-
-extensions:
- psr11: Contributte\Psr11\DI\Psr11ContainerExtension