11 Commits

Author SHA1 Message Date
Meritoo
9dac5bd11c Tests - Docker - update name of image and container 2017-10-18 21:50:02 +02:00
Meritoo
12100db058 Tests - Docker - update port 2017-10-18 20:02:09 +02:00
Meritoo
f9ab0a6194 Tests - Docker - add required libraries, PHP extensions & optimize size of Docker's image 2017-10-18 17:01:13 +02:00
Meritoo
b824808cd4 Tests - use Docker (as environment guard) 2017-10-18 00:31:18 +02:00
Meritoo
71e1eeb81b Start names of special directories with dot
BaseTestCase - add setter for path of directory with data used by test cases
2017-10-17 20:49:13 +02:00
Meritoo
70c273750d .gitignore update 2017-10-10 20:09:40 +02:00
Meritoo
e5e39651f3 Tests - fix names of constructors' tests 2017-10-02 15:56:53 +02:00
Meritoo
4683970c87 composer.json - update versions of the "dev" packages & sort them 2017-10-02 14:06:57 +02:00
Meritoo
559466c0ce composer.json - move tests-related classes to "autoload-dev" section (used for development purposes only and avoid polluting the autoloader in production) 2017-09-29 09:19:03 +02:00
Meritoo
bfd69c1098 Minor fix of coding standard 2017-09-27 21:52:10 +02:00
Meritoo
45493b37b0 Remove composer.lock 2017-09-27 21:51:48 +02:00
86 changed files with 155 additions and 3536 deletions

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

54
.docker/config/Dockerfile Normal file
View File

@@ -0,0 +1,54 @@
FROM php:5.6-cli
#
# Tools & libraries
#
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git \
zip \
unzip \
zlib1g-dev \
libicu-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#
# PHP Extensions
#
RUN docker-php-ext-install \
zip \
intl \
mbstring
#
# PHP configuration:
# - timezone
#
ARG TIMEZONE
RUN echo "date.timezone = $TIMEZONE" >> /usr/local/etc/php/php.ini
#
# Xdebug
#
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
#
# Phing
#
RUN pear channel-discover pear.phing.info \
&& pear install [--alldeps] phing/phing
#
# Composer + https://packagist.org/packages/hirak/prestissimo package
#
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === \
'544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo \
'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');" \
&& composer global require --no-plugins --no-scripts hirak/prestissimo \
&& rm -rf /root/.composer/cache/*

View File

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

1
.env Normal file
View File

@@ -0,0 +1 @@
TIMEZONE=Europe/Warsaw

11
.gitignore vendored
View File

@@ -7,13 +7,14 @@
# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------
### Composer ### Composer
# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------
/composer.lock
/composer.phar /composer.phar
# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------
### Phing ### Phing
# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------
/phing/properties /.phing/properties
# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------
@@ -28,10 +29,16 @@
/.php_cs.cache /.php_cs.cache
# ----------------------------------------------------------------------------------------------------------------------
### Build files
# ----------------------------------------------------------------------------------------------------------------------
/.build/
# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------
### Generated databases ### Generated databases
# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------
/data/tmp /.data/tmp
*.sql *.sql
*.sqlite *.sqlite

View File

@@ -2,12 +2,12 @@
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0"> <project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
<!-- Properties --> <!-- Properties -->
<if> <if>
<available file="phing/properties" property="custom.properties.available"/> <available file=".phing/properties" property="custom.properties.available"/>
<then> <then>
<property file="phing/properties" /> <property file=".phing/properties" />
</then> </then>
<else> <else>
<property file="phing/properties.dist" /> <property file=".phing/properties.dist" />
</else> </else>
</if> </if>

View File

@@ -59,7 +59,7 @@ composer.validate = false
# System directories # System directories
# #
dir.data = ${project.basedir}/data dir.data = ${project.basedir}/.data
dir.src = ${project.basedir}/src dir.src = ${project.basedir}/src
dir.tests = ${project.basedir}/tests dir.tests = ${project.basedir}/tests
@@ -67,7 +67,7 @@ dir.tests = ${project.basedir}/tests
# Build directories # Build directories
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
dir.build = ${project.basedir}/build dir.build = ${project.basedir}/.build
dir.reports = ${dir.build}/logs dir.reports = ${dir.build}/logs
dir.reports.pdepend = ${dir.reports}/pdepend dir.reports.pdepend = ${dir.reports}/pdepend
dir.reports.coverage = ${dir.reports}/phpunit_coverage dir.reports.coverage = ${dir.reports}/phpunit_coverage

View File

@@ -11,12 +11,12 @@
<!-- Properties --> <!-- Properties -->
<if> <if>
<available file="phing/properties" property="custom.properties.available"/> <available file=".phing/properties" property="custom.properties.available"/>
<then> <then>
<property file="phing/properties" /> <property file=".phing/properties" />
</then> </then>
<else> <else>
<property file="phing/properties.dist" /> <property file=".phing/properties.dist" />
</else> </else>
</if> </if>

View File

