mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 17:41:50 +01:00
74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?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\Test\Common\Exception\Reflection;
|
|
|
|
use Generator;
|
|
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
|
use Meritoo\Common\Type\OopVisibilityType;
|
|
use stdClass;
|
|
|
|
/**
|
|
* Test case of an exception used while given class has no child classes
|
|
*
|
|
* @author Meritoo <github@meritoo.pl>
|
|
* @copyright Meritoo <http://www.meritoo.pl>
|
|
*
|
|
* @internal
|
|
* @covers \Meritoo\Common\Exception\Reflection\MissingChildClassesException
|
|
*/
|
|
class MissingChildClassesExceptionTest extends BaseTestCase
|
|
{
|
|
/**
|
|
* Provides name of class that hasn't child classes, but it should, and expected exception's message
|
|
*
|
|
* @return Generator
|
|
*/
|
|
public function provideParentClass(): ?Generator
|
|
{
|
|
$template = 'The \'%s\' class requires one child class at least who will extend her (maybe is an abstract'
|
|
.' class), but the child classes are missing. Did you forget to extend this class?';
|
|
|
|
yield [
|
|
MissingChildClassesException::class,
|
|
sprintf($template, MissingChildClassesException::class),
|
|
];
|
|
|
|
yield [
|
|
[
|
|
new stdClass(),
|
|
new stdClass(),
|
|
],
|
|
sprintf($template, stdClass::class),
|
|
];
|
|
}
|
|
|
|
public function testConstructorVisibilityAndArguments(): void
|
|
{
|
|
static::assertConstructorVisibilityAndArguments(
|
|
MissingChildClassesException::class,
|
|
OopVisibilityType::IS_PUBLIC,
|
|
3
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param array|object|string $parentClass Class that hasn't child classes, but it should. An array of objects,
|
|
* strings, object or string.
|
|
* @param string $expectedMessage Expected exception's message
|
|
*
|
|
* @dataProvider provideParentClass
|
|
*/
|
|
public function testCreate($parentClass, string $expectedMessage): void
|
|
{
|
|
$exception = MissingChildClassesException::create($parentClass);
|
|
static::assertSame($expectedMessage, $exception->getMessage());
|
|
}
|
|
}
|