Base class for one item - add class constructor & allow to set values directly in the constructor

This commit is contained in:
Meritoo
2017-09-29 20:56:39 +02:00
parent bbd466610c
commit 6159731768
17 changed files with 190 additions and 84 deletions

View 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),
];
}
}

View File

@@ -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'),
];
}
}