31 Commits

Author SHA1 Message Date
Piotr Marynczak
a61c52fe1c [WZUW-194] adding function to get uplodaed files info 2023-08-01 12:46:16 +02:00
Piotr Marynczak
06fcaf07a8 [WZUW-194] survey answers prototype 2023-07-28 13:45:59 +02:00
xevolic
e025b71059 Merge pull request #4 from wiosna-dev/fix/UW-2934_Add_support_for_PHP_8.2
[UW-2934] add support for PHP 8.2
2023-03-09 16:57:33 +01:00
Tomasz Kuter
b658e04445 [UW-2934] chore(composer): updated base version of "wiosna-dev/common-library" 2023-03-09 15:29:22 +01:00
Tomasz Kuter
d4e74bc270 [UW-2934] chore(composer): restored previous repository for wiosna-dev/common-library 2023-02-16 16:39:25 +01:00
Tomasz Kuter
8127330642 [UW-2934] chore(composer): temporarily switched to clone of repo wiosna-dev/common-library 2023-02-15 11:04:55 +01:00
Michał Frankiewicz
f0c213fb53 Merge pull request #3 from wiosna-dev/bugfix/UW-2538
[UW-2538] fixes method
2021-07-02 09:02:33 +02:00
Michał Frankiewicz
24f9a237ae [UW-2538] fixes method 2021-07-02 08:59:44 +02:00
Michał Frankiewicz
81ea8e748f Merge pull request #2 from wiosna-dev/bugfix/UW-2538
Bugfix/uw 2538
2021-06-30 08:36:41 +02:00
Michał Frankiewicz
bab7e25c85 [UW-2538] removes broken argument 2021-06-29 17:11:50 +02:00
Michał Frankiewicz
6423195cc6 [UW-2538] adds method to check survey completion 2021-06-29 17:09:27 +02:00
Michał Frankiewicz
b2d4552fb3 [UW-2538] updates docs 2021-06-29 17:01:03 +02:00
Michał Frankiewicz
53d82841e0 Merge pull request #1 from wiosna-dev/bugfix/UW-2256
Bugfix/uw 2256
2020-07-22 08:40:12 +02:00
Michał Frankiewicz
c8ffcafbd8 [UW-2256] moves token property to BaseParticipant 2020-07-08 08:55:14 +02:00
Michał Frankiewicz
7551f6db95 [UW-2256] adds criteria parameter 2020-07-08 08:54:26 +02:00
Krzysztof Nizioł
a1e681b66e Do not modify version 2018-09-07 21:30:15 +02:00
Krzysztof Nizioł
2c42a2165a Composer > use wiosna-dev/common-library instead of meritoo/common-library package 2018-09-07 21:28:28 +02:00
Krzysztof Nizioł
058eb06d4d Merge branch 'master' of github.com:meritoo/limesurvey-api-client 2018-09-07 13:58:30 +02:00
Meritoo
1389e78068 Phing > tests > missing path of directory with code coverage report 2018-09-07 13:57:19 +02:00
Krzysztof Nizioł
2d3e492ed7 Merge branch 'master' of github.com:meritoo/limesurvey-api-client into develop
# Conflicts:
#	.docker/config/Dockerfile
#	README.md
#	composer.json
2018-09-07 00:01:48 +02:00
Meritoo
2c89bbe5f5 Composer > meritoo/common-library package > use latest version 2018-09-06 23:35:08 +02:00
Meritoo
525391083a Docker > update configuration 2018-09-06 23:33:23 +02:00
Meritoo
7ef83dac5d Phing > update XMLs 2018-09-06 23:32:45 +02:00
Meritoo
54bd021649 Bump version 2018-09-06 23:32:13 +02:00
Meritoo
c47016bdea Readme - configuration of LimeSurvey 2017-11-30 23:41:09 +01:00
Meritoo
c5498501d3 Minor refactoring 2017-11-30 22:54:29 +01:00
Krzysztof Niziol
82031194a2 composer.json - update name of this package (name of vendor, actually) & use exact version constraint of wiosna-dev/common-library package 2017-11-08 15:01:43 +01:00
Krzysztof Niziol
a3e5c78dcd Support PHP 5.5.9+ 2017-11-07 19:09:13 +01:00
Krzysztof Niziol
a3f6adb128 composer.json - missing address of wiosna/common-library package 2017-11-07 18:26:16 +01:00
Krzysztof Niziol
da6003b258 composer.json - update name of this package & use wiosna/common-library (forked from meritoo/common-library) instead of meritoo/common-library package 2017-11-07 15:45:10 +01:00
Meritoo
ee62e9f148 SurveyService - add method that allows to get the "start survey url" using participant's token (instead of whole participant's object) 2017-10-30 19:45:29 +01:00
43 changed files with 882 additions and 639 deletions

View File

@@ -1,64 +0,0 @@
FROM php:5.6-cli
#
# Tools & libraries
#
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
vim \
git \
zip \
unzip \
zlib1g-dev \
libicu-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#
# PHP extensions
#
RUN docker-php-ext-install \
zip \
intl \
mbstring
#
# PHP configuration:
# - default configuration
# - timezone
#
COPY php.ini /usr/local/etc/php/php.ini
ARG TIMEZONE
RUN echo "\n""date.timezone = $TIMEZONE""\n" >> /usr/local/etc/php/php.ini
#
# Xdebug
#
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
#
# Phing
#
RUN pear channel-discover pear.phing.info \
&& pear install [--alldeps] phing/phing
#
# Composer + https://packagist.org/packages/hirak/prestissimo package
#
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === \
'544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo \
'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');" \
&& composer global require --no-plugins --no-scripts hirak/prestissimo \
&& rm -rf /root/.composer/cache/*
#
# Bash
#
RUN sed -i 's/^# export/export/g' /root/.bashrc \
&& sed -i 's/^# alias/alias/g' /root/.bashrc \
&& echo "\n"'export PATH=/project/vendor/bin:$PATH'"\n" >> /root/.bashrc

14
.env
View File

@@ -1 +1,15 @@
# -----------------------------------------------------------------------------
### Docker
# -----------------------------------------------------------------------------
#
# All containers
#
DOCKER_CONTAINER_OWNER=meritoo
DOCKER_CONTAINER_PROJECT=limesurvey-api-client
#
# PHP configuration:
# - timezone
#
TIMEZONE=Europe/Warsaw

2
.gitignore vendored
View File

@@ -17,7 +17,7 @@
# ----------------------------------------------------------------------------------------------------------------------
### Phing
# ----------------------------------------------------------------------------------------------------------------------
/.phing/properties
/phing/properties
# ----------------------------------------------------------------------------------------------------------------------
### PHPUnit

View File

@@ -1,89 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
<!-- Properties -->
<if>
<available file=".phing/properties" property="custom.properties.available"/>
<then>
<property file=".phing/properties" />
</then>
<else>
<property file=".phing/properties.dist" />
</else>
</if>
<!-- Default / main target -->
<target name="build:main"
depends="build:app"
description="Builds the application" />
<!-- App target -->
<target name="build:app"
depends="app:composer, app:vendors, app:checkout"
description="Prepares app to build." />
<!-- Check / update composer -->
<target name="app:composer" description="Checks / updates composer">
<echo msg="Checking / updating composer..." />
<if>
<available file="composer.phar" />
<then>
<echo msg="[Skipped] Downloading of Composer skipped, because exist in the project..." />
</then>
<else>
<if>
<os family="windows" />
<then>
<fail message="Composer not found! Go to http://getcomposer.org/download and download the Composer." />
</then>
<else>
<exec command="${composer.download_command}" checkreturn="true" />
</else>
</if>
</else>
</if>
<composer command="selfupdate" />
</target>
<!-- Project Install/update vendors -->
<target name="app:vendors" description="Installs / updates vendors">
<echo msg="Installing / updating vendors..." />
<if>
<istrue value="${composer.self-update}"/>
<then>
<composer php="${composer.php}" composer="${composer.path}" command="self-update"/>
</then>
</if>
<if>
<istrue value="${composer.validate}"/>
<then>
<composer php="${composer.php}" composer="${composer.path}" command="validate"/>
</then>
</if>
<if>
<equals arg1="${env}" arg2="prod" />
<then>
<composer php="${composer.php}" composer="${composer.path}" command="install">
<arg value="--optimize-autoloader" />
</composer>
</then>
<else>
<composer php="${composer.php}" composer="${composer.path}" command="install" />
</else>
</if>
</target>
<!-- Checkout and finalization -->
<target name="app:checkout">
<tstamp>
<format property="date_end" pattern="%Y-%m-%d %H:%M" />
</tstamp>
<echo msg="------------------------------------" />
<echo msg="Build finished at: ${date_end}" />
<echo msg="------------------------------------" />
</target>
</project>