@@ -13,6 +13,15 @@ $ composer require meritoo/common-library
> How to install Composer: https://getcomposer.org/download > How to install Composer: https://getcomposer.org/download
## Rebuilding project and tests running
```bash
$ docker-compose up -d
$ docker-compose exec php-cli phing
```
> What is Docker? https://www.docker.com/what-docker
## Static methods ## Static methods
This package contains a lot of class with static methods, so usage is not so complicated. Just run the static method who would you like to use. Example: This package contains a lot of class with static methods, so usage is not so complicated. Just run the static method who would you like to use. Example:

View File

@@ -2,12 +2,12 @@
<project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0"> <project name="Meritoo Package" basedir="." default="build:main" phingVersion="2.14.0">
<!-- Properties --> <!-- Properties -->
<if> <if>
<available file="phing/properties" property="custom.properties.available"/> <available file=".phing/properties" property="custom.properties.available"/>
<then> <then>
<property file="phing/properties" /> <property file=".phing/properties" />
</then> </then>
<else> <else>
<property file="phing/properties.dist" /> <property file=".phing/properties.dist" />
</else> </else>
</if> </if>
@@ -18,12 +18,12 @@
<!-- Build app --> <!-- Build app -->
<target name="build:app" description="Prepares app to build and tests"> <target name="build:app" description="Prepares app to build and tests">
<phing phingfile="phing/app.xml" haltonfailure="true" /> <phing phingfile=".phing/app.xml" haltonfailure="true" />
</target> </target>
<!-- Build tests --> <!-- Build tests -->
<target name="build:tests" description="Runs all tests, checks and creates docs"> <target name="build:tests" description="Runs all tests, checks and creates docs">
<phing phingfile="phing/tests.xml" haltonfailure="true" /> <phing phingfile=".phing/tests.xml" haltonfailure="true" />
<!-- <!--
Conditional running of tests. Conditional running of tests.
@@ -35,7 +35,7 @@
<if> <if>
<equals arg1="${env}" arg2="test" /> <equals arg1="${env}" arg2="test" />
<then> <then>
<phing phingfile="phing/tests.xml" haltonfailure="true" /> <phing phingfile=".phing/tests.xml" haltonfailure="true" />
</then> </then>
<else> <else>
<echo message="[Skipped] Running tests, checks and creating docs, because it's a not 'test' environment..." /> <echo message="[Skipped] Running tests, checks and creating docs, because it's a not 'test' environment..." />

View File

@@ -2,7 +2,7 @@
"name": "meritoo/common-library", "name": "meritoo/common-library",
"description": "Useful classes, methods, extensions etc.", "description": "Useful classes, methods, extensions etc.",
"license": "MIT", "license": "MIT",
"version": "0.0.13", "version": "0.0.15",
"authors": [ "authors": [
{ {
"name": "Meritoo.pl", "name": "Meritoo.pl",
@@ -17,18 +17,22 @@
"symfony/http-foundation": "^3.3" "symfony/http-foundation": "^3.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^5.7", "friendsofphp/php-cs-fixer": "^2.6",
"squizlabs/php_codesniffer": "^2.9",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^3.0",
"pdepend/pdepend": "^2.5", "pdepend/pdepend": "^2.5",
"phploc/phploc": "^4.0", "phploc/phploc": "^4.0",
"friendsofphp/php-cs-fixer": "^2.6" "phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^5.7",
"sebastian/phpcpd": "^3.0",
"squizlabs/php_codesniffer": "^2.9"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Meritoo\\Common\\": "src/Meritoo/Common/", "Meritoo\\Common\\": "src/"
"Meritoo\\Common\\Test\\": "tests/Meritoo/Common/Test/" }
},
"autoload-dev": {
"psr-4": {
"Meritoo\\Common\\Test\\": "tests/"
} }
} }
} }

3494
composer.lock generated

File diff suppressed because it is too large Load Diff

15
docker-compose.yml Normal file
View File

@@ -0,0 +1,15 @@
version: '3'
services:
php-cli:
image: meritoo/common-library
container_name: meritoo-common-library
working_dir: /project
entrypoint: php
command: -S 0.0.0.0:9999
build:
context: ./.docker/config
args:
- TIMEZONE=$TIMEZONE
volumes:
- .:/project

View File

@@ -30,6 +30,6 @@
</groups> </groups>
<logging> <logging>
<log type="coverage-html" target="./build/logs/phpunit_coverage/html" /> <log type="coverage-html" target="./.build/logs/phpunit_coverage/html" />
</logging> </logging>
</phpunit> </phpunit>

View File

