composer.json - move tests-related classes to "autoload-dev" section (used for development purposes only and avoid polluting the autoloader in production)

This commit is contained in:
Meritoo
2017-09-29 09:24:57 +02:00
parent 0562cb4d21
commit dbd0a65286
45 changed files with 6 additions and 2 deletions

View 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\CannotProcessDataException;
/**
* Test case of an exception used while raw data returned by the LimeSurvey's API cannot be processed
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class CannotProcessDataExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(CannotProcessDataException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
}
/**
* @param string $reason Reason why data cannot be processed, e.g. "Invalid user name or password"
* @param string $expectedMessage Expected exception's message
*
* @dataProvider provideReason
*/
public function testConstructorMessage($reason, $expectedMessage)
{
$exception = new CannotProcessDataException($reason);
static::assertEquals($expectedMessage, $exception->getMessage());
}
/**
* Provides reason why data cannot be processed
*
* @return Generator
*/
public function provideReason()
{
$template = 'Raw data returned by the LimeSurvey\'s API cannot be processed. Reason: \'%s\'.';
yield[
'unknown',
sprintf($template, 'unknown'),
];
yield[
'Invalid user name or password',
sprintf($template, 'Invalid user name or password'),
];
}
}

View File

@@ -0,0 +1,61 @@
<?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\CreateSessionKeyFailedException;
/**
* Test case of an exception used while create of the session key has failed
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class CreateSessionKeyFailedExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(CreateSessionKeyFailedException::class, OopVisibilityType::IS_PUBLIC, 1, 0);
}
/**
* @param string $reason Reason of failure, e.g. "Invalid user name or password"
* @param string $expectedMessage Expected exception's message
*
* @dataProvider provideReason
*/
public function testConstructorMessage($reason, $expectedMessage)
{
$exception = new CreateSessionKeyFailedException($reason);
static::assertEquals($expectedMessage, $exception->getMessage());
}
/**
* Provides reason of failure
*
* @return Generator
*/
public function provideReason()
{
$shortMessage = 'Create of the session key has failed';
$longMessageTemplate = sprintf('%s. Reason: \'%s\'.', $shortMessage, '%s');
yield[
'',
$shortMessage,
];
yield[
'Invalid user name or password',
sprintf($longMessageTemplate, 'Invalid user name or password'),
];
}
}

View File

@@ -0,0 +1,75 @@
<?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 Exception;
use Generator;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
use Meritoo\LimeSurvey\ApiClient\Exception\InvalidResultOfMethodRunException;
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
/**
* Test case of an exception used when an error occurred while running method
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class InvalidResultOfMethodRunExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(InvalidResultOfMethodRunException::class, OopVisibilityType::IS_PUBLIC, 3, 2);
}
/**
* @param Exception $previousException The previous exception, source of an error
* @param string $methodName Name of called method
* @param array $methodArguments Arguments of the called method
* @param string $expectedMessage Expected exception's message
*
* @dataProvider providePreviousExceptionAndMethod
*/
public function testConstructorMessage(Exception $previousException, $methodName, array $methodArguments, $expectedMessage)
{
$exception = new InvalidResultOfMethodRunException($previousException, $methodName, $methodArguments);
static::assertEquals($expectedMessage, $exception->getMessage());
}
/**
* Provides previous exception, name and arguments of called method
*
* @return Generator
*/
public function providePreviousExceptionAndMethod()
{
$template = "Oops, an error occurred while running method. Is there everything ok? Details:\n"
. "- error: %s,\n"
. "- method: %s,\n"
. '- arguments: %s.';
yield[
new Exception('Lorem ipsum'),
MethodType::ADD_RESPONSE,
[],
sprintf($template, 'Lorem ipsum', MethodType::ADD_RESPONSE, '(no arguments)'),
];
yield[
new Exception('Dolor sit amet'),
MethodType::LIST_SURVEYS,
[
'fist_name' => 'John',
'last_name' => 'Scott',
'email' => 'john@scott.com',
],
sprintf($template, 'Dolor sit amet', MethodType::LIST_SURVEYS, 'fist_name="John", last_name="Scott", email="john@scott.com"'),
];
}
}

View File

@@ -0,0 +1,65 @@
<?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\UnknownInstanceOfResultItem;
use Meritoo\LimeSurvey\ApiClient\Result\Processor\ResultProcessor;
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
/**
* Test case of an exception used while instance of one item used by result, with data fetched from the LimeSurvey's
* API, is unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class UnknownInstanceOfResultItemTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownInstanceOfResultItem::class, OopVisibilityType::IS_PUBLIC, 1, 1);
}
/**
* @param string $method Name of called method while talking to the LimeSurvey's API. One of the
* MethodType class constants.
* @param string $expectedMessage Expected exception's message
*
* @dataProvider provideMethodName
*/
public function testConstructorMessage($method, $expectedMessage)
{
$exception = new UnknownInstanceOfResultItem($method);
static::assertEquals($expectedMessage, $exception->getMessage());
}
/**
* Provides name of called method
*
* @return Generator
*/
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?';
yield[
MethodType::LIST_SURVEYS,
sprintf($template, MethodType::LIST_SURVEYS, ResultProcessor::class, 'getItemInstance'),
];
yield[
MethodType::ADD_PARTICIPANTS,
sprintf($template, MethodType::ADD_PARTICIPANTS, ResultProcessor::class, 'getItemInstance'),
];
}
}

View File

@@ -0,0 +1,64 @@
<?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\UnknownMethodException;
use Meritoo\LimeSurvey\ApiClient\Type\MethodType;
/**
* Test case of an exception used while name of method used while talking to the LimeSurvey's API is unknown
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class UnknownMethodExceptionTest extends BaseTestCase
{
public function testConstructorVisibilityAndArguments()
{
static::assertConstructorVisibilityAndArguments(UnknownMethodException::class, OopVisibilityType::IS_PUBLIC, 1, 1);
}
/**
* @param string $unknownType The unknown type of something (value of constant)
* @param string $expectedMessage Expected exception's message
*
* @dataProvider provideUnknownType
*/
public function testConstructorMessage($unknownType, $expectedMessage)
{
$exception = new UnknownMethodException($unknownType);
static::assertEquals($expectedMessage, $exception->getMessage());
}
/**
* Provides name of called method
*
* @return Generator
*/
public function provideUnknownType()
{
$allMethods = implode(', ', (new MethodType())->getAll());
$template = 'The \'%s\' type of name of method used while talking to the LimeSurvey\'s API is unknown. Probably'
. ' doesn\'t exist or there is a typo. You should use one of these types: %s.';
yield[
MethodType::ADD_PARTICIPANTS,
sprintf($template, MethodType::ADD_PARTICIPANTS, $allMethods),
];
yield[
MethodType::ADD_PARTICIPANTS,
sprintf($template, MethodType::ADD_PARTICIPANTS, $allMethods),
];
}
}