View File

@@ -1,315 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
<!--
The AutoloaderTask is required to load binaries installed by Composer.
The "autoloaderpath" attribute of this task is not required, because it's default value is: vendor/autoload.php.
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-23
-->
<autoloader />
<!-- Properties -->
<if>
<available file=".phing/properties" property="custom.properties.available"/>
<then>
<property file=".phing/properties" />
</then>
<else>
<property file=".phing/properties.dist" />
</else>
</if>
<!-- Filesets -->
<fileset id="sourcecode" dir="${dir.src}">
<include name="**/*.php" />
<exclude name="*Test.php" />
<exclude name="**/*Test.php" />
<exclude name="**/Resources/**" />
<exclude name="**/DataFixtures/**" />
<exclude name="**/Tests/**" />
</fileset>
<fileset id="tests" dir="${dir.tests}">
<include name="**/*Test*.php" />
</fileset>
<!-- Default / main target -->
<target name="build:main"
depends="build:fix-coding-standards, build:clean, build:prepare, build:check, build:test, app:checkout"
description="Runs all tests and builds everything" />
<!--
Before:
depends="build:fix-coding-standards, build:clean, build:prepare, build:check, build:test, build:doc, app:checkout"
After:
depends="build:fix-coding-standards, build:clean, build:prepare, build:check, build:test, app:checkout"
The "build:doc" task is disabled, because it cannot be installed via Composer:
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-22
-->
<!-- Fixing coding standards using the PHP Coding Standards Fixer (http://cs.sensiolabs.org) -->
<target name="build:fix-coding-standards" description="Fixes coding standards using the PHP Coding Standards Fixer">
<echo msg="Fixing coding standards using the PHP Coding Standards Fixer (http://cs.sensiolabs.org)..." />
<!--
Attention.
Rules for formatting are defined in /.php_cs.dist file.
-->
<exec
passthru="true"
command="${phpCsFixer.path} fix --verbose"
/>
</target>
<!-- Doc target -->
<!--
Disabled, because it cannot be installed via Composer:
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-22
-->
<!--<target name="build:doc"-->
<!--depends="build:prepare, doc:phpdoc2"-->
<!--description="Generates API documentation" />-->
<!-- Check target -->
<target name="build:check"
depends="check:cs, check:md, check:cpd, check:depend, check:loc"
description="Analyzes code" />
<!-- Test target -->
<target name="build:test"
depends="test:phpunit"
description="Executes all tests" />
<!-- Project build clean -->
<target name="build:clean" description="Cleans up build directories">
<echo msg="Cleaning docs and reports directories..." />
<!--<delete dir="${dir.docs}" />-->
<delete dir="${dir.reports}" />
</target>
<!-- Project build prepare -->
<target name="build:prepare" description="Create build directories">
<echo msg="Creating build directories..." />
<!--<mkdir dir="${dir.docs}" />-->
<!--<mkdir dir="${dir.docs.phpdoc2}" />-->
<mkdir dir="${dir.reports}" />
<mkdir dir="${dir.reports.coverage}" />
<mkdir dir="${dir.reports.pdepend}" />
</target>
<!-- PHPDocumentor2 API documentation target -->
<!--
Disabled, because it cannot be installed via Composer:
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-22
<target name="doc:phpdoc2" description="Generates API documentations">
<echo msg="Generating API Documentation with phpDocumentor 2..." />
<phpdoc2 title="${phing.project.name}"
destdir="${dir.docs.phpdoc2}"
template="responsive">
<fileset refid="sourcecode" />
</phpdoc2>
</target>
-->
<!-- Symfony2 code sniffer -->
<!--
Attention 1.
To use Symfony2 standards to check coding you have to:
copy, symlink or check out repo to a folder called Symfony2 inside the phpcs Standards directory.
Example:
$ pear config-show | grep php_dir
$ cd /path/to/pear/PHP/CodeSniffer/Standards
$ git clone git://github.com/opensky/Symfony2-coding-standard.git Symfony2
Attention 2.
PSR2 standard is used instead of Symfony2 standard, because after installation squizlabs/php_codesniffer package
via Composer the Symfony2 standard is not included / available in this package. In this case the PHP Coding
Standards Fixer (http://cs.sensiolabs.org) is used.
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-22
-->
<target name="check:cs" description="Checks coding standard">
<echo msg="Checking coding standard..." />
<phpcodesniffer standard="PSR2" showWarnings="true">
<fileset refid="sourcecode" />
<formatter type="checkstyle" outfile="${dir.reports}/checkstyle.xml" />
<formatter type="csv" outfile="${dir.reports}/checkstyle.csv" />
<formatter type="summary" outfile="${dir.reports}/checkstyle_summary.txt" />
</phpcodesniffer>
</target>
<!-- copy/paste detector -->
<target name="check:cpd" description="Checks similar code blocks.">
<echo msg="Checking similar code blocks..." />
<phpcpd>
<fileset refid="sourcecode" />
<formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml" />
</phpcpd>
<!--
Previous / old version
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-22
<exec command="phpcpd \-\-log-pmd=${dir.reports}/pmd-cpd.xml ${dir.src}" />
-->
</target>
<!-- Mess detector -->
<target name="check:md" description="Generate code metrics">
<echo msg="Generating code metrics..." />
<phpmd rulesets="codesize,controversial,design,naming,unusedcode">
<fileset refid="sourcecode" />
<formatter type="html" outfile="${dir.reports}/phpmd.html" />
<formatter type="text" outfile="${dir.reports}/phpmd.txt" />
</phpmd>
</target>
<!-- Code dependency -->
<target name="check:depend" description="Checks coupling and dependency">
<echo msg="Checking coupling and dependency..." />
<phpdepend>
<fileset refid="sourcecode" />
<logger type="jdepend-xml" outfile="${dir.reports.pdepend}/jdepend.xml" />
<logger type="jdepend-chart" outfile="${dir.reports.pdepend}/dependencies.svg" />
<logger type="overview-pyramid" outfile="${dir.reports.pdepend}/overview-pyramid.svg" />
</phpdepend>
</target>
<!-- Measure the size and analyzing the structure of a project -->
<target name="check:loc" description="Measures the size and analyzes the structure of a project">
<echo msg="Measuring the size and analyzing the structure of a project..." />
<phploc reportType="txt" reportName="phploc" reportDirectory="${dir.reports}">
<fileset refid="sourcecode" />
</phploc>
<!--
Previous / old version
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-22
<exec command="phploc \-\-log-csv=${dir.reports}/phploc.csv ${dir.src}" />
-->
</target>
<!-- Unit tests -->
<target name="test:phpunit" description="Executes PHPUnit tests">
<!-- Check test database -->
<if>
<not>
<available file="${dir.data.tests}" type="dir" property="dir.data.tests.available" />
</not>
<then>
<mkdir dir="${dir.data.tests}" />
</then>
</if>
<if>
<not>
<available file="${tests.database}" property="tests.database.available" />
</not>
<then>
<touch file="${tests.database}" />
</then>
</if>
<echo msg="Running unit tests..." />
<coverage-setup database="${dir.reports.coverage}/coverage.db">
<fileset refid="sourcecode" />
</coverage-setup>
<exec command="${phpUnit.path} --verbose --configuration ${project.basedir}/phpunit.xml.dist" passthru="true" />
<!--
I have to use ExecTask to run PHPUnit instead of PHPUnitTask, because tests are not running if PHPUnitTask is
used (don't know why):
Total tests run: 0, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-23
<phpunit configuration="${project.basedir}/phpunit.xml.dist" printsummary="true">
<formatter type="xml" todir="${dir.reports}" outfile="phpunit.xml" />
<formatter type="plain" todir="${dir.reports}" outfile="phpunit.txt" />
<formatter type="clover" todir="${dir.reports.coverage}" />
<formatter type="summary" todir="${dir.reports}" outfile="phpunit_summary.txt" />
</phpunit>
-->
<!--
Previous / old version
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
2017-02-22
<if>
<istrue value="${phpunit.useExec}" />
<then>
<if>
<istrue value="${phpunit.withCoverage}" />
<then>
<echo message="Running tests with code coverage..." />
<exec command="phpunit \-\-log-junit ${dir.reports}/phpunit.xml \-\-coverage-clover ${dir.reports.coverage}/clover-coverage.xml \-\-coverage-crap4j ${dir.reports.coverage}/crap4j-coverage.xml \-\-coverage-html ${dir.reports.coverage}/ -c ${project.basedir} \-\-colors" passthru="true" checkreturn="true" />
</then>
<else>
<echo message="Running tests without code coverage..." />
<exec command="phpunit \-\-log-junit ${dir.reports}/phpunit.xml -c ${project.basedir} \-\-colors" passthru="true" checkreturn="true" />
</else>
</if>
</then>
<else>
<if>
<istrue value="${phpunit.withCoverage}" />
<then>
<echo message="Running tests with code coverage..." />
<coverage-setup database="${dir.reports.coverage}/coverage.db">
<fileset refid="sourcecode" />
</coverage-setup>
<phpunit printsummary="true" codecoverage="true">
<formatter type="xml" todir="${dir.reports}" outfile="phpunit.xml" />
<formatter type="plain" todir="${dir.reports}" outfile="phpunit.txt" />
<formatter type="clover" todir="${dir.reports.coverage}" />
<formatter type="summary" todir="${dir.reports}" outfile="phpunit_summary.txt" />
</phpunit>
</then>
<else>
<echo message="Running tests without code coverage..." />
<phpunit printsummary="true">
<formatter todir="${dir.reports}" type="xml" outfile="phpunit.xml" />
<batchtest>
<fileset refid="tests" />
</batchtest>
</phpunit>
</else>
</if>
</else>
</if>
-->
</target>
<!-- Checkout and finalization -->
<target name="app:checkout">
<tstamp>
<format property="date_end" pattern="%Y-%m-%d %H:%M" />
</tstamp>
<echo msg="--------------------------------------------" />
<echo msg="Build tests finished at: ${date_end}" />
<echo msg="--------------------------------------------" />
</target>
</project>

View File

@@ -5,14 +5,38 @@ Client of the [LimeSurvey's API](https://manual.limesurvey.org/RemoteControl_2_A
## Installation
In your `composer.json` add address of repository into `repositories` section:
```json
"repositories": [
(...)
{
"type": "vcs",
"url": "https://github.com/wiosna-dev/limesurvey-api-client"
}
]
```
Run [Composer](https://getcomposer.org) to install this package in your project:
```bash
$ composer require meritoo/limesurvey-api-client
$ composer require wiosna-dev/limesurvey-api-client
```
> How to install Composer: https://getcomposer.org/download
## Configuration of LimeSurvey
1. Login to the LimeSurvey administration, e.g. using https://your-domain/admin address
2. Go to menu: `Configuration` -> `Global settings`
3. Open `Interfaces` tab
4. For `RPC interface enabled` select `JSON-RPC` option
5. Enable `Publish API on /admin/remotecontrol` option
It should look like here:
![Configuration of LimeSurvey](http://www.meritoo.pl/packages/github/limesurvey-api-client/readme/configuration-interfaces.png)
More information: https://manual.limesurvey.org/RemoteControl_2_API#Introduction
## Usage
1. First of all you have to prepare configuration of connection and create instance of a client:

1
VERSION Normal file
View File

@@ -0,0 +1 @@
0.1.1

View File

@@ -2,40 +2,40 @@
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
<!-- Properties -->
<if>
<available file=".phing/properties" property="custom.properties.available"/>
<available file="phing/properties" property="custom.properties.available"/>
<then>
<property file=".phing/properties" />
<property file="phing/properties"/>
</then>
<else>
<property file=".phing/properties.dist" />
<property file="phing/properties.dist"/>
</else>
</if>
<!-- Default / main target -->
<target name="build:main"
depends="build:app, build:tests"
description="Builds everything and runs all tests" />
description="Builds everything and runs all tests"/>
<!-- Build app -->
<target name="build:app" description="Prepares app to build and tests">
<phing phingfile=".phing/app.xml" haltonfailure="true" />
<phing phingfile="phing/app.xml" haltonfailure="true"/>
</target>
<!-- Build tests -->
<target name="build:tests" description="Runs all tests, checks and creates docs">
<phing phingfile=".phing/tests.xml" haltonfailure="true" />
<phing phingfile="phing/tests.xml" haltonfailure="true"/>
<!--
Conditional running of tests.
Disabled, because not required.
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
Meritoo <github@meritoo.pl>
2017-02-22
<if>
<equals arg1="${env}" arg2="test" />
<then>
<phing phingfile=".phing/tests.xml" haltonfailure="true" />
<phing phingfile="phing/tests.xml" haltonfailure="true" />
</then>
<else>
<echo message="[Skipped] Running tests, checks and creating docs, because it's a not 'test' environment..." />

View File

@@ -1,9 +1,8 @@
{
"name": "meritoo/limesurvey-api-client",
"name": "wiosna-dev/limesurvey-api-client",
"description": "Client of LimeSurvey API",
"type": "library",
"license": "MIT",
"version": "0.0.10",
"authors": [
{
"name": "Meritoo",
@@ -13,16 +12,16 @@
"require": {
"php": ">=5.6",
"fguillot/json-rpc": "^1.2",
"meritoo/common-library": "~0.0.1"
"wiosna-dev/common-library": "^0.1.9"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^2.9",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^3.0",
"friendsofphp/php-cs-fixer": "^2.6",
"pdepend/pdepend": "^2.5",
"phploc/phploc": "^4.0",
"friendsofphp/php-cs-fixer": "^2.6"
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^5.7",
"sebastian/phpcpd": "^3.0",
"squizlabs/php_codesniffer": "^2.9"
},
"autoload": {
"psr-4": {
@@ -33,5 +32,14 @@
"psr-4": {
"Meritoo\\LimeSurvey\\Test\\ApiClient\\": "tests/"
}
}
},
"config": {
"sort-packages": true
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wiosna-dev/common-library"
}
]
}

View File

@@ -1,15 +1,20 @@
version: '3'
services:
php-cli:
image: meritoo/limesurvey-api-client
container_name: meritoo-limesurvey-api-client
working_dir: /project
php:
image: ${DOCKER_CONTAINER_OWNER}/${DOCKER_CONTAINER_PROJECT}-php
container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-php
entrypoint: php
command: -S 0.0.0.0:9999
build:
context: ./.docker/config
context: ./docker/config
args:
- TIMEZONE=$TIMEZONE
- TIMEZONE=${TIMEZONE}
volumes:
- .:/project
- .:/project:cached
composer:
image: ${DOCKER_CONTAINER_OWNER}/${DOCKER_CONTAINER_PROJECT}-php
container_name: ${DOCKER_CONTAINER_OWNER}-${DOCKER_CONTAINER_PROJECT}-composer
entrypoint: composer
volumes:
- .:/project:cached

103
docker/config/Dockerfile Normal file
View File

@@ -0,0 +1,103 @@
FROM php:5.6-cli
MAINTAINER Meritoo <github@meritoo.pl>
#
# Tools & libraries
#
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
vim \
git \
zip \
unzip \
zlib1g-dev \
libicu-dev \
&& apt-get clean \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
#
# PHP extensions
#
RUN docker-php-ext-install \
zip \
intl \
mbstring
#
# PHP extensions (PECL):
# - Xdebug
#
RUN pecl install \
xdebug-2.5.5 \
&& docker-php-ext-enable \
xdebug
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
#
# PHP configuration:
# - default configuration
# - timezone
#
COPY php.ini /usr/local/etc/php/php.ini
ARG TIMEZONE
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo ${TIMEZONE} > /etc/timezone \
&& printf '[PHP]\ndate.timezone = "%s"\n' ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
&& "date"
#
# Phing
#
RUN pear channel-discover pear.phing.info \
&& pear install [--alldeps] phing/phing
#
# Composer - environment variables:
# - disable warning about running commands as root/super user
# - disable automatic clearing of sudo sessions
#
# More:
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
#
ENV COMPOSER_ALLOW_SUPERUSER 1
#
# Composer + https://packagist.org/packages/hirak/prestissimo package
#
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === \
'544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo \
'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');" \
&& composer global require \
--no-plugins \
--no-scripts \
--no-progress \
--no-suggest \
--no-interaction \
--prefer-dist \
--optimize-autoloader \
--classmap-authoritative \
hirak/prestissimo \
&& rm -rf ~/.composer/cache/* \
&& composer clear-cache \
&& composer --version
#
# Bash
#
RUN sed -i 's/^# export/export/g; \
s/^# alias/alias/g;' ~/.bashrc \
&& echo 'COLUMNS=200'"\n" >> ~/.bashrc
#
# Use project-related binaries globally
#
ENV PATH="/project/vendor/bin:${PATH}"
WORKDIR /project

164
phing/app.xml Normal file
View File

@@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.16.0">
<!-- Properties -->
<if>
<available file="phing/properties" property="custom.properties.available"/>
<then>
<property file="phing/properties"/>
</then>
<else>
<property file="phing/properties.dist"/>
</else>
</if>
<!-- Filesets -->
<import file="phing/filesets.xml"/>
<!-- Default / main target -->
<target name="build:main"
depends="build:app"
description="Builds the application"/>
<!-- App target -->
<target name="build:app"
depends="app:clean, app:composer, app:vendors, app:composer-validate, app:checkout"
description="Prepares app to build."/>
<!-- Updates Composer -->
<target name="app:composer" description="Updates Composer">
<echo msg="Updating Composer..."/>
<if>
<available file="composer.phar"/>
<then>
<echo msg="[Skipped] Downloading of Composer skipped, because exist in the project..."/>
</then>
<else>
<if>
<os family="windows"/>
<then>
<fail message="Composer not found! Go to http://getcomposer.org/download and download the Composer."/>
</then>
<else>
<exec command="${composer.download_command}" checkreturn="true"/>
</else>
</if>
</else>
</if>
<!-- Update Composer -->
<composer command="selfupdate"/>
</target>
<!-- Validates composer.* files -->
<target name="app:composer-validate" description="Validates composer.* files">
<echo msg="Validating composer.* files..."/>
<!-- Validate Composer -->
<composer command="validate">
<arg line="--no-check-all --strict"/>
</composer>
</target>
<!-- Project clean -->
<target name="app:clean" description="Clears app's directories">
<echo msg="Cleaning project..."/>
<if>
<equals arg1="${env}" arg2="prod"/>
<then>
<echo message="[Skipped] Cleaning project (and directories cleanup) skipped, because of 'prod' environment..."/>
</then>
<else>
<echo msg="Cleaning directories (making them empty)..."/>
<foreach list="${directoriesToEmpty}" param="directory" target="app:clean:empty"/>
</else>
</if>
<echo msg="Preparing directories structure..."/>
<foreach list="${directoriesToCheck}" param="directory" target="app:clean:check"/>
<echo msg="Creating .gitkeep files..."/>
<touch file="${dir.cache}/.gitkeep"/>
<touch file="${dir.logs}/.gitkeep"/>
<touch file="${dir.sessions}/.gitkeep"/>
<echo msg="Setting permissions of directories..."/>
<foreach list="${directoriesToEmpty}" param="directory" target="app:permissions"/>
</target>
<!-- Cleaning directory (making empty) directory -->
<target name="app:clean:empty" description="Empties directory">
<if>
<available file="${directory}" type="dir"/>
<then>
<echo message="Cleaning directory (making empty) ${directory}..."/>
<delete includeemptydirs="true" dir="${directory}"/>
</then>
</if>
</target>
<!-- Checking if directory exists -->
<target name="app:clean:check" description="Checks if directories exist">
<if>
<not>
<available file="${directory}" type="dir"/>
</not>
<then>
<if>
<or>
<contains string="${directory}" substring="cache"/>
<contains string="${directory}" substring="logs"/>
<contains string="${directory}" substring="sessions"/>
</or>
<then>
<mkdir dir="${directory}" mode="0777"/>
</then>
<else>
<mkdir dir="${directory}" mode="0775"/>
</else>
</if>
</then>
</if>
</target>
<!-- Project Install/update vendors -->
<target name="app:vendors" description="Installs / updates vendors">
<echo msg="Installing / updating vendors..."/>
<if>
<istrue value="${composer.self-update}"/>
<then>
<composer php="${composer.php}" composer="${composer.path}" command="self-update"/>
</then>
</if>
<composer php="${composer.php}" composer="${composer.path}" command="install">
<arg value="--optimize-autoloader"/>
<arg value="--prefer-dist"/>
<arg value="--classmap-authoritative"/>
</composer>
</target>
<!-- Setting permissions of given directory -->
<target name="app:permissions" description="Sets permissions of one of the core directories">
<if>
<not>
<os family="windows"/>
</not>
<then>
<exec command="chmod -R 777 ${directory}/*"/>
</then>
</if>
</target>
<!-- Checkout and finalization -->
<target name="app:checkout">
<tstamp>
<format property="date_end" pattern="%Y-%m-%d %H:%M"/>
</tstamp>
<echo msg="------------------------------------"/>
<echo msg="Build finished at: ${date_end}"/>
<echo msg="------------------------------------"/>
</target>
</project>

35
phing/filesets.xml Normal file
View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.16.0">
<!-- Filesets -->
<fileset id="cache" dir="${dir.cache}">
<include name="**/*"/>
<exclude name=".gitkeep"/>
</fileset>
<fileset id="logs" dir="${dir.logs}">
<include name="**/*"/>
<exclude name=".gitkeep"/>
</fileset>
<fileset id="sessions" dir="${dir.sessions}">
<include name="**/*"/>
<exclude name=".gitkeep"/>
</fileset>
<!-- Directories to check -->
<property name="directoriesToCheck" value="
${dir.cache},
${dir.logs},
${dir.sessions},
${dir.data.tests},
${dir.data.temporary},
${dir.docker.data},
${dir.docker.logs}"
/>
<!-- Directories to empty -->
<property name="directoriesToEmpty" value="
${dir.cache},
${dir.logs},
${dir.sessions},
${dir.data.temporary}"
/>
</project>

View File

@@ -9,7 +9,7 @@
# not special chars. This way you can create pseudo-namespaces
#
# You can refer to values of other properties by enclosing their keys in "${}".
# Example: dir.js = ${dir.web}/js
# Example: dir.js = ${dir.public}/js
#
# Everything behind the equal sign is the value, you do
# not have to enclose strings: text=This is some text, Your OS is ${php.os}
@@ -22,13 +22,15 @@
#
env = dev
# Install assets using symlinks
#
assets.installWithSymlink = true
# Clear cache with the "warmup" option
#
cache.clearWithWarmup = true
# The cache:clear command should always be called with the --no-warmup option. Warmup should be done via the cache:warmup command.
# https://github.com/symfony/symfony/blob/master/UPGRADE-3.3.md#frameworkbundle
#
# Meritoo <github@meritoo.pl>
# 2017-06-06
#
cache.clearWithWarmup = false
# --------------------------------------------------------------------------------
# Composer
@@ -39,7 +41,6 @@ composer.download_command = php -r "eval('?>'.file_get_contents('https://getcomp
# Path to composer executable or composer.phar file
#
composer.path = composer.phar
#composer.path = /usr/local/bin/composer
# Path to php executable used by composer
#
@@ -49,77 +50,50 @@ composer.php = php
#
composer.self-update = false
# Validate the composer.json file
#
composer.validate = false
# --------------------------------------------------------------------------------
# Directories
# --------------------------------------------------------------------------------
# System directories
#
dir.data = ${project.basedir}/.data
dir.src = ${project.basedir}/src
dir.var = ${project.basedir}/tests/Resources/var
dir.cache = ${dir.var}/cache
dir.logs = ${dir.var}/log
dir.sessions = ${dir.var}/sessions
dir.data = ${project.basedir}/data
dir.tests = ${project.basedir}/tests
# --------------------------------------------------------------------------------
# Build directories
# --------------------------------------------------------------------------------
dir.build = ${project.basedir}/.build
#
dir.build = ${project.basedir}/build
dir.reports = ${dir.build}/logs
dir.reports.pdepend = ${dir.reports}/pdepend
dir.reports.coverage = ${dir.reports}/phpunit_coverage
#
# Disabled, because unnecessary right now
# phpdocumentor/phpdocumentor cannot be installed via Composer
#
# Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
# 2017-02-22
#
#dir.docs = ${dir.build}/docs
#dir.docs.phpdoc2 = ${dir.docs}/phpdoc2
# --------------------------------------------------------------------------------
# Data directories
# --------------------------------------------------------------------------------
#
dir.data.tests = ${dir.data}/tests
dir.data.temporary = ${dir.data}/tmp
# Docker directories
#
dir.docker = ${project.basedir}/docker
dir.docker.data = ${dir.docker}/data/db
dir.docker.logs = ${dir.docker}/logs/nginx
# --------------------------------------------------------------------------------
# Testing
# --------------------------------------------------------------------------------
# Path of the PHP Coding Standards Fixer (http://cs.sensiolabs.org)
#
tests.cs_fixer.path = ./vendor/bin/php-cs-fixer
# Test database path
#
tests.database = ${dir.data.temporary}/database.sqlite
# Path of the framework used to run unit tests
#
# Disabled, because unnecessary right now
# PHPUnit is installed and loaded by Composer
#
# Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
# 2017-02-22
#
# Run PHPUnit using exec task instead of phpunitTask
#phpunit.useExec = false
#
# Disabled, because unnecessary right now
# We want generate code coverage always
#
# Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
# 2017-02-22
#
# Collect coverage data during tests
#phpunit.withCoverage = true
# Path of the PHPUnit (https://phpunit.de)
#
phpUnit.path = ./vendor/bin/phpunit
# Path of the PHP Coding Standards Fixer (http://cs.sensiolabs.org)
#
phpCsFixer.path = ./vendor/bin/php-cs-fixer
tests.framework.path = ./vendor/bin/phpunit --verbose --no-coverage

230
phing/tests.xml Normal file
View File

@@ -0,0 +1,230 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
<!--
The AutoloaderTask is required to load binaries installed by Composer.
The "autoloaderpath" attribute of this task is not required, because it's default value is: vendor/autoload.php.
Meritoo <github@meritoo.pl>
2017-02-23
-->
<autoloader/>
<!-- Properties -->
<if>
<available file="phing/properties" property="custom.properties.available"/>
<then>
<property file="phing/properties"/>
</then>
<else>
<property file="phing/properties.dist"/>
</else>
</if>
<!-- Filesets -->
<fileset id="sourcecode" dir="${dir.src}">
<include name="**/*.php"/>
<exclude name="*Test.php"/>
<exclude name="**/*Test.php"/>
<exclude name="**/Resources/**"/>
<exclude name="**/DataFixtures/**"/>
<exclude name="**/Tests/**"/>
</fileset>
<fileset id="tests" dir="${dir.tests}">
<include name="**/*Test*.php"/>
</fileset>
<!-- Default / main target -->
<target name="build:main"
depends="build:fix-coding-standards, build:clean, build:prepare, build:check, build:test, app:checkout"
description="Runs all tests and builds everything"/>
<!--
Before:
depends="build:fix-coding-standards, build:clean, build:prepare, build:check, build:test, build:doc, app:checkout"
After:
depends="build:fix-coding-standards, build:clean, build:prepare, build:check, build:test, app:checkout"
The "build:doc" task is disabled, because it cannot be installed via Composer:
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Meritoo <github@meritoo.pl>
2017-02-22
-->
<!-- Fixing coding standards using the PHP Coding Standards Fixer (http://cs.sensiolabs.org) -->
<target name="build:fix-coding-standards" description="Fixes coding standards using the PHP Coding Standards Fixer">
<echo msg="Fixing coding standards using the PHP Coding Standards Fixer (http://cs.sensiolabs.org)..."/>
<!--
Attention.
Rules for formatting are defined in /.php_cs.dist file.
-->
<exec
passthru="true"
command="${tests.cs_fixer.path} fix --verbose"
/>
</target>
<!-- Doc target -->
<!--
Disabled, because it cannot be installed via Composer:
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Meritoo <github@meritoo.pl>
2017-02-22
-->
<!--<target name="build:doc"-->
<!--depends="build:prepare, doc:phpdoc2"-->
<!--description="Generates API documentation" />-->
<!-- Check target -->
<target name="build:check"
depends="check:cs, check:md, check:cpd, check:depend, check:loc"
description="Analyzes code"/>
<!-- Test target -->
<target name="build:test"
depends="test:unit"
description="Executes all tests"/>
<!-- Project build clean -->
<target name="build:clean" description="Cleans up build directories">
<echo msg="Cleaning docs and reports directories..."/>
<!--<delete dir="${dir.docs}" />-->
<delete dir="${dir.reports}"/>
</target>
<!-- Project build prepare -->
<target name="build:prepare" description="Create build directories">
<echo msg="Creating build directories..."/>
<!--<mkdir dir="${dir.docs}" />-->
<!--<mkdir dir="${dir.docs.phpdoc2}" />-->
<mkdir dir="${dir.reports}"/>
<mkdir dir="${dir.reports.pdepend}"/>
<mkdir dir="${dir.reports.coverage}"/>
</target>
<!-- PHPDocumentor2 API documentation target -->
<!--
Disabled, because it cannot be installed via Composer:
a) phpdocumentor/phpdocumentor v2.9.0 requires symfony/validator ~2.2
b) symfony/validator ~2.2 causes to remove symfony/symfony 3.*
Meritoo <github@meritoo.pl>
2017-02-22
<target name="doc:phpdoc2" description="Generates API documentations">
<echo msg="Generating API Documentation with phpDocumentor 2..." />
<phpdoc2 title="${phing.project.name}"
destdir="${dir.docs.phpdoc2}"
template="responsive">
<fileset refid="sourcecode" />
</phpdoc2>
</target>
-->
<!-- Symfony2 code sniffer -->
<!--
Attention 1.
To use Symfony2 standards to check coding you have to:
copy, symlink or check out repo to a folder called Symfony2 inside the phpcs Standards directory.
Example:
$ pear config-show | grep php_dir
$ cd /path/to/pear/PHP/CodeSniffer/Standards
$ git clone git://github.com/opensky/Symfony2-coding-standard.git Symfony2
Attention 2.
PSR2 standard is used instead of Symfony2 standard, because after installation squizlabs/php_codesniffer package
via Composer the Symfony2 standard is not included / available in this package. In this case the PHP Coding
Standards Fixer (http://cs.sensiolabs.org) is used.
Meritoo <github@meritoo.pl>
2017-02-22
-->
<target name="check:cs" description="Checks coding standard">
<echo msg="Checking coding standard..."/>
<phpcodesniffer standard="PSR2" showWarnings="true">
<fileset refid="sourcecode"/>
<formatter type="checkstyle" outfile="${dir.reports}/checkstyle.xml"/>
<formatter type="csv" outfile="${dir.reports}/checkstyle.csv"/>
<formatter type="summary" outfile="${dir.reports}/checkstyle_summary.txt"/>
</phpcodesniffer>
</target>
<!-- copy/paste detector -->
<target name="check:cpd" description="Checks similar code blocks.">
<echo msg="Checking similar code blocks..."/>
<phpcpd>
<fileset refid="sourcecode"/>
<formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml"/>
</phpcpd>
<!--
Previous / old version
Meritoo <github@meritoo.pl>
2017-02-22
<exec command="phpcpd \-\-log-pmd=${dir.reports}/pmd-cpd.xml ${dir.src}" />
-->
</target>
<!-- Mess detector -->
<target name="check:md" description="Generate code metrics">
<echo msg="Generating code metrics..."/>
<phpmd rulesets="codesize,controversial,design,naming,unusedcode">
<fileset refid="sourcecode"/>
<formatter type="html" outfile="${dir.reports}/phpmd.html"/>
<formatter type="text" outfile="${dir.reports}/phpmd.txt"/>
</phpmd>
</target>
<!-- Code dependency -->
<target name="check:depend" description="Checks coupling and dependency">
<echo msg="Checking coupling and dependency..."/>
<phpdepend>
<fileset refid="sourcecode"/>
<logger type="jdepend-xml" outfile="${dir.reports.pdepend}/jdepend.xml"/>
<logger type="jdepend-chart" outfile="${dir.reports.pdepend}/dependencies.svg"/>
<logger type="overview-pyramid" outfile="${dir.reports.pdepend}/overview-pyramid.svg"/>
</phpdepend>
</target>
<!-- Measure the size and analyzing the structure of a project -->
<target name="check:loc" description="Measures the size and analyzes the structure of a project">
<echo msg="Measuring the size and analyzing the structure of a project..."/>
<phploc reportType="txt" reportName="phploc" reportDirectory="${dir.reports}">
<fileset refid="sourcecode"/>
</phploc>
<!--
Previous / old version
Meritoo <github@meritoo.pl>
2017-02-22
<exec command="phploc \-\-log-csv=${dir.reports}/phploc.csv ${dir.src}" />
-->
</target>
<!-- Unit tests -->
<target name="test:unit" description="Runs unit tests">
<echo msg="Running unit tests..."/>
<exec command="${tests.framework.path}" passthru="true"/>
</target>
<!-- Checkout and finalization -->
<target name="app:checkout">
<tstamp>
<format property="date_end" pattern="%Y-%m-%d %H:%M"/>
</tstamp>
<echo msg="--------------------------------------------"/>
<echo msg="Build tests finished at: ${date_end}"/>
<echo msg="--------------------------------------------"/>
</target>
</project>

View File

@@ -39,6 +39,13 @@ abstract class BaseParticipant extends BaseItem
*/
protected $email;
/**
* Token of the participant
*
* @var string
*/
protected $token;
/**
* Returns ID of the participant
*
@@ -78,4 +85,14 @@ abstract class BaseParticipant extends BaseItem
{
return $this->email;
}
/**
* Returns token of the participant
*
* @return string
*/
public function getToken()
{
return $this->token;
}
}

View File

@@ -18,7 +18,7 @@ abstract class BaseParticipantsCollection extends Collection
*/
public function add($element, $index = null)
{
throw new DisabledMethodException(__METHOD__, 'addParticipant');
throw DisabledMethodException::create(__METHOD__, 'addParticipant');
}
/**
@@ -26,7 +26,7 @@ abstract class BaseParticipantsCollection extends Collection
*/
public function addMultiple($elements, $useIndexes = false)
{
throw new DisabledMethodException(__METHOD__, 'addParticipants');
throw DisabledMethodException::create(__METHOD__, 'addParticipants');
}
/**
@@ -34,7 +34,7 @@ abstract class BaseParticipantsCollection extends Collection
*/
public function has($element)
{
throw new DisabledMethodException(__METHOD__, 'hasParticipantsOfSurvey');
throw DisabledMethodException::create(__METHOD__, 'hasParticipantsOfSurvey');
}
/**

View File

@@ -77,6 +77,7 @@ class ConnectionConfiguration
* turned off.
* @param bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification is turned
* on. Otherwise - turned off.
* @throws InvalidUrlException
*/
public function __construct($baseUrl, $username, $password, $debugMode = false, $verifySslCertificate = true)
{

View File

@@ -20,10 +20,16 @@ use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
class UnknownMethodException extends UnknownTypeException
{
/**
* {@inheritdoc}
* Creates exception
*
* @param string $unknownMethod Name of unknown method used while talking to the LimeSurvey's API
* @return UnknownMethodException
*/
public function __construct($unknownType)
public static function createException($unknownMethod)
{
parent::__construct($unknownType, new MethodType(), 'name of method used while talking to the LimeSurvey\'s API');
/* @var UnknownMethodException $exception */
$exception = parent::create($unknownMethod, new MethodType(), 'name of method used while talking to the LimeSurvey\'s API');
return $exception;
}
}

View File

@@ -25,7 +25,7 @@ class SurveysSummaries extends Collection
*/
public function add($element, $index = null)
{
throw new DisabledMethodException(__METHOD__, 'addSurveySummary');
throw DisabledMethodException::create(__METHOD__, 'addSurveySummary');
}
/**
@@ -33,7 +33,7 @@ class SurveysSummaries extends Collection
*/
public function addMultiple($elements, $useIndexes = false)
{
throw new DisabledMethodException(__METHOD__, 'addSurveysSummaries');
throw DisabledMethodException::create(__METHOD__, 'addSurveysSummaries');
}
/**
@@ -41,7 +41,7 @@ class SurveysSummaries extends Collection
*/
public function has($element)
{
throw new DisabledMethodException(__METHOD__, 'hasSurveySummary');
throw DisabledMethodException::create(__METHOD__, 'hasSurveySummary');
}
/**

View File

@@ -42,13 +42,6 @@ class Participant extends BaseParticipant
*/
private $emailStatus;
/**
* Token of the participant
*
* @var string
*/
private $token;
/**
* Language of the participant
*
@@ -232,16 +225,6 @@ class Participant extends BaseParticipant
return $this->emailStatus;
}
/**
* Returns token of the participant
*
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* Returns language of the participant
*

View File

@@ -28,6 +28,10 @@ class ParticipantShort extends BaseParticipant
$this->id = (int)$value;
break;
case 'token':
$this->token = trim($value);
break;
case 'participant_info':
$this->firstName = trim($value['firstname']);
$this->lastName = trim($value['lastname']);
@@ -52,6 +56,7 @@ class ParticipantShort extends BaseParticipant
$data = [
'tid' => $participant->getId(),
'token' => $participant->getToken(),
'participant_info' => $info,
];

View File

@@ -57,9 +57,14 @@ class Result
* class constants.
* @param array $rawData Raw data returned by the LimeSurvey's API
*/
public function __construct($method, array $rawData)
public function __construct($method, $rawData)
{
$this->method = MethodType::getValidatedMethod($method);
if (true === is_string($rawData)) {
$rawData = base64_decode($rawData);
$rawData = json_decode($rawData, true);
}
$this->setRawDataAndStatus($rawData);
}

View File

@@ -12,6 +12,8 @@ use Meritoo\Common\Collection\Collection;
use Meritoo\LimeSurvey\ApiClient\Client\Client;
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
use Meritoo\LimeSurvey\ApiClient\Exception\MissingSurveySummaryException;
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem;
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownMethodException;
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
use Meritoo\LimeSurvey\ApiClient\Result\Collection\SurveysSummaries;
@@ -126,6 +128,8 @@ class SurveyService
* @return Surveys
*
* @throws CannotProcessDataException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
public function getAllSurveys($onlyActive = false)
{
@@ -160,10 +164,13 @@ class SurveyService
/**
* Returns information if survey with given ID exists
*
* @param int $surveyId ID of survey to verify
* @param int $surveyId ID of survey to verify
* @param bool $shouldBeActive (optional) If is set to true, survey should be active. If it's not, it shouldn't
* be returned, even if exists. Otherwise - it doesn't matter (default behaviour).
* @return bool
* @throws CannotProcessDataException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
public function isExistingSurvey($surveyId, $shouldBeActive = false)
{
@@ -189,6 +196,23 @@ class SurveyService
return false;
}
/**
* Returns url used to start survey for given survey and participant's token
*
* @param int $surveyId ID of survey to start
* @param string $participantToken Token of participant who would like to start survey
* @return string
*/
public function getStartSurveyUrlByToken($surveyId, $participantToken)
{
$baseUrl = $this
->client
->getConfiguration()
->getBaseUrl();
return sprintf($this->startSurveyUrlTemplate, $baseUrl, $surveyId, $participantToken);
}
/**
* Returns url used to start survey for given survey and participant
*
@@ -198,23 +222,21 @@ class SurveyService
*/
public function getStartSurveyUrl($surveyId, Participant $participant)
{
$baseUrl = $this
->client
->getConfiguration()
->getBaseUrl();
return sprintf($this->startSurveyUrlTemplate, $baseUrl, $surveyId, $participant->getToken());
return $this->getStartSurveyUrlByToken($surveyId, $participant->getToken());
}
/**
* Returns participants of given survey
*
* @param int $surveyId ID of survey
* @param int $surveyId ID of survey
* @param bool $onlyCompleted (optional) If is set to true, participants who completed survey are returned only.
* Otherwise - all (default behaviour).
* @return Collection
*
* @throws CannotProcessDataException
* @throws MissingSurveySummaryException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
public function getSurveyParticipants($surveyId, $onlyCompleted = false)
{
@@ -263,11 +285,14 @@ class SurveyService
/**
* Adds participant with given data to survey with given ID
*
* @param int $surveyId ID of survey
* @param int $surveyId ID of survey
* @param string $firstName First name of the participant to add
* @param string $lastName Last ame of the participant to add
* @param string $email E-mail address of the participant to add
* @param string $lastName Last ame of the participant to add
* @param string $email E-mail address of the participant to add
* @return Participant
* @throws CannotProcessDataException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
public function addParticipant($surveyId, $firstName, $lastName, $email)
{
@@ -306,9 +331,13 @@ class SurveyService
/**
* Returns short data of one participant with given e-mail (participant of given survey)
*
* @param int $surveyId ID of survey
* @param string $email E-mail address of the participant
* @param int $surveyId ID of survey
* @param string $email E-mail address of the participant
* @return ParticipantShort|null
* @throws CannotProcessDataException
* @throws MissingSurveySummaryException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
public function getParticipant($surveyId, $email)
{
@@ -331,7 +360,10 @@ class SurveyService
* @param int $surveyId ID of survey
* @return int
*
* @throws CannotProcessDataException
* @throws MissingSurveySummaryException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
public function getSurveyTokenCount($surveyId)
{
@@ -362,6 +394,9 @@ class SurveyService
*
* @param int $surveyId ID of survey
* @return SurveySummary|null
* @throws CannotProcessDataException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
private function getSurveySummary($surveyId)
{
@@ -383,4 +418,85 @@ class SurveyService
return $surveySummary;
}
/**
* @param $surveyId
* @param $email
* @return bool
* @throws CannotProcessDataException
* @throws UnknownInstanceOfResultItem
* @throws UnknownMethodException
*/
public function hasSurveyBeenCompletedByEmail($surveyId, $email)
{
$arguments = [
$surveyId,
$offset = 0,
$limit = 10,
$includeUnused = false,
['completed'],
['email' => $email]
];
try {
/** @var Collection $participants */
$participants = $this
->client
->run(MethodType::LIST_PARTICIPANTS, $arguments)
->getData(true);
foreach ($participants as $participant) {
if ('N' !== $participant['completed']) {
return true;
}
}
} catch (CannotProcessDataException $exception) {
if (ReasonType::NO_PARTICIPANTS_FOUND !== $exception->getReason()) {
throw $exception;
}
}
return false;
}
public function getResponseIds($surveyId, $token)
{
$arguments = [
$surveyId,
$token,
];
return $this
->client
->run('get_response_ids', $arguments)
->getData(true);
}
public function exportResponsesByToken($surveyId, $token)
{
$arguments = [
$surveyId,
'json',
$token,
];
return $this
->client
->run('export_responses_by_token', $arguments)
->getData(true);
}
public function exportUploadedFilesByToken($surveyId, $token)
{
$arguments = [
$surveyId,
'json',
$token,
];
return $this
->client
->run('get_uploaded_files', $arguments)
->getData(true);
}
}

View File

@@ -93,6 +93,12 @@ class MethodType extends BaseType
*/
const LIST_USERS = 'list_users';
const EXPORT_RESPONSES_BY_TOKEN = 'export_responses_by_token';
const GET_RESPONSE_IDS = 'get_response_ids';
const EXPORT_UPLOADED_FILES_BY_TOKEN = 'get_uploaded_files';
/**
* Returns validated name of method to call or throws an exception (if method is incorrect)
*
@@ -126,6 +132,9 @@ class MethodType extends BaseType
static::LIST_QUESTIONS,
static::LIST_SURVEYS,
static::LIST_USERS,
static::EXPORT_RESPONSES_BY_TOKEN,
static::GET_RESPONSE_IDS,
static::EXPORT_UPLOADED_FILES_BY_TOKEN
]);
}
}

View File

@@ -45,7 +45,7 @@ class ClientTest extends BaseTestCase
*/
public function testRunWithIncorrectMethod($incorrectMethod)
{
$this->expectException(UnknownMethodException::class);
$this->setExpectedException(UnknownMethodException::class);
$client = new Client($this->configuration);
$client->run($incorrectMethod);
@@ -61,8 +61,8 @@ class ClientTest extends BaseTestCase
*/
public function testRun($method, $arguments, $debugMode, $expectedRawData)
{
$sessionManager = $this->createMock(SessionManager::class);
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
$sessionManager = $this->getMock(SessionManager::class, [], [], '', false);
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$rpcClientManager
->expects(static::any())

View File

@@ -47,7 +47,7 @@ class ConnectionConfigurationTest extends BaseTestCase
*/
public function testConstructorWithEmptyBaseUrl($emptyBaseUrl)
{
$this->expectException(InvalidUrlException::class);
$this->setExpectedException(InvalidUrlException::class);
new ConnectionConfiguration($emptyBaseUrl, '', '');
}
@@ -57,7 +57,7 @@ class ConnectionConfigurationTest extends BaseTestCase
*/
public function testConstructorWithInvalidBaseUrl($invalidBaseUrl)
{
$this->expectException(InvalidUrlException::class);
$this->setExpectedException(InvalidUrlException::class);
new ConnectionConfiguration($invalidBaseUrl, '', '');
}

View File

@@ -24,7 +24,7 @@ class UnknownMethodExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownMethodException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
static::assertConstructorVisibilityAndArguments(UnknownMethodException::class, OopVisibilityType::IS_PUBLIC, 3);
}
/**
@@ -35,7 +35,7 @@ class UnknownMethodExceptionTest extends BaseTestCase
*/
public function testConstructorMessage($unknownType, $expectedMessage)
{
$exception = new UnknownMethodException($unknownType);
$exception = UnknownMethodException::createException($unknownType);
static::assertEquals($expectedMessage, $exception->getMessage());
}

View File

@@ -40,7 +40,7 @@ class JsonRpcClientManagerTest extends BaseTestCase
public function testRunMethodWithEmptyArrayReturned()
{
$rpcClient = $this->createMock(RpcClient::class);
$rpcClient = $this->getMock(RpcClient::class);
$manager = $this
->getMockBuilder(JsonRpcClientManager::class)
@@ -68,8 +68,8 @@ class JsonRpcClientManagerTest extends BaseTestCase
public function testRunMethodWithRawDataReturned()
{
$rpcClient = $this->createMock(RpcClient::class);
$manager = $this->createPartialMock(JsonRpcClientManager::class, ['getRpcClient']);
$rpcClient = $this->getMock(RpcClient::class);
$manager = $this->getMock(JsonRpcClientManager::class, ['getRpcClient'], [], '', false);
$rpcClient
->expects(static::once())
@@ -87,10 +87,10 @@ class JsonRpcClientManagerTest extends BaseTestCase
public function testRunMethodWithException()
{
$this->expectException(InvalidResultOfMethodRunException::class);
$this->setExpectedException(InvalidResultOfMethodRunException::class);
$manager = $this->createPartialMock(JsonRpcClientManager::class, ['getRpcClient']);
$rpcClient = $this->createMock(RpcClient::class);
$manager = $this->getMock(JsonRpcClientManager::class, ['getRpcClient'], [], '', false);
$rpcClient = $this->getMock(RpcClient::class);
$rpcClient
->expects(self::once())

View File

@@ -29,10 +29,9 @@ class SessionManagerTest extends BaseTestCase
public function testGetSessionKeyWhenFailedWithoutReason()
{
$this->expectException(CreateSessionKeyFailedException::class);
$this->expectExceptionMessage('Create of the session key has failed');
$this->setExpectedException(CreateSessionKeyFailedException::class, 'Create of the session key has failed');
$clientManager = $this->createMock(JsonRpcClientManager::class);
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager
->expects(static::any())
@@ -46,10 +45,10 @@ class SessionManagerTest extends BaseTestCase
{
$reason = 'Invalid credentials';
$this->expectException(CreateSessionKeyFailedException::class);
$this->expectExceptionMessage(sprintf('Create of the session key has failed. Reason: \'%s\'.', $reason));
$message = sprintf('Create of the session key has failed. Reason: \'%s\'.', $reason);
$this->setExpectedException(CreateSessionKeyFailedException::class, $message);
$clientManager = $this->createMock(JsonRpcClientManager::class);
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager
->expects(static::any())
@@ -63,7 +62,7 @@ class SessionManagerTest extends BaseTestCase
public function testGetSessionKey()
{
$clientManager = $this->createMock(JsonRpcClientManager::class);
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager
->expects(static::any())
@@ -76,7 +75,7 @@ class SessionManagerTest extends BaseTestCase
public function testReleaseSessionKey()
{
$clientManager = $this->createMock(JsonRpcClientManager::class);
$clientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$clientManager
->expects(static::any())

0
tests/Resources/var/cache/.gitkeep vendored Normal file
View File

View File

View File

View File

@@ -52,19 +52,19 @@ class ParticipantsTest extends BaseTestCase
public function testAdd()
{
$this->expectException(DisabledMethodException::class);
$this->setExpectedException(DisabledMethodException::class);
(new Participants())->add('');
}
public function testAddMultiple()
{
$this->expectException(DisabledMethodException::class);
$this->setExpectedException(DisabledMethodException::class);
(new Participants())->addMultiple([]);
}
public function testHas()
{
$this->expectException(DisabledMethodException::class);
$this->setExpectedException(DisabledMethodException::class);
(new Participants())->has(new Participant());
}

View File

@@ -44,19 +44,19 @@ class SurveysSummariesTest extends BaseTestCase
public function testAdd()
{
$this->expectException(DisabledMethodException::class);
$this->setExpectedException(DisabledMethodException::class);
(new SurveysSummaries())->add('');
}
public function testAddMultiple()
{
$this->expectException(DisabledMethodException::class);
$this->setExpectedException(DisabledMethodException::class);
(new SurveysSummaries())->addMultiple([]);
}
public function testHas()
{
$this->expectException(DisabledMethodException::class);
$this->setExpectedException(DisabledMethodException::class);
(new SurveysSummaries())->has(new SurveySummary());
}

View File

@@ -32,7 +32,7 @@ class SurveySummaryTest extends BaseTestCase
* @param array $rawData Raw data of survey's summary
* @dataProvider provideRawData
*/
public function testCreateOfTheSurveySummary($rawData)
public function testCreateOfTheSurveySummary(array $rawData)
{
$processor = new ResultProcessor();
$processed = $processor->process(MethodType::GET_SUMMARY, $rawData);

View File

@@ -82,7 +82,7 @@ class ResultProcessorTest extends BaseTestCase
public function testRunWithUnknownResultClass()
{
$this->expectException(UnknownInstanceOfResultItem::class);
$this->setExpectedException(UnknownInstanceOfResultItem::class);
$rawData = [
'lorem' => 'ipsum',

View File

@@ -128,7 +128,7 @@ class ResultTest extends BaseTestCase
public function testGetDataUsingProcessedDataWhoCannotBeProcessed()
{
$this->expectException(CannotProcessDataException::class);
$this->setExpectedException(CannotProcessDataException::class);
$this->statusInsteadDataResult->getData();
}

View File

@@ -112,9 +112,7 @@ class ParticipantServiceTest extends BaseTestCase
public function testGetParticipantDetailsWithException()
{
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
$this->expectException(CannotProcessDataException::class);
$this->expectExceptionMessage($exception->getMessage());
$this->setExpectedException(CannotProcessDataException::class, $exception->getMessage());
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
$sessionManager = $this->getSessionManager();
@@ -158,7 +156,7 @@ class ParticipantServiceTest extends BaseTestCase
public function testHasParticipantFilledSurveyWithoutParticipants()
{
$this->expectException(MissingParticipantOfSurveyException::class);
$this->setExpectedException(MissingParticipantOfSurveyException::class);
$rpcClientManager = $this->getJsonRpcClientManager(1);
$sessionManager = $this->getSessionManager();
@@ -178,7 +176,7 @@ class ParticipantServiceTest extends BaseTestCase
public function testHasParticipantFilledSurveyUsingNotExistingParticipant()
{
$this->expectException(MissingParticipantOfSurveyException::class);
$this->setExpectedException(MissingParticipantOfSurveyException::class);
$rpcClientManager = $this->getJsonRpcClientManager(1);
$sessionManager = $this->getSessionManager();
@@ -253,7 +251,7 @@ class ParticipantServiceTest extends BaseTestCase
*/
private function getSessionManager()
{
return $this->createMock(SessionManager::class);
return $this->getMock(SessionManager::class, [], [], '', false);
}
/**
@@ -265,7 +263,7 @@ class ParticipantServiceTest extends BaseTestCase
*/
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
{
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$mocker = $rpcClientManager
->expects(static::exactly($runMethodCallCount))
@@ -297,7 +295,7 @@ class ParticipantServiceTest extends BaseTestCase
*/
private function getJsonRpcClientManagerWithException($runMethodCallCount, Exception $exception)
{
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$rpcClientManager
->expects(static::exactly($runMethodCallCount))

View File

@@ -100,7 +100,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetAllSurveysWithNoTableException()
{
$this->expectException(CannotProcessDataException::class);
$this->setExpectedException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -181,6 +181,22 @@ class SurveyServiceTest extends BaseTestCase
static::assertFalse($this->serviceWithSurveys->isExistingSurvey(4, true));
}
public function testGetStartSurveyUrlByToken()
{
$rpcClientManager = $this->getJsonRpcClientManager(0);
$sessionManager = $this->getSessionManager();
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
$surveyId = 123;
$token = uniqid();
$expectedUrl = sprintf('%s/%d?token=%s', $this->connectionBaseUrl, $surveyId, $token);
static::assertEquals($expectedUrl, $this->serviceWithoutSurveys->getStartSurveyUrlByToken($surveyId, $token));
static::assertEquals($expectedUrl, $this->serviceWithSurveys->getStartSurveyUrlByToken($surveyId, $token));
}
public function testGetStartSurveyUrl()
{
$rpcClientManager = $this->getJsonRpcClientManager(0);
@@ -208,9 +224,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyParticipantsWithNotExistingSurveyException()
{
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
$this->expectException(CannotProcessDataException::class);
$this->expectExceptionMessage($exception->getMessage());
$this->setExpectedException(CannotProcessDataException::class, $exception->getMessage());
$runMethodCallResults = [
[
@@ -316,7 +330,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyParticipantsWithNoTableException()
{
$this->expectException(CannotProcessDataException::class);
$this->setExpectedException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -328,7 +342,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyParticipantsWithNoParticipantsException()
{
$this->expectException(CannotProcessDataException::class);
$this->setExpectedException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NO_PARTICIPANTS_FOUND);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -340,7 +354,7 @@ class SurveyServiceTest extends BaseTestCase
public function testAddParticipantForNotExistingSurvey()
{
$this->expectException(CannotProcessDataException::class);
$this->setExpectedException(CannotProcessDataException::class);
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
@@ -450,7 +464,7 @@ class SurveyServiceTest extends BaseTestCase
public function testGetSurveyTokenCountWithException()
{
$this->expectException(MissingSurveySummaryException::class);
$this->setExpectedException(MissingSurveySummaryException::class);
$runMethodCallResults = [
null,
@@ -480,7 +494,7 @@ class SurveyServiceTest extends BaseTestCase
*/
private function getSessionManager()
{
return $this->createMock(SessionManager::class);
return $this->getMock(SessionManager::class, [], [], '', false);
}
/**
@@ -492,7 +506,7 @@ class SurveyServiceTest extends BaseTestCase
*/
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
{
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$mocker = $rpcClientManager
->expects(static::exactly($runMethodCallCount))
@@ -524,7 +538,7 @@ class SurveyServiceTest extends BaseTestCase
*/
private function getJsonRpcClientManagerWithException($runMethodCallCount, Exception $exception)
{
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
$rpcClientManager
->expects(static::exactly($runMethodCallCount))

View File

@@ -33,7 +33,7 @@ class MethodTypeTest extends BaseTypeTestCase
*/
public function testGetValidatedMethodWithIncorrectMethod($incorrectMethod)
{
$this->expectException(UnknownMethodException::class);
$this->setExpectedException(UnknownMethodException::class);
MethodType::getValidatedMethod($incorrectMethod);
}
@@ -52,7 +52,7 @@ class MethodTypeTest extends BaseTypeTestCase
*/
public function testIsResultIterableWithIncorrectMethod($incorrectMethod)
{
$this->expectException(UnknownMethodException::class);
$this->setExpectedException(UnknownMethodException::class);
MethodType::isResultIterable($incorrectMethod);
}