9 Commits

Author SHA1 Message Date
Meritoo
73030d703b composer.json - bump version 2017-11-02 12:25:39 +01:00
Meritoo
36ddb326b9 Tests - increase code coverage 2017-10-31 21:27:42 +01:00
Meritoo
452a4ec458 Tests - BaseTestCase - rename method getFilePathToTests() -> getFilePathForTesting() 2017-10-31 21:26:39 +01:00
Meritoo
325fe6b141 Support PHP 5.5.9+ 2017-10-31 20:28:55 +01:00
Meritoo
a1c26b3812 Phing - tests - phpcodesniffer task - fix "This task requires the PHP_CodeSniffer package installed and available on the include path" bug
Details: https://github.com/phingofficial/phing/issues/716
2017-10-26 20:04:05 +02:00
Meritoo
67d93036cf Phing - update properties.dist file 2017-10-22 21:40:23 +02:00
Meritoo
9368616dfe composer.json - update versions of the "dev" packages 2017-10-22 20:09:02 +02:00
Meritoo
5ab68d3667 Tests - Docker - update Xdebug configuration
Required to fix problem "Connection with XDebug 2.5.1 was not established. Validate installation."
2017-10-22 17:55:49 +02:00
Meritoo
4613a63f02 Tests - Docker - install vim, add custom php.ini, add "vendor/bin" to the $PATH global variable 2017-10-20 00:03:38 +02:00
15 changed files with 221 additions and 31 deletions

View File

@@ -1,10 +1,11 @@
FROM php:5.6-cli
FROM php:5.5-cli
#
# Tools & libraries
#
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
vim \
git \
zip \
unzip \
@@ -14,7 +15,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#
# PHP Extensions
# PHP extensions
#
RUN docker-php-ext-install \
zip \
@@ -23,10 +24,12 @@ RUN docker-php-ext-install \
#
# PHP configuration:
# - default configuration
# - timezone
#
COPY php.ini /usr/local/etc/php/php.ini
ARG TIMEZONE
RUN echo "date.timezone = $TIMEZONE" >> /usr/local/etc/php/php.ini
RUN echo "\n""date.timezone = $TIMEZONE""\n" >> /usr/local/etc/php/php.ini
#
# Xdebug
@@ -52,3 +55,10 @@ RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "unlink('composer-setup.php');" \
&& composer global require --no-plugins --no-scripts hirak/prestissimo \
&& rm -rf /root/.composer/cache/*
#
# Bash
#
RUN sed -i 's/^# export/export/g' /root/.bashrc \
&& sed -i 's/^# alias/alias/g' /root/.bashrc \
&& echo "\n"'export PATH=/project/vendor/bin:$PATH'"\n" >> /root/.bashrc

3
.docker/config/php.ini Normal file
View File

@@ -0,0 +1,3 @@
display_errors = On
display_startup_errors = On
error_reporting = E_ALL

View File

@@ -1,7 +1,6 @@
[xdebug]
zend_extension='xdebug.so'
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.idekey='PHPSTORM'
xdebug.remote_port=9001
xdebug.remote_host=10.254.254.254

View File

@@ -28,7 +28,13 @@ 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
#
# Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
# 2017-06-06
#
cache.clearWithWarmup = false
# --------------------------------------------------------------------------------
# Composer

View File

@@ -2,7 +2,7 @@
"name": "meritoo/common-library",
"description": "Useful classes, methods, extensions etc.",
"license": "MIT",
"version": "0.0.15",
"version": "0.0.16",
"authors": [
{
"name": "Meritoo.pl",
@@ -11,18 +11,18 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">=5.5.9",
"doctrine/orm": "^2.5",
"gedmo/doctrine-extensions": "^2.4",
"symfony/http-foundation": "^3.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.6",
"friendsofphp/php-cs-fixer": "^2.2",
"pdepend/pdepend": "^2.5",
"phploc/phploc": "^4.0",
"phploc/phploc": "^2.1",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^5.7",
"sebastian/phpcpd": "^3.0",
"phpunit/phpunit": "^4.8",
"sebastian/phpcpd": "^2.0",
"squizlabs/php_codesniffer": "^2.9"
},
"autoload": {
@@ -34,5 +34,8 @@
"psr-4": {
"Meritoo\\Common\\Test\\": "tests/"
}
},
"config": {
"sort-packages": true
}
}

View File

@@ -111,7 +111,7 @@ abstract class BaseTestCase extends TestCase
* @param string $directoryPath (optional) Path of directory containing the file
* @return string
*/
public function getFilePathToTests($fileName, $directoryPath = '')
public function getFilePathForTesting($fileName, $directoryPath = '')
{
$rootPath = Miscellaneous::getProjectRootPath();

View File

@@ -1,5 +1,11 @@
<?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\Common\Test\Base;
use Generator;

View File

@@ -33,7 +33,7 @@ class UnknownTypeExceptionTest extends BaseTestCase
public function testTheException()
{
$this->expectException(UnknownTestTypeException::class);
$this->setExpectedException(UnknownTestTypeException::class);
self::assertEmpty((new TestService())->getTranslatedType('test_3'));
}
}