@@ -25,6 +25,13 @@ use ReflectionMethod;
*/ */
abstract class BaseTestCase extends TestCase abstract class BaseTestCase extends TestCase
{ {
/**
* Path of directory with data used by test cases
*
* @var string
*/
private static $testsDataDirPath = '.data/tests';
/** /**
* Provides an empty value * Provides an empty value
* *
@@ -98,7 +105,7 @@ abstract class BaseTestCase extends TestCase
/** /**
* Returns path of file used by tests. * Returns path of file used by tests.
* It should be placed in /data/tests directory of this project. * It should be placed in /.data/tests directory of this project.
* *
* @param string $fileName Name of file * @param string $fileName Name of file
* @param string $directoryPath (optional) Path of directory containing the file * @param string $directoryPath (optional) Path of directory containing the file
@@ -110,7 +117,7 @@ abstract class BaseTestCase extends TestCase
$paths = [ $paths = [
$rootPath, $rootPath,
'data/tests', self::$testsDataDirPath,
$directoryPath, $directoryPath,
$fileName, $fileName,
]; ];
@@ -218,4 +225,14 @@ abstract class BaseTestCase extends TestCase
static::assertNull($constructor); static::assertNull($constructor);
} }
/**
* Sets path of directory with data used by test cases
*
* @param string $testsDataDirPath Path of directory with data used by test cases
*/
protected static function setTestsDataDirPath($testsDataDirPath)
{
static::$testsDataDirPath = $testsDataDirPath;
}
} }

View File

@@ -25,7 +25,7 @@ class ArraysTest extends BaseTestCase
private $complexArray; private $complexArray;
private $superComplexArray; private $superComplexArray;
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Arrays::class); static::assertHasNoConstructor(Arrays::class);
} }

View File

@@ -19,7 +19,7 @@ use Meritoo\Common\Utilities\Bundle;
*/ */
class BundleTest extends BaseTestCase class BundleTest extends BaseTestCase
{ {
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Bundle::class); static::assertHasNoConstructor(Bundle::class);
} }

View File

@@ -27,7 +27,7 @@ class ComposerTest extends BaseTestCase
*/ */
private $composerJsonPath; private $composerJsonPath;
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Composer::class); static::assertHasNoConstructor(Composer::class);
} }

View File

@@ -23,7 +23,7 @@ use Meritoo\Common\Utilities\Date;
*/ */
class DateTest extends BaseTestCase class DateTest extends BaseTestCase
{ {
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Date::class); static::assertHasNoConstructor(Date::class);
} }

View File

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

View File

@@ -20,7 +20,7 @@ use Meritoo\Common\Utilities\Locale;
*/ */
class LocaleTest extends BaseTestCase class LocaleTest extends BaseTestCase
{ {
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Locale::class); static::assertHasNoConstructor(Locale::class);
} }

View File

@@ -20,7 +20,7 @@ use Meritoo\Common\Utilities\MimeTypes;
*/ */
class MimeTypesTest extends BaseTestCase class MimeTypesTest extends BaseTestCase
{ {
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(MimeTypes::class); static::assertHasNoConstructor(MimeTypes::class);
} }

View File

@@ -28,7 +28,7 @@ class MiscellaneousTest extends BaseTestCase
private $stringCommaSeparated; private $stringCommaSeparated;
private $stringDotSeparated; private $stringDotSeparated;
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Miscellaneous::class); static::assertHasNoConstructor(Miscellaneous::class);
} }
@@ -159,8 +159,8 @@ class MiscellaneousTest extends BaseTestCase
$expected = "int(123)\n"; $expected = "int(123)\n";
if ($xdebugLoaded) { if ($xdebugLoaded) {
$libraryPath = realpath(sprintf('%s%s', dirname(__FILE__), '/../../../../..')); $libraryPath = realpath(sprintf('%s%s', dirname(__FILE__), '/../..'));
$filePath = sprintf('%s%s', $libraryPath, '/src/Meritoo/Common/Utilities/Miscellaneous.php:'); $filePath = sprintf('%s%s', $libraryPath, '/src/Utilities/Miscellaneous.php:');
/* /*
* Attention. I have to use "\d+" at the end of $filePath, because number of line may be different if new * Attention. I have to use "\d+" at the end of $filePath, because number of line may be different if new

View File

@@ -33,7 +33,7 @@ use ReflectionProperty;
*/ */
class ReflectionTest extends BaseTestCase class ReflectionTest extends BaseTestCase
{ {
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Reflection::class); static::assertHasNoConstructor(Reflection::class);
} }
@@ -270,7 +270,6 @@ class ReflectionTest extends BaseTestCase
self::assertEquals($city, Reflection::getPropertyValue($f, 'city')); self::assertEquals($city, Reflection::getPropertyValue($f, 'city'));
} }
public function testGetPropertyValueWithPrivateGetter() public function testGetPropertyValueWithPrivateGetter()
{ {
$accountBalance = 1000; $accountBalance = 1000;

View File

@@ -21,7 +21,7 @@ class RegexTest extends BaseTestCase
private $simpleText; private $simpleText;
private $camelCaseText; private $camelCaseText;
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Regex::class); static::assertHasNoConstructor(Regex::class);
} }

View File

@@ -19,7 +19,7 @@ use Meritoo\Common\Utilities\Uri;
*/ */
class UriTest extends BaseTestCase class UriTest extends BaseTestCase
{ {
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Uri::class); static::assertHasNoConstructor(Uri::class);
} }

View File

@@ -23,7 +23,7 @@ class XmlTest extends BaseTestCase
private $simpleXml; private $simpleXml;
private $advancedXml; private $advancedXml;
public function verifyConstructor() public function testConstructor()
{ {
static::assertHasNoConstructor(Xml::class); static::assertHasNoConstructor(Xml::class);
} }