BaseTestCase - assertHasNoConstructor() method - asserts that class with given namespace has no constructor

This commit is contained in:
Meritoo
2017-09-21 16:47:41 +02:00
parent 6c70fdd673
commit 318a635ffd
14 changed files with 86 additions and 10 deletions

View File

@@ -2,7 +2,7 @@
"name": "meritoo/common-library",
"description": "Useful classes, methods, extensions etc.",
"license": "MIT",
"version": "0.0.10",
"version": "0.0.11",
"authors": [
{
"name": "Meritoo.pl",

View File

@@ -180,7 +180,7 @@ abstract class BaseTestCase extends TestCase
/**
* Verifies visibility and arguments of class constructor
*
* @param string $classNamespace Namespace of class that contains method to verify
* @param string $classNamespace Namespace of class that contains constructor to verify
* @param string $visibilityType Expected visibility of verified method. One of OopVisibilityType class
* constants.
* @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method
@@ -202,4 +202,20 @@ abstract class BaseTestCase extends TestCase
return $this->verifyMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
}
/**
* Asserts that class with given namespace has no constructor
*
* @param string $classNamespace Namespace of class that contains constructor to verify
*/
protected static function assertHasNoConstructor($classNamespace)
{
/*
* Let's grab the constructor
*/
$reflection = new ReflectionClass($classNamespace);
$constructor = $reflection->getConstructor();
static::assertNull($constructor);
}
}

View File

@@ -8,8 +8,8 @@
namespace Meritoo\Common\Test\Utilities;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Utilities\Arrays;
use PHPUnit\Framework\TestCase;
/**
* Tests of the useful arrays methods
@@ -17,7 +17,7 @@ use PHPUnit\Framework\TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class ArraysTest extends TestCase
class ArraysTest extends BaseTestCase
{
private $simpleArray;
private $simpleArrayWithKeys;
@@ -25,6 +25,11 @@ class ArraysTest extends TestCase
private $complexArray;
private $superComplexArray;
public function verifyConstructor()
{
static::assertHasNoConstructor(Arrays::class);
}
public function testValues2string()
{
/*

View File

@@ -8,8 +8,8 @@
namespace Meritoo\Common\Test\Utilities;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Utilities\Bundle;
use PHPUnit\Framework\TestCase;
/**
* Tests of the useful methods for bundle
@@ -17,8 +17,13 @@ use PHPUnit\Framework\TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class BundleTest extends TestCase
class BundleTest extends BaseTestCase
{
public function verifyConstructor()
{
static::assertHasNoConstructor(Bundle::class);
}
public function testGetBundleViewPathEmptyPathAndBundle()
{
self::assertNull(Bundle::getBundleViewPath('', ''));

View File

@@ -27,6 +27,11 @@ class ComposerTest extends BaseTestCase
*/
private $composerJsonPath;
public function verifyConstructor()
{
static::assertHasNoConstructor(Composer::class);
}
/**
* @param string $composerJsonPath Empty value, e.g. ""
* @dataProvider provideEmptyValue

View File

@@ -23,6 +23,11 @@ use Meritoo\Common\Utilities\Date;
*/
class DateTest extends BaseTestCase
{
public function verifyConstructor()
{
static::assertHasNoConstructor(Date::class);
}
/**
* @param mixed $value Empty value, e.g. ""
* @dataProvider provideEmptyValue

View File

@@ -19,6 +19,11 @@ use Meritoo\Common\Utilities\GeneratorUtility;
*/
class GeneratorUtilityTest extends BaseTestCase
{
public function verifyConstructor()
{
static::assertHasNoConstructor(GeneratorUtility::class);
}
public function testGetGeneratorElements()
{
/*

View File

@@ -20,6 +20,11 @@ use Meritoo\Common\Utilities\Locale;
*/
class LocaleTest extends BaseTestCase
{
public function verifyConstructor()
{
static::assertHasNoConstructor(Locale::class);
}
/**
* @param mixed $languageCode Empty value, e.g. ""
* @dataProvider provideEmptyValue

View File

@@ -20,6 +20,11 @@ use Meritoo\Common\Utilities\MimeTypes;
*/
class MimeTypesTest extends BaseTestCase
{
public function verifyConstructor()
{
static::assertHasNoConstructor(MimeTypes::class);
}
/**
* @param mixed $mimeType Empty value, e.g. ""
* @dataProvider provideEmptyValue

View File

@@ -28,6 +28,11 @@ class MiscellaneousTest extends BaseTestCase
private $stringCommaSeparated;
private $stringDotSeparated;
public function verifyConstructor()
{
static::assertHasNoConstructor(Miscellaneous::class);
}
public function testGetDirectoryContent()
{
$directoryPath = __DIR__ . '/../';

View File

@@ -29,6 +29,11 @@ use Meritoo\Common\Utilities\Reflection;
*/
class ReflectionTest extends BaseTestCase
{
public function verifyConstructor()
{
static::assertHasNoConstructor(Reflection::class);
}
/**
* @param mixed $invalidClass Empty value, e.g. ""
* @dataProvider provideEmptyValue

View File

@@ -8,7 +8,7 @@
namespace Meritoo\Common\Utilities;
use PHPUnit\Framework\TestCase;
use Meritoo\Common\Test\Base\BaseTestCase;
/**
* Tests of the useful regular expressions methods
@@ -16,11 +16,16 @@ use PHPUnit\Framework\TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class RegexTest extends TestCase
class RegexTest extends BaseTestCase
{
private $simpleText;
private $camelCaseText;
public function verifyConstructor()
{
static::assertHasNoConstructor(Regex::class);
}
public function testGetCamelCaseParts()
{
$parts = [];

View File

@@ -19,6 +19,11 @@ use Meritoo\Common\Utilities\Uri;
*/
class UriTest extends BaseTestCase
{
public function verifyConstructor()
{
static::assertHasNoConstructor(Uri::class);
}
public function testAddProtocolToUrl()
{
$http = 'http';

View File

@@ -8,8 +8,8 @@
namespace Meritoo\Common\Test\Utilities;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Utilities\Xml;
use PHPUnit\Framework\TestCase;
use SimpleXMLElement;
/**
@@ -18,11 +18,16 @@ use SimpleXMLElement;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class XmlTest extends TestCase
class XmlTest extends BaseTestCase
{
private $simpleXml;
private $advancedXml;
public function verifyConstructor()
{
static::assertHasNoConstructor(Xml::class);
}
public function testMergeNodes()
{
/*