View File

@@ -0,0 +1,156 @@
<?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\Common\Test\Test\Base;
use DateTime;
use Generator;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
use Meritoo\Common\Utilities\GeneratorUtility;
/**
* Test case of the base test case with common methods and data providers
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class BaseTestCaseTest extends BaseTestCase
{
public function testConstructor()
{
static::assertConstructorVisibilityAndArguments(BaseTestCase::class, OopVisibilityType::IS_PUBLIC, 3);
}
public function testProvideEmptyValue()
{
$elements = [
[''],
[' '],
[null],
[0],
[false],
[[]],
];
$generator = (new SimpleTestCase())->provideEmptyValue();
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
}
public function testProvideBooleanValue()
{
$elements = [
[false],
[true],
];
$generator = (new SimpleTestCase())->provideBooleanValue();
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
}
public function testProvideDateTimeInstance()
{
$elements = [
[new DateTime()],
[new DateTime('yesterday')],
[new DateTime('now')],
[new DateTime('tomorrow')],
];
$generator = (new SimpleTestCase())->provideDateTimeInstance();
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
}
public function testProvideDateTimeRelativeFormat()
{
$elements = [
['now'],
['yesterday'],
['tomorrow'],
['back of 10'],
['front of 10'],
['last day of February'],
['first day of next month'],
['last day of previous month'],
['last day of next month'],
['Y-m-d'],
['Y-m-d 10:00'],
];
$generator = (new SimpleTestCase())->provideDateTimeRelativeFormat();
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
}
public function testProvideNotExistingFilePath()
{
$elements = [
['lets-test.doc'],
['lorem/ipsum.jpg'],
['surprise/me/one/more/time.txt'],
];
$generator = (new SimpleTestCase())->provideNotExistingFilePath();
self::assertEquals($elements, GeneratorUtility::getGeneratorElements($generator));
}
/**
* @param string $fileName Name of file
* @param string $directoryPath Path of directory containing the file
*
* @dataProvider provideFileNameAndDirectoryPath
*/
public function testGetFilePathForTesting($fileName, $directoryPath)
{
$path = (new SimpleTestCase())->getFilePathForTesting($fileName, $directoryPath);
if (!empty($directoryPath)) {
$directoryPath .= '/';
}
$expectedContains = sprintf('/.data/tests/%s%s', $directoryPath, $fileName);
static::assertContains($expectedContains, $path);
}
/**
* Provides name of file and path of directory containing the file
*
* @return Generator
*/
public function provideFileNameAndDirectoryPath()
{
yield[
'abc.jpg',
'',
];
yield[
'abc.def.jpg',
'',
];
yield[
'abc.jpg',
'def',
];
yield[
'abc.def.jpg',
'def',
];
}
}
/**
* Simple test case
*
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class SimpleTestCase extends BaseTestCase
{
}

View File

@@ -9,8 +9,8 @@
namespace Meritoo\Common\Test\Type\Base;
use Generator;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\Base\BaseType;
use PHPUnit\Framework\TestCase;
/**
* Test case of the base / abstract type of something
@@ -18,8 +18,13 @@ use PHPUnit\Framework\TestCase;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class BaseTypeTest extends TestCase
class BaseTypeTest extends BaseTestCase
{
public function testConstructor()
{
static::assertHasNoConstructor(BaseType::class);
}
/**
* @param BaseType $type Type of something
* @param array $expectedTypes Expected concrete types of given instance of type

View File

@@ -88,6 +88,6 @@ class ComposerTest extends BaseTestCase
{
parent::setUp();
$this->composerJsonPath = $this->getFilePathToTests(Composer::FILE_NAME_MAIN);
$this->composerJsonPath = $this->getFilePathForTesting(Composer::FILE_NAME_MAIN);
}
}

View File

@@ -223,7 +223,7 @@ class DateTest extends BaseTestCase
*/
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
{
$this->expectException(UnknownDatePartTypeException::class);
$this->setExpectedException(UnknownDatePartTypeException::class);
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
}

