Merge pull request #1582 from mailpoet/symfony-di

Add symfony dependency injection container [MAILPOET-1605]
This commit is contained in:
M. Shull
2018-11-05 13:50:05 -05:00
committed by GitHub
26 changed files with 1118 additions and 374 deletions

View File

@ -61,7 +61,7 @@ jobs:
- run: - run:
name: "PHP Unit tests" name: "PHP Unit tests"
command: | command: |
WP_TEST_PATH="/home/circleci/mailpoet/wordpress" ./do t:u --xml WP_ROOT="/home/circleci/mailpoet/wordpress" ./do t:u --xml
- store_test_results: - store_test_results:
path: tests/_output path: tests/_output
- store_artifacts: - store_artifacts:
@ -97,7 +97,7 @@ jobs:
- run: - run:
name: "PHP Integration tests" name: "PHP Integration tests"
command: | command: |
WP_TEST_PATH="/home/circleci/mailpoet/wordpress" ./do t:i --xml WP_ROOT="/home/circleci/mailpoet/wordpress" ./do t:i --xml
- store_test_results: - store_test_results:
path: test-results/mocha path: test-results/mocha
- store_artifacts: - store_artifacts:

View File

@ -40,14 +40,14 @@ function setup {
# Add a second blog # Add a second blog
wp site create --slug=php7_multisite $wp_cli_wordpress_path $wp_cli_allow_root wp site create --slug=php7_multisite $wp_cli_wordpress_path $wp_cli_allow_root
echo "WP_TEST_MULTISITE_SLUG=php7_multisite" >> .env echo "WP_TEST_MULTISITE_SLUG=php7_multisite" >> .env
echo "WP_TEST_PATH_MULTISITE=/home/circleci/mailpoet/wordpress" >> .env echo "WP_ROOT_MULTISITE=/home/circleci/mailpoet/wordpress" >> .env
echo "HTTP_HOST=mailpoet.loc" >> .env echo "HTTP_HOST=mailpoet.loc" >> .env
# Add a third dummy blog # Add a third dummy blog
wp site create --slug=dummy_multisite $wp_cli_wordpress_path $wp_cli_allow_root wp site create --slug=dummy_multisite $wp_cli_wordpress_path $wp_cli_allow_root
else else
wp core install --admin_name=admin --admin_password=admin --admin_email=admin@mailpoet.loc --url=http://mailpoet.loc --title="WordPress Single" $wp_cli_wordpress_path $wp_cli_allow_root wp core install --admin_name=admin --admin_password=admin --admin_email=admin@mailpoet.loc --url=http://mailpoet.loc --title="WordPress Single" $wp_cli_wordpress_path $wp_cli_allow_root
echo "WP_TEST_PATH=/home/circleci/mailpoet/wordpress" >> .env echo "WP_ROOT=/home/circleci/mailpoet/wordpress" >> .env
fi fi
# Softlink plugin to plugin path # Softlink plugin to plugin path

View File

@ -1,10 +1,10 @@
# Required # Required
WP_TEST_PATH="/var/www/wordpress" WP_ROOT="/var/www/wordpress"
WP_TEST_ENABLE_NETWORK_TESTS="false" WP_TEST_ENABLE_NETWORK_TESTS="false"
WP_TEST_MAILER_ENABLE_SENDING="false" WP_TEST_MAILER_ENABLE_SENDING="false"
# Optional: for multisite acceptance tests # Optional: for multisite acceptance tests
WP_TEST_PATH_MULTISITE="/var/www/wordpress" WP_ROOT_MULTISITE="/var/www/wordpress"
WP_TEST_MULTISITE_SLUG="" WP_TEST_MULTISITE_SLUG=""
HTTP_HOST="" // URL of your site (used for multisite env and equals to DOMAIN_CURRENT_SITE from wp-config.php) HTTP_HOST="" // URL of your site (used for multisite env and equals to DOMAIN_CURRENT_SITE from wp-config.php)

6
.gitignore vendored
View File

@ -23,4 +23,8 @@ lang
.mp_svn .mp_svn
/nbproject/ /nbproject/
tests/_data/acceptanceGenerated.sql tests/_data/acceptanceGenerated.sql
lib/Dependencies lib/Dependencies
lib/DI/CachedContainer.php
mozart/Dependencies
mozart/Classes
mozart/vendor

View File

@ -5,7 +5,7 @@ ENV COMPOSER_ALLOW_SUPERUSER=1
RUN composer global require --optimize-autoloader "hirak/prestissimo" RUN composer global require --optimize-autoloader "hirak/prestissimo"
WORKDIR /wp-core/wp-content/plugins/mailpoet WORKDIR /wp-core/wp-content/plugins/mailpoet
ENV WP_TEST_PATH=/wp-core ENV WP_ROOT=/wp-core
ADD docker-entrypoint.sh / ADD docker-entrypoint.sh /

View File

@ -41,6 +41,8 @@ $ ./do compile:all
# Frameworks and libraries # Frameworks and libraries
- [Paris ORM](https://github.com/j4mie/paris). - [Paris ORM](https://github.com/j4mie/paris).
- [Symfony/dependency-injection](https://github.com/symfony/dependency-injection) ([docs for 3.4](https://symfony.com/doc/3.4/components/dependency_injection.html)).
- [Mozart](https://github.com/coenjacobs/mozart) for moving dependencies into MP namespace
- [Twig](https://twig.symfony.com/) and [Handlebars](https://handlebarsjs.com/) are used for templates rendering. - [Twig](https://twig.symfony.com/) and [Handlebars](https://handlebarsjs.com/) are used for templates rendering.
- [Monolog](https://seldaek.github.io/monolog/) is used for logging. - [Monolog](https://seldaek.github.io/monolog/) is used for logging.
- [Robo](https://robo.li/) is used to write and run workflow commands. - [Robo](https://robo.li/) is used to write and run workflow commands.
@ -94,10 +96,23 @@ $ ./do delete:docker # stop and remove all running docker containers.
$ ./do qa:lint # PHP code linter. $ ./do qa:lint # PHP code linter.
$ ./do qa:lint:javascript # JS code linter. $ ./do qa:lint:javascript # JS code linter.
$ ./do qa # PHP and JS linters. $ ./do qa # PHP and JS linters.
$ ./do container:dump # Generates DI container cache.
``` ```
# Coding and Testing # Coding and Testing
## DI
We use Symfony/dependency-injection container. Container configuration can be found in `libs/DI/ContainerFactory.php`
The container is configured and used with minimum sub-dependencies to keep final package size small.
You can check [the docs](https://symfony.com/doc/3.4/components/dependency_injection.html) to learn more about Symfony Container.
## Mozart
We use Mozart plugin for composer to prevent plugin libraries conflicts in PHP. Two plugins may be using different versions of a library. Mozart prefix dependencies namespaces and moves them into `libs\Dependencies` directory.
Dependencies handled by Mozart are configured in extra configuration file `mozart/composer.json`. Installation and processing is triggered in post scripts of the main `composer.json` file.
## i18n ## i18n
We use functions `__()`, `_n()` and `_x()` with domain `mailpoet` to translate strings. We use functions `__()`, `_n()` and `_x()` with domain `mailpoet` to translate strings.

View File

@ -282,6 +282,21 @@ class RoboFile extends \Robo\Tasks {
return $this->_exec('vendor/bin/codecept run integration -g failed'); return $this->_exec('vendor/bin/codecept run integration -g failed');
} }
function containerDump() {
$this->say('Deleting DI Container');
$this->_exec('rm -f ./lib/DI/CachedContainer.php');
$this->say('Generating DI container cache');
$this->loadEnv();
define('ABSPATH', getenv('WP_ROOT') . '/');
if (!file_exists(ABSPATH . 'wp-config.php')) {
$this->yell('WP_ROOT env variable does not contain valid path to wordpress root.', 40, 'red');
exit(1);
}
require_once __DIR__ . '/vendor/autoload.php';
$container_factory = new \MailPoet\DI\ContainerFactory();
$container_factory->dumpContainer();
}
function qa() { function qa() {
$collection = $this->collectionBuilder(); $collection = $this->collectionBuilder();
$collection->addCode(array($this, 'qaLint')); $collection->addCode(array($this, 'qaLint'));

View File

@ -22,11 +22,19 @@ test -d node_modules && rm -rf node_modules
npm install npm install
./do compile:all --env production ./do compile:all --env production
# Dependency injection container cache.
echo '[BUILD] Building DI Container cache'
./composer.phar install
./do container:dump
# Production libraries. # Production libraries.
echo '[BUILD] Fetching production libraries' echo '[BUILD] Fetching production libraries'
test -d vendor && rm -rf vendor test -d vendor && rm -rf vendor
./composer.phar install --no-dev --prefer-dist --optimize-autoloader --no-scripts ./composer.phar install --no-dev --prefer-dist --optimize-autoloader --no-scripts
echo '[BUILD] Fetching mozart managed production libraries'
./composer.phar install --no-dev --prefer-dist --working-dir=./mozart/
# Copy release folders. # Copy release folders.
echo '[BUILD] Copying release folders' echo '[BUILD] Copying release folders'
cp -Rf lang $plugin_name cp -Rf lang $plugin_name

View File

@ -22,8 +22,7 @@
"sabberworm/php-css-parser": "^8.1", "sabberworm/php-css-parser": "^8.1",
"symfony/polyfill-php72": "^1.9", "symfony/polyfill-php72": "^1.9",
"symfony/polyfill-mbstring": "^1.9", "symfony/polyfill-mbstring": "^1.9",
"sensiolabs/security-checker": "^5.0", "sensiolabs/security-checker": "^5.0"
"monolog/monolog": "^1.23"
}, },
"require-dev": { "require-dev": {
"codeception/aspect-mock": "2.0.1", "codeception/aspect-mock": "2.0.1",
@ -38,8 +37,7 @@
"umpirsky/twig-gettext-extractor": "1.1.*", "umpirsky/twig-gettext-extractor": "1.1.*",
"kint-php/kint": "^3.0", "kint-php/kint": "^3.0",
"squizlabs/php_codesniffer": "^3.3", "squizlabs/php_codesniffer": "^3.3",
"phpcompatibility/php-compatibility": "^9.0", "phpcompatibility/php-compatibility": "^9.0"
"coenjacobs/mozart": "^0.2.2"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -49,28 +47,15 @@
}, },
"scripts": { "scripts": {
"post-update-cmd": [ "post-update-cmd": [
"\"vendor/bin/mozart\" compose", "@fixPHPUnit57CodeCoverageForPHP72",
"rm -rf vendor/monolog", "./composer.phar install --working-dir=./mozart/"
"@fixPHPUnit57CodeCoverageForPHP72"
], ],
"post-install-cmd": [ "post-install-cmd": [
"\"vendor/bin/mozart\" compose", "@fixPHPUnit57CodeCoverageForPHP72",
"rm -rf vendor/monolog", "./composer.phar install --working-dir=./mozart/"
"@fixPHPUnit57CodeCoverageForPHP72"
], ],
"fixPHPUnit57CodeCoverageForPHP72": "sed -i -- 's/\\$numTests = count(\\$coverageData\\[\\$i\\]);/$numTests = (is_array($coverageData[$i]) ? count($coverageData[$i]) : 0);/g' vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php" "fixPHPUnit57CodeCoverageForPHP72": "sed -i -- 's/\\$numTests = count(\\$coverageData\\[\\$i\\]);/$numTests = (is_array($coverageData[$i]) ? count($coverageData[$i]) : 0);/g' vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php"
}, },
"extra": {
"mozart": {
"dep_namespace": "MailPoet\\Dependencies\\",
"dep_directory": "/lib/Dependencies/",
"classmap_directory": "/classes/dependencies/",
"classmap_prefix": "MP_",
"packages": [
"monolog/monolog"
]
}
},
"config": { "config": {
"platform": { "platform": {
"php": "5.6.30" "php": "5.6.30"

260
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "548dd0db75412e7939828d57012876ea", "content-hash": "7e713c50c195e507fc3cd4053d434af0",
"packages": [ "packages": [
{ {
"name": "cerdic/css-tidy", "name": "cerdic/css-tidy",
@ -47,16 +47,16 @@
}, },
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",
"version": "1.1.2", "version": "1.1.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/composer/ca-bundle.git", "url": "https://github.com/composer/ca-bundle.git",
"reference": "46afded9720f40b9dc63542af4e3e43a1177acb0" "reference": "8afa52cd417f4ec417b4bfe86b68106538a87660"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/46afded9720f40b9dc63542af4e3e43a1177acb0", "url": "https://api.github.com/repos/composer/ca-bundle/zipball/8afa52cd417f4ec417b4bfe86b68106538a87660",
"reference": "46afded9720f40b9dc63542af4e3e43a1177acb0", "reference": "8afa52cd417f4ec417b4bfe86b68106538a87660",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -99,7 +99,7 @@
"ssl", "ssl",
"tls" "tls"
], ],
"time": "2018-08-08T08:57:40+00:00" "time": "2018-10-18T06:09:13+00:00"
}, },
{ {
"name": "j4mie/idiorm", "name": "j4mie/idiorm",
@ -226,84 +226,6 @@
], ],
"time": "2017-03-21T02:13:30+00:00" "time": "2017-03-21T02:13:30+00:00"
}, },
{
"name": "monolog/monolog",
"version": "1.23.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"psr/log": "~1.0"
},
"provide": {
"psr/log-implementation": "1.0.0"
},
"require-dev": {
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
"doctrine/couchdb": "~1.0@dev",
"graylog2/gelf-php": "~1.0",
"jakub-onderka/php-parallel-lint": "0.9",
"php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3",
"phpunit/phpunit": "~4.5",
"phpunit/phpunit-mock-objects": "2.3.0",
"ruflin/elastica": ">=0.90 <3.0",
"sentry/sentry": "^0.13",
"swiftmailer/swiftmailer": "^5.3|^6.0"
},
"suggest": {
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongo": "Allow sending log messages to a MongoDB server",
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
"mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver",
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
"php-console/php-console": "Allow sending log messages to Google Chrome",
"rollbar/rollbar": "Allow sending log messages to Rollbar",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"sentry/sentry": "Allow sending log messages to a Sentry server"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Monolog\\": "src/Monolog"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
"homepage": "http://github.com/Seldaek/monolog",
"keywords": [
"log",
"logging",
"psr-3"
],
"time": "2017-06-19T01:22:40+00:00"
},
{ {
"name": "mtdowling/cron-expression", "name": "mtdowling/cron-expression",
"version": "v1.2.1", "version": "v1.2.1",
@ -496,16 +418,16 @@
}, },
{ {
"name": "sensiolabs/security-checker", "name": "sensiolabs/security-checker",
"version": "v5.0.0", "version": "v5.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sensiolabs/security-checker.git", "url": "https://github.com/sensiolabs/security-checker.git",
"reference": "df4625e39868ecf4e868355caf45352f566791db" "reference": "9ea927417c949039a9cfb0d92af76fd1c538d9e9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/df4625e39868ecf4e868355caf45352f566791db", "url": "https://api.github.com/repos/sensiolabs/security-checker/zipball/9ea927417c949039a9cfb0d92af76fd1c538d9e9",
"reference": "df4625e39868ecf4e868355caf45352f566791db", "reference": "9ea927417c949039a9cfb0d92af76fd1c538d9e9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -538,7 +460,7 @@
} }
], ],
"description": "A security checker for your composer.lock", "description": "A security checker for your composer.lock",
"time": "2018-09-04T07:02:17+00:00" "time": "2018-10-16T10:30:44+00:00"
}, },
{ {
"name": "soundasleep/html2text", "name": "soundasleep/html2text",
@ -1534,51 +1456,6 @@
"description": "BDD assertion library for PHPUnit", "description": "BDD assertion library for PHPUnit",
"time": "2017-07-12T16:50:18+00:00" "time": "2017-07-12T16:50:18+00:00"
}, },
{
"name": "coenjacobs/mozart",
"version": "0.2.2",
"source": {
"type": "git",
"url": "https://github.com/coenjacobs/mozart.git",
"reference": "f9218cc4643ba15d775bb8018a2c1b716a2951a6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/coenjacobs/mozart/zipball/f9218cc4643ba15d775bb8018a2c1b716a2951a6",
"reference": "f9218cc4643ba15d775bb8018a2c1b716a2951a6",
"shasum": ""
},
"require": {
"league/flysystem": "^1.0",
"php": ">=5.5.0",
"symfony/console": "^3.2",
"symfony/finder": "^3.2"
},
"require-dev": {
"coenjacobs/php-composter-phpcs": "^0.1.0",
"phpunit/phpunit": "^4.0"
},
"bin": [
"bin/mozart"
],
"type": "library",
"autoload": {
"psr-4": {
"CoenJacobs\\Mozart\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Coen Jacobs",
"email": "coenjacobs@gmail.com"
}
],
"time": "2018-06-25T14:11:53+00:00"
},
{ {
"name": "composer/composer", "name": "composer/composer",
"version": "1.7.2", "version": "1.7.2",
@ -1880,16 +1757,16 @@
}, },
{ {
"name": "consolidation/config", "name": "consolidation/config",
"version": "1.1.0", "version": "1.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/consolidation/config.git", "url": "https://github.com/consolidation/config.git",
"reference": "c9fc25e9088a708637e18a256321addc0670e578" "reference": "925231dfff32f05b787e1fddb265e789b939cf4c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/consolidation/config/zipball/c9fc25e9088a708637e18a256321addc0670e578", "url": "https://api.github.com/repos/consolidation/config/zipball/925231dfff32f05b787e1fddb265e789b939cf4c",
"reference": "c9fc25e9088a708637e18a256321addc0670e578", "reference": "925231dfff32f05b787e1fddb265e789b939cf4c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1930,7 +1807,7 @@
} }
], ],
"description": "Provide configuration services for a commandline tool.", "description": "Provide configuration services for a commandline tool.",
"time": "2018-08-07T22:57:00+00:00" "time": "2018-10-24T17:55:35+00:00"
}, },
{ {
"name": "consolidation/log", "name": "consolidation/log",
@ -1983,19 +1860,20 @@
}, },
{ {
"name": "consolidation/output-formatters", "name": "consolidation/output-formatters",
"version": "3.2.1", "version": "3.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/consolidation/output-formatters.git", "url": "https://github.com/consolidation/output-formatters.git",
"reference": "d78ef59aea19d3e2e5a23f90a055155ee78a0ad5" "reference": "a942680232094c4a5b21c0b7e54c20cce623ae19"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/consolidation/output-formatters/zipball/d78ef59aea19d3e2e5a23f90a055155ee78a0ad5", "url": "https://api.github.com/repos/consolidation/output-formatters/zipball/a942680232094c4a5b21c0b7e54c20cce623ae19",
"reference": "d78ef59aea19d3e2e5a23f90a055155ee78a0ad5", "reference": "a942680232094c4a5b21c0b7e54c20cce623ae19",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"dflydev/dot-access-data": "^1.1.0",
"php": ">=5.4.0", "php": ">=5.4.0",
"symfony/console": "^2.8|^3|^4", "symfony/console": "^2.8|^3|^4",
"symfony/finder": "^2.5|^3|^4" "symfony/finder": "^2.5|^3|^4"
@ -2034,7 +1912,7 @@
} }
], ],
"description": "Format text by applying transformations provided by plug-in formatters.", "description": "Format text by applying transformations provided by plug-in formatters.",
"time": "2018-05-25T18:02:34+00:00" "time": "2018-10-19T22:35:38+00:00"
}, },
{ {
"name": "consolidation/robo", "name": "consolidation/robo",
@ -2119,16 +1997,16 @@
}, },
{ {
"name": "consolidation/self-update", "name": "consolidation/self-update",
"version": "1.1.3", "version": "1.1.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/consolidation/self-update.git", "url": "https://github.com/consolidation/self-update.git",
"reference": "de33822f907e0beb0ffad24cf4b1b4fae5ada318" "reference": "4422e52d3fabeca9129ecb1780f198f202debdce"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/consolidation/self-update/zipball/de33822f907e0beb0ffad24cf4b1b4fae5ada318", "url": "https://api.github.com/repos/consolidation/self-update/zipball/4422e52d3fabeca9129ecb1780f198f202debdce",
"reference": "de33822f907e0beb0ffad24cf4b1b4fae5ada318", "reference": "4422e52d3fabeca9129ecb1780f198f202debdce",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2165,7 +2043,7 @@
} }
], ],
"description": "Provides a self:update command for Symfony Console applications.", "description": "Provides a self:update command for Symfony Console applications.",
"time": "2018-08-24T17:01:46+00:00" "time": "2018-10-21T20:17:55+00:00"
}, },
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
@ -3533,90 +3411,6 @@
], ],
"time": "2017-05-10T09:20:27+00:00" "time": "2017-05-10T09:20:27+00:00"
}, },
{
"name": "league/flysystem",
"version": "1.0.47",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
"reference": "a11e4a75f256bdacf99d20780ce42d3b8272975c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/a11e4a75f256bdacf99d20780ce42d3b8272975c",
"reference": "a11e4a75f256bdacf99d20780ce42d3b8272975c",
"shasum": ""
},
"require": {
"ext-fileinfo": "*",
"php": ">=5.5.9"
},
"conflict": {
"league/flysystem-sftp": "<1.0.6"
},
"require-dev": {
"phpspec/phpspec": "^3.4",
"phpunit/phpunit": "^5.7.10"
},
"suggest": {
"ext-fileinfo": "Required for MimeType",
"ext-ftp": "Allows you to use FTP server storage",
"ext-openssl": "Allows you to use FTPS server storage",
"league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2",
"league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3",
"league/flysystem-azure": "Allows you to use Windows Azure Blob storage",
"league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching",
"league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem",
"league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files",
"league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib",
"league/flysystem-webdav": "Allows you to use WebDAV storage",
"league/flysystem-ziparchive": "Allows you to use ZipArchive adapter",
"spatie/flysystem-dropbox": "Allows you to use Dropbox storage",
"srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"League\\Flysystem\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frank de Jonge",
"email": "info@frenky.net"
}
],
"description": "Filesystem abstraction: Many filesystems, one API.",
"keywords": [
"Cloud Files",
"WebDAV",
"abstraction",
"aws",
"cloud",
"copy.com",
"dropbox",
"file systems",
"files",
"filesystem",
"filesystems",
"ftp",
"rackspace",
"remote",
"s3",
"sftp",
"storage"
],
"time": "2018-09-14T15:30:29+00:00"
},
{ {
"name": "lucatume/codeception-setup-local", "name": "lucatume/codeception-setup-local",
"version": "1.0.3", "version": "1.0.3",

View File

@ -4,6 +4,8 @@ namespace MailPoet\Config;
use MailPoet\API; use MailPoet\API;
use MailPoet\Cron\CronTrigger; use MailPoet\Cron\CronTrigger;
use MailPoet\Dependencies\Symfony\Component\DependencyInjection\Container;
use MailPoet\DI\ContainerFactory;
use MailPoet\Models\Setting; use MailPoet\Models\Setting;
use MailPoet\Router; use MailPoet\Router;
use MailPoet\Util\ConflictResolver; use MailPoet\Util\ConflictResolver;
@ -18,6 +20,8 @@ require_once(ABSPATH . 'wp-admin/includes/plugin.php');
class Initializer { class Initializer {
private $access_control; private $access_control;
private $renderer; private $renderer;
/** @var Container */
private $container;
const INITIALIZED = 'MAILPOET_INITIALIZED'; const INITIALIZED = 'MAILPOET_INITIALIZED';
@ -50,6 +54,8 @@ class Initializer {
)); ));
} }
$this->loadContainer();
// activation function // activation function
register_activation_hook( register_activation_hook(
Env::$file, Env::$file,
@ -90,6 +96,11 @@ class Initializer {
)); ));
} }
function loadContainer() {
$container_factory = new ContainerFactory(WP_DEBUG);
$this->container = $container_factory->getContainer();
}
function checkRequirements() { function checkRequirements() {
$requirements = new RequirementsChecker(); $requirements = new RequirementsChecker();
return $requirements->checkAllRequirements(); return $requirements->checkAllRequirements();
@ -170,7 +181,7 @@ class Initializer {
} }
function setupAccessControl() { function setupAccessControl() {
$this->access_control = new AccessControl(); $this->access_control = $this->container->get(AccessControl::class);
} }
function setupInstaller() { function setupInstaller() {
@ -254,7 +265,7 @@ class Initializer {
} }
function setupRouter() { function setupRouter() {
$router = new Router\Router($this->access_control); $router = new Router\Router($this->access_control, $this->container);
$router->init(); $router->init();
} }

View File

@ -6,7 +6,6 @@ require_once(ABSPATH . 'wp-includes/pluggable.php');
class DaemonHttpRunner { class DaemonHttpRunner {
public $settings_daemon_data; public $settings_daemon_data;
public $request_data;
public $timer; public $timer;
public $token; public $token;
@ -15,15 +14,11 @@ class DaemonHttpRunner {
const PING_SUCCESS_RESPONSE = 'pong'; const PING_SUCCESS_RESPONSE = 'pong';
function __construct($request_data = false, $daemon = null) { function __construct(Daemon $daemon = null) {
$this->request_data = $request_data;
$this->settings_daemon_data = CronHelper::getDaemon(); $this->settings_daemon_data = CronHelper::getDaemon();
$this->token = CronHelper::createToken(); $this->token = CronHelper::createToken();
$this->timer = microtime(true); $this->timer = microtime(true);
$this->daemon = $daemon; $this->daemon = $daemon;
if(!$daemon) {
$this->daemon = new Daemon($this->settings_daemon_data);
}
} }
function ping() { function ping() {
@ -31,20 +26,20 @@ class DaemonHttpRunner {
$this->terminateRequest(self::PING_SUCCESS_RESPONSE); $this->terminateRequest(self::PING_SUCCESS_RESPONSE);
} }
function run() { function run($request_data) {
ignore_user_abort(true); ignore_user_abort(true);
if(strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { if(strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
set_time_limit(0); set_time_limit(0);
} }
$this->addCacheHeaders(); $this->addCacheHeaders();
if(!$this->request_data) { if(!$request_data) {
$error = __('Invalid or missing request data.', 'mailpoet'); $error = __('Invalid or missing request data.', 'mailpoet');
} else { } else {
if(!$this->settings_daemon_data) { if(!$this->settings_daemon_data) {
$error = __('Daemon does not exist.', 'mailpoet'); $error = __('Daemon does not exist.', 'mailpoet');
} else { } else {
if(!isset($this->request_data['token']) || if(!isset($request_data['token']) ||
$this->request_data['token'] !== $this->settings_daemon_data['token'] $request_data['token'] !== $this->settings_daemon_data['token']
) { ) {
$error = 'Invalid or missing token.'; $error = 'Invalid or missing token.';
} }

View File

@ -0,0 +1,70 @@
<?php
namespace MailPoet\DI;
use MailPoet\Dependencies\Symfony\Component\DependencyInjection\ContainerBuilder;
use MailPoet\Dependencies\Symfony\Component\DependencyInjection\Dumper\PhpDumper;
class ContainerFactory {
/** @var ContainerBuilder */
private $container;
/** @var string */
private $dump_file = 'CachedContainer.php';
/** @var string */
private $dump_class = 'CachedContainer';
/** @var bool */
private $debug;
/**
* ContainerFactory constructor.
* @param bool $debug
*/
public function __construct($debug = false) {
$this->debug = $debug;
}
function getContainer() {
if($this->container) {
return $this->container;
}
$dump_file = __DIR__ . '/' . $this->dump_file;
if(!$this->debug && file_exists($dump_file)) {
require_once $dump_file;
$this->container = new $this->dump_class();
} else {
$this->container = $this->createContainer();
$this->container->compile();
}
return $this->container;
}
function createContainer() {
$container = new ContainerBuilder();
$container->autowire(\MailPoet\Config\AccessControl::class);
$container->autowire(\MailPoet\Cron\Daemon::class);
$container->autowire(\MailPoet\Cron\DaemonHttpRunner::class);
$container->autowire(\MailPoet\Router\Endpoints\CronDaemon::class);
$container->autowire(\MailPoet\Router\Endpoints\Subscription::class);
$container->autowire(\MailPoet\Router\Endpoints\Track::class);
$container->autowire(\MailPoet\Router\Endpoints\ViewInBrowser::class);
return $container;
}
function dumpContainer() {
$container = $this->createContainer();
$container->compile();
$dumper = new PhpDumper($container);
file_put_contents(
__DIR__ . '/' . $this->dump_file,
$dumper->dump([
'class' => $this->dump_class
])
);
}
}

View File

@ -23,13 +23,15 @@ class CronDaemon {
'global' => AccessControl::NO_ACCESS_RESTRICTION 'global' => AccessControl::NO_ACCESS_RESTRICTION
); );
function __construct($data) { /** @var DaemonHttpRunner */
$this->data = $data; private $daemon_runner;
function __construct(DaemonHttpRunner $daemon_runner) {
$this->daemon_runner = $daemon_runner;
} }
function run() { function run($data) {
$queue = new DaemonHttpRunner($this->data); $this->daemon_runner->run($data);
$queue->run();
} }
function ping() { function ping() {
@ -37,7 +39,6 @@ class CronDaemon {
} }
function pingResponse() { function pingResponse() {
$queue = new DaemonHttpRunner(); $this->daemon_runner->ping();
$queue->ping();
} }
} }

View File

@ -17,30 +17,25 @@ class Subscription {
self::ACTION_MANAGE, self::ACTION_MANAGE,
self::ACTION_UNSUBSCRIBE self::ACTION_UNSUBSCRIBE
); );
public $data;
public $permissions = array( public $permissions = array(
'global' => AccessControl::NO_ACCESS_RESTRICTION 'global' => AccessControl::NO_ACCESS_RESTRICTION
); );
function __construct($data) { function confirm($data) {
$this->data = $data; $subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_CONFIRM, $data);
}
function confirm() {
$subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_CONFIRM);
$subscription->confirm(); $subscription->confirm();
} }
function manage() { function manage($data) {
$subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_MANAGE); $subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_MANAGE, $data);
} }
function unsubscribe() { function unsubscribe($data) {
$subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_UNSUBSCRIBE); $subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_UNSUBSCRIBE, $data);
$subscription->unsubscribe(); $subscription->unsubscribe();
} }
private function initSubscriptionPage($action) { private function initSubscriptionPage($action, $data) {
return new UserSubscription\Pages($action, $this->data, true, true); return new UserSubscription\Pages($action, $data, true, true);
} }
} }

View File

@ -22,23 +22,18 @@ class Track {
self::ACTION_CLICK, self::ACTION_CLICK,
self::ACTION_OPEN self::ACTION_OPEN
); );
public $data;
public $permissions = array( public $permissions = array(
'global' => AccessControl::NO_ACCESS_RESTRICTION 'global' => AccessControl::NO_ACCESS_RESTRICTION
); );
function __construct($data) { function click($data) {
$this->data = $this->_processTrackData($data);
}
function click() {
$click_event = new Clicks(); $click_event = new Clicks();
return $click_event->track($this->data); return $click_event->track($this->_processTrackData($data));
} }
function open() { function open($data) {
$open_event = new Opens(); $open_event = new Opens();
return $open_event->track($this->data); return $open_event->track($this->_processTrackData($data));
} }
function _processTrackData($data) { function _processTrackData($data) {
@ -82,7 +77,7 @@ class Track {
false; false;
} }
private function terminate($code) { function terminate($code) {
status_header($code); status_header($code);
get_template_part((string)$code); get_template_part((string)$code);
exit; exit;

View File

@ -17,19 +17,18 @@ class ViewInBrowser {
const ENDPOINT = 'view_in_browser'; const ENDPOINT = 'view_in_browser';
const ACTION_VIEW = 'view'; const ACTION_VIEW = 'view';
public $allowed_actions = array(self::ACTION_VIEW); public $allowed_actions = array(self::ACTION_VIEW);
public $data;
public $permissions = array( public $permissions = array(
'global' => AccessControl::NO_ACCESS_RESTRICTION 'global' => AccessControl::NO_ACCESS_RESTRICTION
); );
function __construct($data, AccessControl $access_control) { function __construct(AccessControl $access_control) {
$this->access_control = $access_control; $this->access_control = $access_control;
$this->data = $this->_processBrowserPreviewData($data);
} }
function view() { function view($data) {
$data = $this->_processBrowserPreviewData($data);
$view_in_browser = new NewsletterViewInBrowser(); $view_in_browser = new NewsletterViewInBrowser();
return $this->_displayNewsletter($view_in_browser->view($this->data)); return $this->_displayNewsletter($view_in_browser->view($data));
} }
function _processBrowserPreviewData($data) { function _processBrowserPreviewData($data) {

View File

@ -3,6 +3,7 @@
namespace MailPoet\Router; namespace MailPoet\Router;
use MailPoet\Config\AccessControl; use MailPoet\Config\AccessControl;
use MailPoet\Dependencies\Symfony\Component\DependencyInjection\Container;
use MailPoet\Util\Helpers; use MailPoet\Util\Helpers;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
@ -12,11 +13,13 @@ class Router {
public $endpoint; public $endpoint;
public $action; public $action;
public $data; public $data;
/** @var Container */
private $container;
const NAME = 'mailpoet_router'; const NAME = 'mailpoet_router';
const RESPONSE_ERROR = 404; const RESPONSE_ERROR = 404;
const RESPONE_FORBIDDEN = 403; const RESPONE_FORBIDDEN = 403;
function __construct(AccessControl $access_control, $api_data = false) { function __construct(AccessControl $access_control, Container $container, $api_data = false) {
$api_data = ($api_data) ? $api_data : $_GET; $api_data = ($api_data) ? $api_data : $_GET;
$this->api_request = isset($api_data[self::NAME]); $this->api_request = isset($api_data[self::NAME]);
$this->endpoint = isset($api_data['endpoint']) ? $this->endpoint = isset($api_data['endpoint']) ?
@ -29,15 +32,19 @@ class Router {
self::decodeRequestData($api_data['data']) : self::decodeRequestData($api_data['data']) :
array(); array();
$this->access_control = $access_control; $this->access_control = $access_control;
$this->container = $container;
} }
function init() { function init() {
$endpoint_class = __NAMESPACE__ . "\\Endpoints\\" . ucfirst($this->endpoint);
if(!$this->api_request) return; if(!$this->api_request) return;
$endpoint_class = __NAMESPACE__ . "\\Endpoints\\" . ucfirst($this->endpoint);
if(!$this->endpoint || !class_exists($endpoint_class)) { if(!$this->endpoint || !class_exists($endpoint_class)) {
return $this->terminateRequest(self::RESPONSE_ERROR, __('Invalid router endpoint', 'mailpoet')); return $this->terminateRequest(self::RESPONSE_ERROR, __('Invalid router endpoint', 'mailpoet'));
} }
$endpoint = new $endpoint_class($this->data, $this->access_control);
$endpoint = $this->container->get($endpoint_class);
if(!method_exists($endpoint, $this->endpoint_action) || !in_array($this->endpoint_action, $endpoint->allowed_actions)) { if(!method_exists($endpoint, $this->endpoint_action) || !in_array($this->endpoint_action, $endpoint->allowed_actions)) {
return $this->terminateRequest(self::RESPONSE_ERROR, __('Invalid router endpoint action', 'mailpoet')); return $this->terminateRequest(self::RESPONSE_ERROR, __('Invalid router endpoint action', 'mailpoet'));
} }
@ -46,10 +53,11 @@ class Router {
} }
do_action('mailpoet_conflict_resolver_router_url_query_parameters'); do_action('mailpoet_conflict_resolver_router_url_query_parameters');
return call_user_func( return call_user_func(
array( [
$endpoint, $endpoint,
$this->endpoint_action $this->endpoint_action,
) ],
$this->data
); );
} }
@ -88,4 +96,4 @@ class Router {
$this->access_control->validatePermission($permissions['actions'][$endpoint_action]) : $this->access_control->validatePermission($permissions['actions'][$endpoint_action]) :
$this->access_control->validatePermission($permissions['global']); $this->access_control->validatePermission($permissions['global']);
} }
} }

44
mozart/composer.json Normal file
View File

@ -0,0 +1,44 @@
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/costasovo/mozart"
}
],
"require": {
"php": ">=5.5",
"symfony/dependency-injection": "3.4.17",
"symfony/config": "3.4.17",
"monolog/monolog": "^1.23",
"coenjacobs/mozart": "dev-dependency-tree"
},
"scripts": {
"post-update-cmd": [
"@cleanup",
"vendor/bin/mozart compose",
"@unwantedDepsRemoval",
"mv ./Dependencies ../lib/"
],
"post-install-cmd": [
"@cleanup",
"vendor/bin/mozart compose",
"@unwantedDepsRemoval",
"mv ./Dependencies ../lib/"
],
"cleanup": "rm -rf vendor/symfony/**/Tests;rm -rf ../lib/Dependencies",
"unwantedDepsRemoval": "rm -rf ./Dependencies/Symfony/Debug;rm -rf ./Dependencies/Symfony/Finder;rm -rf ./Dependencies/Symfony/Console"
},
"extra": {
"mozart": {
"dep_namespace": "MailPoet\\Dependencies\\",
"dep_directory": "/Dependencies/",
"classmap_directory": "/Classes/",
"classmap_prefix": "MP_",
"packages": [
"monolog/monolog",
"symfony/dependency-injection"
]
}
}
}

803
mozart/composer.lock generated Normal file
View File

@ -0,0 +1,803 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b1d5ff6371e4e69fedf30c37692ca610",
"packages": [
{
"name": "coenjacobs/mozart",
"version": "dev-dependency-tree",
"source": {
"type": "git",
"url": "https://github.com/costasovo/mozart.git",
"reference": "e7f04ffc136f8175dec82615dcee43e234f001ae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/costasovo/mozart/zipball/e7f04ffc136f8175dec82615dcee43e234f001ae",
"reference": "e7f04ffc136f8175dec82615dcee43e234f001ae",
"shasum": ""
},
"require": {
"league/flysystem": "^1.0",
"php": ">=5.5.0",
"symfony/console": "^3.2",
"symfony/finder": "^3.2"
},
"require-dev": {
"coenjacobs/php-composter-phpcs": "^0.1.0",
"phpunit/phpunit": "^4.0"
},
"bin": [
"bin/mozart"
],
"type": "library",
"autoload": {
"psr-4": {
"CoenJacobs\\Mozart\\": "src/"
}
},
"license": [
"MIT"
],
"authors": [
{
"name": "Coen Jacobs",
"email": "coenjacobs@gmail.com"
}
],
"support": {
"source": "https://github.com/costasovo/mozart/tree/dependency-tree"
},
"time": "2018-10-23T18:15:03+00:00"
},
{
"name": "league/flysystem",
"version": "1.0.48",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
"reference": "a6ded5b2f6055e2db97b4b859fdfca2b952b78aa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/a6ded5b2f6055e2db97b4b859fdfca2b952b78aa",
"reference": "a6ded5b2f6055e2db97b4b859fdfca2b952b78aa",
"shasum": ""
},
"require": {
"ext-fileinfo": "*",
"php": ">=5.5.9"
},
"conflict": {
"league/flysystem-sftp": "<1.0.6"
},
"require-dev": {
"phpspec/phpspec": "^3.4",
"phpunit/phpunit": "^5.7.10"
},
"suggest": {
"ext-fileinfo": "Required for MimeType",
"ext-ftp": "Allows you to use FTP server storage",
"ext-openssl": "Allows you to use FTPS server storage",
"league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2",
"league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3",
"league/flysystem-azure": "Allows you to use Windows Azure Blob storage",
"league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching",
"league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem",
"league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files",
"league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib",
"league/flysystem-webdav": "Allows you to use WebDAV storage",
"league/flysystem-ziparchive": "Allows you to use ZipArchive adapter",
"spatie/flysystem-dropbox": "Allows you to use Dropbox storage",
"srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"League\\Flysystem\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frank de Jonge",
"email": "info@frenky.net"
}
],
"description": "Filesystem abstraction: Many filesystems, one API.",
"keywords": [
"Cloud Files",
"WebDAV",
"abstraction",
"aws",
"cloud",
"copy.com",
"dropbox",
"file systems",
"files",
"filesystem",
"filesystems",
"ftp",
"rackspace",
"remote",
"s3",
"sftp",
"storage"
],
"time": "2018-10-15T13:53:10+00:00"
},
{
"name": "monolog/monolog",
"version": "1.23.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"psr/log": "~1.0"
},
"provide": {
"psr/log-implementation": "1.0.0"
},
"require-dev": {
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
"doctrine/couchdb": "~1.0@dev",
"graylog2/gelf-php": "~1.0",
"jakub-onderka/php-parallel-lint": "0.9",
"php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3",
"phpunit/phpunit": "~4.5",
"phpunit/phpunit-mock-objects": "2.3.0",
"ruflin/elastica": ">=0.90 <3.0",
"sentry/sentry": "^0.13",
"swiftmailer/swiftmailer": "^5.3|^6.0"
},
"suggest": {
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongo": "Allow sending log messages to a MongoDB server",
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
"mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver",
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
"php-console/php-console": "Allow sending log messages to Google Chrome",
"rollbar/rollbar": "Allow sending log messages to Rollbar",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"sentry/sentry": "Allow sending log messages to a Sentry server"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Monolog\\": "src/Monolog"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
"homepage": "http://github.com/Seldaek/monolog",
"keywords": [
"log",
"logging",
"psr-3"
],
"time": "2017-06-19T01:22:40+00:00"
},
{
"name": "psr/container",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"time": "2017-02-14T16:28:37+00:00"
},
{
"name": "psr/log",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2016-10-10T12:19:37+00:00"
},
{
"name": "symfony/config",
"version": "v3.4.17",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
"reference": "e5389132dc6320682de3643091121c048ff796b3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/config/zipball/e5389132dc6320682de3643091121c048ff796b3",
"reference": "e5389132dc6320682de3643091121c048ff796b3",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"symfony/filesystem": "~2.8|~3.0|~4.0",
"symfony/polyfill-ctype": "~1.8"
},
"conflict": {
"symfony/dependency-injection": "<3.3",
"symfony/finder": "<3.3"
},
"require-dev": {
"symfony/dependency-injection": "~3.3|~4.0",
"symfony/event-dispatcher": "~3.3|~4.0",
"symfony/finder": "~3.3|~4.0",
"symfony/yaml": "~3.0|~4.0"
},
"suggest": {
"symfony/yaml": "To use the yaml reference dumper"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Config\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
"time": "2018-09-08T13:15:14+00:00"
},
{
"name": "symfony/console",
"version": "v3.4.17",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b",
"reference": "3b2b415d4c48fbefca7dc742aa0a0171bfae4e0b",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"symfony/debug": "~2.8|~3.0|~4.0",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"symfony/dependency-injection": "<3.4",
"symfony/process": "<3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~3.3|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/event-dispatcher": "~2.8|~3.0|~4.0",
"symfony/lock": "~3.4|~4.0",
"symfony/process": "~3.3|~4.0"
},
"suggest": {
"psr/log-implementation": "For using the console logger",
"symfony/event-dispatcher": "",
"symfony/lock": "",
"symfony/process": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Console\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2018-10-02T16:33:53+00:00"
},
{
"name": "symfony/debug",
"version": "v4.1.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/debug.git",
"reference": "e3f76ce6198f81994e019bb2b4e533e9de1b9b90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/e3f76ce6198f81994e019bb2b4e533e9de1b9b90",
"reference": "e3f76ce6198f81994e019bb2b4e533e9de1b9b90",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"psr/log": "~1.0"
},
"conflict": {
"symfony/http-kernel": "<3.4"
},
"require-dev": {
"symfony/http-kernel": "~3.4|~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.1-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Debug\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Debug Component",
"homepage": "https://symfony.com",
"time": "2018-10-02T16:36:10+00:00"
},
{
"name": "symfony/dependency-injection",
"version": "v3.4.17",
"source": {
"type": "git",
"url": "https://github.com/symfony/dependency-injection.git",
"reference": "aea20fef4e92396928b5db175788b90234c0270d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dependency-injection/zipball/aea20fef4e92396928b5db175788b90234c0270d",
"reference": "aea20fef4e92396928b5db175788b90234c0270d",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"psr/container": "^1.0"
},
"conflict": {
"symfony/config": "<3.3.7",
"symfony/finder": "<3.3",
"symfony/proxy-manager-bridge": "<3.4",
"symfony/yaml": "<3.4"
},
"provide": {
"psr/container-implementation": "1.0"
},
"require-dev": {
"symfony/config": "~3.3|~4.0",
"symfony/expression-language": "~2.8|~3.0|~4.0",
"symfony/yaml": "~3.4|~4.0"
},
"suggest": {
"symfony/config": "",
"symfony/expression-language": "For using expressions in service container configuration",
"symfony/finder": "For using double-star glob patterns or when GLOB_BRACE portability is required",
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\DependencyInjection\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony DependencyInjection Component",
"homepage": "https://symfony.com",
"time": "2018-10-02T12:28:39+00:00"
},
{
"name": "symfony/filesystem",
"version": "v4.1.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "596d12b40624055c300c8b619755b748ca5cf0b5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/596d12b40624055c300c8b619755b748ca5cf0b5",
"reference": "596d12b40624055c300c8b619755b748ca5cf0b5",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/polyfill-ctype": "~1.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.1-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Filesystem\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
"time": "2018-10-02T12:40:59+00:00"
},
{
"name": "symfony/finder",
"version": "v3.4.17",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/54ba444dddc5bd5708a34bd095ea67c6eb54644d",
"reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Finder\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
"time": "2018-10-03T08:46:40+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.9.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "e3d826245268269cd66f8326bd8bc066687b4a19"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19",
"reference": "e3d826245268269cd66f8326bd8bc066687b4a19",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-ctype": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
},
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"time": "2018-08-06T14:22:27+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.9.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8",
"reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"time": "2018-08-06T14:22:27+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"coenjacobs/mozart": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.5"
},
"platform-dev": []
}

