mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 10:11:49 +01:00
Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d3e492ed7 | ||
|
|
2c89bbe5f5 | ||
|
|
525391083a | ||
|
|
7ef83dac5d | ||
|
|
54bd021649 | ||
|
|
c47016bdea | ||
|
|
c5498501d3 | ||
|
|
82031194a2 | ||
|
|
a3e5c78dcd | ||
|
|
a3f6adb128 | ||
|
|
da6003b258 | ||
|
|
ee62e9f148 | ||
|
|
64e0fb3152 | ||
|
|
b58c346e95 | ||
|
|
83ff76776c | ||
|
|
ac72c6bd76 | ||
|
|
bf7392853f | ||
|
|
e902568a91 | ||
|
|
626174953b | ||
|
|
ddb568adf7 | ||
|
|
835c4325b8 | ||
|
|
24a3d478b5 | ||
|
|
e38df1a8f2 | ||
|
|
db6a6f22e2 | ||
|
|
f5334f816f | ||
|
|
e43712f218 | ||
|
|
e464ae30af | ||
|
|
98cad233d9 | ||
|
|
5154f05ee4 | ||
|
|
0c44140c89 | ||
|
|
41156ed058 | ||
|
|
54bd0ca114 | ||
|
|
5243294bd5 | ||
|
|
6159731768 | ||
|
|
bbd466610c | ||
|
|
d54765b378 | ||
|
|
ab328b96ee | ||
|
|
cd6dbf72bc | ||
|
|
beaf61d2ea | ||
|
|
cacb2b3b92 | ||
|
|
dfa64fee43 | ||
|
|
6c44a62f36 | ||
|
|
4f26bca282 | ||
|
|
dbd0a65286 | ||
|
|
0562cb4d21 | ||
|
|
f8a675d0fb | ||
|
|
a5b534b00d | ||
|
|
a6866d994c | ||
|
|
5061f5a295 | ||
|
|
f5de59f50b | ||
|
|
6e54d39972 | ||
|
|
b3b0e66fb3 | ||
|
|
0fbfc9780d | ||
|
|
92315bd853 | ||
|
|
c3e6935dd8 |
15
.env
Normal file
15
.env
Normal file
@@ -0,0 +1,15 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
### Docker
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# All containers
|
||||
#
|
||||
DOCKER_CONTAINER_OWNER=meritoo
|
||||
DOCKER_CONTAINER_PROJECT=limesurvey-api-client
|
||||
|
||||
#
|
||||
# PHP configuration:
|
||||
# - timezone
|
||||
#
|
||||
TIMEZONE=Europe/Warsaw
|
||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -11,6 +11,7 @@
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
### Composer
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
/composer.lock
|
||||
/composer.phar
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
@@ -28,10 +29,16 @@
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
/.php_cs.cache
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
### Build files
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
/.build/
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
### Generated databases
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
/data/tmp
|
||||
/.data/tmp
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
|
||||
26
README.md
26
README.md
@@ -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:
|
||||