View File

@@ -447,12 +447,12 @@ class MimeTypesTest extends BaseTestCase
public function provideFilePathToGetMimeTypeOfRealFile()
{
yield[
$this->getFilePathToTests('minion.jpg'),
$this->getFilePathForTesting('minion.jpg'),
'image/jpeg',
];
yield[
$this->getFilePathToTests('lorem-ipsum.txt'),
$this->getFilePathForTesting('lorem-ipsum.txt'),
'text/plain',
];
}
@@ -465,12 +465,12 @@ class MimeTypesTest extends BaseTestCase
public function provideExistingFilePathToCheckIsImagePath()
{
yield[
$this->getFilePathToTests('minion.jpg'),
$this->getFilePathForTesting('minion.jpg'),
true,
];
yield[
$this->getFilePathToTests('lorem-ipsum.txt'),
$this->getFilePathForTesting('lorem-ipsum.txt'),
false,
];
}

View File

@@ -663,7 +663,8 @@ class MiscellaneousTest extends BaseTestCase
public function testGetInvertedColorWithIncorrectLength()
{
$this->expectException(IncorrectColorHexLengthException::class);
$this->setExpectedException(IncorrectColorHexLengthException::class);
Miscellaneous::getInvertedColor(null);
Miscellaneous::getInvertedColor('');
Miscellaneous::getInvertedColor(1);
@@ -676,7 +677,8 @@ class MiscellaneousTest extends BaseTestCase
public function testGetInvertedColorWithInvalidValue()
{
$this->expectException(InvalidColorHexValueException::class);
$this->setExpectedException(InvalidColorHexValueException::class);
Miscellaneous::getInvertedColor('0011zz');
Miscellaneous::getInvertedColor('001#zz');
Miscellaneous::getInvertedColor('001!zz');

View File

@@ -122,7 +122,7 @@ class ReflectionTest extends BaseTestCase
*/
public function testGetChildClassesInvalidClass($invalidClass)
{
$this->expectException(CannotResolveClassNameException::class);
$this->setExpectedException(CannotResolveClassNameException::class);
self::assertNull(Reflection::getChildClasses($invalidClass));
self::assertNull(Reflection::getChildClasses(123));
@@ -130,7 +130,7 @@ class ReflectionTest extends BaseTestCase
public function testGetChildClassesNotExistingClass()
{
$this->expectException(CannotResolveClassNameException::class);
$this->setExpectedException(CannotResolveClassNameException::class);
self::assertEquals('', Reflection::getChildClasses('xyz'));
}
@@ -161,13 +161,13 @@ class ReflectionTest extends BaseTestCase
public function testGetOneChildClassWithMissingChildClasses()
{
$this->expectException(MissingChildClassesException::class);
$this->setExpectedException(MissingChildClassesException::class);
self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class));
}
public function testGetOneChildClassWithTooManyChildClasses()
{
$this->expectException(TooManyChildClassesException::class);
$this->setExpectedException(TooManyChildClassesException::class);
self::assertEquals(B::class, Reflection::getOneChildClass(A::class));
self::assertEquals(C::class, Reflection::getOneChildClass(A::class));
@@ -195,7 +195,7 @@ class ReflectionTest extends BaseTestCase
*/
public function testUsesTraitInvalidClass($class, $trait)
{
$this->expectException(CannotResolveClassNameException::class);
$this->setExpectedException(CannotResolveClassNameException::class);
self::assertNull(Reflection::usesTrait($class, $trait));
}
@@ -205,7 +205,7 @@ class ReflectionTest extends BaseTestCase
*/
public function testUsesTraitInvalidTrait($trait)
{
$this->expectException(CannotResolveClassNameException::class);
$this->setExpectedException(CannotResolveClassNameException::class);
self::assertNull(Reflection::usesTrait(DateTime::class, $trait));
}