View File

@ -14,15 +14,14 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
CronHelper::DAEMON_SETTING, CronHelper::DAEMON_SETTING,
[] []
); );
$daemon = new DaemonHttpRunner($request_data = 'request data'); $daemon = new DaemonHttpRunner();
expect($daemon->request_data)->equals('request data');
expect(strlen($daemon->timer))->greaterOrEquals(5); expect(strlen($daemon->timer))->greaterOrEquals(5);
expect(strlen($daemon->token))->greaterOrEquals(5); expect(strlen($daemon->token))->greaterOrEquals(5);
} }
function testItDoesNotRunWithoutRequestData() { function testItDoesNotRunWithoutRequestData() {
$daemon = Stub::construct( $daemon = Stub::construct(
new DaemonHttpRunner(), new DaemonHttpRunner(new Daemon()),
array(), array(),
array( array(
'abortWithError' => function($message) { 'abortWithError' => function($message) {
@ -30,13 +29,12 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
} }
) )
); );
$daemon->request_data = false; expect($daemon->run(false))->equals('Invalid or missing request data.');
expect($daemon->run())->equals('Invalid or missing request data.');
} }
function testItDoesNotRunWhenThereIsInvalidOrMissingToken() { function testItDoesNotRunWhenThereIsInvalidOrMissingToken() {
$daemon = Stub::construct( $daemon = Stub::construct(
new DaemonHttpRunner(), new DaemonHttpRunner(new Daemon()),
array(), array(),
array( array(
'abortWithError' => function($message) { 'abortWithError' => function($message) {
@ -47,8 +45,7 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
$daemon->settings_daemon_data = array( $daemon->settings_daemon_data = array(
'token' => 123 'token' => 123
); );
$daemon->request_data = array('token' => 456); expect($daemon->run(['token' => 456]))->equals('Invalid or missing token.');
expect($daemon->run())->equals('Invalid or missing token.');
} }
function testItStoresErrorMessageAndContinuesExecutionWhenWorkersThrowException() { function testItStoresErrorMessageAndContinuesExecutionWhenWorkersThrowException() {
@ -63,13 +60,13 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
throw new \Exception(); throw new \Exception();
}, },
), $this); ), $this);
$daemon_http_runner = Stub::make(new DaemonHttpRunner($data, $daemon), array( $daemon_http_runner = Stub::make(new DaemonHttpRunner($daemon), array(
'pauseExecution' => null, 'pauseExecution' => null,
'callSelf' => null 'callSelf' => null
), $this); ), $this);
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon_http_runner->__construct($data, $daemon); $daemon_http_runner->__construct($daemon);
$daemon_http_runner->run(); $daemon_http_runner->run($data);
$updated_daemon = Setting::getValue(CronHelper::DAEMON_SETTING); $updated_daemon = Setting::getValue(CronHelper::DAEMON_SETTING);
expect($updated_daemon['last_error'])->greaterOrEquals('Message'); expect($updated_daemon['last_error'])->greaterOrEquals('Message');
} }
@ -79,7 +76,7 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'executeScheduleWorker' => null, 'executeScheduleWorker' => null,
'executeQueueWorker' => null, 'executeQueueWorker' => null,
), $this); ), $this);
$daemon_http_runner = Stub::make(new DaemonHttpRunner(true, $daemon), array( $daemon_http_runner = Stub::make(new DaemonHttpRunner($daemon), array(
'pauseExecution' => Expected::exactly(1, function($pause_delay) { 'pauseExecution' => Expected::exactly(1, function($pause_delay) {
expect($pause_delay)->lessThan(CronHelper::DAEMON_EXECUTION_LIMIT); expect($pause_delay)->lessThan(CronHelper::DAEMON_EXECUTION_LIMIT);
expect($pause_delay)->greaterThan(CronHelper::DAEMON_EXECUTION_LIMIT - 1); expect($pause_delay)->greaterThan(CronHelper::DAEMON_EXECUTION_LIMIT - 1);
@ -90,13 +87,13 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'token' => 123 'token' => 123
); );
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon_http_runner->__construct($data, $daemon); $daemon_http_runner->__construct($daemon);
$daemon_http_runner->run(); $daemon_http_runner->run($data);
} }
function testItTerminatesExecutionWhenDaemonIsDeleted() { function testItTerminatesExecutionWhenDaemonIsDeleted() {
$daemon = Stub::make(new DaemonHttpRunner(true), array( $daemon = Stub::make(new DaemonHttpRunner(new Daemon()), array(
'executeScheduleWorker' => function() { 'executeScheduleWorker' => function() {
Setting::deleteValue(CronHelper::DAEMON_SETTING); Setting::deleteValue(CronHelper::DAEMON_SETTING);
}, },
@ -108,12 +105,12 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'token' => 123 'token' => 123
); );
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon->__construct($data); $daemon->__construct(new Daemon());
$daemon->run(); $daemon->run($data);
} }
function testItTerminatesExecutionWhenDaemonTokenChangesAndKeepsChangedToken() { function testItTerminatesExecutionWhenDaemonTokenChangesAndKeepsChangedToken() {
$daemon = Stub::make(new DaemonHttpRunner(true), array( $daemon = Stub::make(new DaemonHttpRunner(new Daemon()), array(
'executeScheduleWorker' => function() { 'executeScheduleWorker' => function() {
Setting::setValue( Setting::setValue(
CronHelper::DAEMON_SETTING, CronHelper::DAEMON_SETTING,
@ -128,14 +125,14 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'token' => 123 'token' => 123
); );
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon->__construct($data); $daemon->__construct(new Daemon());
$daemon->run(); $daemon->run($data);
$data_after_run = Setting::getValue(CronHelper::DAEMON_SETTING); $data_after_run = Setting::getValue(CronHelper::DAEMON_SETTING);
expect($data_after_run['token'], 567); expect($data_after_run['token'], 567);
} }
function testItTerminatesExecutionWhenDaemonIsDeactivated() { function testItTerminatesExecutionWhenDaemonIsDeactivated() {
$daemon = Stub::make(new DaemonHttpRunner(true), [ $daemon = Stub::make(new DaemonHttpRunner(new Daemon()), [
'executeScheduleWorker' => null, 'executeScheduleWorker' => null,
'executeQueueWorker' => null, 'executeQueueWorker' => null,
'pauseExecution' => null, 'pauseExecution' => null,
@ -146,12 +143,12 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'status' => CronHelper::DAEMON_STATUS_INACTIVE, 'status' => CronHelper::DAEMON_STATUS_INACTIVE,
]; ];
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon->__construct($data); $daemon->__construct(new Daemon());
$daemon->run(); $daemon->run($data);
} }
function testItUpdatesDaemonTokenDuringExecution() { function testItUpdatesDaemonTokenDuringExecution() {
$daemon_http_runner = Stub::make(new DaemonHttpRunner(true), array( $daemon_http_runner = Stub::make(new DaemonHttpRunner(new Daemon()), array(
'executeScheduleWorker' => null, 'executeScheduleWorker' => null,
'executeQueueWorker' => null, 'executeQueueWorker' => null,
'pauseExecution' => null, 'pauseExecution' => null,
@ -161,8 +158,8 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'token' => 123 'token' => 123
); );
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon_http_runner->__construct($data); $daemon_http_runner->__construct(new Daemon());
$daemon_http_runner->run(); $daemon_http_runner->run($data);
$updated_daemon = Setting::getValue(CronHelper::DAEMON_SETTING); $updated_daemon = Setting::getValue(CronHelper::DAEMON_SETTING);
expect($updated_daemon['token'])->equals($daemon_http_runner->token); expect($updated_daemon['token'])->equals($daemon_http_runner->token);
} }
@ -174,7 +171,7 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
}, },
'executeQueueWorker' => null, 'executeQueueWorker' => null,
), $this); ), $this);
$daemon_http_runner = Stub::make(new DaemonHttpRunner(true, $daemon), array( $daemon_http_runner = Stub::make(new DaemonHttpRunner($daemon), array(
'pauseExecution' => null, 'pauseExecution' => null,
'callSelf' => null 'callSelf' => null
), $this); ), $this);
@ -183,8 +180,8 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
); );
$now = time(); $now = time();
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon_http_runner->__construct($data, $daemon); $daemon_http_runner->__construct($daemon);
$daemon_http_runner->run(); $daemon_http_runner->run($data);
$updated_daemon = Setting::getValue(CronHelper::DAEMON_SETTING); $updated_daemon = Setting::getValue(CronHelper::DAEMON_SETTING);
expect($updated_daemon['run_started_at'])->greaterOrEquals($now); expect($updated_daemon['run_started_at'])->greaterOrEquals($now);
expect($updated_daemon['run_started_at'])->lessThan($now + 2); expect($updated_daemon['run_started_at'])->lessThan($now + 2);
@ -195,7 +192,7 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
function testItCanRun() { function testItCanRun() {
ignore_user_abort(0); ignore_user_abort(0);
expect(ignore_user_abort())->equals(0); expect(ignore_user_abort())->equals(0);
$daemon = Stub::make(new DaemonHttpRunner(true), array( $daemon = Stub::make(new DaemonHttpRunner(new Daemon()), array(
'pauseExecution' => null, 'pauseExecution' => null,
// workers should be executed // workers should be executed
'executeScheduleWorker' => Expected::exactly(1), 'executeScheduleWorker' => Expected::exactly(1),
@ -207,13 +204,13 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'token' => 123 'token' => 123
); );
Setting::setValue(CronHelper::DAEMON_SETTING, $data); Setting::setValue(CronHelper::DAEMON_SETTING, $data);
$daemon->__construct($data); $daemon->__construct(new Daemon());
$daemon->run(); $daemon->run($data);
expect(ignore_user_abort())->equals(1); expect(ignore_user_abort())->equals(1);
} }
function testItRespondsToPingRequest() { function testItRespondsToPingRequest() {
$daemon = Stub::make(new DaemonHttpRunner(true), array( $daemon = Stub::make(new DaemonHttpRunner(new Daemon()), array(
'terminateRequest' => Expected::exactly(1, function($message) { 'terminateRequest' => Expected::exactly(1, function($message) {
expect($message)->equals('pong'); expect($message)->equals('pong');
}) })

View File

@ -1,7 +1,7 @@
<?php <?php
namespace MailPoet\Test\Router\Endpoints; namespace MailPoet\Test\Router\Endpoints;
use AspectMock\Test as Mock; use Codeception\Stub;
use MailPoet\Models\Newsletter; use MailPoet\Models\Newsletter;
use MailPoet\Models\NewsletterLink; use MailPoet\Models\NewsletterLink;
use MailPoet\Models\ScheduledTask; use MailPoet\Models\ScheduledTask;
@ -74,9 +74,10 @@ class TrackTest extends \MailPoetTest {
) )
); );
$data->subscriber->email = 'random@email.com'; $data->subscriber->email = 'random@email.com';
$track = Mock::double($this->track, array('terminate' => null)); $track = Stub::make(new Track(), ['terminate' => function($code) {
expect($code)->equals(403);
}]);
$track->_validateTrackData($data); $track->_validateTrackData($data);
$track->verifyInvokedOnce('terminate', array(403));
} }
function testItFailsWhenSubscriberIsNotOnProcessedList() { function testItFailsWhenSubscriberIsNotOnProcessedList() {
@ -167,4 +168,4 @@ class TrackTest extends \MailPoetTest {
\ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table); \ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table);
\ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table); \ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table);
} }
} }

View File

@ -39,7 +39,7 @@ class ViewInBrowserTest extends \MailPoetTest {
'preview' => false 'preview' => false
); );
// instantiate class // instantiate class
$this->view_in_browser = new ViewInBrowser($this->browser_preview_data, new AccessControl()); $this->view_in_browser = new ViewInBrowser(new AccessControl());
} }
function testItAbortsWhenBrowserPreviewDataIsMissing() { function testItAbortsWhenBrowserPreviewDataIsMissing() {
@ -203,8 +203,7 @@ class ViewInBrowserTest extends \MailPoetTest {
$view_in_browser = Stub::make($this->view_in_browser, array( $view_in_browser = Stub::make($this->view_in_browser, array(
'_displayNewsletter' => Expected::exactly(1) '_displayNewsletter' => Expected::exactly(1)
), $this); ), $this);
$view_in_browser->data = $view_in_browser->_processBrowserPreviewData($this->browser_preview_data); $view_in_browser->view($this->browser_preview_data);
$view_in_browser->view();
} }
function _after() { function _after() {
@ -216,4 +215,4 @@ class ViewInBrowserTest extends \MailPoetTest {
$wp_user = wp_get_current_user(); $wp_user = wp_get_current_user();
$wp_user->add_role('administrator'); $wp_user->add_role('administrator');
} }
} }

View File

@ -5,6 +5,9 @@ namespace MailPoet\Test\Router;
use Codeception\Stub; use Codeception\Stub;
use Codeception\Stub\Expected; use Codeception\Stub\Expected;
use MailPoet\Config\AccessControl; use MailPoet\Config\AccessControl;
use MailPoet\Dependencies\Symfony\Component\DependencyInjection\Container;
use MailPoet\DI\ContainerFactory;
use MailPoet\Router\Endpoints\RouterTestMockEndpoint;
use MailPoet\Router\Router; use MailPoet\Router\Router;
require_once('RouterTestMockEndpoint.php'); require_once('RouterTestMockEndpoint.php');
@ -12,6 +15,8 @@ require_once('RouterTestMockEndpoint.php');
class RouterTest extends \MailPoetTest { class RouterTest extends \MailPoetTest {
public $access_control; public $access_control;
public $router_data; public $router_data;
/** @var Container */
private $container;
function _before() { function _before() {
$this->router_data = array( $this->router_data = array(
@ -21,7 +26,11 @@ class RouterTest extends \MailPoetTest {
'data' => base64_encode(json_encode(array('data' => 'dummy data'))) 'data' => base64_encode(json_encode(array('data' => 'dummy data')))
); );
$this->access_control = new AccessControl(); $this->access_control = new AccessControl();
$this->router = new Router($this->access_control, $this->router_data); $container_factory = new ContainerFactory(true);
$this->container = $container_factory->createContainer();
$this->container->register(RouterTestMockEndpoint::class)->setPublic(true);
$this->container->compile();
$this->router = new Router($this->access_control, $this->container, $this->router_data);
} }
function testItCanGetAPIDataFromGetRequest() { function testItCanGetAPIDataFromGetRequest() {
@ -29,7 +38,7 @@ class RouterTest extends \MailPoetTest {
$url = 'http://example.com/?' . Router::NAME . '&endpoint=view_in_browser&action=view&data=' $url = 'http://example.com/?' . Router::NAME . '&endpoint=view_in_browser&action=view&data='
. base64_encode(json_encode($data)); . base64_encode(json_encode($data));
parse_str(parse_url($url, PHP_URL_QUERY), $_GET); parse_str(parse_url($url, PHP_URL_QUERY), $_GET);
$router = new Router($this->access_control); $router = new Router($this->access_control, $this->container);
expect($router->api_request)->equals(true); expect($router->api_request)->equals(true);
expect($router->endpoint)->equals('viewInBrowser'); expect($router->endpoint)->equals('viewInBrowser');
expect($router->endpoint_action)->equals('view'); expect($router->endpoint_action)->equals('view');
@ -41,7 +50,7 @@ class RouterTest extends \MailPoetTest {
unset($router_data[Router::NAME]); unset($router_data[Router::NAME]);
$router = Stub::construct( $router = Stub::construct(
'\MailPoet\Router\Router', '\MailPoet\Router\Router',
array($this->access_control, $router_data) array($this->access_control, $this->container, $router_data)
); );
$result = $router->init(); $result = $router->init();
expect($result)->null(); expect($result)->null();
@ -52,7 +61,7 @@ class RouterTest extends \MailPoetTest {
$router_data['endpoint'] = 'invalid_endpoint'; $router_data['endpoint'] = 'invalid_endpoint';
$router = Stub::construct( $router = Stub::construct(
'\MailPoet\Router\Router', '\MailPoet\Router\Router',
array($this->access_control, $router_data), array($this->access_control, $this->container, $router_data),
array( array(
'terminateRequest' => function($code, $error) { 'terminateRequest' => function($code, $error) {
return array( return array(
@ -76,7 +85,7 @@ class RouterTest extends \MailPoetTest {
$router_data['action'] = 'invalid_action'; $router_data['action'] = 'invalid_action';
$router = Stub::construct( $router = Stub::construct(
'\MailPoet\Router\Router', '\MailPoet\Router\Router',
array($this->access_control, $router_data), array($this->access_control, $this->container, $router_data),
array( array(
'terminateRequest' => function($code, $error) { 'terminateRequest' => function($code, $error) {
return array( return array(
@ -164,7 +173,7 @@ class RouterTest extends \MailPoetTest {
function testItValidatesPermissionBeforeProcessingEndpointAction() { function testItValidatesPermissionBeforeProcessingEndpointAction() {
$router = Stub::construct( $router = Stub::construct(
'\MailPoet\Router\Router', '\MailPoet\Router\Router',
array($this->access_control, $this->router_data), array($this->access_control, $this->container, $this->router_data),
array( array(
'validatePermissions' => function($action, $permissions) { 'validatePermissions' => function($action, $permissions) {
expect($action)->equals($this->router_data['action']); expect($action)->equals($this->router_data['action']);
@ -186,7 +195,7 @@ class RouterTest extends \MailPoetTest {
function testItReturnsForbiddenResponseWhenPermissionFailsValidation() { function testItReturnsForbiddenResponseWhenPermissionFailsValidation() {
$router = Stub::construct( $router = Stub::construct(
'\MailPoet\Router\Router', '\MailPoet\Router\Router',
array($this->access_control, $this->router_data), array($this->access_control, $this->container, $this->router_data),
array( array(
'validatePermissions' => false, 'validatePermissions' => false,
'terminateRequest' => function($code, $error) { 'terminateRequest' => function($code, $error) {

View File

@ -14,11 +14,7 @@ class RouterTestMockEndpoint {
'global' => AccessControl::NO_ACCESS_RESTRICTION 'global' => AccessControl::NO_ACCESS_RESTRICTION
); );
function __construct($data) { function test($data) {
$this->data = $data; return $data;
} }
}
function test() {
return $this->data;
}
}

View File

@ -3,9 +3,9 @@
if((boolean)getenv('MULTISITE') === true) { if((boolean)getenv('MULTISITE') === true) {
// REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated // REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated
$_SERVER['REQUEST_URI'] = '/' . getenv('WP_TEST_MULTISITE_SLUG'); $_SERVER['REQUEST_URI'] = '/' . getenv('WP_TEST_MULTISITE_SLUG');
$wp_load_file = getenv('WP_TEST_PATH_MULTISITE') . '/wp-load.php'; $wp_load_file = getenv('WP_ROOT_MULTISITE') . '/wp-load.php';
} else { } else {
$wp_load_file = getenv('WP_TEST_PATH') . '/wp-load.php'; $wp_load_file = getenv('WP_ROOT') . '/wp-load.php';
} }
require_once($wp_load_file); require_once($wp_load_file);