|
||||
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:
|
||||
|
||||
12
build.xml
12
build.xml
@@ -4,32 +4,32 @@
|
||||
<if>
|
||||
<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>
|
||||
|
||||
@@ -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.4",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Meritoo",
|
||||
@@ -11,22 +10,36 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.6",
|
||||
"fguillot/json-rpc": "^1.2",
|
||||
"meritoo/common-library": "~0.0.1"
|
||||
"meritoo/common-library": "^0.1.0"
|
||||
},
|
||||
"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": {
|
||||
"Meritoo\\LimeSurvey\\": "src/Meritoo/LimeSurvey/",
|
||||
"Meritoo\\LimeSurvey\\Test\\": "tests/Meritoo/LimeSurvey/Test/"
|
||||
"Meritoo\\LimeSurvey\\ApiClient\\": "src/"
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Meritoo\\LimeSurvey\\Test\\ApiClient\\": "tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/wiosna-dev/common-library"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
3581
composer.lock
generated
3581
composer.lock
generated
File diff suppressed because it is too large
Load Diff
20
docker-compose.yml
Normal file
20
docker-compose.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
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
|
||||
args:
|
||||
- TIMEZONE=${TIMEZONE}
|
||||
volumes:
|
||||
- .:/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
103
docker/config/Dockerfile
Normal 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
|
||||
3
docker/config/php.ini
Normal file
3
docker/config/php.ini
Normal file
@@ -0,0 +1,3 @@
|
||||
display_errors = On
|
||||
display_startup_errors = On
|
||||
error_reporting = E_ALL
|
||||
6
docker/config/xdebug.ini
Normal file
6
docker/config/xdebug.ini
Normal file
@@ -0,0 +1,6 @@
|
||||
[xdebug]
|
||||
zend_extension=xdebug.so
|
||||
|
||||
xdebug.remote_enable=1
|
||||
xdebug.remote_port=9001
|
||||
xdebug.remote_host=10.254.254.254
|
||||
141
phing/app.xml
141
phing/app.xml
@@ -1,53 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
|
||||
<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" />
|
||||
<property file="phing/properties"/>
|
||||
</then>
|
||||
<else>
|
||||
<property file="phing/properties.dist" />
|
||||
<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" />
|
||||
description="Builds the application"/>
|
||||
|
||||
<!-- App target -->
|
||||
<target name="build:app"
|
||||
depends="app:composer, app:vendors, app:checkout"
|
||||
description="Prepares app to build." />
|
||||
depends="app:clean, app:composer, app:vendors, app:composer-validate, app:checkout"
|
||||
description="Prepares app to build."/>
|
||||
|
||||
<!-- Check / update composer -->
|
||||
<target name="app:composer" description="Checks / updates composer">
|
||||
<echo msg="Checking / updating composer..." />
|
||||
<!-- Updates Composer -->
|
||||
<target name="app:composer" description="Updates Composer">
|
||||
<echo msg="Updating Composer..."/>
|
||||
|
||||
<if>
|
||||
<available file="composer.phar" />
|
||||
<available file="composer.phar"/>
|
||||
<then>
|
||||
<echo msg="[Skipped] Downloading of Composer skipped, because exist in the project..." />
|
||||
<echo msg="[Skipped] Downloading of Composer skipped, because exist in the project..."/>
|
||||
</then>
|
||||
<else>
|
||||
<if>
|
||||
<os family="windows" />
|
||||
<os family="windows"/>
|
||||
<then>
|
||||
<fail message="Composer not found! Go to http://getcomposer.org/download and download the Composer." />
|
||||
<fail message="Composer not found! Go to http://getcomposer.org/download and download the Composer."/>
|
||||
</then>
|
||||
<else>
|
||||
<exec command="${composer.download_command}" checkreturn="true" />
|
||||
<exec command="${composer.download_command}" checkreturn="true"/>
|
||||
</else>
|
||||
</if>
|
||||
</else>
|
||||
</if>
|
||||
<composer command="selfupdate" />
|
||||
|
||||
<!-- 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..." />
|
||||
<echo msg="Installing / updating vendors..."/>
|
||||
|
||||
<if>
|
||||
<istrue value="${composer.self-update}"/>
|
||||
@@ -56,34 +132,33 @@
|
||||
</then>
|
||||
</if>
|
||||
|
||||
<if>
|
||||
<istrue value="${composer.validate}"/>
|
||||
<then>
|
||||
<composer php="${composer.php}" composer="${composer.path}" command="validate"/>
|
||||
</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>
|
||||
<equals arg1="${env}" arg2="prod" />
|
||||
<not>
|
||||
<os family="windows"/>
|
||||
</not>
|
||||
<then>
|
||||
<composer php="${composer.php}" composer="${composer.path}" command="install">
|
||||
<arg value="--optimize-autoloader" />
|
||||
</composer>
|
||||
<exec command="chmod -R 777 ${directory}/*"/>
|
||||
</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" />
|
||||
<format property="date_end" pattern="%Y-%m-%d %H:%M"/>
|
||||
</tstamp>
|
||||
|
||||
<echo msg="------------------------------------" />
|
||||
<echo msg="Build finished at: ${date_end}" />
|
||||
<echo msg="------------------------------------" />
|
||||
<echo msg="------------------------------------"/>
|
||||
<echo msg="Build finished at: ${date_end}"/>
|
||||
<echo msg="------------------------------------"/>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
35
phing/filesets.xml
Normal file
35
phing/filesets.xml
Normal 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>
|
||||
@@ -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,49 @@ 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.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
|
||||
|
||||
201
phing/tests.xml
201
phing/tests.xml
@@ -4,39 +4,39 @@
|
||||
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>
|
||||
Meritoo <github@meritoo.pl>
|
||||
2017-02-23
|
||||
-->
|
||||
<autoloader />
|
||||
<autoloader/>
|
||||
|
||||
<!-- Properties -->
|
||||
<if>
|
||||
<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>
|
||||
|
||||
<!-- 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/**" />
|
||||
<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" />
|
||||
<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" />
|
||||
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"
|
||||
@@ -48,13 +48,13 @@
|
||||
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>
|
||||
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)..." />
|
||||
<echo msg="Fixing coding standards using the PHP Coding Standards Fixer (http://cs.sensiolabs.org)..."/>
|
||||
|
||||
<!--
|
||||
Attention.
|
||||
@@ -62,8 +62,8 @@
|
||||
-->
|
||||
|
||||
<exec
|
||||
passthru="true"
|
||||
command="${phpCsFixer.path} fix --verbose"
|
||||
passthru="true"
|
||||
command="${tests.cs_fixer.path} fix --verbose"
|
||||
/>
|
||||
</target>
|
||||
|
||||
@@ -73,38 +73,38 @@
|
||||
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>
|
||||
Meritoo <github@meritoo.pl>
|
||||
2017-02-22
|
||||
-->
|
||||
<!--<target name="build:doc"-->
|
||||
<!--depends="build:prepare, doc:phpdoc2"-->
|
||||
<!--description="Generates API documentation" />-->
|
||||
<!--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" />
|
||||
description="Analyzes code"/>
|
||||
|
||||
<!-- Test target -->
|
||||
<target name="build:test"
|
||||
depends="test:phpunit"
|
||||
description="Executes all tests" />
|
||||
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..." />
|
||||
<echo msg="Cleaning docs and reports directories..."/>
|
||||
<!--<delete dir="${dir.docs}" />-->
|
||||
<delete dir="${dir.reports}" />
|
||||
<delete dir="${dir.reports}"/>
|
||||
</target>
|
||||
|
||||
<!-- Project build prepare -->
|
||||
<target name="build:prepare" description="Create build directories">
|
||||
<echo msg="Creating 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}" />
|
||||
<mkdir dir="${dir.reports}"/>
|
||||
<mkdir dir="${dir.reports.pdepend}"/>
|
||||
<mkdir dir="${dir.reports.coverage}"/>
|
||||
</target>
|
||||
|
||||
<!-- PHPDocumentor2 API documentation target -->
|
||||
@@ -113,7 +113,7 @@
|
||||
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>
|
||||
Meritoo <github@meritoo.pl>
|
||||
2017-02-22
|
||||
|
||||
<target name="doc:phpdoc2" description="Generates API documentations">
|
||||
@@ -142,31 +142,31 @@
|
||||
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>
|
||||
Meritoo <github@meritoo.pl>
|
||||
2017-02-22
|
||||
-->
|
||||
<target name="check:cs" description="Checks coding standard">
|
||||
<echo msg="Checking 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" />
|
||||
<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..." />
|
||||
<echo msg="Checking similar code blocks..."/>
|
||||
<phpcpd>
|
||||
<fileset refid="sourcecode" />
|
||||
<formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml" />
|
||||
<fileset refid="sourcecode"/>
|
||||
<formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml"/>
|
||||
</phpcpd>
|
||||
|
||||
<!--
|
||||
Previous / old version
|
||||
|
||||
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
Meritoo <github@meritoo.pl>
|
||||
2017-02-22
|
||||
|
||||
<exec command="phpcpd \-\-log-pmd=${dir.reports}/pmd-cpd.xml ${dir.src}" />
|
||||
@@ -175,36 +175,36 @@
|
||||
|
||||
<!-- Mess detector -->
|
||||
<target name="check:md" description="Generate code metrics">
|
||||
<echo msg="Generating 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" />
|
||||
<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..." />
|
||||
<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" />
|
||||
<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..." />
|
||||
<echo msg="Measuring the size and analyzing the structure of a project..."/>
|
||||
<phploc reportType="txt" reportName="phploc" reportDirectory="${dir.reports}">
|
||||
<fileset refid="sourcecode" />
|
||||
<fileset refid="sourcecode"/>
|
||||
</phploc>
|
||||
|
||||
<!--
|
||||
Previous / old version
|
||||
|
||||
Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
Meritoo <github@meritoo.pl>
|
||||
2017-02-22
|
||||
|
||||
<exec command="phploc \-\-log-csv=${dir.reports}/phploc.csv ${dir.src}" />
|
||||
@@ -212,104 +212,19 @@
|
||||
</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 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" />
|
||||
<format property="date_end" pattern="%Y-%m-%d %H:%M"/>
|
||||
</tstamp>
|
||||
|
||||
<echo msg="--------------------------------------------" />
|
||||
<echo msg="Build tests finished at: ${date_end}" />
|
||||
<echo msg="--------------------------------------------" />
|
||||
<echo msg="--------------------------------------------"/>
|
||||
<echo msg="Build tests finished at: ${date_end}"/>
|
||||
<echo msg="--------------------------------------------"/>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -30,6 +30,6 @@
|
||||
</groups>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-html" target="./build/logs/phpunit_coverage/html" />
|
||||
<log type="coverage-html" target="./.build/logs/phpunit_coverage/html" />
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
||||
@@ -16,13 +16,32 @@ namespace Meritoo\LimeSurvey\ApiClient\Base\Result;
|
||||
*/
|
||||
abstract class BaseItem
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $data (optional) Data to set in properties of the item
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->setValues($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets given value in given property
|
||||
*
|
||||
* @param string $property Name of property to set the value
|
||||
* @param mixed $value Value to set in property
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function setValue($property, $value);
|
||||
|
||||
/**
|
||||
* Sets values in each property of the item
|
||||
*
|
||||
* @param array $data Data to set in properties of the item
|
||||
* @return $this
|
||||
*/
|
||||
public function setValues($data)
|
||||
private function setValues(array $data)
|
||||
{
|
||||
/*
|
||||
* Oops, no data
|
||||
@@ -40,13 +59,4 @@ abstract class BaseItem
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets given value in given property
|
||||
*
|
||||
* @param string $property Name of property to set the value
|
||||
* @param mixed $value Value to set in property
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function setValue($property, $value);
|
||||
}
|
||||
@@ -1,68 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Base\Result;
|
||||
|
||||
/**
|
||||
* One item of the result/data: short data of one participant
|
||||
* Base class for participant of survey.
|
||||
* Used as a foundation for short or full participant's data.
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantShort extends BaseItem
|
||||
abstract class BaseParticipant extends BaseItem
|
||||
{
|
||||
/**
|
||||
* ID of the participant
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* First name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $firstName;
|
||||
protected $firstName;
|
||||
|
||||
/**
|
||||
* Last name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $lastName;
|
||||
protected $lastName;
|
||||
|
||||
/**
|
||||
* E-mail of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
switch ($property) {
|
||||
case 'tid':
|
||||
$this->id = (int)$value;
|
||||
break;
|
||||
|
||||
case 'participant_info':
|
||||
$this->firstName = trim($value['firstname']);
|
||||
$this->lastName = trim($value['lastname']);
|
||||
$this->email = trim($value['email']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* Returns ID of the participant
|
||||
@@ -1,35 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Collection;
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Base\Result;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
|
||||
/**
|
||||
* Participants of survey.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* It's a collection of participants' collections.
|
||||
* The survey ID is used as an index per each collection of participants, so they are grouped by survey.
|
||||
* Base class for participants' collection
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Participants extends Collection
|
||||
abstract class BaseParticipantsCollection extends Collection
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($element, $index = null)
|
||||
{
|
||||
throw new DisabledMethodException(__METHOD__, 'addParticipants');
|
||||
throw DisabledMethodException::create(__METHOD__, 'addParticipant');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,13 +26,21 @@ class Participants extends Collection
|
||||
*/
|
||||
public function addMultiple($elements, $useIndexes = false)
|
||||
{
|
||||
throw new DisabledMethodException(__METHOD__, 'addParticipants');
|
||||
throw DisabledMethodException::create(__METHOD__, 'addParticipants');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($element)
|
||||
{
|
||||
throw DisabledMethodException::create(__METHOD__, 'hasParticipantsOfSurvey');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participants of given survey
|
||||
*
|
||||
* @param Collection $participants Participants to add. Collection of Participant classes.
|
||||
* @param Collection $participants Participants to add. Collection of ParticipantShort or Participant instances.
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
@@ -64,35 +61,6 @@ class Participants extends Collection
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participant of given survey
|
||||
*
|
||||
* @param Participant $participant Participant to add
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
public function addParticipant(Participant $participant, $surveyId)
|
||||
{
|
||||
$this
|
||||
->getBySurvey($surveyId)
|
||||
->add($participant);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if there are participants of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipantsOfSurvey($surveyId)
|
||||
{
|
||||
return false === $this
|
||||
->getBySurvey($surveyId)
|
||||
->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participants of given survey
|
||||
*
|
||||
@@ -115,23 +83,54 @@ class Participants extends Collection
|
||||
return $this[$surveyId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if there are participants of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipantsOfSurvey($surveyId)
|
||||
{
|
||||
return false === $this
|
||||
->getBySurvey($surveyId)
|
||||
->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participant of given survey
|
||||
*
|
||||
* @param BaseParticipant $participant Participant to add
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
public function addParticipant(BaseParticipant $participant, $surveyId)
|
||||
{
|
||||
$this
|
||||
->getBySurvey($surveyId)
|
||||
->add($participant);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participant of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $participantEmail E-mail of searched participant
|
||||
* @return Participant|null
|
||||
* @return BaseParticipant|null
|
||||
*/
|
||||
public function getParticipantOfSurvey($surveyId, $participantEmail)
|
||||
{
|
||||
/* @var Collection $participants */
|
||||
$participants = $this->getBySurvey($surveyId);
|
||||
|
||||
/*
|
||||
* No participants?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($participants->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* @var Participant $participant */
|
||||
foreach ($participants as $participant) {
|
||||
if ($participant->getEmail() == $participantEmail) {
|
||||
return $participant;
|
||||
@@ -119,6 +119,16 @@ class Client
|
||||
return new Result($method, $rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return ConnectionConfiguration
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
*
|
||||
@@ -59,21 +59,34 @@ class ConnectionConfiguration
|
||||
*/
|
||||
private $debugMode = false;
|
||||
|
||||
/**
|
||||
* If is set to true, the SSL certificate verification is turned on. Otherwise - turned off.
|
||||
* It's useful while running application with custom, non-official SSL certificate, e.g. while development process.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $verifySslCertificate = true;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $baseUrl Base url. Protocol & domain.
|
||||
* @param string $username Name of user used to authenticate to LimeSurvey
|
||||
* @param string $password Password used to authenticate to LimeSurvey
|
||||
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise - turned off.
|
||||
* @param string $baseUrl Base url. Protocol & domain.
|
||||
* @param string $username Name of user used to authenticate to LimeSurvey
|
||||
* @param string $password Password used to authenticate to LimeSurvey
|
||||
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise -
|
||||
* 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)
|
||||
public function __construct($baseUrl, $username, $password, $debugMode = false, $verifySslCertificate = true)
|
||||
{
|
||||
$this
|
||||
->setBaseUrl($baseUrl)
|
||||
->setUsername($username)
|
||||
->setPassword($password)
|
||||
->setDebugMode($debugMode);
|
||||
$this->setBaseUrl($baseUrl);
|
||||
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->debugMode = $debugMode;
|
||||
$this->verifySslCertificate = $verifySslCertificate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,29 +99,6 @@ class ConnectionConfiguration
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base url, protocol & domain
|
||||
*
|
||||
* @param string $baseUrl The base url, protocol & domain
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidUrlException
|
||||
*/
|
||||
public function setBaseUrl($baseUrl)
|
||||
{
|
||||
if (!Regex::isValidUrl($baseUrl)) {
|
||||
throw new InvalidUrlException($baseUrl);
|
||||
}
|
||||
|
||||
if (Regex::endsWith($baseUrl, '/')) {
|
||||
$baseUrl = substr($baseUrl, 0, strlen($baseUrl) - 1);
|
||||
}
|
||||
|
||||
$this->baseUrl = $baseUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the url of the LimeSurvey's remote control
|
||||
*
|
||||
@@ -142,19 +132,6 @@ class ConnectionConfiguration
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of user used to authenticate to LimeSurvey
|
||||
*
|
||||
* @param string $username The name of user used to authenticate to LimeSurvey
|
||||
* @return $this
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password used to authenticate to LimeSurvey
|
||||
*
|
||||
@@ -165,19 +142,6 @@ class ConnectionConfiguration
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password used to authenticate to LimeSurvey
|
||||
*
|
||||
* @param string $password The password used to authenticate to LimeSurvey
|
||||
* @return $this
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if the "debug" mode is turned on
|
||||
*
|
||||
@@ -189,24 +153,15 @@ class ConnectionConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets information if the "debug" mode is turned on
|
||||
* Returns information if the SSL certificate verification is turned on
|
||||
*
|
||||
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise - turned off.
|
||||
* @return $this
|
||||
* @return bool
|
||||
*/
|
||||
public function setDebugMode($debugMode = false)
|
||||
public function isVerifySslCertificateOn()
|
||||
{
|
||||
$this->debugMode = $debugMode;
|
||||
|
||||
return $this;
|
||||
return $this->verifySslCertificate;
|
||||
}
|
||||
|
||||
/*
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
* Additional / extra methods (neither getters, nor setters)
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns full url of the LimeSurvey's API.
|
||||
* It's a base url with part related to remote control.
|
||||
@@ -217,4 +172,27 @@ class ConnectionConfiguration
|
||||
{
|
||||
return sprintf('%s/%s', $this->baseUrl, $this->remoteControlUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base url, protocol & domain
|
||||
*
|
||||
* @param string $baseUrl The base url, protocol & domain
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidUrlException
|
||||
*/
|
||||
private function setBaseUrl($baseUrl)
|
||||
{
|
||||
if (!Regex::isValidUrl($baseUrl)) {
|
||||
throw new InvalidUrlException($baseUrl);
|
||||
}
|
||||
|
||||
if (Regex::endsWith($baseUrl, '/')) {
|
||||
$baseUrl = substr($baseUrl, 0, strlen($baseUrl) - 1);
|
||||
}
|
||||
|
||||
$this->baseUrl = $baseUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,13 @@ namespace Meritoo\LimeSurvey\ApiClient\Exception;
|
||||
*/
|
||||
class CannotProcessDataException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Reason why data cannot be processed, e.g. "Invalid user name or password"
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $reason;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
@@ -23,9 +30,21 @@ class CannotProcessDataException extends \Exception
|
||||
*/
|
||||
public function __construct($reason)
|
||||
{
|
||||
$this->reason = $reason;
|
||||
|
||||
$template = 'Raw data returned by the LimeSurvey\'s API cannot be processed. Reason: \'%s\'.';
|
||||
$message = sprintf($template, $reason);
|
||||
$message = sprintf($template, $this->reason);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns reason why data cannot be processed, e.g. "Invalid user name or password"
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReason()
|
||||
{
|
||||
return $this->reason;
|
||||
}
|
||||
}
|
||||
35
src/Exception/IncorrectClassOfResultItemException.php
Normal file
35
src/Exception/IncorrectClassOfResultItemException.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Exception;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
|
||||
/**
|
||||
* An exception used while class used to create instance of one item of the result, with data fetched from the
|
||||
* LimeSurvey's API, is incorrect
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class IncorrectClassOfResultItemException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $className Incorrect class name used to create instance of one item
|
||||
*/
|
||||
public function __construct($className)
|
||||
{
|
||||
$template = 'Class %s used to create instance of one item of the result should extend %s, but it does not. Did'
|
||||
. ' you forget to use proper base class?';
|
||||
|
||||
$message = sprintf($template, $className, BaseItem::class);
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
32
src/Exception/MissingParticipantOfSurveyException.php
Normal file
32
src/Exception/MissingParticipantOfSurveyException.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Exception;
|
||||
|
||||
/**
|
||||
* An exception used when participant of survey is missing
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MissingParticipantOfSurveyException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $email E-mail address of the participant
|
||||
*/
|
||||
public function __construct($surveyId, $email)
|
||||
{
|
||||
$template = 'Participant with e-mail %s of survey with ID %s is missing. Maybe was not added to the survey?';
|
||||
$message = sprintf($template, $email, $surveyId);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
31
src/Exception/MissingSurveySummaryException.php
Normal file
31
src/Exception/MissingSurveySummaryException.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Exception;
|
||||
|
||||
/**
|
||||
* An exception used when survey's summary is missing
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MissingSurveySummaryException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
*/
|
||||
public function __construct($surveyId)
|
||||
{
|
||||
$template = 'Summary of survey with ID %d is missing. Does the survey exist?';
|
||||
$message = sprintf($template, $surveyId);
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ use Exception;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
|
||||
/**
|
||||
* An exception used while instance of one item used by result, with data fetched from the LimeSurvey's API, is unknown
|
||||
* An exception used while class name used to create instance of one item of the result, with data fetched from the
|
||||
* LimeSurvey's API, is unknown
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
@@ -27,10 +28,10 @@ class UnknownInstanceOfResultItem extends Exception
|
||||
*/
|
||||
public function __construct($method)
|
||||
{
|
||||
$template = 'Instance of one item used by result the of \'%s\' LimeSurvey API\'s method is unknown. Proper'
|
||||
. ' class is not mapped in %s::%s() method. Did you forget about this?';
|
||||
$template = 'Class name used to create instance of one item used by result the of \'%s\' LimeSurvey API\'s'
|
||||
. ' method is unknown. Proper class is not mapped in %s::%s() method. Did you forget about this?';
|
||||
|
||||
$message = sprintf($template, $method, ResultProcessor::class, 'getItemInstance');
|
||||
$message = sprintf($template, $method, ResultProcessor::class, 'getItemClassName');
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,20 @@ class JsonRpcClientManager
|
||||
* The "debug" mode is turned on?
|
||||
*/
|
||||
if ($this->connectionConfiguration->isDebugModeOn()) {
|
||||
$this->rpcClient->getHttpClient()->withDebug();
|
||||
$this
|
||||
->rpcClient
|
||||
->getHttpClient()
|
||||
->withDebug();
|
||||
}
|
||||
|
||||
/*
|
||||
* The SSL certificate verification is turned off?
|
||||
*/
|
||||
if (!$this->connectionConfiguration->isVerifySslCertificateOn()) {
|
||||
$this
|
||||
->rpcClient
|
||||
->getHttpClient()
|
||||
->withoutSslVerification();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Service;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Serves participants
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantService
|
||||
{
|
||||
/**
|
||||
* Client of the LimeSurvey's API
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* Participants of survey.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $allParticipants;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Client $client Client of the LimeSurvey's API
|
||||
* @param Participants $allParticipants (optional) Participants of survey. All participants grouped per survey.
|
||||
*/
|
||||
public function __construct(Client $client, Participants $allParticipants = null)
|
||||
{
|
||||
if (null === $allParticipants) {
|
||||
$allParticipants = new Participants();
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
$this->allParticipants = $allParticipants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participants of given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return Collection
|
||||
*/
|
||||
public function getSurveyParticipants($surveyId)
|
||||
{
|
||||
$hasSurvey = $this
|
||||
->allParticipants
|
||||
->hasParticipantsOfSurvey($surveyId);
|
||||
|
||||
if (!$hasSurvey) {
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
];
|
||||
|
||||
$participants = $this
|
||||
->client
|
||||
->run(MethodType::LIST_PARTICIPANTS, $arguments)
|
||||
->getData();
|
||||
|
||||
$this
|
||||
->allParticipants
|
||||
->addParticipants($participants, $surveyId);
|
||||
}
|
||||
|
||||
return $this
|
||||
->allParticipants
|
||||
->getBySurvey($surveyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if given survey has participant with given e-mail
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $email E-mail address of the participant
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipant($surveyId, $email)
|
||||
{
|
||||
/*
|
||||
* I have to get all participants of survey to avoid problem when participants exist but are not loaded
|
||||
*/
|
||||
$this->getSurveyParticipants($surveyId);
|
||||
|
||||
return null !== $this
|
||||
->allParticipants
|
||||
->getParticipantOfSurvey($surveyId, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participant with given data to survey with given ID
|
||||
*
|
||||
* @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
|
||||
* @return Participant
|
||||
*/
|
||||
public function addParticipant($surveyId, $firstName, $lastName, $email)
|
||||
{
|
||||
$participantsData = [
|
||||
[
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
],
|
||||
];
|
||||
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
$participantsData,
|
||||
];
|
||||
|
||||
$participantCollection = $this
|
||||
->client
|
||||
->run(MethodType::ADD_PARTICIPANTS, $arguments)
|
||||
->getData();
|
||||
|
||||
$this
|
||||
->allParticipants
|
||||
->addParticipants($participantCollection, $surveyId);
|
||||
|
||||
return $participantCollection->getFirst();
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Service;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Serves surveys
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyService
|
||||
{
|
||||
/**
|
||||
* Client of the LimeSurvey's API
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* All surveys
|
||||
*
|
||||
* @var Collection
|
||||
*/
|
||||
private $allSurveys;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Client $client Client of the LimeSurvey's API
|
||||
* @param Collection $allSurveys (optional) All surveys
|
||||
*/
|
||||
public function __construct(Client $client, Collection $allSurveys = null)
|
||||
{
|
||||
if (null === $allSurveys) {
|
||||
$allSurveys = new Collection();
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
$this->allSurveys = $allSurveys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all surveys
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllSurveys()
|
||||
{
|
||||
if ($this->allSurveys->isEmpty()) {
|
||||
$surveys = $this
|
||||
->client
|
||||
->run(MethodType::LIST_SURVEYS)
|
||||
->getData();
|
||||
|
||||
if (null !== $surveys) {
|
||||
$this->allSurveys = $surveys;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->allSurveys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if survey with given ID exists
|
||||
*
|
||||
* @param int $surveyId ID of survey to verify
|
||||
* @return bool
|
||||
*/
|
||||
public function isExistingSurvey($surveyId)
|
||||
{
|
||||
$allSurveys = $this->getAllSurveys();
|
||||
|
||||
/*
|
||||
* No surveys?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($allSurveys->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$surveyId = (int)$surveyId;
|
||||
|
||||
/* @var Survey $survey */
|
||||
foreach ($allSurveys as $survey) {
|
||||
if ($survey->getId() == $surveyId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
25
src/Result/Collection/Participants.php
Normal file
25
src/Result/Collection/Participants.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseParticipantsCollection;
|
||||
|
||||
/**
|
||||
* Collection of participants' short data.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* It's a collection of participants' collections.
|
||||
* The survey ID is used as an index per each collection of participants, so they are grouped by survey.
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Participants extends BaseParticipantsCollection
|
||||
{
|
||||
}
|
||||
36
src/Result/Collection/ParticipantsDetails.php
Normal file
36
src/Result/Collection/ParticipantsDetails.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseParticipantsCollection;
|
||||
|
||||
/**
|
||||
* Collection of participants' full data.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* It's a collection of participants' collections.
|
||||
* The survey ID is used as an index per each collection of participants, so they are grouped by survey.
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantsDetails extends BaseParticipantsCollection
|
||||
{
|
||||
/**
|
||||
* Returns information if survey with given ID has participant with given e-mail address
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $participantEmail E-mail of searched participant
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipantOfSurvey($surveyId, $participantEmail)
|
||||
{
|
||||
return null !== $this->getParticipantOfSurvey($surveyId, $participantEmail);
|
||||
}
|
||||
}
|
||||
58
src/Result/Collection/Surveys.php
Normal file
58
src/Result/Collection/Surveys.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
|
||||
/**
|
||||
* Collection of surveys (the Survey class instances)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Surveys extends Collection
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($element, $index = null)
|
||||
{
|
||||
if (null === $index) {
|
||||
/* @var Survey $element */
|
||||
$index = $element->getId();
|
||||
}
|
||||
|
||||
return parent::add($element, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all or active only surveys
|
||||
*
|
||||
* @param bool $onlyActive (optional) If is set to true, active surveys are returned only. Otherwise - all.
|
||||
* @return $this
|
||||
*/
|
||||
public function getAll($onlyActive = false)
|
||||
{
|
||||
if ($this->isEmpty() || !$onlyActive) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$all = new static();
|
||||
|
||||
/* @var Survey $survey */
|
||||
foreach ($this as $survey) {
|
||||
if ($survey->isActive()) {
|
||||
$all->add($survey);
|
||||
}
|
||||
}
|
||||
|
||||
return $all;
|
||||
}
|
||||
}
|
||||
116
src/Result/Collection/SurveysSummaries.php
Normal file
116
src/Result/Collection/SurveysSummaries.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\SurveySummary;
|
||||
|
||||
/**
|
||||
* Collection of surveys' summaries (the SurveySummary class instances)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveysSummaries extends Collection
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($element, $index = null)
|
||||
{
|
||||
throw DisabledMethodException::create(__METHOD__, 'addSurveySummary');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addMultiple($elements, $useIndexes = false)
|
||||
{
|
||||
throw DisabledMethodException::create(__METHOD__, 'addSurveysSummaries');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($element)
|
||||
{
|
||||
throw DisabledMethodException::create(__METHOD__, 'hasSurveySummary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds survey's summary
|
||||
*
|
||||
* @param SurveySummary $summary Survey's summary
|
||||
* @param int $surveyId ID of survey
|
||||
* @return $this
|
||||
*/
|
||||
public function addSurveySummary(SurveySummary $summary, $surveyId)
|
||||
{
|
||||
$this[$surveyId] = $summary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds surveys' summaries
|
||||
*
|
||||
* @param array $summaries Surveys' summaries to add
|
||||
* @return $this
|
||||
*/
|
||||
public function addSurveysSummaries(array $summaries)
|
||||
{
|
||||
/*
|
||||
* No summaries?
|
||||
* Nothing to do
|
||||
*/
|
||||
if (empty($summaries)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
foreach ($summaries as $surveyId => $summary) {
|
||||
$this->addSurveySummary($summary, $surveyId);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if there is summary of survey with given ID
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSurveySummary($surveyId)
|
||||
{
|
||||
/*
|
||||
* There are no surveys' summaries or there is no summary of survey with given ID?
|
||||
*/
|
||||
if ($this->isEmpty() || !isset($this[$surveyId])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns summary of survey with given ID
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return SurveySummary|null
|
||||
*/
|
||||
public function getSurveySummary($surveyId)
|
||||
{
|
||||
if ($this->hasSurveySummary($surveyId)) {
|
||||
return $this[$surveyId];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -10,23 +10,16 @@ namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Utilities\Date;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseParticipant;
|
||||
|
||||
/**
|
||||
* One item of the result/data: full data of participant
|
||||
* One item of the result/data: full data of one participant
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class Participant extends BaseItem
|
||||
class Participant extends BaseParticipant
|
||||
{
|
||||
/**
|
||||
* ID of the participant
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* Another ID of the participant?
|
||||
* Don't know where it is used.
|
||||
@@ -42,27 +35,6 @@ class Participant extends BaseItem
|
||||
*/
|
||||
private $mpId;
|
||||
|
||||
/**
|
||||
* First name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $firstName;
|
||||
|
||||
/**
|
||||
* Last name of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $lastName;
|
||||
|
||||
/**
|
||||
* E-mail of the participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* Status of the e-mail
|
||||
*
|
||||
@@ -183,15 +155,15 @@ class Participant extends BaseItem
|
||||
break;
|
||||
|
||||
case 'blacklisted':
|
||||
$this->blacklisted = 'Y' === trim($value);
|
||||
$this->blacklisted = 'Y' === trim(strtoupper($value));
|
||||
break;
|
||||
|
||||
case 'sent':
|
||||
$this->sent = 'Y' === trim($value);
|
||||
$this->sent = 'Y' === trim(strtoupper($value));
|
||||
break;
|
||||
|
||||
case 'remindersent':
|
||||
$this->reminderSent = 'Y' === trim($value);
|
||||
$this->reminderSent = 'Y' === trim(strtoupper($value));
|
||||
break;
|
||||
|
||||
case 'remindercount':
|
||||
@@ -199,7 +171,12 @@ class Participant extends BaseItem
|
||||
break;
|
||||
|
||||
case 'completed':
|
||||
$this->completed = 'Y' === trim($value);
|
||||
if ('N' === trim(strtoupper($value))) {
|
||||
$this->completed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->completed = Date::isValidDate($value, true);
|
||||
break;
|
||||
|
||||
case 'usesleft':
|
||||
@@ -211,7 +188,7 @@ class Participant extends BaseItem
|
||||
break;
|
||||
}
|
||||
|
||||
$this->validFrom = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
$this->validFrom = Date::getDateTime($value, true);
|
||||
break;
|
||||
|
||||
case 'validuntil':
|
||||
@@ -219,21 +196,11 @@ class Participant extends BaseItem
|
||||
break;
|
||||
}
|
||||
|
||||
$this->validUntil = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
$this->validUntil = Date::getDateTime($value, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ID of the participant
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns another ID of the participant?
|
||||
* Don't know where it is used.
|
||||
@@ -255,36 +222,6 @@ class Participant extends BaseItem
|
||||
return $this->mpId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first name of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last name of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns e-mail of the participant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns status of the e-mail
|
||||
*
|
||||
60
src/Result/Item/ParticipantShort.php
Normal file
60
src/Result/Item/ParticipantShort.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseParticipant;
|
||||
|
||||
/**
|
||||
* One item of the result/data: short data of one participant
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantShort extends BaseParticipant
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
switch ($property) {
|
||||
case 'tid':
|
||||
$this->id = (int)$value;
|
||||
break;
|
||||
|
||||
case 'participant_info':
|
||||
$this->firstName = trim($value['firstname']);
|
||||
$this->lastName = trim($value['lastname']);
|
||||
$this->email = trim($value['email']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns short data of participant created from full data of participant
|
||||
*
|
||||
* @param Participant $participant Full data of participant
|
||||
* @return $this
|
||||
*/
|
||||
public static function fromParticipant(Participant $participant)
|
||||
{
|
||||
$info = [
|
||||
'firstname' => $participant->getFirstName(),
|
||||
'lastname' => $participant->getLastName(),
|
||||
'email' => $participant->getEmail(),
|
||||
];
|
||||
|
||||
$data = [
|
||||
'tid' => $participant->getId(),
|
||||
'participant_info' => $info,
|
||||
];
|
||||
|
||||
return new self($data);
|
||||
}
|
||||
}
|
||||
@@ -193,11 +193,11 @@ class QuestionShort extends BaseItem
|
||||
break;
|
||||
|
||||
case 'other':
|
||||
$this->other = 'Y' === trim($value);
|
||||
$this->other = 'Y' === trim(strtoupper($value));
|
||||
break;
|
||||
|
||||
case 'mandatory':
|
||||
$this->mandatory = 'Y' === trim($value);
|
||||
$this->mandatory = 'Y' === trim(strtoupper($value));
|
||||
break;
|
||||
|
||||
case 'question_order':
|
||||
@@ -74,7 +74,7 @@ class Survey extends BaseItem
|
||||
break;
|
||||
}
|
||||
|
||||
$this->startsAt = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
$this->startsAt = Date::getDateTime($value, true);
|
||||
break;
|
||||
|
||||
case 'expires':
|
||||
@@ -82,11 +82,11 @@ class Survey extends BaseItem
|
||||
break;
|
||||
}
|
||||
|
||||
$this->expiresAt = Date::getDateTime($value, false, 'Y-m-d H:i:s');
|
||||
$this->expiresAt = Date::getDateTime($value, true);
|
||||
break;
|
||||
|
||||
case 'active':
|
||||
$this->active = 'Y' === trim($value);
|
||||
$this->active = 'Y' === trim(strtoupper($value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
196
src/Result/Item/SurveySummary.php
Normal file
196
src/Result/Item/SurveySummary.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
|
||||
/**
|
||||
* One item of the result/data: survey's summary (contains aggregated data)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveySummary extends BaseItem
|
||||
{
|
||||
/**
|
||||
* Count/Amount of tokens
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $tokenCount;
|
||||
|
||||
/**
|
||||
* Count/Amount of invalid tokens
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $tokenInvalidCount;
|
||||
|
||||
/**
|
||||
* Count/Amount of sent tokens
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $tokenSentCount;
|
||||
|
||||
/**
|
||||
* Count/Amount of opted out tokens
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $tokenOptedOutCount;
|
||||
|
||||
/**
|
||||
* Count/Amount of completed tokens
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $tokenCompletedCount;
|
||||
|
||||
/**
|
||||
* Count/Amount of complete responses
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $completeResponsesCount;
|
||||
|
||||
/**
|
||||
* Count/Amount of incomplete responses
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $incompleteResponsesCount;
|
||||
|
||||
/**
|
||||
* Count/Amount of full responses
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $fullResponsesCount;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($property, $value)
|
||||
{
|
||||
switch ($property) {
|
||||
case 'token_count':
|
||||
$this->tokenCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'token_invalid':
|
||||
$this->tokenInvalidCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'token_sent':
|
||||
$this->tokenSentCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'token_opted_out':
|
||||
$this->tokenOptedOutCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'token_completed':
|
||||
$this->tokenCompletedCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'completed_responses':
|
||||
$this->completeResponsesCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'incomplete_responses':
|
||||
$this->incompleteResponsesCount = (int)$value;
|
||||
break;
|
||||
|
||||
case 'full_responses':
|
||||
$this->fullResponsesCount = (int)$value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of tokens
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTokenCount()
|
||||
{
|
||||
return $this->tokenCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of invalid tokens
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTokenInvalidCount()
|
||||
{
|
||||
return $this->tokenInvalidCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of sent tokens
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTokenSentCount()
|
||||
{
|
||||
return $this->tokenSentCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of opted out tokens
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTokenOptedOutCount()
|
||||
{
|
||||
return $this->tokenOptedOutCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of completed tokens
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTokenCompletedCount()
|
||||
{
|
||||
return $this->tokenCompletedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of complete responses
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCompleteResponsesCount()
|
||||
{
|
||||
return $this->completeResponsesCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of incomplete responses
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getIncompleteResponsesCount()
|
||||
{
|
||||
return $this->incompleteResponsesCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of full responses
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFullResponsesCount()
|
||||
{
|
||||
return $this->fullResponsesCount;
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,16 @@
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Result\Processor;
|
||||
|
||||
use Meritoo\Common\Utilities\Reflection;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\IncorrectClassOfResultItemException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Question;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\QuestionShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\SurveySummary;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
@@ -31,7 +34,9 @@ class ResultProcessor
|
||||
* @param string $method Name of called method while talking to the LimeSurvey's API. One of the MethodType
|
||||
* class constants.
|
||||
* @param array $rawData Data returned by the LimeSurvey's API
|
||||
* @return null|BaseItem|array
|
||||
* @return array|BaseItem|null
|
||||
*
|
||||
* @throws IncorrectClassOfResultItemException
|
||||
*/
|
||||
public function process($method, array $rawData)
|
||||
{
|
||||
@@ -46,60 +51,65 @@ class ResultProcessor
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare instance of one item
|
||||
* Prepare class name for instance of one item
|
||||
*/
|
||||
$item = $this->getItemInstance($method);
|
||||
$itemClassName = $this->getItemClassName($method);
|
||||
|
||||
/*
|
||||
* The raw data is or, actually, should be iterable?
|
||||
*/
|
||||
if (MethodType::isResultIterable($method)) {
|
||||
$items = [];
|
||||
$emptyItem = clone $item;
|
||||
|
||||
foreach ($rawData as $itemData) {
|
||||
$items[] = $emptyItem->setValues($itemData);
|
||||
$items[] = new $itemClassName($itemData);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
return $item->setValues($rawData);
|
||||
return new $itemClassName($rawData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance of one item of the result
|
||||
* Returns class name used to create instance of one item of the result
|
||||
*
|
||||
* @param string $method Name of called method while talking to the LimeSurvey's API. One of the MethodType
|
||||
* class constants.
|
||||
* @return BaseItem
|
||||
* @return string
|
||||
*
|
||||
* @throws IncorrectClassOfResultItemException
|
||||
* @throws UnknownInstanceOfResultItem
|
||||
*/
|
||||
private function getItemInstance($method)
|
||||
private function getItemClassName($method)
|
||||
{
|
||||
$item = null;
|
||||
$className = null;
|
||||
$method = MethodType::getValidatedMethod($method);
|
||||
|
||||
switch ($method) {
|
||||
case MethodType::ADD_PARTICIPANTS:
|
||||
case MethodType::GET_PARTICIPANT_PROPERTIES:
|
||||
$item = new Participant();
|
||||
$className = Participant::class;
|
||||
break;
|
||||
|
||||
case MethodType::GET_QUESTION_PROPERTIES:
|
||||
$item = new Question();
|
||||
$className = Question::class;
|
||||
break;
|
||||
|
||||
case MethodType::GET_SUMMARY:
|
||||
$className = SurveySummary::class;
|
||||
break;
|
||||
|
||||
case MethodType::LIST_PARTICIPANTS:
|
||||
$item = new ParticipantShort();
|
||||
$className = ParticipantShort::class;
|
||||
break;
|
||||
|
||||
case MethodType::LIST_QUESTIONS:
|
||||
$item = new QuestionShort();
|
||||
$className = QuestionShort::class;
|
||||
break;
|
||||
|
||||
case MethodType::LIST_SURVEYS:
|
||||
$item = new Survey();
|
||||
$className = Survey::class;
|
||||
break;
|
||||
|
||||
/*
|
||||
@@ -108,12 +118,19 @@ class ResultProcessor
|
||||
}
|
||||
|
||||
/*
|
||||
* Instance of the item is unknown?
|
||||
* Oops, class name for instance of the item is unknown
|
||||
*/
|
||||
if (null === $item) {
|
||||
if (null === $className) {
|
||||
throw new UnknownInstanceOfResultItem($method);
|
||||
}
|
||||
|
||||
return $item;
|
||||
if (Reflection::isChildOfClass($className, BaseItem::class)) {
|
||||
return $className;
|
||||
}
|
||||
|
||||
/*
|
||||
* Oops, class is incorrect (should extend BaseItem)
|
||||
*/
|
||||
throw new IncorrectClassOfResultItemException($className);
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,11 @@ class Result
|
||||
->getResultProcessor()
|
||||
->process($this->method, $rawData);
|
||||
|
||||
if (null === $processed || is_array($processed)) {
|
||||
/*
|
||||
* Result is unknown and it should be iterable the result is an array?
|
||||
* Let's prepare and return collection
|
||||
*/
|
||||
if ((null === $processed && MethodType::isResultIterable($this->method)) || is_array($processed)) {
|
||||
$collection = new Collection();
|
||||
|
||||
if (is_array($processed)) {
|
||||
150
src/Service/ParticipantService.php
Normal file
150
src/Service/ParticipantService.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Service;
|
||||
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingParticipantOfSurveyException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\ParticipantsDetails;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
|
||||
/**
|
||||
* Service that serves participants
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantService
|
||||
{
|
||||
/**
|
||||
* Client of the LimeSurvey's API
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* Collection of participants' full data.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* @var ParticipantsDetails
|
||||
*/
|
||||
private $participantsDetails;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Client $client Client of the LimeSurvey's API
|
||||
* @param ParticipantsDetails $participantsDetails (optional) Collection of participants' full data. All
|
||||
* participants grouped per survey.
|
||||
*/
|
||||
public function __construct(
|
||||
Client $client,
|
||||
ParticipantsDetails $participantsDetails = null
|
||||
) {
|
||||
if (null === $participantsDetails) {
|
||||
$participantsDetails = new ParticipantsDetails();
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
$this->participantsDetails = $participantsDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns client of the LimeSurvey's API
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
public function getClient()
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if given survey has participant with given e-mail
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $email E-mail address of the participant
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParticipant($surveyId, $email)
|
||||
{
|
||||
return null !== $this->getParticipantDetails($surveyId, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns full data of participant with given e-mail (participant of given survey)
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $email E-mail address of the participant
|
||||
* @return Participant|null
|
||||
*
|
||||
* @throws CannotProcessDataException
|
||||
*/
|
||||
public function getParticipantDetails($surveyId, $email)
|
||||
{
|
||||
if (!$this->participantsDetails->hasParticipantOfSurvey($surveyId, $email)) {
|
||||
$participant = null;
|
||||
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
[
|
||||
'email' => $email,
|
||||
],
|
||||
];
|
||||
|
||||
try {
|
||||
/* @var Participant $participant */
|
||||
$participant = $this
|
||||
->client
|
||||
->run(MethodType::GET_PARTICIPANT_PROPERTIES, $arguments)
|
||||
->getData();
|
||||
} catch (CannotProcessDataException $exception) {
|
||||
/*
|
||||
* Oops, something is broken, because the reason is different than "participant was not found"
|
||||
*/
|
||||
if (ReasonType::NO_PARTICIPANT_PROPERTIES !== $exception->getReason()) {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $participant) {
|
||||
$this->participantsDetails->addParticipant($participant, $surveyId);
|
||||
}
|
||||
}
|
||||
|
||||
$participant = $this
|
||||
->participantsDetails
|
||||
->getParticipantOfSurvey($surveyId, $email);
|
||||
|
||||
return $participant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if participant with given e-mail has filled given survey
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $email E-mail address of the participant
|
||||
* @return bool
|
||||
*
|
||||
* @throws MissingParticipantOfSurveyException
|
||||
*/
|
||||
public function hasParticipantFilledSurvey($surveyId, $email)
|
||||
{
|
||||
if ($this->hasParticipant($surveyId, $email)) {
|
||||
return true === $this
|
||||
->getParticipantDetails($surveyId, $email)
|
||||
->isCompleted();
|
||||
}
|
||||
|
||||
throw new MissingParticipantOfSurveyException($surveyId, $email);
|
||||
}
|
||||
}
|
||||
398
src/Service/SurveyService.php
Normal file
398
src/Service/SurveyService.php
Normal file
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Service;
|
||||
|
||||
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\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\SurveysSummaries;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\SurveySummary;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
|
||||
/**
|
||||
* Service that serves surveys and participants of surveys
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyService
|
||||
{
|
||||
/**
|
||||
* Client of the LimeSurvey's API
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* All surveys.
|
||||
* Collection of surveys (the Survey class instances).
|
||||
*
|
||||
* @var Surveys
|
||||
*/
|
||||
private $allSurveys;
|
||||
|
||||
/**
|
||||
* Collection of participants' short data.
|
||||
* All participants grouped per survey.
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $allParticipants;
|
||||
|
||||
/**
|
||||
* Collection of surveys' summaries (the SurveySummary class instances)
|
||||
*
|
||||
* @var SurveysSummaries
|
||||
*/
|
||||
private $surveySummaries;
|
||||
|
||||
/**
|
||||
* Template of the url used to start survey
|
||||
*
|
||||
* Example:
|
||||
* - url: https://your.limesurvey.instance/12345?token=q1w2e3r4t5y6
|
||||
* - LimeSurvey frontend: https://your.limesurvey.instance
|
||||
* - survey ID: 12345
|
||||
* - token: q1w2e3r4t5y6
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $startSurveyUrlTemplate = '%s/%d?token=%s';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param Client $client Client of the LimeSurvey's API
|
||||
* @param Surveys $allSurveys (optional) All surveys. Collection of surveys (the Survey class
|
||||
* instances).
|
||||
* @param Participants $allParticipants (optional) Collection of participants' short data. All participants
|
||||
* grouped per survey.
|
||||
* @param SurveysSummaries $surveysSummaries (optional) Collection of surveys' summaries (the SurveySummary class
|
||||
* instances)
|
||||
*/
|
||||
public function __construct(
|
||||
Client $client,
|
||||
Surveys $allSurveys = null,
|
||||
Participants $allParticipants = null,
|
||||
SurveysSummaries $surveysSummaries = null
|
||||
) {
|
||||
if (null === $allSurveys) {
|
||||
$allSurveys = new Surveys();
|
||||
}
|
||||
|
||||
if (null === $allParticipants) {
|
||||
$allParticipants = new Participants();
|
||||
}
|
||||
|
||||
if (null === $surveysSummaries) {
|
||||
$surveysSummaries = new SurveysSummaries();
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
$this->allSurveys = $allSurveys;
|
||||
$this->allParticipants = $allParticipants;
|
||||
$this->surveySummaries = $surveysSummaries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns client of the LimeSurvey's API
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
public function getClient()
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all surveys
|
||||
*
|
||||
* @param bool $onlyActive (optional) If is set to true, active surveys are returned only. Otherwise - all (default
|
||||
* behaviour).
|
||||
* @return Surveys
|
||||
*
|
||||
* @throws CannotProcessDataException
|
||||
*/
|
||||
public function getAllSurveys($onlyActive = false)
|
||||
{
|
||||
if ($this->allSurveys->isEmpty()) {
|
||||
$surveys = new Surveys();
|
||||
|
||||
try {
|
||||
$surveys = $this
|
||||
->client
|
||||
->run(MethodType::LIST_SURVEYS)
|
||||
->getData();
|
||||
} catch (CannotProcessDataException $exception) {
|
||||
$reason = $exception->getReason();
|
||||
|
||||
/*
|
||||
* Reason of the exception is different than "Oops, there is no surveys. Everything else is fine."?
|
||||
* Let's throw the exception
|
||||
*/
|
||||
if (ReasonType::NO_SURVEYS_FOUND !== $reason) {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $surveys && $surveys instanceof Collection) {
|
||||
$this->allSurveys = new Surveys($surveys->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->allSurveys->getAll($onlyActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information if survey with given ID exists
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function isExistingSurvey($surveyId, $shouldBeActive = false)
|
||||
{
|
||||
$allSurveys = $this->getAllSurveys($shouldBeActive);
|
||||
|
||||
/*
|
||||
* No surveys?
|
||||
* Nothing to do
|
||||
*/
|
||||
if ($allSurveys->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$surveyId = (int)$surveyId;
|
||||
|
||||
/* @var Survey $survey */
|
||||
foreach ($allSurveys as $survey) {
|
||||
if ($survey->getId() == $surveyId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
* @param int $surveyId ID of survey to start
|
||||
* @param Participant $participant Participant who would like to start survey
|
||||
* @return string
|
||||
*/
|
||||
public function getStartSurveyUrl($surveyId, Participant $participant)
|
||||
{
|
||||
return $this->getStartSurveyUrlByToken($surveyId, $participant->getToken());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns participants of given 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
|
||||
*/
|
||||
public function getSurveyParticipants($surveyId, $onlyCompleted = false)
|
||||
{
|
||||
$hasSurvey = $this
|
||||
->allParticipants
|
||||
->hasParticipantsOfSurvey($surveyId);
|
||||
|
||||
if (!$hasSurvey) {
|
||||
$offset = 0;
|
||||
$limit = $this->getSurveyTokenCount($surveyId);
|
||||
$includeUnused = !$onlyCompleted;
|
||||
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
$offset,
|
||||
$limit,
|
||||
$includeUnused,
|
||||
];
|
||||
|
||||
try {
|
||||
$participants = $this
|
||||
->client
|
||||
->run(MethodType::LIST_PARTICIPANTS, $arguments)
|
||||
->getData();
|
||||
} catch (CannotProcessDataException $exception) {
|
||||
/*
|
||||
* Oops, something is broken, because the reason is different than "there are no participants"
|
||||
*/
|
||||
if (ReasonType::NO_PARTICIPANTS_FOUND !== $exception->getReason()) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$participants = new Collection();
|
||||
}
|
||||
|
||||
$this
|
||||
->allParticipants
|
||||
->addParticipants($participants, $surveyId);
|
||||
}
|
||||
|
||||
return $this
|
||||
->allParticipants
|
||||
->getBySurvey($surveyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds participant with given data to survey with given ID
|
||||
*
|
||||
* @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
|
||||
* @return Participant
|
||||
*/
|
||||
public function addParticipant($surveyId, $firstName, $lastName, $email)
|
||||
{
|
||||
$participantsData = [
|
||||
[
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
],
|
||||
];
|
||||
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
$participantsData,
|
||||
];
|
||||
|
||||
$participantCollection = $this
|
||||
->client
|
||||
->run(MethodType::ADD_PARTICIPANTS, $arguments)
|
||||
->getData();
|
||||
|
||||
/* @var Participant $addedParticipant */
|
||||
$addedParticipant = $participantCollection->getFirst();
|
||||
|
||||
$participants = new Collection([
|
||||
ParticipantShort::fromParticipant($addedParticipant),
|
||||
]);
|
||||
|
||||
$this
|
||||
->allParticipants
|
||||
->addParticipants($participants, $surveyId);
|
||||
|
||||
return $participantCollection->getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return ParticipantShort|null
|
||||
*/
|
||||
public function getParticipant($surveyId, $email)
|
||||
{
|
||||
/*
|
||||
* I have to get all participants of survey to avoid problem when participants exist but are not loaded
|
||||
*/
|
||||
$this->getSurveyParticipants($surveyId);
|
||||
|
||||
$participant = $this
|
||||
->allParticipants
|
||||
->getParticipantOfSurvey($surveyId, $email);
|
||||
|
||||
/* @var ParticipantShort $participant */
|
||||
return $participant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count/amount of tokens of survey with given ID
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return int
|
||||
*
|
||||
* @throws MissingSurveySummaryException
|
||||
*/
|
||||
public function getSurveyTokenCount($surveyId)
|
||||
{
|
||||
$surveySummary = $this
|
||||
->surveySummaries
|
||||
->getSurveySummary($surveyId);
|
||||
|
||||
/*
|
||||
* Unknown survey's summary?
|
||||
* Let's fetch it
|
||||
*/
|
||||
if (null === $surveySummary) {
|
||||
$surveySummary = $this->getSurveySummary($surveyId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Oops, survey's summary is missing
|
||||
*/
|
||||
if (null === $surveySummary) {
|
||||
throw new MissingSurveySummaryException($surveyId);
|
||||
}
|
||||
|
||||
return $surveySummary->getTokenCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns summary of survey with given ID
|
||||
*
|
||||
* @param int $surveyId ID of survey
|
||||
* @return SurveySummary|null
|
||||
*/
|
||||
private function getSurveySummary($surveyId)
|
||||
{
|
||||
$arguments = [
|
||||
$surveyId,
|
||||
];
|
||||
|
||||
/* @var SurveySummary $surveySummary */
|
||||
$surveySummary = $this
|
||||
->client
|
||||
->run(MethodType::GET_SUMMARY, $arguments)
|
||||
->getData();
|
||||
|
||||
if (null !== $surveySummary) {
|
||||
$this
|
||||
->surveySummaries
|
||||
->addSurveySummary($surveySummary, $surveyId);
|
||||
}
|
||||
|
||||
return $surveySummary;
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,13 @@ class MethodType extends BaseType
|
||||
*/
|
||||
const GET_QUESTION_PROPERTIES = 'get_question_properties';
|
||||
|
||||
/**
|
||||
* Get survey summary, regarding token usage and survey participation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const GET_SUMMARY = 'get_summary';
|
||||
|
||||
/**
|
||||
* Return the IDs and properties of token/participants of a survey
|
||||
*
|
||||
49
src/Type/ReasonType.php
Normal file
49
src/Type/ReasonType.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Meritoo\LimeSurvey\ApiClient\Type;
|
||||
|
||||
use Meritoo\Common\Type\Base\BaseType;
|
||||
|
||||
/**
|
||||
* Type of reason used by LimeSurvey's exception
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ReasonType extends BaseType
|
||||
{
|
||||
/**
|
||||
* Reason of exception when there is no survey with given ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NOT_EXISTING_SURVEY_ID = 'Error: Invalid survey ID';
|
||||
|
||||
/**
|
||||
* Reason of exception when there is no participants of survey
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NO_PARTICIPANTS_FOUND = 'No survey participants found.';
|
||||
|
||||
/**
|
||||
* Reason of exception when there is no participant's properties/details
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NO_PARTICIPANT_PROPERTIES = 'Error: No results were found based on your attributes.';
|
||||
|
||||
/**
|
||||
* Reason of exception when there is no surveys
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NO_SURVEYS_FOUND = 'No surveys found';
|
||||
|
||||
/**
|
||||
* Reason of exception when there is no table with tokens/participants of survey
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NO_TOKEN_TABLE = 'Error: No token table';
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Base\Result;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
|
||||
/**
|
||||
@@ -21,31 +22,11 @@ class BaseItemTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(BaseItem::class);
|
||||
static::assertConstructorVisibilityAndArguments(BaseItem::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testSetValues()
|
||||
public function testSetValuesVisibilityAndArguments()
|
||||
{
|
||||
$mock = $this->getBaseItemMock();
|
||||
|
||||
static::assertInstanceOf(BaseItem::class, $mock->setValues([]));
|
||||
static::assertInstanceOf(BaseItem::class, $mock->setValues(['lorem']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mock of the tested class
|
||||
*
|
||||
* @return BaseItem
|
||||
*/
|
||||
private function getBaseItemMock()
|
||||
{
|
||||
$mock = $this->getMockForAbstractClass(BaseItem::class);
|
||||
|
||||
$mock
|
||||
->expects(static::any())
|
||||
->method('setValue')
|
||||
->willReturn(null);
|
||||
|
||||
return $mock;
|
||||
static::assertMethodVisibilityAndArguments(BaseItem::class, 'setValues', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
}
|
||||
@@ -45,35 +45,48 @@ class ClientTest extends BaseTestCase
|
||||
*/
|
||||
public function testRunWithIncorrectMethod($incorrectMethod)
|
||||
{
|
||||
$this->expectException(UnknownMethodException::class);
|
||||
$this->setExpectedException(UnknownMethodException::class);
|
||||
|
||||
$client = new Client($this->configuration);
|
||||
$client->run($incorrectMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method Name of method to call
|
||||
* @param array $arguments Arguments of the method to call
|
||||
* @param bool $debugMode If is set to true, the "debug" mode is turned on. Otherwise - turned off.
|
||||
* @param string $method Name of method to call
|
||||
* @param array $arguments Arguments of the method to call
|
||||
* @param bool $debugMode If is set to true, the "debug" mode is turned on. Otherwise - turned off.
|
||||
* @param mixed $expectedRawData Expected raw data returned by JsonRpcClient
|
||||
*
|
||||
* @dataProvider provideMethod
|
||||
*/
|
||||
public function testRun($method, $arguments, $debugMode)
|
||||
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())
|
||||
->method('runMethod')
|
||||
->willReturn([]);
|
||||
->willReturn($expectedRawData);
|
||||
|
||||
$this->configuration->setDebugMode($debugMode);
|
||||
$client = new Client($this->configuration, $rpcClientManager, $sessionManager);
|
||||
$configuration = new ConnectionConfiguration(
|
||||
$this->configuration->getBaseUrl(),
|
||||
$this->configuration->getUsername(),
|
||||
$this->configuration->getPassword(),
|
||||
$debugMode,
|
||||
$this->configuration->isVerifySslCertificateOn()
|
||||
);
|
||||
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
static::assertInstanceOf(Result::class, $client->run($method, $arguments));
|
||||
}
|
||||
|
||||
public function testGetConfiguration()
|
||||
{
|
||||
$client = new Client($this->configuration);
|
||||
static::assertEquals($this->configuration, $client->getConfiguration());
|
||||
}
|
||||
|
||||
public function testGetRpcClientManagerVisibilityAndArguments()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(Client::class, 'getRpcClientManager', OopVisibilityType::IS_PRIVATE);
|
||||
@@ -115,18 +128,21 @@ class ClientTest extends BaseTestCase
|
||||
MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
[],
|
||||
true,
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
[],
|
||||
false,
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::LIST_PARTICIPANTS,
|
||||
[],
|
||||
false,
|
||||
null,
|
||||
];
|
||||
|
||||
/*
|
||||
140
tests/Configuration/ConnectionConfigurationTest.php
Normal file
140
tests/Configuration/ConnectionConfigurationTest.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Configuration;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Regex\InvalidUrlException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
|
||||
/**
|
||||
* Test case of the configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ConnectionConfigurationTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Configuration with default values of optional constructor's arguments
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $configurationWithDefaults;
|
||||
|
||||
/**
|
||||
* Configuration without default values of optional constructor's arguments
|
||||
*
|
||||
* @var ConnectionConfiguration
|
||||
*/
|
||||
private $configurationAnother;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 5, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $emptyBaseUrl Empty base url
|
||||
* @dataProvider provideEmptyBaseUrl
|
||||
*/
|
||||
public function testConstructorWithEmptyBaseUrl($emptyBaseUrl)
|
||||
{
|
||||
$this->setExpectedException(InvalidUrlException::class);
|
||||
new ConnectionConfiguration($emptyBaseUrl, '', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $invalidBaseUrl Invalid base url
|
||||
* @dataProvider provideInvalidBaseUrl
|
||||
*/
|
||||
public function testConstructorWithInvalidBaseUrl($invalidBaseUrl)
|
||||
{
|
||||
$this->setExpectedException(InvalidUrlException::class);
|
||||
new ConnectionConfiguration($invalidBaseUrl, '', '');
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
static::assertEquals('http://test.com', $this->configurationWithDefaults->getBaseUrl());
|
||||
static::assertEquals('test1', $this->configurationWithDefaults->getUsername());
|
||||
static::assertEquals('test2', $this->configurationWithDefaults->getPassword());
|
||||
static::assertFalse($this->configurationWithDefaults->isDebugModeOn());
|
||||
static::assertTrue($this->configurationWithDefaults->isVerifySslCertificateOn());
|
||||
|
||||
static::assertEquals('http://lets-test.com', $this->configurationAnother->getBaseUrl());
|
||||
static::assertEquals('test11', $this->configurationAnother->getUsername());
|
||||
static::assertEquals('test22', $this->configurationAnother->getPassword());
|
||||
static::assertTrue($this->configurationAnother->isDebugModeOn());
|
||||
static::assertFalse($this->configurationAnother->isVerifySslCertificateOn());
|
||||
}
|
||||
|
||||
public function testGetRemoteControlUrl()
|
||||
{
|
||||
$this->configurationWithDefaults->setRemoteControlUrl('lorem/ipsum');
|
||||
static::assertEquals('lorem/ipsum', $this->configurationWithDefaults->getRemoteControlUrl());
|
||||
|
||||
$this->configurationAnother->setRemoteControlUrl('dolor/sit');
|
||||
static::assertEquals('dolor/sit', $this->configurationAnother->getRemoteControlUrl());
|
||||
}
|
||||
|
||||
public function testGetFullUrl()
|
||||
{
|
||||
$this->configurationWithDefaults->setRemoteControlUrl('lorem/ipsum');
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $this->configurationWithDefaults->getFullUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides empty base url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideEmptyBaseUrl()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid base url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideInvalidBaseUrl()
|
||||
{
|
||||
yield[
|
||||
'lorem',
|
||||
];
|
||||
|
||||
yield[
|
||||
'ipsum',
|
||||
];
|
||||
|
||||
yield[
|
||||
'htp:/dolor.com',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->configurationWithDefaults = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$this->configurationAnother = new ConnectionConfiguration('http://lets-test.com/', 'test11', 'test22', true, false);
|
||||
}
|
||||
}
|
||||
58
tests/Exception/IncorrectClassOfResultItemExceptionTest.php
Normal file
58
tests/Exception/IncorrectClassOfResultItemExceptionTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Exception;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\IncorrectClassOfResultItemException;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while class used to create instance of one item of the result is incorrect
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class IncorrectClassOfResultItemExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(IncorrectClassOfResultItemException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className Incorrect class name used to create instance of one item
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideIncorrectClassName
|
||||
*/
|
||||
public function testConstructorMessage($className, $expectedMessage)
|
||||
{
|
||||
$exception = new IncorrectClassOfResultItemException($className);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect class name used to create instance of one item
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideIncorrectClassName()
|
||||
{
|
||||
$template = 'Class %s used to create instance of one item of the result should extend %s, but it does not. Did'
|
||||
. ' you forget to use proper base class?';
|
||||
|
||||
yield[
|
||||
stdClass::class,
|
||||
sprintf($template, stdClass::class, BaseItem::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
63
tests/Exception/MissingParticipantOfSurveyExceptionTest.php
Normal file
63
tests/Exception/MissingParticipantOfSurveyExceptionTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Exception;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingParticipantOfSurveyException;
|
||||
|
||||
/**
|
||||
* Test case of an exception used when participant of survey is missing
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MissingParticipantOfSurveyExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(MissingParticipantOfSurveyException::class, OopVisibilityType::IS_PUBLIC, 2, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $email E-mail address of the participant
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideSurveyIdAndEmail
|
||||
*/
|
||||
public function testConstructorMessage($surveyId, $email, $expectedMessage)
|
||||
{
|
||||
$exception = new MissingParticipantOfSurveyException($surveyId, $email);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides ID of survey and e-mail address of the participant
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideSurveyIdAndEmail()
|
||||
{
|
||||
$template = 'Participant with e-mail %s of survey with ID %s is missing. Maybe was not added to the survey?';
|
||||
|
||||
yield[
|
||||
1,
|
||||
'lorem@ipsum.com',
|
||||
sprintf($template, 'lorem@ipsum.com', 1),
|
||||
];
|
||||
|
||||
yield[
|
||||
1234,
|
||||
'another@email.comm',
|
||||
sprintf($template, 'another@email.comm', 1234),
|
||||
];
|
||||
}
|
||||
}
|
||||
60
tests/Exception/MissingSurveySummaryExceptionTest.php
Normal file
60
tests/Exception/MissingSurveySummaryExceptionTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Exception;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingSurveySummaryException;
|
||||
|
||||
/**
|
||||
* Test case of an exception used when survey's summary is missing
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class MissingSurveySummaryExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(MissingSurveySummaryException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $surveyId ID of survey
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideSurveyId
|
||||
*/
|
||||
public function testConstructorMessage($surveyId, $expectedMessage)
|
||||
{
|
||||
$exception = new MissingSurveySummaryException($surveyId);
|
||||
static::assertEquals($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides ID of survey
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideSurveyId()
|
||||
{
|
||||
$template = 'Summary of survey with ID %d is missing. Does the survey exist?';
|
||||
|
||||
yield[
|
||||
1,
|
||||
sprintf($template, 1),
|
||||
];
|
||||
|
||||
yield[
|
||||
'123',
|
||||
sprintf($template, '123'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -49,17 +49,17 @@ class UnknownInstanceOfResultItemTest extends BaseTestCase
|
||||
*/
|
||||
public function provideMethodName()
|
||||
{
|
||||
$template = 'Instance of one item used by result the of \'%s\' LimeSurvey API\'s method is unknown. Proper'
|
||||
. ' class is not mapped in %s::%s() method. Did you forget about this?';
|
||||
$template = 'Class name used to create instance of one item used by result the of \'%s\' LimeSurvey API\'s'
|
||||
. ' method is unknown. Proper class is not mapped in %s::%s() method. Did you forget about this?';
|
||||
|
||||
yield[
|
||||
MethodType::LIST_SURVEYS,
|
||||
sprintf($template, MethodType::LIST_SURVEYS, ResultProcessor::class, 'getItemInstance'),
|
||||
sprintf($template, MethodType::LIST_SURVEYS, ResultProcessor::class, 'getItemClassName'),
|
||||
];
|
||||
|
||||
yield[
|
||||
MethodType::ADD_PARTICIPANTS,
|
||||
sprintf($template, MethodType::ADD_PARTICIPANTS, ResultProcessor::class, 'getItemInstance'),
|
||||
sprintf($template, MethodType::ADD_PARTICIPANTS, ResultProcessor::class, 'getItemClassName'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
@@ -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())
|
||||
@@ -1,152 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Configuration;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Regex\InvalidUrlException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
|
||||
/**
|
||||
* Test case of the configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ConnectionConfigurationTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 4, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $emptyBaseUrl Empty base url
|
||||
* @dataProvider provideEmptyBaseUrl
|
||||
*/
|
||||
public function testConstructorWithEmptyBaseUrl($emptyBaseUrl)
|
||||
{
|
||||
$this->expectException(InvalidUrlException::class);
|
||||
new ConnectionConfiguration($emptyBaseUrl, '', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $invalidBaseUrl Invalid base url
|
||||
* @dataProvider provideInvalidBaseUrl
|
||||
*/
|
||||
public function testConstructorWithInvalidBaseUrl($invalidBaseUrl)
|
||||
{
|
||||
$this->expectException(InvalidUrlException::class);
|
||||
new ConnectionConfiguration($invalidBaseUrl, '', '');
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
|
||||
static::assertEquals('http://test.com', $configuration->getBaseUrl());
|
||||
static::assertEquals('test1', $configuration->getUsername());
|
||||
static::assertEquals('test2', $configuration->getPassword());
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
}
|
||||
|
||||
public function testSetBaseUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
|
||||
$configuration->setBaseUrl('http://lorem.ipsum/');
|
||||
static::assertEquals('http://lorem.ipsum', $configuration->getBaseUrl());
|
||||
}
|
||||
|
||||
public function testSetRemoteControlUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('/lorem/ipsum');
|
||||
|
||||
static::assertEquals('/lorem/ipsum', $configuration->getRemoteControlUrl());
|
||||
}
|
||||
|
||||
public function testSetUsername()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setUsername('lorem');
|
||||
|
||||
static::assertEquals('lorem', $configuration->getUsername());
|
||||
}
|
||||
|
||||
public function testSetPassword()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setPassword('ipsum');
|
||||
|
||||
static::assertEquals('ipsum', $configuration->getPassword());
|
||||
}
|
||||
|
||||
public function testSetDebugMode()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
|
||||
$configuration->setDebugMode();
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode(false);
|
||||
static::assertFalse($configuration->isDebugModeOn());
|
||||
|
||||
$configuration->setDebugMode(true);
|
||||
static::assertTrue($configuration->isDebugModeOn());
|
||||
}
|
||||
|
||||
public function testGetFullUrl()
|
||||
{
|
||||
$configuration = new ConnectionConfiguration('http://test.com', 'test1', 'test2');
|
||||
$configuration->setRemoteControlUrl('lorem/ipsum');
|
||||
|
||||
static::assertEquals('http://test.com/lorem/ipsum', $configuration->getFullUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides empty base url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideEmptyBaseUrl()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid base url
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideInvalidBaseUrl()
|
||||
{
|
||||
yield[
|
||||
'lorem',
|
||||
];
|
||||
|
||||
yield[
|
||||
'ipsum',
|
||||
];
|
||||
|
||||
yield[
|
||||
'htp:/dolor.com',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Service;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Service\ParticipantService;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the service that serves participants
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Serves participants.
|
||||
* Service without participants.
|
||||
*
|
||||
* @var ParticipantService
|
||||
*/
|
||||
private $serviceWithoutParticipants;
|
||||
|
||||
/**
|
||||
* Serves participants.
|
||||
* Service with participants.
|
||||
*
|
||||
* @var ParticipantService
|
||||
*/
|
||||
private $serviceWithParticipants;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ParticipantService::class, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsFromEmptyParticipants()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(3);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(2));
|
||||
|
||||
static::assertCount(2, $this->serviceWithParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(1, $this->serviceWithParticipants->getSurveyParticipants(2));
|
||||
static::assertCount(0, $this->serviceWithParticipants->getSurveyParticipants(3));
|
||||
}
|
||||
|
||||
public function testHasParticipant()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(3);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertFalse($this->serviceWithoutParticipants->hasParticipant(1, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithoutParticipants->hasParticipant(2, 'john@scott.com'));
|
||||
|
||||
static::assertTrue($this->serviceWithParticipants->hasParticipant(1, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(2, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(3, 'john@scott.com'));
|
||||
}
|
||||
|
||||
public function testAddParticipant()
|
||||
{
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
$runMethodCallCount = 1;
|
||||
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager($runMethodCallCount, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$result = $this->serviceWithoutParticipants->addParticipant(1, $firstName, $lastName, $email);
|
||||
static::assertInstanceOf(Participant::class, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return ConnectionConfiguration
|
||||
*/
|
||||
private function getConnectionConfiguration()
|
||||
{
|
||||
return new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getSessionManager()
|
||||
{
|
||||
return $this->createMock(SessionManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param array $runMethodCallResults (optional) Results of calls of the runMethod() method (who is mocked)
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
|
||||
{
|
||||
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod')
|
||||
->will(static::returnValue($runMethodCallResults));
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service without participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithoutParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutParticipants = new ParticipantService($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service with participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$allParticipants = new Participants([
|
||||
1 => new Collection([
|
||||
(new Participant())->setValues([
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
]),
|
||||
new Participant(),
|
||||
]),
|
||||
2 => new Collection([
|
||||
new Participant(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithParticipants = new ParticipantService($client, $allParticipants);
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Service;
|
||||
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Service\SurveyService;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the service that serves surveys
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Serves surveys.
|
||||
* Service without surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithoutSurveys;
|
||||
|
||||
/**
|
||||
* Serves surveys.
|
||||
* Service with surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithSurveys;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveyService::class, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
public function testGetAllSurveys()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertCount(0, $this->serviceWithoutSurveys->getAllSurveys());
|
||||
static::assertCount(2, $this->serviceWithSurveys->getAllSurveys());
|
||||
}
|
||||
|
||||
public function testIsExistingSurvey()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(1));
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(2));
|
||||
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(1));
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(2));
|
||||
static::assertFalse($this->serviceWithSurveys->isExistingSurvey(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return ConnectionConfiguration
|
||||
*/
|
||||
private function getConnectionConfiguration()
|
||||
{
|
||||
return new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getSessionManager()
|
||||
{
|
||||
return $this->createMock(SessionManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param array $runMethodCallResults (optional) Results of calls of the runMethod() method (who is mocked)
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
|
||||
{
|
||||
$rpcClientManager = $this->createMock(JsonRpcClientManager::class);
|
||||
|
||||
$rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod')
|
||||
->will(static::returnValue($runMethodCallResults));
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service without surveys
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithoutSurveys(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutSurveys = new SurveyService($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service with surveys
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithSurveys(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$allSurveys = new Collection([
|
||||
(new Survey())->setValues([
|
||||
'sid' => 1,
|
||||
'surveyls_title' => 'Test',
|
||||
]),
|
||||
(new Survey())->setValues([
|
||||
'sid' => 2,
|
||||
'surveyls_title' => 'Another Test',
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithSurveys = new SurveyService($client, $allSurveys);
|
||||
}
|
||||
}
|
||||
0
tests/Resources/var/cache/.gitkeep
vendored
Normal file
0
tests/Resources/var/cache/.gitkeep
vendored
Normal file
0
tests/Resources/var/log/.gitkeep
Normal file
0
tests/Resources/var/log/.gitkeep
Normal file
0
tests/Resources/var/sessions/.gitkeep
Normal file
0
tests/Resources/var/sessions/.gitkeep
Normal file
@@ -14,9 +14,10 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
|
||||
/**
|
||||
* Test case of the participants of survey
|
||||
* Test case of the collection of participants' short data
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
@@ -24,21 +25,21 @@ use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
class ParticipantsTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* An empty collection of participants
|
||||
* An empty collection of participants' short data
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsEmpty;
|
||||
|
||||
/**
|
||||
* Participants of 1 survey
|
||||
* Collection of participants of 1 survey
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
private $participantsOfOneSurvey;
|
||||
|
||||
/**
|
||||
* Participants of more than 1 survey
|
||||
* Collection of participants of more than 1 survey
|
||||
*
|
||||
* @var Participants
|
||||
*/
|
||||
@@ -51,17 +52,23 @@ 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 testAddParticipantsWithoutParticipants()
|
||||
public function testHas()
|
||||
{
|
||||
$this->setExpectedException(DisabledMethodException::class);
|
||||
(new Participants())->has(new Participant());
|
||||
}
|
||||
|
||||
public function testAddParticipantsUsingEmptyCollection()
|
||||
{
|
||||
$surveyId = 1;
|
||||
|
||||
@@ -115,6 +122,55 @@ class ParticipantsTest extends BaseTestCase
|
||||
static::assertCount(2, $this->participantsOfOneSurvey->getBySurvey($surveyId));
|
||||
}
|
||||
|
||||
public function testAddParticipantFirstParticipant()
|
||||
{
|
||||
$surveyId = 1;
|
||||
$email = 'john@scott.com';
|
||||
|
||||
$participant = new ParticipantShort([
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => $email,
|
||||
],
|
||||
]);
|
||||
|
||||
$participants = new Participants();
|
||||
$result = $participants->addParticipant($participant, $surveyId);
|
||||
|
||||
static::assertEquals($participants, $result);
|
||||
static::assertEquals($participant, $participants->getParticipantOfSurvey($surveyId, $email));
|
||||
|
||||
static::assertTrue($participants->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($participants->hasParticipantsOfSurvey(2));
|
||||
}
|
||||
|
||||
public function testAddParticipantNotFirstParticipant()
|
||||
{
|
||||
$surveyId = 1;
|
||||
$email = 'john@scott.com';
|
||||
|
||||
$participant = new ParticipantShort([
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => $email,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = $this
|
||||
->participantsOfOneSurvey
|
||||
->addParticipant($participant, $surveyId);
|
||||
|
||||
static::assertEquals($this->participantsOfOneSurvey, $result);
|
||||
static::assertEquals($participant, $this->participantsOfOneSurvey->getParticipantOfSurvey($surveyId, $email));
|
||||
|
||||
static::assertTrue($this->participantsOfOneSurvey->hasParticipantsOfSurvey($surveyId));
|
||||
static::assertFalse($this->participantsOfOneSurvey->hasParticipantsOfSurvey(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
174
tests/Result/Collection/SurveysSummariesTest.php
Normal file
174
tests/Result/Collection/SurveysSummariesTest.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Collection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Method\DisabledMethodException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\SurveysSummaries;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\SurveySummary;
|
||||
|
||||
/**
|
||||
* Test case of the collection of surveys' summaries (the SurveySummary class instances)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveysSummariesTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Empty collection of surveys' summaries
|
||||
*
|
||||
* @var SurveysSummaries
|
||||
*/
|
||||
private $emptySurveysSummaries;
|
||||
|
||||
/**
|
||||
* Non-empty collection of surveys' summaries
|
||||
*
|
||||
* @var SurveysSummaries
|
||||
*/
|
||||
private $nonEmptySurveysSummaries;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveysSummaries::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$this->setExpectedException(DisabledMethodException::class);
|
||||
(new SurveysSummaries())->add('');
|
||||
}
|
||||
|
||||
public function testAddMultiple()
|
||||
{
|
||||
$this->setExpectedException(DisabledMethodException::class);
|
||||
(new SurveysSummaries())->addMultiple([]);
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->setExpectedException(DisabledMethodException::class);
|
||||
(new SurveysSummaries())->has(new SurveySummary());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $summaries Surveys' summaries to add
|
||||
* @dataProvider provideSurveysSummaries
|
||||
*/
|
||||
public function testAddSurveysSummaries(array $summaries)
|
||||
{
|
||||
$existingSummariesCount = $this->nonEmptySurveysSummaries->count();
|
||||
|
||||
$this->emptySurveysSummaries->addSurveysSummaries($summaries);
|
||||
$this->nonEmptySurveysSummaries->addSurveysSummaries($summaries);
|
||||
|
||||
static::assertCount(count($summaries), $this->emptySurveysSummaries);
|
||||
static::assertCount(count($summaries) + $existingSummariesCount, $this->nonEmptySurveysSummaries);
|
||||
}
|
||||
|
||||
public function testHasSurveySummaryUsingNonExistingSurvey()
|
||||
{
|
||||
static::assertFalse($this->emptySurveysSummaries->hasSurveySummary(1));
|
||||
static::assertFalse($this->emptySurveysSummaries->hasSurveySummary(2));
|
||||
|
||||
static::assertFalse($this->nonEmptySurveysSummaries->hasSurveySummary(3));
|
||||
static::assertFalse($this->nonEmptySurveysSummaries->hasSurveySummary(4));
|
||||
}
|
||||
|
||||
public function testHasSurveySummaryUsingExistingSurvey()
|
||||
{
|
||||
static::assertTrue($this->nonEmptySurveysSummaries->hasSurveySummary(1));
|
||||
static::assertTrue($this->nonEmptySurveysSummaries->hasSurveySummary(2));
|
||||
}
|
||||
|
||||
public function testGetSurveySummaryUsingNonExistingSurvey()
|
||||
{
|
||||
static::assertNull($this->emptySurveysSummaries->getSurveySummary(1));
|
||||
static::assertNull($this->emptySurveysSummaries->getSurveySummary(2));
|
||||
|
||||
static::assertNull($this->nonEmptySurveysSummaries->getSurveySummary(3));
|
||||
static::assertNull($this->nonEmptySurveysSummaries->getSurveySummary(4));
|
||||
}
|
||||
|
||||
public function testGetSurveySummaryUsingExistingSurvey()
|
||||
{
|
||||
$surveySummary1 = $this->nonEmptySurveysSummaries->getSurveySummary(1);
|
||||
$surveySummary2 = $this->nonEmptySurveysSummaries->getSurveySummary(2);
|
||||
|
||||
static::assertInstanceOf(SurveySummary::class, $surveySummary1);
|
||||
static::assertInstanceOf(SurveySummary::class, $surveySummary2);
|
||||
|
||||
static::assertEquals(0, $surveySummary1->getTokenCount());
|
||||
static::assertEquals(5, $surveySummary2->getTokenCount());
|
||||
|
||||
static::assertEquals(0, $surveySummary1->getFullResponsesCount());
|
||||
static::assertEquals(3, $surveySummary2->getFullResponsesCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides surveys' summaries
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideSurveysSummaries()
|
||||
{
|
||||
yield[
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
123 => new SurveySummary(),
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
100 => new SurveySummary(),
|
||||
500 => new SurveySummary(),
|
||||
800 => new SurveySummary(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->emptySurveysSummaries = new SurveysSummaries();
|
||||
|
||||
$this->nonEmptySurveysSummaries = new SurveysSummaries([
|
||||
1 => new SurveySummary([
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
]),
|
||||
2 => new SurveySummary([
|
||||
'token_count' => '5',
|
||||
'token_invalid' => '2',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '2',
|
||||
'completed_responses' => '1',
|
||||
'incomplete_responses' => '2',
|
||||
'full_responses' => '3',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
108
tests/Result/Collection/SurveysTest.php
Normal file
108
tests/Result/Collection/SurveysTest.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Collection;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
|
||||
/**
|
||||
* Test case of the collection of surveys (the Survey class instances)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveysTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* An empty collection of surveys
|
||||
*
|
||||
* @var Surveys
|
||||
*/
|
||||
private $surveysEmpty;
|
||||
|
||||
/**
|
||||
* Not empty collection of surveys
|
||||
*
|
||||
* @var Surveys
|
||||
*/
|
||||
private $surveysNotEmpty;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(Surveys::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testAddWithoutIndex()
|
||||
{
|
||||
$survey1 = new Survey([
|
||||
'sid' => 3,
|
||||
'surveyls_title' => 'Test Test Test',
|
||||
]);
|
||||
|
||||
$survey2 = new Survey([
|
||||
'sid' => 4,
|
||||
'surveyls_title' => 'Another Test Test Test',
|
||||
]);
|
||||
|
||||
$this
|
||||
->surveysEmpty
|
||||
->add($survey1)
|
||||
->add($survey2);
|
||||
|
||||
$this
|
||||
->surveysNotEmpty
|
||||
->add($survey1)
|
||||
->add($survey2);
|
||||
|
||||
static::assertEquals($survey1, $this->surveysEmpty[3]);
|
||||
static::assertEquals($survey2, $this->surveysEmpty[4]);
|
||||
|
||||
static::assertEquals($survey1, $this->surveysNotEmpty[3]);
|
||||
static::assertEquals($survey2, $this->surveysNotEmpty[4]);
|
||||
}
|
||||
|
||||
public function testGetAll()
|
||||
{
|
||||
static::assertCount(0, $this->surveysEmpty->getAll());
|
||||
static::assertCount(0, $this->surveysEmpty->getAll(true));
|
||||
|
||||
static::assertCount(3, $this->surveysNotEmpty->getAll());
|
||||
static::assertCount(2, $this->surveysNotEmpty->getAll(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$surveys = [
|
||||
new Survey([
|
||||
'sid' => 1,
|
||||
'surveyls_title' => 'Test',
|
||||
'active' => 'Y',
|
||||
]),
|
||||
new Survey([
|
||||
'sid' => 2,
|
||||
'surveyls_title' => 'Another Test',
|
||||
'active' => 'Y',
|
||||
]),
|
||||
new Survey([
|
||||
'sid' => 3,
|
||||
'surveyls_title' => 'I am inactive',
|
||||
]),
|
||||
];
|
||||
|
||||
$this->surveysEmpty = new Surveys();
|
||||
$this->surveysNotEmpty = new Surveys($surveys);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
@@ -44,7 +46,7 @@ class ParticipantShortTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(ParticipantShort::class);
|
||||
static::assertConstructorVisibilityAndArguments(ParticipantShort::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testCreateOfTheParticipant()
|
||||
@@ -79,33 +81,50 @@ class ParticipantShortTest extends BaseTestCase
|
||||
static::assertEquals('dolor@sit.com', $this->participant2ndInstance->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of participants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getParticipantsRawData()
|
||||
public function testFromParticipantUsingEmptyParticipant()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tid' => '123',
|
||||
'token' => uniqid(),
|
||||
'participant_info' => [
|
||||
'firstname' => 'Lorem',
|
||||
'lastname' => 'Ipsum',
|
||||
'email' => 'lorem@ipsum.com',
|
||||
],
|
||||
],
|
||||
[
|
||||
'tid' => '456',
|
||||
'token' => uniqid(),
|
||||
'participant_info' => [
|
||||
'firstname' => 'Dolor',
|
||||
'lastname' => 'Sit',
|
||||
'email' => 'dolor@sit.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
$participant = new Participant();
|
||||
$participantShort = ParticipantShort::fromParticipant($participant);
|
||||
|
||||
static::assertEquals(0, $participantShort->getId());
|
||||
static::assertEquals('', $participantShort->getFirstName());
|
||||
static::assertEquals('', $participantShort->getLastName());
|
||||
static::assertEquals('', $participantShort->getEmail());
|
||||
|
||||
static::assertEquals($participant->getId(), $participantShort->getId());
|
||||
static::assertEquals($participant->getFirstName(), $participantShort->getFirstName());
|
||||
static::assertEquals($participant->getLastName(), $participantShort->getLastName());
|
||||
static::assertEquals($participant->getEmail(), $participantShort->getEmail());
|
||||
}
|
||||
|
||||
public function testFromParticipant()
|
||||
{
|
||||
$participant1 = new Participant([
|
||||
'tid' => $this->rawData[0]['tid'],
|
||||
'firstname' => $this->rawData[0]['participant_info']['firstname'],
|
||||
'lastname' => $this->rawData[0]['participant_info']['lastname'],
|
||||
'email' => $this->rawData[0]['participant_info']['email'],
|
||||
]);
|
||||
|
||||
$participant2 = new Participant([
|
||||
'tid' => $this->rawData[1]['tid'],
|
||||
'firstname' => $this->rawData[1]['participant_info']['firstname'],
|
||||
'lastname' => $this->rawData[1]['participant_info']['lastname'],
|
||||
'email' => $this->rawData[1]['participant_info']['email'],
|
||||
]);
|
||||
|
||||
$participantShort1 = ParticipantShort::fromParticipant($participant1);
|
||||
$participantShort2 = ParticipantShort::fromParticipant($participant2);
|
||||
|
||||
static::assertEquals($participant1->getId(), $participantShort1->getId());
|
||||
static::assertEquals($participant1->getFirstName(), $participantShort1->getFirstName());
|
||||
static::assertEquals($participant1->getLastName(), $participantShort1->getLastName());
|
||||
static::assertEquals($participant1->getEmail(), $participantShort1->getEmail());
|
||||
|
||||
static::assertEquals($participant2->getId(), $participantShort2->getId());
|
||||
static::assertEquals($participant2->getFirstName(), $participantShort2->getFirstName());
|
||||
static::assertEquals($participant2->getLastName(), $participantShort2->getLastName());
|
||||
static::assertEquals($participant2->getEmail(), $participantShort2->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +135,34 @@ class ParticipantShortTest extends BaseTestCase
|
||||
parent::setUp();
|
||||
$this->rawData = static::getParticipantsRawData();
|
||||
|
||||
$this->participant1stInstance = (new ParticipantShort())->setValues($this->rawData[0]);
|
||||
$this->participant2ndInstance = (new ParticipantShort())->setValues($this->rawData[1]);
|
||||
$this->participant1stInstance = new ParticipantShort($this->rawData[0]);
|
||||
$this->participant2ndInstance = new ParticipantShort($this->rawData[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of participants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getParticipantsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tid' => '123',
|
||||
'participant_info' => [
|
||||
'firstname' => 'Lorem',
|
||||
'lastname' => 'Ipsum',
|
||||
'email' => 'lorem@ipsum.com',
|
||||
],
|
||||
],
|
||||
[
|
||||
'tid' => '456',
|
||||
'participant_info' => [
|
||||
'firstname' => 'Dolor',
|
||||
'lastname' => 'Sit',
|
||||
'email' => 'dolor@sit.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,11 @@ namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: full data of participant
|
||||
@@ -45,7 +47,7 @@ class ParticipantTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Participant::class);
|
||||
static::assertConstructorVisibilityAndArguments(Participant::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testCreateOfTheParticipant()
|
||||
@@ -158,12 +160,24 @@ class ParticipantTest extends BaseTestCase
|
||||
static::assertNull($this->participant2ndInstance->getValidUntil());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getParticipantsRawData();
|
||||
|
||||
$this->participant1stInstance = new Participant($this->rawData[0]);
|
||||
$this->participant2ndInstance = new Participant($this->rawData[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of participants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getParticipantsRawData()
|
||||
private static function getParticipantsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
@@ -183,7 +197,7 @@ class ParticipantTest extends BaseTestCase
|
||||
'completed' => 'N',
|
||||
'usesleft' => 10,
|
||||
'validfrom' => null,
|
||||
'validuntil' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'validuntil' => DateUtility::getDateTime(),
|
||||
],
|
||||
[
|
||||
'tid' => '456',
|
||||
@@ -199,23 +213,11 @@ class ParticipantTest extends BaseTestCase
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 1,
|
||||
'completed' => 'Y',
|
||||
'completed' => DateUtility::getDateTime(false),
|
||||
'usesleft' => 5,
|
||||
'validfrom' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'validfrom' => DateUtility::getDateTime(),
|
||||
'validuntil' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getParticipantsRawData();
|
||||
|
||||
$this->participant1stInstance = (new Participant())->setValues($this->rawData[0]);
|
||||
$this->participant2ndInstance = (new Participant())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\QuestionShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
@@ -44,7 +45,7 @@ class QuestionShortTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(QuestionShort::class);
|
||||
static::assertConstructorVisibilityAndArguments(QuestionShort::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testCreateOfTheQuestionShort()
|
||||
@@ -157,12 +158,24 @@ class QuestionShortTest extends BaseTestCase
|
||||
static::assertEquals('HR', $this->question2ndInstance->getModuleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getQuestionsRawData();
|
||||
|
||||
$this->question1stInstance = new QuestionShort($this->rawData[0]);
|
||||
$this->question2ndInstance = new QuestionShort($this->rawData[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of questions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getQuestionsRawData()
|
||||
private static function getQuestionsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
@@ -213,16 +226,4 @@ class QuestionShortTest extends BaseTestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getQuestionsRawData();
|
||||
|
||||
$this->question1stInstance = (new QuestionShort())->setValues($this->rawData[0]);
|
||||
$this->question2ndInstance = (new QuestionShort())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Question;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
@@ -44,7 +45,7 @@ class QuestionTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Question::class);
|
||||
static::assertConstructorVisibilityAndArguments(Question::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testCreateOfTheQuestionShort()
|
||||
@@ -193,12 +194,24 @@ class QuestionTest extends BaseTestCase
|
||||
static::assertNull($this->question2ndInstance->getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getQuestionsRawData();
|
||||
|
||||
$this->question1stInstance = new Question($this->rawData[0]);
|
||||
$this->question2ndInstance = new Question($this->rawData[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns raw data of questions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getQuestionsRawData()
|
||||
private static function getQuestionsRawData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
@@ -275,16 +288,4 @@ class QuestionTest extends BaseTestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->rawData = static::getQuestionsRawData();
|
||||
|
||||
$this->question1stInstance = (new Question())->setValues($this->rawData[0]);
|
||||
$this->question2ndInstance = (new Question())->setValues($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
97
tests/Result/Item/SurveySummaryTest.php
Normal file
97
tests/Result/Item/SurveySummaryTest.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\SurveySummary;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: survey's summary (contains aggregated data)
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveySummaryTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveySummary::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $rawData Raw data of survey's summary
|
||||
* @dataProvider provideRawData
|
||||
*/
|
||||
public function testCreateOfTheSurveySummary(array $rawData)
|
||||
{
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::GET_SUMMARY, $rawData);
|
||||
|
||||
/* @var SurveySummary $processed */
|
||||
static::assertEquals($rawData['token_count'], $processed->getTokenCount());
|
||||
static::assertEquals($rawData['token_invalid'], $processed->getTokenInvalidCount());
|
||||
static::assertEquals($rawData['token_sent'], $processed->getTokenSentCount());
|
||||
static::assertEquals($rawData['token_opted_out'], $processed->getTokenOptedOutCount());
|
||||
static::assertEquals($rawData['token_completed'], $processed->getTokenCompletedCount());
|
||||
static::assertEquals($rawData['completed_responses'], $processed->getCompleteResponsesCount());
|
||||
static::assertEquals($rawData['incomplete_responses'], $processed->getIncompleteResponsesCount());
|
||||
static::assertEquals($rawData['full_responses'], $processed->getFullResponsesCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides raw data of survey's summary
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideRawData()
|
||||
{
|
||||
yield[
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'token_count' => '28',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '5',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '6',
|
||||
'completed_responses' => '6',
|
||||
'incomplete_responses' => '10',
|
||||
'full_responses' => '16',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
'token_count' => '28',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '2',
|
||||
'completed_responses' => '2',
|
||||
'incomplete_responses' => '12',
|
||||
'full_responses' => '14',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,11 @@ namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Item;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
|
||||
|
||||
/**
|
||||
* Test case of the one item of the result/data: survey
|
||||
@@ -45,7 +47,7 @@ class SurveyTest extends BaseTestCase
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(Survey::class);
|
||||
static::assertConstructorVisibilityAndArguments(Survey::class, OopVisibilityType::IS_PUBLIC, 1, 0);
|
||||
}
|
||||
|
||||
public function testCreateOfTheSurvey()
|
||||
@@ -98,13 +100,13 @@ class SurveyTest extends BaseTestCase
|
||||
'sid' => '123',
|
||||
'surveyls_title' => 'Test',
|
||||
'startdate' => null,
|
||||
'expires' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'expires' => DateUtility::getDateTime(),
|
||||
'active' => 'N',
|
||||
],
|
||||
[
|
||||
'sid' => '456',
|
||||
'surveyls_title' => 'Another Test',
|
||||
'startdate' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'startdate' => DateUtility::getDateTime(),
|
||||
'expires' => null,
|
||||
'active' => 'Y',
|
||||
],
|
||||
@@ -119,7 +121,7 @@ class SurveyTest extends BaseTestCase
|
||||
parent::setUp();
|
||||
$this->rawData = static::getSurveysRawData();
|
||||
|
||||
$this->survey1stInstance = (new Survey())->setValues($this->rawData[0]);
|
||||
$this->survey2ndInstance = (new Survey())->setValues($this->rawData[1]);
|
||||
$this->survey1stInstance = new Survey($this->rawData[0]);
|
||||
$this->survey2ndInstance = new Survey($this->rawData[1]);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\UnknownInstanceOfResultItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Result\Item\SurveyTest;
|
||||
@@ -39,12 +40,24 @@ class ResultProcessorTest extends BaseTestCase
|
||||
|
||||
public function testProcessWithIterableData()
|
||||
{
|
||||
$surveysRawData = SurveyTest::getSurveysRawData();
|
||||
$processor = new ResultProcessor();
|
||||
$processed = $processor->process(MethodType::LIST_SURVEYS, SurveyTest::getSurveysRawData());
|
||||
$processed = $processor->process(MethodType::LIST_SURVEYS, $surveysRawData);
|
||||
|
||||
static::assertNotEmpty($processed);
|
||||
static::assertTrue(is_array($processed));
|
||||
static::assertCount(2, $processed);
|
||||
|
||||
/* @var Survey $firstSurvey */
|
||||
$firstSurvey = $processed[0];
|
||||
|
||||
/* @var Survey $secondSurvey */
|
||||
$secondSurvey = $processed[1];
|
||||
|
||||
static::assertEquals($surveysRawData[0]['sid'], $firstSurvey->getId());
|
||||
static::assertEquals($surveysRawData[1]['sid'], $secondSurvey->getId());
|
||||
|
||||
static::assertEquals($surveysRawData[0]['surveyls_title'], $firstSurvey->getTitle());
|
||||
static::assertEquals($surveysRawData[1]['surveyls_title'], $secondSurvey->getTitle());
|
||||
}
|
||||
|
||||
public function testProcessWithNotIterableData()
|
||||
@@ -62,14 +75,14 @@ class ResultProcessorTest extends BaseTestCase
|
||||
static::assertInstanceOf(BaseItem::class, $processed);
|
||||
}
|
||||
|
||||
public function testGetItemInstanceVisibilityAndArguments()
|
||||
public function testGetItemClassNameVisibilityAndArguments()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(ResultProcessor::class, 'getItemInstance', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
static::assertMethodVisibilityAndArguments(ResultProcessor::class, 'getItemClassName', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
public function testRunWithUnknownResultClass()
|
||||
{
|
||||
$this->expectException(UnknownInstanceOfResultItem::class);
|
||||
$this->setExpectedException(UnknownInstanceOfResultItem::class);
|
||||
|
||||
$rawData = [
|
||||
'lorem' => 'ipsum',
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Result\Result;
|
||||
|
||||
use DateTime;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Base\Result\BaseItem;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Result;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
@@ -128,7 +128,7 @@ class ResultTest extends BaseTestCase
|
||||
|
||||
public function testGetDataUsingProcessedDataWhoCannotBeProcessed()
|
||||
{
|
||||
$this->expectException(CannotProcessDataException::class);
|
||||
$this->setExpectedException(CannotProcessDataException::class);
|
||||
$this->statusInsteadDataResult->getData();
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ class ResultTest extends BaseTestCase
|
||||
[
|
||||
'sid' => '456',
|
||||
'surveyls_title' => 'Another Test',
|
||||
'startdate' => (new DateTime())->format('Y-m-d H:i:s'),
|
||||
'startdate' => DateUtility::getDateTime(),
|
||||
'expires' => null,
|
||||
'active' => 'Y',
|
||||
],
|
||||
344
tests/Service/ParticipantServiceTest.php
Normal file
344
tests/Service/ParticipantServiceTest.php
Normal file
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Service;
|
||||
|
||||
use Exception;
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingParticipantOfSurveyException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\ParticipantsDetails;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Service\ParticipantService;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
use Meritoo\LimeSurvey\Test\ApiClient\Utilities\DateUtility;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the service that serves participants
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ParticipantServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Raw data of participants
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $participantsRawData;
|
||||
|
||||
/**
|
||||
* Service that serves participants.
|
||||
* Without participants.
|
||||
*
|
||||
* @var ParticipantService
|
||||
*/
|
||||
private $serviceWithoutParticipants;
|
||||
|
||||
/**
|
||||
* Service that serves participants.
|
||||
* With participants.
|
||||
*
|
||||
* @var ParticipantService
|
||||
*/
|
||||
private $serviceWithParticipants;
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(ParticipantService::class, OopVisibilityType::IS_PUBLIC, 2, 1);
|
||||
}
|
||||
|
||||
public function testGetClient()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertInstanceOf(Client::class, $this->serviceWithoutParticipants->getClient());
|
||||
static::assertInstanceOf(Client::class, $this->serviceWithParticipants->getClient());
|
||||
|
||||
$connectionConfiguration = $this->getConnectionConfiguration();
|
||||
$client = new Client($connectionConfiguration);
|
||||
$participantService = new ParticipantService($client);
|
||||
|
||||
static::assertEquals($client, $participantService->getClient());
|
||||
}
|
||||
|
||||
public function testHasParticipantUsingServiceWithoutParticipants()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertFalse($this->serviceWithoutParticipants->hasParticipant(1, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithoutParticipants->hasParticipant(2, 'john@scott.com'));
|
||||
}
|
||||
|
||||
public function testHasParticipant()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
null,
|
||||
],
|
||||
[
|
||||
null,
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertTrue($this->serviceWithParticipants->hasParticipant(1, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(2, 'john@scott.com'));
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(3, 'john@scott.com'));
|
||||
}
|
||||
|
||||
public function testGetParticipantDetailsWithException()
|
||||
{
|
||||
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
|
||||
$this->setExpectedException(CannotProcessDataException::class, $exception->getMessage());
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$this->serviceWithParticipants->getParticipantDetails(1, 'lorem@ipsum.com');
|
||||
}
|
||||
|
||||
public function testGetParticipantDetails()
|
||||
{
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$participant1 = $this->serviceWithoutParticipants->getParticipantDetails(1, 'john@scott.com');
|
||||
$participant2 = $this->serviceWithParticipants->getParticipantDetails(1, 'john@scott.com');
|
||||
|
||||
$rawData = $this->participantsRawData[0];
|
||||
$id = $rawData['tid'];
|
||||
$firstName = $rawData['firstname'];
|
||||
$lastName = $rawData['lastname'];
|
||||
$email = $rawData['email'];
|
||||
$token = $rawData['token'];
|
||||
|
||||
static::assertNull($participant1);
|
||||
static::assertInstanceOf(Participant::class, $participant2);
|
||||
static::assertEquals($id, $participant2->getId());
|
||||
static::assertEquals($firstName, $participant2->getFirstName());
|
||||
static::assertEquals($lastName, $participant2->getLastName());
|
||||
static::assertEquals($email, $participant2->getEmail());
|
||||
static::assertEquals($token, $participant2->getToken());
|
||||
static::assertTrue($participant2->isSent());
|
||||
static::assertTrue($participant2->isCompleted());
|
||||
static::assertFalse($participant2->isBlacklisted());
|
||||
static::assertNull($participant2->getValidFrom());
|
||||
}
|
||||
|
||||
public function testHasParticipantFilledSurveyWithoutParticipants()
|
||||
{
|
||||
$this->setExpectedException(MissingParticipantOfSurveyException::class);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$this->serviceWithoutParticipants->hasParticipantFilledSurvey(1, 'john@scott.com');
|
||||
}
|
||||
|
||||
public function testHasParticipantFilledSurveyUsingExistingParticipant()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertTrue($this->serviceWithParticipants->hasParticipantFilledSurvey(1, 'john@scott.com'));
|
||||
}
|
||||
|
||||
public function testHasParticipantFilledSurveyUsingNotExistingParticipant()
|
||||
{
|
||||
$this->setExpectedException(MissingParticipantOfSurveyException::class);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$this->serviceWithParticipants->hasParticipantFilledSurvey(3, 'mary@jane.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->participantsRawData = [
|
||||
[
|
||||
'tid' => 1,
|
||||
'participant_id' => null,
|
||||
'mpid' => null,
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
'emailstatus' => 'OK',
|
||||
'token' => uniqid(),
|
||||
'language' => 'pl',
|
||||
'blacklisted' => 'N',
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 0,
|
||||
'completed' => DateUtility::getDateTime(),
|
||||
'usesleft' => 10,
|
||||
'validfrom' => null,
|
||||
'validuntil' => DateUtility::getDateTime(),
|
||||
],
|
||||
[
|
||||
'tid' => 2,
|
||||
'participant_id' => null,
|
||||
'mpid' => null,
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
'emailstatus' => 'OK',
|
||||
'token' => uniqid(),
|
||||
'language' => 'pl',
|
||||
'blacklisted' => 'N',
|
||||
'sent' => 'Y',
|
||||
'remindersent' => 'N',
|
||||
'remindercount' => 0,
|
||||
'completed' => 'N',
|
||||
'usesleft' => 10,
|
||||
'validfrom' => null,
|
||||
'validuntil' => DateUtility::getDateTime(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return ConnectionConfiguration
|
||||
*/
|
||||
private function getConnectionConfiguration()
|
||||
{
|
||||
return new ConnectionConfiguration('http://test.com', 'test', 'test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getSessionManager()
|
||||
{
|
||||
return $this->getMock(SessionManager::class, [], [], '', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API with mocked method runMethod()
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param array $runMethodCallResults (optional) Results of calls of the runMethod() method (who is mocked)
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
|
||||
{
|
||||
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
|
||||
|
||||
$mocker = $rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod');
|
||||
|
||||
if (!empty($runMethodCallResults)) {
|
||||
$function = [
|
||||
$mocker,
|
||||
'willReturnOnConsecutiveCalls',
|
||||
];
|
||||
|
||||
/*
|
||||
* I have to use the call_user_func_array() function to pass elements of $runMethodCallResults array as
|
||||
* arguments of the willReturnOnConsecutiveCalls() method
|
||||
*/
|
||||
call_user_func_array($function, $runMethodCallResults);
|
||||
}
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API with mocked method runMethod()
|
||||
* that throws an exception
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param Exception $exception The exception that should be thrown
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManagerWithException($runMethodCallCount, Exception $exception)
|
||||
{
|
||||
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
|
||||
|
||||
$rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod')
|
||||
->willThrowException($exception);
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service without participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithoutParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutParticipants = new ParticipantService($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service with participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$participantsDetails = new ParticipantsDetails([
|
||||
1 => new Collection([
|
||||
new Participant($this->participantsRawData[0]),
|
||||
new Participant($this->participantsRawData[1]),
|
||||
]),
|
||||
2 => new Collection([
|
||||
new Participant(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithParticipants = new ParticipantService($client, $participantsDetails);
|
||||
}
|
||||
}
|
||||
645
tests/Service/SurveyServiceTest.php
Normal file
645
tests/Service/SurveyServiceTest.php
Normal file
@@ -0,0 +1,645 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Service;
|
||||
|
||||
use Exception;
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\LimeSurvey\ApiClient\Client\Client;
|
||||
use Meritoo\LimeSurvey\ApiClient\Configuration\ConnectionConfiguration;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\CannotProcessDataException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Exception\MissingSurveySummaryException;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\JsonRpcClientManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Manager\SessionManager;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Participants;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Collection\Surveys;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
|
||||
use Meritoo\LimeSurvey\ApiClient\Result\Item\Survey;
|
||||
use Meritoo\LimeSurvey\ApiClient\Service\SurveyService;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
|
||||
/**
|
||||
* Test case of the service that serves surveys and participants of surveys
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class SurveyServiceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* Without surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithoutSurveys;
|
||||
|
||||
/**
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* With surveys.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithSurveys;
|
||||
|
||||
/**
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* Without participants.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithoutParticipants;
|
||||
|
||||
/**
|
||||
* Service that serves surveys and participants of surveys.
|
||||
* With participants.
|
||||
*
|
||||
* @var SurveyService
|
||||
*/
|
||||
private $serviceWithParticipants;
|
||||
|
||||
/**
|
||||
* Base url of LimeSurvey's instance.
|
||||
* Used to prepare configuration of connection.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $connectionBaseUrl = 'http://test.com';
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(SurveyService::class, OopVisibilityType::IS_PUBLIC, 4, 1);
|
||||
}
|
||||
|
||||
public function testGetClient()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(0);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertInstanceOf(Client::class, $this->serviceWithoutSurveys->getClient());
|
||||
static::assertInstanceOf(Client::class, $this->serviceWithSurveys->getClient());
|
||||
|
||||
$connectionConfiguration = $this->getConnectionConfiguration();
|
||||
$client = new Client($connectionConfiguration);
|
||||
$surveyService = new SurveyService($client);
|
||||
|
||||
static::assertEquals($client, $surveyService->getClient());
|
||||
}
|
||||
|
||||
public function testGetAllSurveysWithNoTableException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::class);
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutSurveys->getAllSurveys();
|
||||
}
|
||||
|
||||
public function testGetAllSurveysWithNoSurveysException()
|
||||
{
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_SURVEYS_FOUND);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
static::assertCount(0, $this->serviceWithoutSurveys->getAllSurveys());
|
||||
}
|
||||
|
||||
public function testGetAllSurveys()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
/*
|
||||
* If there are no surveys, count of all or active only surveys is the same
|
||||
*/
|
||||
static::assertCount(0, $this->serviceWithoutSurveys->getAllSurveys());
|
||||
static::assertCount(0, $this->serviceWithoutSurveys->getAllSurveys(true));
|
||||
|
||||
/*
|
||||
* If there are surveys, here we've got difference between count of all or active only surveys
|
||||
*/
|
||||
static::assertCount(3, $this->serviceWithSurveys->getAllSurveys());
|
||||
static::assertCount(2, $this->serviceWithSurveys->getAllSurveys(true));
|
||||
}
|
||||
|
||||
public function testIsExistingSurvey()
|
||||
{
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(4);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
/*
|
||||
* If there are no surveys, verification of existence any survey always return false
|
||||
*/
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(1));
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(1, true));
|
||||
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(2));
|
||||
static::assertFalse($this->serviceWithoutSurveys->isExistingSurvey(2, true));
|
||||
|
||||
/*
|
||||
* If there are surveys, verification of existence active survey always return true
|
||||
*/
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(1));
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(1, true));
|
||||
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(2));
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(2, true));
|
||||
|
||||
/*
|
||||
* If there are surveys, verification of existence of non-active survey shows difference
|
||||
*/
|
||||
static::assertTrue($this->serviceWithSurveys->isExistingSurvey(3));
|
||||
static::assertFalse($this->serviceWithSurveys->isExistingSurvey(3, true));
|
||||
|
||||
/*
|
||||
* If there are surveys, verification of existence non-existing survey always return false
|
||||
*/
|
||||
static::assertFalse($this->serviceWithSurveys->isExistingSurvey(4));
|
||||
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);
|
||||
$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);
|
||||
|
||||
$participant = new Participant([
|
||||
'tid' => 1,
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
'token' => $token,
|
||||
]);
|
||||
|
||||
static::assertEquals($expectedUrl, $this->serviceWithoutSurveys->getStartSurveyUrl($surveyId, $participant));
|
||||
static::assertEquals($expectedUrl, $this->serviceWithSurveys->getStartSurveyUrl($surveyId, $participant));
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNotExistingSurveyException()
|
||||
{
|
||||
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
|
||||
$this->setExpectedException(CannotProcessDataException::class, $exception->getMessage());
|
||||
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
[
|
||||
'status' => ReasonType::NOT_EXISTING_SURVEY_ID,
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$this->serviceWithParticipants->getSurveyParticipants(3);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNoParticipantsFoundException()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
[
|
||||
'status' => ReasonType::NO_PARTICIPANTS_FOUND,
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
$participants = $this->serviceWithParticipants->getSurveyParticipants(3);
|
||||
|
||||
static::assertInstanceOf(Collection::class, $participants);
|
||||
static::assertCount(0, $participants);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipants()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
null,
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
null,
|
||||
[
|
||||
'token_count' => '2',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(6, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(0, $this->serviceWithoutParticipants->getSurveyParticipants(2));
|
||||
|
||||
static::assertCount(2, $this->serviceWithParticipants->getSurveyParticipants(1));
|
||||
static::assertCount(1, $this->serviceWithParticipants->getSurveyParticipants(2));
|
||||
static::assertCount(0, $this->serviceWithParticipants->getSurveyParticipants(3));
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNoTableException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::class);
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_TOKEN_TABLE);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
$this->serviceWithParticipants->getSurveyParticipants(3);
|
||||
}
|
||||
|
||||
public function testGetSurveyParticipantsWithNoParticipantsException()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::class);
|
||||
$exception = new CannotProcessDataException(ReasonType::NO_PARTICIPANTS_FOUND);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
static::assertCount(0, $this->serviceWithParticipants->getSurveyParticipants(3));
|
||||
}
|
||||
|
||||
public function testAddParticipantForNotExistingSurvey()
|
||||
{
|
||||
$this->setExpectedException(CannotProcessDataException::class);
|
||||
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
|
||||
$this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
$this->serviceWithParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
}
|
||||
|
||||
public function testAddParticipant()
|
||||
{
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
$runMethodCallCount = 1;
|
||||
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
[
|
||||
'firstname' => $firstName,
|
||||
'lastname' => $lastName,
|
||||
'email' => $email,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager($runMethodCallCount, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$result = $this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
|
||||
static::assertInstanceOf(Participant::class, $result);
|
||||
static::assertEquals($firstName, $result->getFirstName());
|
||||
static::assertEquals($lastName, $result->getLastName());
|
||||
static::assertEquals($email, $result->getEmail());
|
||||
}
|
||||
|
||||
public function testGetParticipant()
|
||||
{
|
||||
$runMethodCallResults = [
|
||||
[
|
||||
'token_count' => '0',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
null,
|
||||
[
|
||||
[
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
],
|
||||
],
|
||||
[
|
||||
'tid' => 2,
|
||||
'participant_info' => [
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'token_count' => '2',
|
||||
'token_invalid' => '0',
|
||||
'token_sent' => '0',
|
||||
'token_opted_out' => '0',
|
||||
'token_completed' => '0',
|
||||
'completed_responses' => '0',
|
||||
'incomplete_responses' => '0',
|
||||
'full_responses' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(2, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$participant1 = $this->serviceWithoutParticipants->getParticipant(1, 'john@scott.com');
|
||||
$participant2 = $this->serviceWithParticipants->getParticipant(1, 'john@scott.com');
|
||||
|
||||
static::assertNull($participant1);
|
||||
static::assertInstanceOf(ParticipantShort::class, $participant2);
|
||||
static::assertEquals('John', $participant2->getFirstName());
|
||||
static::assertEquals('Scott', $participant2->getLastName());
|
||||
static::assertEquals('john@scott.com', $participant2->getEmail());
|
||||
}
|
||||
|
||||
public function testGetSurveyTokenCountWithException()
|
||||
{
|
||||
$this->setExpectedException(MissingSurveySummaryException::class);
|
||||
|
||||
$runMethodCallResults = [
|
||||
null,
|
||||
];
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithoutSurveys($rpcClientManager, $sessionManager);
|
||||
|
||||
$this->serviceWithoutSurveys->getSurveyTokenCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration used while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return ConnectionConfiguration
|
||||
*/
|
||||
private function getConnectionConfiguration()
|
||||
{
|
||||
return new ConnectionConfiguration($this->connectionBaseUrl, 'test', 'test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of session started while connecting to LimeSurvey's API
|
||||
*
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getSessionManager()
|
||||
{
|
||||
return $this->getMock(SessionManager::class, [], [], '', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API with mocked method runMethod()
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param array $runMethodCallResults (optional) Results of calls of the runMethod() method (who is mocked)
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManager($runMethodCallCount, array $runMethodCallResults = [])
|
||||
{
|
||||
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
|
||||
|
||||
$mocker = $rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod');
|
||||
|
||||
if (!empty($runMethodCallResults)) {
|
||||
$function = [
|
||||
$mocker,
|
||||
'willReturnOnConsecutiveCalls',
|
||||
];
|
||||
|
||||
/*
|
||||
* I have to use the call_user_func_array() function to pass elements of $runMethodCallResults array as
|
||||
* arguments of the willReturnOnConsecutiveCalls() method
|
||||
*/
|
||||
call_user_func_array($function, $runMethodCallResults);
|
||||
}
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manager of the JsonRPC client used while connecting to LimeSurvey's API with mocked method runMethod()
|
||||
* that throws an exception
|
||||
*
|
||||
* @param int $runMethodCallCount Count of calls of the runMethod() method (who is mocked)
|
||||
* @param Exception $exception The exception that should be thrown
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getJsonRpcClientManagerWithException($runMethodCallCount, Exception $exception)
|
||||
{
|
||||
$rpcClientManager = $this->getMock(JsonRpcClientManager::class, [], [], '', false);
|
||||
|
||||
$rpcClientManager
|
||||
->expects(static::exactly($runMethodCallCount))
|
||||
->method('runMethod')
|
||||
->willThrowException($exception);
|
||||
|
||||
return $rpcClientManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service without surveys
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithoutSurveys(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutSurveys = new SurveyService($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service with surveys
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithSurveys(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$allSurveys = new Surveys([
|
||||
new Survey([
|
||||
'sid' => 1,
|
||||
'surveyls_title' => 'Test',
|
||||
'active' => 'Y',
|
||||
]),
|
||||
new Survey([
|
||||
'sid' => 2,
|
||||
'surveyls_title' => 'Another Test',
|
||||
'active' => 'Y',
|
||||
]),
|
||||
new Survey([
|
||||
'sid' => 3,
|
||||
'surveyls_title' => 'I am inactive',
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithSurveys = new SurveyService($client, $allSurveys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service without participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithoutParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
$this->serviceWithoutParticipants = new SurveyService($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates instance of the tested service with participants
|
||||
*
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $rpcClientManager Manager of the JsonRPC client used while connecting to LimeSurvey's API
|
||||
* @param PHPUnit_Framework_MockObject_MockObject $sessionManager Manager of session started while connecting to LimeSurvey's API
|
||||
*/
|
||||
private function createServiceWithParticipants(PHPUnit_Framework_MockObject_MockObject $rpcClientManager, PHPUnit_Framework_MockObject_MockObject $sessionManager)
|
||||
{
|
||||
$configuration = $this->getConnectionConfiguration();
|
||||
$client = new Client($configuration, $rpcClientManager, $sessionManager);
|
||||
|
||||
$allParticipants = new Participants([
|
||||
1 => new Collection([
|
||||
new ParticipantShort([
|
||||
'tid' => 1,
|
||||
'participant_info' => [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Scott',
|
||||
'email' => 'john@scott.com',
|
||||
],
|
||||
]),
|
||||
new ParticipantShort([
|
||||
'tid' => 2,
|
||||
'participant_info' => [
|
||||
'firstname' => 'Mary',
|
||||
'lastname' => 'Jane',
|
||||
'email' => 'mary@jane.com',
|
||||
],
|
||||
]),
|
||||
]),
|
||||
2 => new Collection([
|
||||
new ParticipantShort(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->serviceWithParticipants = new SurveyService($client, null, $allParticipants);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ class MethodTypeTest extends BaseTypeTestCase
|
||||
'EXPORT_STATISTICS' => MethodType::EXPORT_STATISTICS,
|
||||
'GET_PARTICIPANT_PROPERTIES' => MethodType::GET_PARTICIPANT_PROPERTIES,
|
||||
'GET_QUESTION_PROPERTIES' => MethodType::GET_QUESTION_PROPERTIES,
|
||||
'GET_SUMMARY' => MethodType::GET_SUMMARY,
|
||||
'LIST_PARTICIPANTS' => MethodType::LIST_PARTICIPANTS,
|
||||
'LIST_QUESTIONS' => MethodType::LIST_QUESTIONS,
|
||||
'LIST_SURVEYS' => MethodType::LIST_SURVEYS,
|
||||
84
tests/Type/ReasonTypeTest.php
Normal file
84
tests/Type/ReasonTypeTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Type;
|
||||
|
||||
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\LimeSurvey\ApiClient\Type\ReasonType;
|
||||
|
||||
/**
|
||||
* Test case of the type of reason used by LimeSurvey's exception
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class ReasonTypeTest extends BaseTypeTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertHasNoConstructor(ReasonType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAllExpectedTypes()
|
||||
{
|
||||
return [
|
||||
'NOT_EXISTING_SURVEY_ID' => ReasonType::NOT_EXISTING_SURVEY_ID,
|
||||
'NO_PARTICIPANTS_FOUND' => ReasonType::NO_PARTICIPANTS_FOUND,
|
||||
'NO_PARTICIPANT_PROPERTIES' => ReasonType::NO_PARTICIPANT_PROPERTIES,
|
||||
'NO_SURVEYS_FOUND' => ReasonType::NO_SURVEYS_FOUND,
|
||||
'NO_TOKEN_TABLE' => ReasonType::NO_TOKEN_TABLE,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTestedTypeInstance()
|
||||
{
|
||||
return new ReasonType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify()
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
ReasonType::NOT_EXISTING_SURVEY_ID,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
ReasonType::NO_PARTICIPANTS_FOUND,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
ReasonType::NO_SURVEYS_FOUND,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
ReasonType::NO_TOKEN_TABLE,
|
||||
true,
|
||||
];
|
||||
}
|
||||
}
|
||||
38
tests/Utilities/DateUtility.php
Normal file
38
tests/Utilities/DateUtility.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\LimeSurvey\Test\ApiClient\Utilities;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Date-related utility
|
||||
*
|
||||
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
|
||||
* @copyright Meritoo.pl
|
||||
*/
|
||||
class DateUtility
|
||||
{
|
||||
/**
|
||||
* Returns date formatted with long or medium format
|
||||
*
|
||||
* @param bool $useLongFormat (optional) If is set to true, long format will be used (default behaviour).
|
||||
* Otherwise - medium format.
|
||||
* @return string
|
||||
*/
|
||||
public static function getDateTime($useLongFormat = true)
|
||||
{
|
||||
$format = 'Y-m-d H:i';
|
||||
|
||||
if ($useLongFormat) {
|
||||
$format = 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
return (new DateTime())->format($format);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user